MCPcopy Index your code
hub / github.com/react/react / filterOutEntrypoints

Function filterOutEntrypoints

scripts/rollup/packaging.js:171–251  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

169}
170
171function filterOutEntrypoints(name) {
172 // Remove entry point files that are not built in this configuration.
173 let jsonPath = `build/node_modules/${name}/package.json`;
174 let packageJSON = JSON.parse(readFileSync(jsonPath));
175 let files = packageJSON.files;
176 let exportsJSON = packageJSON.exports;
177 let browserJSON = packageJSON.browser;
178 if (!Array.isArray(files)) {
179 throw new Error('expected all package.json files to contain a files field');
180 }
181 let changed = false;
182 for (let i = 0; i < files.length; i++) {
183 let filename = files[i];
184 let entry =
185 filename === 'index.js'
186 ? name
187 : name + '/' + filename.replace(/\.js$/, '');
188 let hasBundle = entryPointsToHasBundle.get(entry);
189 if (hasBundle === undefined) {
190 // This entry doesn't exist in the bundles. Check if something similar exists.
191 hasBundle =
192 entryPointsToHasBundle.get(entry + '.node') ||
193 entryPointsToHasBundle.get(entry + '.browser');
194
195 // The .react-server and .rsc suffixes may not have a bundle representation but
196 // should infer their bundle status from the non-suffixed entry point.
197 if (entry.endsWith('.react-server')) {
198 hasBundle = entryPointsToHasBundle.get(
199 entry.slice(0, '.react-server'.length * -1)
200 );
201 } else if (entry.endsWith('.rsc')) {
202 hasBundle = entryPointsToHasBundle.get(
203 entry.slice(0, '.rsc'.length * -1)
204 );
205 }
206 }
207 if (hasBundle === undefined) {
208 // This doesn't exist in the bundles. It's an extra file.
209 } else if (hasBundle === true) {
210 // This is built in this release channel.
211 } else {
212 // This doesn't have any bundleTypes in this release channel.
213 // Let's remove it.
214 files.splice(i, 1);
215 i--;
216 try {
217 unlinkSync(`build/node_modules/${name}/${filename}`);
218 } catch (err) {
219 // If the file doesn't exist we can just move on. Otherwise throw the halt the build
220 if (err.code !== 'ENOENT') {
221 throw err;
222 }
223 }
224 changed = true;
225 // Remove it from the exports field too if it exists.
226 if (exportsJSON) {
227 if (filename === 'index.js') {
228 delete exportsJSON['.'];

Callers 1

prepareNpmPackageFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected