MCPcopy
hub / github.com/webpack/webpack / execute

Function execute

test/PersistentCaching.test.js:115–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113 };
114
115 const execute = () => {
116 /** @type {Record<string, { exports: unknown }>} */
117 const cache = {};
118 const require = (/** @type {string} */ name) => {
119 if (cache[name]) return cache[name].exports;
120 if (!name.endsWith(".js")) name += ".js";
121 const p = path.resolve(outputPath, name);
122 const source = fs.readFileSync(p, "utf8");
123 const context = {};
124 const fn =
125 /** @type {(require: (name: string) => EXPECTED_ANY, module: { exports: unknown }, exports: unknown) => void} */ (
126 /** @type {EXPECTED_ANY} */ (vm.runInThisContext)(
127 `(function(require, module, exports) { ${source} })`,
128 context,
129 {
130 filename: p
131 }
132 )
133 );
134 const m = { exports: /** @type {unknown} */ ({}) };
135 cache[name] = m;
136 fn(require, m, m.exports);
137 return m.exports;
138 };
139 return require("./main");
140 };
141
142 it("should compile fine (warmup)", async () => {
143 const data = {

Callers 1

Calls 1

requireFunction · 0.70

Tested by

no test coverage detected