From 1760b27c02b632594048183a93afc7881203a230 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 22 Feb 2022 20:13:33 -0500 Subject: [PATCH] Remove ./src/* export from public build (#23262) 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. --- scripts/rollup/packaging.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/rollup/packaging.js b/scripts/rollup/packaging.js index 87675ae9f73c0..592314c394240 100644 --- a/scripts/rollup/packaging.js +++ b/scripts/rollup/packaging.js @@ -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'); } @@ -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['.']; @@ -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, ' ');