filterOutEntrypoints() — react Function Reference
Architecture documentation for the filterOutEntrypoints() function in packaging.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 331d1458_b7bf_3efa_ecd7_4dabd174a520["filterOutEntrypoints()"] fef369e3_6dfd_944a_16c1_5addc35f485d["packaging.js"] 331d1458_b7bf_3efa_ecd7_4dabd174a520 -->|defined in| fef369e3_6dfd_944a_16c1_5addc35f485d 7c67dee2_eb13_96b1_25ba_6fce3f0ea220["prepareNpmPackage()"] 7c67dee2_eb13_96b1_25ba_6fce3f0ea220 -->|calls| 331d1458_b7bf_3efa_ecd7_4dabd174a520 style 331d1458_b7bf_3efa_ecd7_4dabd174a520 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
scripts/rollup/packaging.js lines 171–251
function filterOutEntrypoints(name) {
// Remove entry point files that are not built in this configuration.
let jsonPath = `build/node_modules/${name}/package.json`;
let packageJSON = JSON.parse(readFileSync(jsonPath));
let files = packageJSON.files;
let exportsJSON = packageJSON.exports;
let browserJSON = packageJSON.browser;
if (!Array.isArray(files)) {
throw new Error('expected all package.json files to contain a files field');
}
let changed = false;
for (let i = 0; i < files.length; i++) {
let filename = files[i];
let entry =
filename === 'index.js'
? name
: name + '/' + filename.replace(/\.js$/, '');
let hasBundle = entryPointsToHasBundle.get(entry);
if (hasBundle === undefined) {
// This entry doesn't exist in the bundles. Check if something similar exists.
hasBundle =
entryPointsToHasBundle.get(entry + '.node') ||
entryPointsToHasBundle.get(entry + '.browser');
// The .react-server and .rsc suffixes may not have a bundle representation but
// should infer their bundle status from the non-suffixed entry point.
if (entry.endsWith('.react-server')) {
hasBundle = entryPointsToHasBundle.get(
entry.slice(0, '.react-server'.length * -1)
);
} else if (entry.endsWith('.rsc')) {
hasBundle = entryPointsToHasBundle.get(
entry.slice(0, '.rsc'.length * -1)
);
}
}
if (hasBundle === undefined) {
// This doesn't exist in the bundles. It's an extra file.
} else if (hasBundle === true) {
// This is built in this release channel.
} else {
// This doesn't have any bundleTypes in this release channel.
// Let's remove it.
files.splice(i, 1);
i--;
try {
unlinkSync(`build/node_modules/${name}/${filename}`);
} catch (err) {
// If the file doesn't exist we can just move on. Otherwise throw the halt the build
if (err.code !== 'ENOENT') {
throw err;
}
}
changed = true;
// Remove it from the exports field too if it exists.
if (exportsJSON) {
if (filename === 'index.js') {
delete exportsJSON['.'];
} else {
delete exportsJSON['./' + filename.replace(/\.js$/, '')];
}
}
if (browserJSON) {
delete browserJSON['./' + filename];
}
}
// 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, ' ');
writeFileSync(jsonPath, newJSON);
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does filterOutEntrypoints() do?
filterOutEntrypoints() is a function in the react codebase, defined in scripts/rollup/packaging.js.
Where is filterOutEntrypoints() defined?
filterOutEntrypoints() is defined in scripts/rollup/packaging.js at line 171.
What calls filterOutEntrypoints()?
filterOutEntrypoints() is called by 1 function(s): prepareNpmPackage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free