Skip to content

Commit

Permalink
Refactor build scripts and add config/doc codegens, start maintainers…
Browse files Browse the repository at this point in the history
… guide
  • Loading branch information
etrepum committed Apr 14, 2024
1 parent a951969 commit b7139d1
Show file tree
Hide file tree
Showing 45 changed files with 1,985 additions and 2,014 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
**/config/**
**/build/**
**/npm/**
!scripts/npm/**
**/*.js.flow
**/*.d.ts
**/playwright*/**
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module.exports = {
// node scripts should be console logging so don't lint against that
files: ['scripts/**/*.js'],
rules: {
// https://github.com/Stuk/eslint-plugin-header/issues/39
'header/header': OFF,
'no-console': OFF,
},
},
Expand Down
150 changes: 63 additions & 87 deletions .flowconfig

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ node_modules

base-build
build
build
coverage
dist
npm
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ packages/playwright
packages/playwright-core
packages/**/vite.config.js
packages/**/vite.prod.config.js
packages/lexical-website/docs/api
**/*.md
**/*.js.flow
**/node_modules
Expand Down
25 changes: 8 additions & 17 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,15 @@ const fs = require('fs-extra');
* Currently this alias map points at the cjs version of the build product,
* as that is what was measured previously in #3600.
*/
const {packagesManager} = require('./scripts/shared/packagesManager');
const alias = Object.fromEntries(
glob('./packages/*/package.json', {sync: true}).flatMap((fn) => {
const pkg = fs.readJsonSync(fn);
if (!pkg.private) {
return Object.entries(pkg.exports).flatMap(([k, v]) => {
if (k.endsWith('.js')) {
return [];
}
return [
[
`${pkg.name}${k.replace(/^\.(\/$)?/, '')}`,
path.resolve(path.dirname(fn), 'dist', v.require.default),
],
];
});
}
return [];
}),
packagesManager
.getPublicPackages()
.flatMap((pkg) =>
pkg
.getNormalizedNpmModuleExportEntries()
.map(([k, v]) => [k, pkg.resolve('dist', v.require.default)]),
),
);

