mirror of https://github.com/webpack/webpack.git
Compare commits
8 Commits
869e73da32
...
e270331275
Author | SHA1 | Date |
---|---|---|
|
e270331275 | |
|
9f98d803c0 | |
|
8804459884 | |
|
bc91301142 | |
|
b8c489f690 | |
|
90d15f96ee | |
|
cf2634d839 | |
|
a4027ea889 |
|
@ -97,7 +97,7 @@ jobs:
|
|||
- run: yarn link webpack --frozen-lockfile
|
||||
|
||||
- name: Run benchmarks
|
||||
uses: CodSpeedHQ/action@653fdc30e6c40ffd9739e40c8a0576f4f4523ca1 # v4.0.1
|
||||
uses: CodSpeedHQ/action@3959e9e296ef25296e93e32afcc97196f966e57f # v4.1.0
|
||||
with:
|
||||
run: yarn benchmark --ci
|
||||
mode: "instrumentation"
|
||||
|
|
|
@ -284,6 +284,7 @@
|
|||
"url's",
|
||||
"valign",
|
||||
"valtype",
|
||||
"walltime",
|
||||
"wasi",
|
||||
"wasm",
|
||||
"watchings",
|
||||
|
@ -304,7 +305,6 @@
|
|||
"commithash",
|
||||
"formaters",
|
||||
"akait",
|
||||
"Akait",
|
||||
"evenstensberg",
|
||||
"Stensberg",
|
||||
"ovflowd",
|
||||
|
|
|
@ -3349,7 +3349,6 @@ export interface JavascriptParserOptions {
|
|||
* Set the inner regular expression for partial dynamic dependencies.
|
||||
*/
|
||||
wrappedContextRegExp?: RegExp;
|
||||
[k: string]: any;
|
||||
}
|
||||
/**
|
||||
* Generator options for json modules.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"use strict";
|
||||
|
||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||
const { getLibraryType } = require("../util/LibraryHelpers");
|
||||
const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
|
||||
const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
|
||||
|
||||
|
@ -104,7 +105,15 @@ class ModuleChunkLoadingPlugin {
|
|||
set.add(RuntimeGlobals.publicPath);
|
||||
}
|
||||
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
// Avoid generating dynamic filename helper for ESM libraries with outputModule
|
||||
const outputModule =
|
||||
compilation.options &&
|
||||
compilation.options.experiments &&
|
||||
compilation.options.experiments.outputModule;
|
||||
const isESMLibrary = getLibraryType(chunk, compilation) === "module";
|
||||
if (!(outputModule && isESMLibrary)) {
|
||||
set.add(RuntimeGlobals.getChunkScriptFilename);
|
||||
}
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
|
|
|
@ -17,6 +17,7 @@ const {
|
|||
getChunkFilenameTemplate
|
||||
} = require("../javascript/JavascriptModulesPlugin");
|
||||
const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
||||
const { getLibraryType } = require("../util/LibraryHelpers");
|
||||
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
||||
const { getUndoPath } = require("../util/identifier");
|
||||
|
||||
|
@ -95,6 +96,13 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
runtimeTemplate,
|
||||
outputOptions: { importFunctionName, crossOriginLoading, charset }
|
||||
} = compilation;
|
||||
const outputModule =
|
||||
compilation.options &&
|
||||
compilation.options.experiments &&
|
||||
compilation.options.experiments.outputModule;
|
||||
|
||||
const libraryType = getLibraryType(chunk, compilation);
|
||||
const isESMLibrary = libraryType === "module";
|
||||
const fn = RuntimeGlobals.ensureChunkHandlers;
|
||||
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
||||
const withExternalInstallChunk = this._runtimeRequirements.has(
|
||||
|
@ -221,19 +229,83 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
: `if(${hasJsMatcher("chunkId")}) {`,
|
||||
Template.indent([
|
||||
"// setup Promise in chunk cache",
|
||||
`var promise = ${importFunctionName}(${
|
||||
compilation.outputOptions.publicPath === "auto"
|
||||
? JSON.stringify(rootOutputDir)
|
||||
: RuntimeGlobals.publicPath
|
||||
} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`,
|
||||
outputModule && isESMLibrary
|
||||
? // For ESM library output generate statically analyzable imports per chunk
|
||||
(() => {
|
||||
// Build a switch over known async JS chunks with literal URLs
|
||||
const meta =
|
||||
compilation.outputOptions.importMetaName ||
|
||||
"import.meta";
|
||||
const relevantChunks = new Set();
|
||||
for (const c of chunk.getAllAsyncChunks()) {
|
||||
relevantChunks.add(c);
|
||||
}
|
||||
const includeEntries = chunkGraph
|
||||
.getTreeRuntimeRequirements(chunk)
|
||||
.has(
|
||||
RuntimeGlobals.ensureChunkIncludeEntries
|
||||
);
|
||||
if (includeEntries) {
|
||||
for (const c of chunkGraph.getRuntimeChunkDependentChunksIterable(
|
||||
chunk
|
||||
)) {
|
||||
relevantChunks.add(c);
|
||||
}
|
||||
}
|
||||
for (const ep of chunk.getAllReferencedAsyncEntrypoints()) {
|
||||
relevantChunks.add(
|
||||
ep.chunks[ep.chunks.length - 1]
|
||||
);
|
||||
}
|
||||
const cases = [];
|
||||
for (const c of relevantChunks) {
|
||||
if (!chunkHasJs(c, chunkGraph)) continue;
|
||||
const filename = compilation.getPath(
|
||||
getChunkFilenameTemplate(
|
||||
c,
|
||||
compilation.outputOptions
|
||||
),
|
||||
{ chunk: c, contentHashType: "javascript" }
|
||||
);
|
||||
const spec = JSON.stringify(
|
||||
rootOutputDir + filename
|
||||
);
|
||||
const cid = JSON.stringify(
|
||||
/** @type {string|number} */ (c.id)
|
||||
);
|
||||
cases.push(
|
||||
`case ${cid}: promise = ${importFunctionName}(new URL(${spec}, ${meta}.url).href); break;`
|
||||
);
|
||||
}
|
||||
return Template.asString([
|
||||
"var promise;",
|
||||
"switch(chunkId) {",
|
||||
Template.indent(cases),
|
||||
"default: promise = Promise.reject(new Error('Missing chunk mapping for ' + chunkId));",
|
||||
"}",
|
||||
`promise = promise.then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`
|
||||
]);
|
||||
})()
|
||||
: // Traditional string concatenation for non-ESM output
|
||||
`var promise = ${importFunctionName}(${
|
||||
compilation.outputOptions.publicPath === "auto"
|
||||
? JSON.stringify(rootOutputDir)
|
||||
: RuntimeGlobals.publicPath
|
||||
} + ${
|
||||
RuntimeGlobals.getChunkScriptFilename
|
||||
}(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
|
||||
"e",
|
||||
[
|
||||
"if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;",
|
||||
"throw e;"
|
||||
]
|
||||
)});`,
|
||||
`var promise = Promise.race([promise, new Promise(${runtimeTemplate.expressionFunction(
|
||||
"installedChunkData = installedChunks[chunkId] = [resolve]",
|
||||
"resolve"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
|
||||
/**
|
||||
* Determine library type from chunk entry options or compilation output options
|
||||
* @param {Chunk} chunk The chunk to get library type for
|
||||
* @param {Compilation} compilation The compilation
|
||||
* @returns {LibraryType | undefined} The library type or undefined
|
||||
*/
|
||||
module.exports.getLibraryType = (chunk, compilation) => {
|
||||
const entryOptions = chunk.getEntryOptions();
|
||||
const libraryType =
|
||||
entryOptions && entryOptions.library !== undefined
|
||||
? entryOptions.library.type
|
||||
: compilation.outputOptions.library &&
|
||||
typeof compilation.outputOptions.library === "object" &&
|
||||
!Array.isArray(compilation.outputOptions.library)
|
||||
? compilation.outputOptions.library.type
|
||||
: undefined;
|
||||
return libraryType;
|
||||
};
|
|
@ -110,7 +110,7 @@
|
|||
"devDependencies": {
|
||||
"@babel/core": "^7.27.1",
|
||||
"@babel/preset-react": "^7.27.1",
|
||||
"@codspeed/core": "^4.0.1",
|
||||
"@codspeed/core": "^5.0.1",
|
||||
"@eslint/js": "^9.36.0",
|
||||
"@eslint/markdown": "^7.3.0",
|
||||
"@stylistic/eslint-plugin": "^5.4.0",
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1786,7 +1786,7 @@
|
|||
"JavascriptParserOptions": {
|
||||
"description": "Parser options for javascript modules.",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"amd": {
|
||||
"$ref": "#/definitions/Amd"
|
||||
|
|
|
@ -3,6 +3,15 @@ import fs from "fs/promises";
|
|||
import { Session } from "inspector";
|
||||
import path from "path";
|
||||
import { fileURLToPath, pathToFileURL } from "url";
|
||||
import {
|
||||
InstrumentHooks,
|
||||
getCodspeedRunnerMode,
|
||||
getGitDir,
|
||||
getV8Flags,
|
||||
mongoMeasurement,
|
||||
setupCore,
|
||||
teardownCore
|
||||
} from "@codspeed/core";
|
||||
import { simpleGit } from "simple-git";
|
||||
import { Bench, hrtimeNow } from "tinybench";
|
||||
|
||||
|
@ -12,32 +21,6 @@ const git = simpleGit(rootPath);
|
|||
|
||||
const REV_LIST_REGEXP = /^([a-f0-9]+)\s*([a-f0-9]+)\s*([a-f0-9]+)?\s*$/;
|
||||
|
||||
const getV8Flags = () => {
|
||||
const nodeVersionMajor = Number.parseInt(
|
||||
process.version.slice(1).split(".")[0],
|
||||
10
|
||||
);
|
||||
const flags = [
|
||||
"--hash-seed=1",
|
||||
"--random-seed=1",
|
||||
"--no-opt",
|
||||
"--predictable",
|
||||
"--predictable-gc-schedule",
|
||||
"--interpreted-frames-native-stack",
|
||||
"--allow-natives-syntax",
|
||||
"--expose-gc",
|
||||
"--no-concurrent-sweeping",
|
||||
"--max-old-space-size=4096"
|
||||
];
|
||||
if (nodeVersionMajor < 18) {
|
||||
flags.push("--no-randomize-hashes");
|
||||
}
|
||||
if (nodeVersionMajor < 20) {
|
||||
flags.push("--no-scavenge-task");
|
||||
}
|
||||
return flags;
|
||||
};
|
||||
|
||||
const checkV8Flags = () => {
|
||||
const requiredFlags = getV8Flags();
|
||||
const actualFlags = process.execArgv;
|
||||
|
@ -248,6 +231,8 @@ for (const baselineInfo of baselineRevisions) {
|
|||
}
|
||||
}
|
||||
|
||||
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
||||
|
||||
function buildConfiguration(
|
||||
test,
|
||||
baseline,
|
||||
|
@ -385,105 +370,239 @@ const scenarios = [
|
|||
}
|
||||
];
|
||||
|
||||
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
||||
function getStackTrace(belowFn) {
|
||||
const oldLimit = Error.stackTraceLimit;
|
||||
Error.stackTraceLimit = Infinity;
|
||||
const dummyObject = {};
|
||||
const v8Handler = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = (dummyObject, v8StackTrace) => v8StackTrace;
|
||||
Error.captureStackTrace(dummyObject, belowFn || getStackTrace);
|
||||
const v8StackTrace = dummyObject.stack;
|
||||
Error.prepareStackTrace = v8Handler;
|
||||
Error.stackTraceLimit = oldLimit;
|
||||
return v8StackTrace;
|
||||
}
|
||||
|
||||
function getCallingFile() {
|
||||
const stack = getStackTrace();
|
||||
let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
|
||||
const gitDir = getGitDir(callingFile);
|
||||
if (gitDir === undefined) {
|
||||
throw new Error("Could not find a git repository");
|
||||
}
|
||||
if (callingFile.startsWith("file://")) {
|
||||
callingFile = fileURLToPath(callingFile);
|
||||
}
|
||||
return path.relative(gitDir, callingFile);
|
||||
}
|
||||
|
||||
const taskUriMap = new WeakMap();
|
||||
|
||||
function getOrCreateUriMap(bench) {
|
||||
let uriMap = taskUriMap.get(bench);
|
||||
if (!uriMap) {
|
||||
uriMap = new Map();
|
||||
taskUriMap.set(bench, uriMap);
|
||||
}
|
||||
return uriMap;
|
||||
}
|
||||
|
||||
function getTaskUri(bench, taskName, rootCallingFile) {
|
||||
const uriMap = taskUriMap.get(bench);
|
||||
return uriMap?.get(taskName) || `${rootCallingFile}::${taskName}`;
|
||||
}
|
||||
|
||||
const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
||||
const { Measurement, getGitDir, mongoMeasurement, setupCore, teardownCore } =
|
||||
await import("@codspeed/core");
|
||||
const codspeedRunnerMode = getCodspeedRunnerMode();
|
||||
|
||||
if (!Measurement.isInstrumented()) {
|
||||
const rawRun = bench.run;
|
||||
bench.run = async () => {
|
||||
console.warn(
|
||||
`[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`
|
||||
);
|
||||
return await rawRun.bind(bench)();
|
||||
};
|
||||
if (codspeedRunnerMode === "disabled") {
|
||||
return bench;
|
||||
}
|
||||
|
||||
const getStackTrace = (belowFn) => {
|
||||
const oldLimit = Error.stackTraceLimit;
|
||||
Error.stackTraceLimit = Infinity;
|
||||
const dummyObject = {};
|
||||
const v8Handler = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = (dummyObject, v8StackTrace) => v8StackTrace;
|
||||
Error.captureStackTrace(dummyObject, belowFn || getStackTrace);
|
||||
const v8StackTrace = dummyObject.stack;
|
||||
Error.prepareStackTrace = v8Handler;
|
||||
Error.stackTraceLimit = oldLimit;
|
||||
return v8StackTrace;
|
||||
};
|
||||
|
||||
const getCallingFile = () => {
|
||||
const stack = getStackTrace();
|
||||
let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
|
||||
const gitDir = getGitDir(callingFile);
|
||||
if (gitDir === undefined) {
|
||||
throw new Error("Could not find a git repository");
|
||||
}
|
||||
if (callingFile.startsWith("file://")) {
|
||||
callingFile = fileURLToPath(callingFile);
|
||||
}
|
||||
return path.relative(gitDir, callingFile);
|
||||
};
|
||||
|
||||
const rawAdd = bench.add;
|
||||
const uriMap = getOrCreateUriMap(bench);
|
||||
bench.add = (name, fn, opts) => {
|
||||
const callingFile = getCallingFile();
|
||||
const uri = `${callingFile}::${name}`;
|
||||
const options = { ...opts, uri };
|
||||
return rawAdd.bind(bench)(name, fn, options);
|
||||
let uri = callingFile;
|
||||
if (bench.name !== undefined) {
|
||||
uri += `::${bench.name}`;
|
||||
}
|
||||
uri += `::${name}`;
|
||||
uriMap.set(name, uri);
|
||||
return rawAdd.bind(bench)(name, fn, opts);
|
||||
};
|
||||
const rootCallingFile = getCallingFile();
|
||||
bench.run = async function run() {
|
||||
const iterations = bench.opts.iterations - 1;
|
||||
console.log("[CodSpeed] running");
|
||||
setupCore();
|
||||
for (const task of bench.tasks) {
|
||||
await bench.opts.setup?.(task, "run");
|
||||
await task.fnOpts.beforeAll?.call(task);
|
||||
const samples = [];
|
||||
async function iteration() {
|
||||
try {
|
||||
await task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
await task.fn();
|
||||
samples.push(bench.opts.now() - start || 0);
|
||||
await task.fnOpts.afterEach?.call(this, "run");
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (codspeedRunnerMode === "instrumented") {
|
||||
const setupBenchRun = () => {
|
||||
setupCore();
|
||||
console.log(
|
||||
"[CodSpeed] running with @codspeed/tinybench (instrumented mode)"
|
||||
);
|
||||
};
|
||||
const finalizeBenchRun = () => {
|
||||
teardownCore();
|
||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||
return bench.tasks;
|
||||
};
|
||||
|
||||
const wrapFunctionWithFrame = (fn, isAsync) => {
|
||||
if (isAsync) {
|
||||
return async function __codspeed_root_frame__() {
|
||||
await fn();
|
||||
};
|
||||
}
|
||||
|
||||
return function __codspeed_root_frame__() {
|
||||
fn();
|
||||
};
|
||||
};
|
||||
|
||||
const logTaskCompletion = (uri, status) => {
|
||||
console.log(`[CodSpeed] ${status} ${uri}`);
|
||||
};
|
||||
|
||||
const taskCompletionMessage = () =>
|
||||
InstrumentHooks.isInstrumented() ? "Measured" : "Checked";
|
||||
|
||||
const iterationAsync = async (task) => {
|
||||
try {
|
||||
await task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
await task.fn();
|
||||
const end = bench.opts.now() - start || 0;
|
||||
await task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
while (samples.length < iterations) {
|
||||
await iteration();
|
||||
}
|
||||
// Codspeed Measure
|
||||
const uri =
|
||||
task.opts && "uri" in task.options
|
||||
? task.opts.uri
|
||||
: `${rootCallingFile}::${task.name}`;
|
||||
await task.fnOpts.beforeEach?.call(task);
|
||||
await mongoMeasurement.start(uri);
|
||||
await (async function __codspeed_root_frame__() {
|
||||
Measurement.startInstrumentation();
|
||||
await task.fn();
|
||||
Measurement.stopInstrumentation(uri);
|
||||
})();
|
||||
await mongoMeasurement.stop(uri);
|
||||
await task.fnOpts.afterEach?.call(task);
|
||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||
await task.fnOpts.afterAll?.call(task);
|
||||
};
|
||||
|
||||
const wrapWithInstrumentHooksAsync = async (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = await fn();
|
||||
InstrumentHooks.stopBenchmark();
|
||||
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||
return result;
|
||||
};
|
||||
|
||||
const runTaskAsync = async (task, uri) => {
|
||||
const { fnOpts, fn } = task;
|
||||
|
||||
// Custom setup
|
||||
await bench.opts.setup?.(task, "run");
|
||||
|
||||
await fnOpts?.beforeAll?.call(task, "run");
|
||||
|
||||
// Custom warmup
|
||||
// We don't run `optimizeFunction` because our function is never optimized, instead we just warmup webpack
|
||||
const samples = [];
|
||||
|
||||
while (samples.length < bench.opts.iterations - 1) {
|
||||
samples.push(await iterationAsync(task));
|
||||
}
|
||||
|
||||
await fnOpts?.beforeEach?.call(task, "run");
|
||||
await mongoMeasurement.start(uri);
|
||||
global.gc?.();
|
||||
await wrapWithInstrumentHooksAsync(wrapFunctionWithFrame(fn, true), uri);
|
||||
await mongoMeasurement.stop(uri);
|
||||
await fnOpts?.afterEach?.call(task, "run");
|
||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||
await fnOpts?.afterAll?.call(task, "run");
|
||||
|
||||
// Custom teardown
|
||||
await bench.opts.teardown?.(task, "run");
|
||||
task.processRunResult({ latencySamples: samples });
|
||||
}
|
||||
teardownCore();
|
||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||
return bench.tasks;
|
||||
};
|
||||
|
||||
logTaskCompletion(uri, taskCompletionMessage());
|
||||
};
|
||||
|
||||
const iteration = (task) => {
|
||||
try {
|
||||
task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
task.fn();
|
||||
const end = bench.opts.now() - start || 0;
|
||||
task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const wrapWithInstrumentHooks = (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = fn();
|
||||
InstrumentHooks.stopBenchmark();
|
||||
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||
return result;
|
||||
};
|
||||
|
||||
const runTaskSync = (task, uri) => {
|
||||
const { fnOpts, fn } = task;
|
||||
|
||||
// Custom setup
|
||||
bench.opts.setup?.(task, "run");
|
||||
|
||||
fnOpts?.beforeAll?.call(task, "run");
|
||||
|
||||
// Custom warmup
|
||||
const samples = [];
|
||||
|
||||
while (samples.length < bench.opts.iterations - 1) {
|
||||
samples.push(iteration(task));
|
||||
}
|
||||
|
||||
fnOpts?.beforeEach?.call(task, "run");
|
||||
|
||||
wrapWithInstrumentHooks(wrapFunctionWithFrame(fn, false), uri);
|
||||
|
||||
fnOpts?.afterEach?.call(task, "run");
|
||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||
fnOpts?.afterAll?.call(task, "run");
|
||||
|
||||
// Custom teardown
|
||||
bench.opts.teardown?.(task, "run");
|
||||
|
||||
logTaskCompletion(uri, taskCompletionMessage());
|
||||
};
|
||||
|
||||
const finalizeAsyncRun = () => {
|
||||
finalizeBenchRun();
|
||||
};
|
||||
const finalizeSyncRun = () => {
|
||||
finalizeBenchRun();
|
||||
};
|
||||
|
||||
bench.run = async () => {
|
||||
setupBenchRun();
|
||||
|
||||
for (const task of bench.tasks) {
|
||||
const uri = getTaskUri(task.bench, task.name, rootCallingFile);
|
||||
await runTaskAsync(task, uri);
|
||||
}
|
||||
|
||||
return finalizeAsyncRun();
|
||||
};
|
||||
|
||||
bench.runSync = () => {
|
||||
setupBenchRun();
|
||||
|
||||
for (const task of bench.tasks) {
|
||||
const uri = getTaskUri(task.bench, task.name, rootCallingFile);
|
||||
runTaskSync(task, uri);
|
||||
}
|
||||
|
||||
return finalizeSyncRun();
|
||||
};
|
||||
} else if (codspeedRunnerMode === "walltime") {
|
||||
// We don't need it
|
||||
}
|
||||
|
||||
return bench;
|
||||
};
|
||||
|
||||
|
@ -495,7 +614,6 @@ const bench = await withCodSpeed(
|
|||
warmupIterations: 2,
|
||||
iterations: 8,
|
||||
setup(task, mode) {
|
||||
global.gc();
|
||||
console.log(`Setup (${mode} mode): ${task.name}`);
|
||||
},
|
||||
teardown(task, mode) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default function () {
|
||||
return 2;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export default async function getNumber() {
|
||||
const num = (await import("./chunk.js")).default;
|
||||
return 1 + num();
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
// Test for issue #15947 - ESM library with dynamic imports
|
||||
it("should generate statically analyzable dynamic imports for ESM library output", () => {
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const outputPath = path.join(__dirname, "lib.js");
|
||||
const content = fs.readFileSync(outputPath, "utf-8");
|
||||
|
||||
// Should use new URL with import.meta.url and literal path
|
||||
expect(content).toMatch(/import\(\s*new\s+URL\(\s*"[^"]+"\s*,\s*import\.meta\.url\s*\)\.href\s*\)/);
|
||||
// Should not use dynamic __webpack_require__.u() or publicPath string concatenation
|
||||
expect(content).not.toMatch(/__webpack_require__\.u\(/);
|
||||
expect(content).not.toMatch(/\+\s*__webpack_require__\.p\s*\+/);
|
||||
|
||||
// Verify that the chunk file was created
|
||||
const chunkFiles = fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(f => f.startsWith("chunk.") && f.endsWith(".js"));
|
||||
expect(chunkFiles.length).toBeGreaterThan(0);
|
||||
|
||||
// Verify the ESM export is present
|
||||
expect(content).toMatch(/export\s*\{/);
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
findBundle() {
|
||||
return ["./index.js"];
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = [
|
||||
{
|
||||
entry: "./entry.js",
|
||||
output: {
|
||||
filename: "lib.js",
|
||||
chunkFilename: "chunk.[chunkhash:8].js",
|
||||
library: {
|
||||
type: "module"
|
||||
}
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./index.js",
|
||||
output: {
|
||||
filename: "index.js"
|
||||
}
|
||||
}
|
||||
];
|
|
@ -8195,8 +8195,6 @@ declare class JavascriptParser extends ParserClass {
|
|||
* Parser options for javascript modules.
|
||||
*/
|
||||
declare interface JavascriptParserOptions {
|
||||
[index: string]: any;
|
||||
|
||||
/**
|
||||
* Set the value of `require.amd` and `define.amd`. Or disable AMD support.
|
||||
*/
|
||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -332,14 +332,14 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@codspeed/core@^4.0.1":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@codspeed/core/-/core-4.0.1.tgz#91049cce17b8c1d1b4b6cbc481f5ddc1145d6e1e"
|
||||
integrity sha512-fJ53arfgtzCDZa8DuGJhpTZ3Ll9A1uW5nQ2jSJnfO4Hl5MRD2cP8P4vPvIUAGbdbjwCxR1jat6cW8OloMJkJXw==
|
||||
"@codspeed/core@^5.0.1":
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@codspeed/core/-/core-5.0.1.tgz#6145c898a86a6d56a169611c3e9657a8b97c7642"
|
||||
integrity sha512-4g5ZyFAin8QywK4+0FK1uXG3GLRPu0oc3xbP+7OUhhFxbwpzFuaJtKmnTofMqLy9/pHH6Bl/7H0/DTVH3cpFkA==
|
||||
dependencies:
|
||||
axios "^1.4.0"
|
||||
find-up "^6.3.0"
|
||||
form-data "^4.0.0"
|
||||
form-data "^4.0.4"
|
||||
node-gyp-build "^4.6.0"
|
||||
|
||||
"@cspell/cspell-bundled-dicts@9.1.3":
|
||||
|
@ -3878,7 +3878,7 @@ fork-ts-checker-webpack-plugin@^9.0.2:
|
|||
semver "^7.3.5"
|
||||
tapable "^2.2.1"
|
||||
|
||||
form-data@^4.0.0, form-data@^4.0.4:
|
||||
form-data@^4.0.4:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
|
||||
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
|
||||
|
|
Loading…
Reference in New Issue