Skip to content

Commit

Permalink
Remove ./src/* export from public build (#23262)
Browse files Browse the repository at this point in the history
We only export the source directory so Jest and Rollup can access them
during local development and at build time. The files don't exist in the
public builds, so we don't need the export entry, either.
  • Loading branch information
acdlite authored Feb 23, 2022
1 parent 552c067 commit 1760b27
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function filterOutEntrypoints(name) {
let jsonPath = `build/node_modules/${name}/package.json`;
let packageJSON = JSON.parse(readFileSync(jsonPath));
let files = packageJSON.files;
let exportsJSON = packageJSON.exports;
if (!Array.isArray(files)) {
throw new Error('expected all package.json files to contain a files field');
}
Expand Down Expand Up @@ -181,7 +182,6 @@ function filterOutEntrypoints(name) {
unlinkSync(`build/node_modules/${name}/${filename}`);
changed = true;
// Remove it from the exports field too if it exists.
const exportsJSON = packageJSON.exports;
if (exportsJSON) {
if (filename === 'index.js') {
delete exportsJSON['.'];
Expand All @@ -190,6 +190,15 @@ function filterOutEntrypoints(name) {
}
}
}

// We only export the source directory so Jest and Rollup can access them
// during local development and at build time. The files don't exist in the
// public builds, so we don't need the export entry, either.
const sourceWildcardExport = './src/*';
if (exportsJSON && exportsJSON[sourceWildcardExport]) {
delete exportsJSON[sourceWildcardExport];
changed = true;
}
}
if (changed) {
let newJSON = JSON.stringify(packageJSON, null, ' ');
Expand Down

0 comments on commit 1760b27

Please sign in to comment.