const extendConfig = {resolve: {alias}};
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ editor.registerUpdateListener(({editorState}) => {
- [Concepts](https://lexical.dev/docs/concepts/editor-state)
- [How Lexical was designed](https://lexical.dev/docs/design)
- [Testing](https://lexical.dev/docs/testing)
- [Maintainers' Guide](https://lexical.dev/docs/maintainers-guide)

## Browser Support

Expand Down
8 changes: 4 additions & 4 deletions examples/react-rich/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"typescript": "^5.2.2",
"vite": "^5.1.4",
"@vitejs/plugin-react": "^4.2.1",
"@types/react": "^18.2.59",
"@types/react-dom": "^18.2.19"
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.2.2",
"vite": "^5.1.4"
}
}
124 changes: 17 additions & 107 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@

'use strict';

const tsconfig = require('./tsconfig.json');

const common = {
modulePathIgnorePatterns: ['/npm'],
};

// Use tsconfig's paths to configure jest's module name mapper
const moduleNameMapper = Object.fromEntries(
Object.entries(tsconfig.compilerOptions.paths).map(([name, [firstPath]]) => [
`^${name}$`,
firstPath.replace(/^\./, '<rootDir>'),
]),
);

module.exports = {
projects: [
{
Expand All @@ -20,119 +30,19 @@ module.exports = {
globals: {
IS_REACT_ACT_ENVIRONMENT: true,
__DEV__: true,
'ts-jest': {
tsconfig: 'tsconfig.test.json',
},
},
moduleNameMapper: {
'^./dist/(.+)': './src/$1',
'^@lexical/clipboard$':
'<rootDir>/packages/lexical-clipboard/src/index.ts',
'^@lexical/code$': '<rootDir>/packages/lexical-code/src/index.ts',
'^@lexical/devtools-core$':
'<rootDir>/packages/lexical-devools-core/src/index.ts',
'^@lexical/dragon$': '<rootDir>/packages/lexical-dragon/src/index.ts',
'^@lexical/file$': '<rootDir>/packages/lexical-file/src/index.ts',
'^@lexical/hashtag$': '<rootDir>/packages/lexical-hashtag/src/index.ts',
'^@lexical/headless$':
'<rootDir>/packages/lexical-headless/src/index.ts',
'^@lexical/history$': '<rootDir>/packages/lexical-history/src/index.ts',
'^@lexical/html$': '<rootDir>/packages/lexical-html/src/index.ts',
'^@lexical/link$': '<rootDir>/packages/lexical-link/src/index.ts',
'^@lexical/list$': '<rootDir>/packages/lexical-list/src/index.ts',
'^@lexical/mark$': '<rootDir>/packages/lexical-mark/src/index.ts',
'^@lexical/markdown$':
'<rootDir>/packages/lexical-markdown/src/index.ts',
'^@lexical/offset$': '<rootDir>/packages/lexical-offset/src/index.ts',
'^@lexical/overflow$':
'<rootDir>/packages/lexical-overflow/src/index.ts',
'^@lexical/plain-text$':
'<rootDir>/packages/lexical-plain-text/src/index.ts',

'^@lexical/react/LexicalAutoEmbedPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalAutoEmbedPlugin.tsx',
'^@lexical/react/LexicalAutoFocusPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalAutoFocusPlugin.ts',
'^@lexical/react/LexicalAutoLinkPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalAutoLinkPlugin.ts',
'^@lexical/react/LexicalCheckListPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalCheckListPlugin.ts',
'^@lexical/react/LexicalCollaborationContext$':
'<rootDir>/packages/lexical-react/src/LexicalCollaborationContext.ts',
'^@lexical/react/LexicalCollaborationPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalCollaborationPlugin.ts',
'^@lexical/react/LexicalComposer$':
'<rootDir>/packages/lexical-react/src/LexicalComposer.tsx',
'^@lexical/react/LexicalComposerContext$':
'<rootDir>/packages/lexical-react/src/LexicalComposerContext.ts',
'^@lexical/react/LexicalContentEditable$':
'<rootDir>/packages/lexical-react/src/LexicalContentEditable.tsx',
'^@lexical/react/LexicalErrorBoundary$':
'<rootDir>/packages/lexical-react/src/LexicalErrorBoundary.tsx',
'^@lexical/react/LexicalHistoryPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalHistoryPlugin.ts',
'^@lexical/react/LexicalLinkPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalLinkPlugin.ts',
'^@lexical/react/LexicalListPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalListPlugin.ts',
'^@lexical/react/LexicalPlainTextPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalPlainTextPlugin.ts',
'^@lexical/react/LexicalRichTextPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalRichTextPlugin.tsx',
'^@lexical/react/LexicalTabIndentationPlugin$':
'<rootDir>/packages/lexical-react/src/LexicalTabIndentationPlugin.tsx',
'^@lexical/react/LexicalTablePlugin$':
'<rootDir>/packages/lexical-react/src/LexicalTablePlugin.ts',
'^@lexical/react/useLexicalCanShowPlaceholder$':
'<rootDir>/packages/lexical-react/src/useLexicalCanShowPlaceholder.ts',
'^@lexical/react/useLexicalDecorators$':
'<rootDir>/packages/lexical-react/src/useLexicalDecorators.ts',
'^@lexical/react/useLexicalEditable$':
'<rootDir>/packages/lexical-react/src/useLexicalEditable.ts',
'^@lexical/react/useLexicalEditor$':
'<rootDir>/packages/lexical-react/src/useLexicalEditor.ts',
'^@lexical/react/useLexicalSubscription$':
'<rootDir>/packages/lexical-react/src/useLexicalSubscription.ts',
'^@lexical/rich-text$':
'<rootDir>/packages/lexical-rich-text/src/index.ts',
'^@lexical/selection$':
'<rootDir>/packages/lexical-selection/src/index.ts',
'^@lexical/selection/src/__tests__/utils$':
'<rootDir>/packages/lexical-selection/src/__tests__/utils/index.ts',
'^@lexical/table$': '<rootDir>/packages/lexical-table/src/index.ts',
'^@lexical/text$': '<rootDir>/packages/lexical-text/src/index.ts',
'^@lexical/utils$': '<rootDir>/packages/lexical-utils/src/index.ts',
'^@lexical/yjs$': '<rootDir>/packages/lexical-yjs/src/index.ts',
'^@lexical/yjs/src/index$':
'<rootDir>/packages/lexical-yjs/src/index.ts',
'^lexical$': '<rootDir>/packages/lexical/src/index.ts',
'^lexical/src/([^/]+)$': '<rootDir>/packages/lexical/src/$1.ts',
'^lexical/src/__tests__/utils$':
'<rootDir>/packages/lexical/src/__tests__/utils/index.tsx',
'^lexical/src/nodes/([^/]+)$':
'<rootDir>/packages/lexical/src/nodes/$1.ts',
'^shared/canUseDOM$': '<rootDir>/packages/shared/src/canUseDOM.ts',
'^shared/caretFromPoint$':
'<rootDir>/packages/shared/src/caretFromPoint.ts',
'^shared/environment$': '<rootDir>/packages/shared/src/environment.ts',
'^shared/invariant$': '<rootDir>/packages/shared/src/invariant.ts',
'^shared/normalizeClassNames$':
'<rootDir>/packages/shared/src/normalizeClassNames.ts',
'^shared/simpleDiffWithCursor$':
'<rootDir>/packages/shared/src/simpleDiffWithCursor.ts',
'^shared/useLayoutEffect$':
'<rootDir>/packages/shared/src/useLayoutEffect.ts',
'^shared/warnOnlyOnce$':
'<rootDir>/packages/shared/src/warnOnlyOnce.ts',
formatProdErrorMessage:
'<rootDir>/scripts/error-codes/formatProdErrorMessage.js',
},
moduleNameMapper,
preset: 'ts-jest',
testEnvironment: 'jsdom',
testMatch: ['**/__tests__/unit/**/*.test{.ts,.tsx,.js,.jsx}'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.tsx$': 'ts-jest',
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json',
},
],
},
},
{
Expand Down
Loading

0 comments on commit b7139d1

Please sign in to comment.