MCPcopy
hub / github.com/webpack/webpack / collectStaticExternalRequests

Function collectStaticExternalRequests

lib/hmr/LazyCompilationPlugin.js:107–138  ·  view source on GitHub ↗
(externals, layer)

Source from the content-addressed store, hash-verified

105 * @returns {Set<string>} requests to reserve in the entry chunk
106 */
107const collectStaticExternalRequests = (externals, layer) => {
108 /** @type {Set<string>} */
109 const requests = new Set();
110 if (!externals) return requests;
111 /** @param {import("../../declarations/WebpackOptions").ExternalItem} item one item */
112 const visit = (item) => {
113 if (typeof item === "string") {
114 requests.add(item);
115 return;
116 }
117 if (!item || typeof item !== "object" || item instanceof RegExp) return;
118 const resolved = /** @type {Record<string, unknown>} */ (
119 resolveByProperty(
120 /** @type {Record<string, unknown>} */ (item),
121 "byLayer",
122 layer
123 )
124 );
125 for (const [request, value] of Object.entries(resolved)) {
126 // `false` explicitly opts the request out of externalization; reserving
127 // it would pull the actual module into the entry chunk.
128 if (value === false) continue;
129 requests.add(request);
130 }
131 };
132 if (Array.isArray(externals)) {
133 for (const item of externals) visit(item);
134 } else {
135 visit(externals);
136 }
137 return requests;
138};
139
140/**
141 * Defines the backend api type used by this module.

Callers 1

buildMethod · 0.85

Calls 2

visitFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected