Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tsup bundling local package imported types #2663

Merged
merged 9 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 113 additions & 112 deletions apps/www/src/registry/default/example/playground-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,124 +126,125 @@ export const usePlaygroundPlugins = ({

return useMemo(
() => {
const plugins = [
// Nodes
createParagraphPlugin({ enabled: !!enabled.p }),
createHeadingPlugin({ enabled: !!enabled.heading }),
createBlockquotePlugin({ enabled: !!enabled.blockquote }),
createCodeBlockPlugin({ enabled: !!enabled.code_block }),
createHorizontalRulePlugin({ enabled: !!enabled.hr }),
createLinkPlugin({ ...linkPlugin, enabled: !!enabled.a }),
createListPlugin({
enabled: id === 'list' || !!enabled.list,
}),
createImagePlugin({ enabled: !!enabled.img }),
createMediaEmbedPlugin({ enabled: !!enabled.media_embed }),
createCaptionPlugin({ ...captionPlugin, enabled: !!enabled.caption }),
createMentionPlugin({
enabled: !!enabled.mention,
options: {
triggerPreviousCharPattern: /^$|^[\s"']$/,
},
}),
createTablePlugin({ enabled: !!enabled.table }),
createTodoListPlugin({ enabled: !!enabled.action_item }),
createExcalidrawPlugin({ enabled: !!enabled.excalidraw }),
return createPlugins(
[
// Nodes
createParagraphPlugin({ enabled: !!enabled.p }),
createHeadingPlugin({ enabled: !!enabled.heading }),
createBlockquotePlugin({ enabled: !!enabled.blockquote }),
createCodeBlockPlugin({ enabled: !!enabled.code_block }),
createHorizontalRulePlugin({ enabled: !!enabled.hr }),
createLinkPlugin({ ...linkPlugin, enabled: !!enabled.a }),
createListPlugin({
enabled: id === 'list' || !!enabled.list,
}),
createImagePlugin({ enabled: !!enabled.img }),
createMediaEmbedPlugin({ enabled: !!enabled.media_embed }),
createCaptionPlugin({ ...captionPlugin, enabled: !!enabled.caption }),
createMentionPlugin({
enabled: !!enabled.mention,
options: {
triggerPreviousCharPattern: /^$|^[\s"']$/,
},
}),
createTablePlugin({ enabled: !!enabled.table }),
createTodoListPlugin({ enabled: !!enabled.action_item }),
createExcalidrawPlugin({ enabled: !!enabled.excalidraw }),

// Marks
createBoldPlugin({ enabled: !!enabled.bold }),
createItalicPlugin({ enabled: !!enabled.italic }),
createUnderlinePlugin({ enabled: !!enabled.underline }),
createStrikethroughPlugin({ enabled: !!enabled.strikethrough }),
createCodePlugin({ enabled: !!enabled.code }),
createSubscriptPlugin({ enabled: !!enabled.subscript }),
createSuperscriptPlugin({ enabled: !!enabled.superscript }),
createFontColorPlugin({ enabled: !!enabled.color }),
createFontBackgroundColorPlugin({
enabled: !!enabled.backgroundColor,
}),
createFontSizePlugin({ enabled: !!enabled.fontSize }),
createHighlightPlugin({ enabled: !!enabled.highlight }),
createKbdPlugin({ enabled: !!enabled.kbd }),
// Marks
createBoldPlugin({ enabled: !!enabled.bold }),
createItalicPlugin({ enabled: !!enabled.italic }),
createUnderlinePlugin({ enabled: !!enabled.underline }),
createStrikethroughPlugin({ enabled: !!enabled.strikethrough }),
createCodePlugin({ enabled: !!enabled.code }),
createSubscriptPlugin({ enabled: !!enabled.subscript }),
createSuperscriptPlugin({ enabled: !!enabled.superscript }),
createFontColorPlugin({ enabled: !!enabled.color }),
createFontBackgroundColorPlugin({
enabled: !!enabled.backgroundColor,
}),
createFontSizePlugin({ enabled: !!enabled.fontSize }),
createHighlightPlugin({ enabled: !!enabled.highlight }),
createKbdPlugin({ enabled: !!enabled.kbd }),

// Block Style
createAlignPlugin({ ...alignPlugin, enabled: !!enabled.align }),
createIndentPlugin({ ...indentPlugin, enabled: !!enabled.indent }),
createIndentListPlugin({
...indentPlugin,
enabled: id === 'indentlist' || !!enabled.listStyleType,
}),
createLineHeightPlugin({
...lineHeightPlugin,
enabled: !!enabled.lineHeight,
}),
// Block Style
createAlignPlugin({ ...alignPlugin, enabled: !!enabled.align }),
createIndentPlugin({ ...indentPlugin, enabled: !!enabled.indent }),
createIndentListPlugin({
...indentPlugin,
enabled: id === 'indentlist' || !!enabled.listStyleType,
}),
createLineHeightPlugin({
...lineHeightPlugin,
enabled: !!enabled.lineHeight,
}),

// Functionality
createAutoformatPlugin({
enabled: !!enabled.autoformat,
options: autoformatOptions,
}),
createBlockSelectionPlugin({
options: {
sizes: {
top: 0,
bottom: 0,
// Functionality
createAutoformatPlugin({
enabled: !!enabled.autoformat,
options: autoformatOptions,
}),
createBlockSelectionPlugin({
options: {
sizes: {
top: 0,
bottom: 0,
},
},
},
enabled: id === 'blockselection' || !!enabled.blockSelection,
}),
createComboboxPlugin({ enabled: !!enabled.combobox }),
createDndPlugin({
options: { enableScroller: true },
enabled: !!enabled.dnd,
}),
createEmojiPlugin({ ...emojiPlugin, enabled: !!enabled.emoji }),
createExitBreakPlugin({
...exitBreakPlugin,
enabled: !!enabled.exitBreak,
}),
createNodeIdPlugin({ enabled: !!enabled.nodeId }),
createNormalizeTypesPlugin({
...forcedLayoutPlugin,
enabled: !!enabled.normalizeTypes,
}),
createResetNodePlugin({
...resetBlockTypePlugin,
enabled: !!enabled.resetNode,
}),
createSelectOnBackspacePlugin({
...selectOnBackspacePlugin,
enabled: !!enabled.selectOnBackspace,
}),
createSingleLinePlugin({
enabled: id === 'singleline' || !!enabled.singleLine,
}),
createSoftBreakPlugin({
...softBreakPlugin,
enabled: !!enabled.softBreak,
}),
createTabbablePlugin({
...tabbablePlugin,
enabled: !!enabled.tabbable,
}),
createTrailingBlockPlugin({
...trailingBlockPlugin,
enabled: id !== 'singleline' && !!enabled.trailingBlock,
}),
{ ...dragOverCursorPlugin, enabled: !!enabled.dragOverCursor },

// Collaboration
createCommentsPlugin({ enabled: !!enabled.comment }),
enabled: id === 'blockselection' || !!enabled.blockSelection,
}),
createComboboxPlugin({ enabled: !!enabled.combobox }),
createDndPlugin({
options: { enableScroller: true },
enabled: !!enabled.dnd,
}),
createEmojiPlugin({ ...emojiPlugin, enabled: !!enabled.emoji }),
createExitBreakPlugin({
...exitBreakPlugin,
enabled: !!enabled.exitBreak,
}),
createNodeIdPlugin({ enabled: !!enabled.nodeId }),
createNormalizeTypesPlugin({
...forcedLayoutPlugin,
enabled: !!enabled.normalizeTypes,
}),
createResetNodePlugin({
...resetBlockTypePlugin,
enabled: !!enabled.resetNode,
}),
createSelectOnBackspacePlugin({
...selectOnBackspacePlugin,
enabled: !!enabled.selectOnBackspace,
}),
createSingleLinePlugin({
enabled: id === 'singleline' || !!enabled.singleLine,
}),
createSoftBreakPlugin({
...softBreakPlugin,
enabled: !!enabled.softBreak,
}),
createTabbablePlugin({
...tabbablePlugin,
enabled: !!enabled.tabbable,
}),
createTrailingBlockPlugin({
...trailingBlockPlugin,
enabled: id !== 'singleline' && !!enabled.trailingBlock,
}),
{ ...dragOverCursorPlugin, enabled: !!enabled.dragOverCursor },

// Deserialization
createDeserializeDocxPlugin({ enabled: !!enabled.deserializeDocx }),
createDeserializeMdPlugin({ enabled: !!enabled.deserializeMd }),
createJuicePlugin({ enabled: !!enabled.juice }),
];
// Collaboration
createCommentsPlugin({ enabled: !!enabled.comment }),

return createPlugins(plugins, {
components,
});
// Deserialization
createDeserializeDocxPlugin({ enabled: !!enabled.deserializeDocx }),
createDeserializeMdPlugin({ enabled: !!enabled.deserializeMd }),
createJuicePlugin({ enabled: !!enabled.juice }),
],
{
components,
}
);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[enabled]
Expand Down
26 changes: 16 additions & 10 deletions config/eslint/bases/next.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,31 @@ module.exports = {
'import/no-unresolved': [
'error',
{
ignore: ['^@/plate'],
ignore: ['^@/'],
},
],
'import/prefer-default-export': 'off',
},
overrides: [
{
files: ['**/packages/**'],
excludedFiles: ['**/*.test.*', '**/*.spec.*', '**/*.fixtures.*', '**/__tests__/**/*', '**/apps/**/*'],
excludedFiles: [
'**/*.test.*',
'**/*.spec.*',
'**/*.fixtures.*',
'**/__tests__/**/*',
'**/apps/**/*',
],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
includeInternal: false,
includeTypes: false,
},
],
}
'error',
{
devDependencies: false,
includeInternal: false,
includeTypes: false,
},
],
},
},
{
files: ['apps/www/next.config.mjs'],
Expand Down
15 changes: 14 additions & 1 deletion config/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {}
"compilerOptions": {
"baseUrl": "../",
"paths": {
"@/plate/*": ["apps/www/src/lib/plate/*"],
"@/lib/*": ["apps/www/src/lib/*"],
"@/types/*": ["apps/www/src/types/*"],
"@/styles/*": ["apps/www/src/styles/*"],
"@/components/*": ["apps/www/src/components/*"],
"@/registry/*": ["apps/www/src/registry/*"],
"@/__registry__/*": ["apps/www/src/__registry__/*"],
"@/hooks/*": ["apps/www/src/hooks/*"],
"@/config/*": ["apps/www/src/config/*"]
}
}
}
16 changes: 4 additions & 12 deletions config/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default defineConfig((opts) => {
entry: [INPUT_FILE],
format: ['cjs', 'esm'],
skipNodeModulesBundle: true,
dts: true,
dts: {
resolve: false,
},
sourcemap: true,
clean: true,
esbuildPlugins: [
Expand All @@ -37,16 +39,6 @@ export default defineConfig((opts) => {
console.info('Build succeeded!');
},
silent: true,
// plugins: [
// {
// name: 'add-mjs',
// setup(build: any) {
// build.onResolve({ filter: /.*/ }, (args: any) => {
// if (args.importer)
// return { path: args.path + '.mjs', external: true };
// });
// },
// },
// ],
plugins: [],
};
});
7 changes: 5 additions & 2 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const appRoot = require('app-root-path');

const packageJson = require(`${process.cwd()}/package.json`);
const packageName = packageJson.name ?? 'plate';
const { compilerOptions: baseTsConfig } = require(`${appRoot}/tsconfig.json`);
const {
compilerOptions: baseTsConfig,
} = require(`${appRoot}/config/tsconfig.test.json`);

// Take the paths from tsconfig automatically from base tsconfig.json
// @link https://kulshekhar.github.io/ts-jest/docs/paths-mapping
Expand All @@ -25,7 +27,8 @@ Object.keys(aliases).forEach((key) => {
modules[`^${key}$`] = `<rootDir>/packages/${value}/src`;
});

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest').JestConfigWithTsJest} */
//@ts-check
module.exports = {
displayName: packageName,
collectCoverageFrom: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @jsx jsx */

import { autoformatPlugin } from '@/plate/demo/plugins/autoformatPlugin';
import { mockPlugin } from '@udecode/plate-common';
import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatPlugin } from 'www/src/lib/plate/demo/plugins/autoformatPlugin';

import { withAutoformat } from '../../../withAutoformat';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/** @jsx jsx */

import { autoformatPlugin } from '@/plate/demo/plugins/autoformatPlugin';
import { preFormat } from '@/plate/demo/plugins/autoformatUtils';
import { AutoformatPlugin } from '@udecode/plate-autoformat';
import {
ELEMENT_CODE_BLOCK,
Expand All @@ -18,6 +16,8 @@ import {
import { jsx } from '@udecode/plate-test-utils';
import { Range } from 'slate';
import { withReact } from 'slate-react';
import { autoformatPlugin } from 'www/src/lib/plate/demo/plugins/autoformatPlugin';
import { preFormat } from 'www/src/lib/plate/demo/plugins/autoformatUtils';

import { withAutoformat } from '../../../withAutoformat';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** @jsx jsx */

import { autoformatPlugin } from '@/plate/demo/plugins/autoformatPlugin';
import { preFormat } from '@/plate/demo/plugins/autoformatUtils';
import { mockPlugin } from '@udecode/plate-common';
import { ELEMENT_H1 } from '@udecode/plate-heading';
import { jsx } from '@udecode/plate-test-utils';
import { withReact } from 'slate-react';
import { autoformatPlugin } from 'www/src/lib/plate/demo/plugins/autoformatPlugin';
import { preFormat } from 'www/src/lib/plate/demo/plugins/autoformatUtils';

import { withAutoformat } from '../../../withAutoformat';

Expand Down Expand Up @@ -38,7 +38,7 @@ describe('when #space', () => {
mode: 'block',
type: ELEMENT_H1,
match: '# ',
preFormat,
preFormat: preFormat,
},
],
},
Expand Down
Loading
Loading