@samitouri / QOS-React / commits / 1760b27c02

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.

Andrew Clark committed Feb 22, 2022 at 20:13 UTC 1760b27c02b632594048183a93afc7881203a230
1 file changed +10 -1
scripts/rollup/packaging.js
+10 -1
@@ -152,6 +152,7 @@ function filterOutEntrypoints(name) {
152 let jsonPath = `build/node_modules/${name}/package.json`;
153 let packageJSON = JSON.parse(readFileSync(jsonPath));
154 let files = packageJSON.files;
155 + let exportsJSON = packageJSON.exports;
156 if (!Array.isArray(files)) {
157 throw new Error('expected all package.json files to contain a files field');
158 }
@@ -181,7 +182,6 @@ function filterOutEntrypoints(name) {
182 unlinkSync(`build/node_modules/${name}/${filename}`);
183 changed = true;
184 // Remove it from the exports field too if it exists.
184 - const exportsJSON = packageJSON.exports;
185 if (exportsJSON) {
186 if (filename === 'index.js') {
187 delete exportsJSON['.'];
@@ -190,6 +190,15 @@ function filterOutEntrypoints(name) {
190 }
191 }
192 }
193 +
194 + // We only export the source directory so Jest and Rollup can access them
195 + // during local development and at build time. The files don't exist in the
196 + // public builds, so we don't need the export entry, either.
197 + const sourceWildcardExport = './src/*';
198 + if (exportsJSON && exportsJSON[sourceWildcardExport]) {
199 + delete exportsJSON[sourceWildcardExport];
200 + changed = true;
201 + }
202 }
203 if (changed) {
204 let newJSON = JSON.stringify(packageJSON, null, ' ');