GeezerVison is showing github.com — Remove ./src/* export from public build (#23262) · react/react@1760b27
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: scripts/rollup/packaging.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,6 +152,7 @@ function filterOutEntrypoints(name) { |
152 | 152 | let jsonPath = `build/node_modules/${name}/package.json`; |
153 | 153 | let packageJSON = JSON.parse(readFileSync(jsonPath)); |
154 | 154 | let files = packageJSON.files; |
| 155 | + let exportsJSON = packageJSON.exports; |
155 | 156 | if (!Array.isArray(files)) { |
156 | 157 | throw new Error('expected all package.json files to contain a files field'); |
157 | 158 | } |
@@ -181,7 +182,6 @@ function filterOutEntrypoints(name) { |
181 | 182 | unlinkSync(`build/node_modules/${name}/${filename}`); |
182 | 183 | changed = true; |
183 | 184 | // Remove it from the exports field too if it exists. |
184 | | - const exportsJSON = packageJSON.exports; |
185 | 185 | if (exportsJSON) { |
186 | 186 | if (filename === 'index.js') { |
187 | 187 | delete exportsJSON['.']; |
@@ -190,6 +190,15 @@ function filterOutEntrypoints(name) { |
190 | 190 | } |
191 | 191 | } |
192 | 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 | + } |
193 | 202 | } |
194 | 203 | if (changed) { |
195 | 204 | let newJSON = JSON.stringify(packageJSON, null, ' '); |
|