Skip to content

Commit

Permalink
Fix facebook#5731 by generating default entry last
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Mar 18, 2024
1 parent e3615cd commit 0a8f44a
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ function withEsmExtension(fileName) {
return fileName.replace(/\.js$/, '.esm.js');
}

function exportEntry(file) {
return {
import: {
types: `./${file.replace(/\.js$/, '.d.ts')}`,
// webpack requires default to be the last entry per #5731
// eslint-disable-next-line sort-keys-fix/sort-keys-fix
default: `./${withEsmExtension(file)}`,
},
require: `./${file}`,
};
}

function updateModule(packageJSON, pkg) {
if (packageJSON.sideEffects === undefined) {
packageJSON.sideEffects = false;
Expand All @@ -68,23 +80,12 @@ function updateModule(packageJSON, pkg) {
const exports = {};
for (const file of fs.readdirSync(`./packages/${pkg}/dist`)) {
if (/^[^.]+\.js$/.test(file)) {
const entry = exportEntry(file);
// support for import "@lexical/react/LexicalComposer"
exports[`./${file.replace(/\.js$/, '')}`] = {
import: {
default: `./${withEsmExtension(file)}`,
types: `./${file.replace(/\.js$/, '.d.ts')}`,
},
require: `./${file}`,
};
exports[`./${file.replace(/\.js$/, '')}`] = entry;
// support for import "@lexical/react/LexicalComposer.js"
// @mdxeditor/editor uses this at least as of 2.13.1
exports[`./${file}`] = {
import: {
default: `./${withEsmExtension(file)}`,
types: `./${file.replace(/\.js$/, '.d.ts')}`,
},
require: `./${file}`,
};
exports[`./${file}`] = entry;
}
}
packageJSON.exports = exports;
Expand Down

0 comments on commit 0a8f44a

Please sign in to comment.