Skip to content

Commit

Permalink
Change fork modules to not use dynamic imports with top-level await.
Browse files Browse the repository at this point in the history
This seems to solve a bunch of compatibility issues I ran into,
the ecosystem just isn't ready for top-level await.

With package.json marked as not having side-effects, it seems this
can be optimized properly (at least by vite, tested w/ SvelteKit).
I verified this by building a SvelteKit app that uses lexical and
searching for strings that would only be in the dev build, e.g.
`should implement "importDOM"`.
  • Loading branch information
etrepum committed Mar 14, 2024
1 parent 9717280 commit c6bf94e
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/lexical-clipboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-clipboard"
},
"module": "LexicalClipboard.esm.js"
"module": "LexicalClipboard.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"devDependencies": {
"@types/prismjs": "^1.26.0"
},
"module": "LexicalCode.esm.js"
"module": "LexicalCode.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-dragon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-dragon"
},
"module": "LexicalDragon.esm.js"
"module": "LexicalDragon.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-file"
},
"module": "LexicalFile.esm.js"
"module": "LexicalFile.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-hashtag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-hashtag"
},
"module": "LexicalHashtag.esm.js"
"module": "LexicalHashtag.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-headless"
},
"module": "LexicalHeadless.esm.js"
"module": "LexicalHeadless.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-history/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-history"
},
"module": "LexicalHistory.esm.js"
"module": "LexicalHistory.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"@lexical/selection": "0.13.1",
"@lexical/utils": "0.13.1"
},
"module": "LexicalHtml.esm.js"
"module": "LexicalHtml.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-link"
},
"module": "LexicalLink.esm.js"
"module": "LexicalLink.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-list"
},
"module": "LexicalList.esm.js"
"module": "LexicalList.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-mark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-mark"
},
"module": "LexicalMark.esm.js"
"module": "LexicalMark.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-markdown"
},
"module": "LexicalMarkdown.esm.js"
"module": "LexicalMarkdown.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-offset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-offset"
},
"module": "LexicalOffset.esm.js"
"module": "LexicalOffset.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-overflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-overflow"
},
"module": "LexicalOverflow.esm.js"
"module": "LexicalOverflow.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-plain-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-plain-text"
},
"module": "LexicalPlainText.esm.js"
"module": "LexicalPlainText.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
"rollup-plugin-copy": "^3.5.0",
"vite": "^2.9.16",
"vite-plugin-replace": "0.1.1"
}
},
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,6 @@
},
"require": "./useLexicalTextEntity.js"
}
}
},
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-rich-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-rich-text"
},
"module": "LexicalRichText.esm.js"
"module": "LexicalRichText.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-selection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-selection"
},
"module": "LexicalSelection.esm.js"
"module": "LexicalSelection.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-table"
},
"module": "LexicalTable.esm.js"
"module": "LexicalTable.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-text"
},
"module": "LexicalText.esm.js"
"module": "LexicalText.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-utils"
},
"module": "LexicalUtils.esm.js"
"module": "LexicalUtils.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical-yjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-yjs"
},
"module": "LexicalYjs.esm.js"
"module": "LexicalYjs.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/lexical/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical"
},
"module": "Lexical.esm.js"
"module": "Lexical.esm.js",
"sideEffects": false
}
3 changes: 2 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/shared"
}
},
"sideEffects": false
}
4 changes: 3 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ function buildForkModule(outputPath, outputFileName, format, exports) {
const prodFileName = `./${outputFileName}.prod${extension}`;
if (format === 'esm') {
lines.push(
`const mod = process.env.NODE_ENV === 'development' ? await import('${devFileName}') : await import('${prodFileName}');`,
`import * as modDev from '${devFileName}';`,
`import * as modProd from '${prodFileName}';`,
`const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;`,
);
for (const name of exports) {
lines.push(
Expand Down
3 changes: 3 additions & 0 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ function withEsmExtension(fileName) {
}

function updateModule(packageJSON, pkg) {
if (packageJSON.sideEffects === undefined) {
packageJSON.sideEffects = false;
}
if (packageJSON.main) {
packageJSON.module = withEsmExtension(packageJSON.main);
} else if (fs.existsSync(`./packages/${pkg}/dist`)) {
Expand Down

0 comments on commit c6bf94e

Please sign in to comment.