mirror of https://github.com/webpack/webpack.git
Compare commits
8 Commits
15fc825577
...
c1cb82f508
Author | SHA1 | Date |
---|---|---|
|
c1cb82f508 | |
|
b6c781a0f1 | |
|
2be6c6e0fa | |
|
59be3dc128 | |
|
154195fa4d | |
|
3c08fd105c | |
|
f508e8b705 | |
|
5c11f27b6b |
|
@ -214,7 +214,7 @@ jobs:
|
|||
|
||||
# Install old `jest` version and deps for legacy node versions
|
||||
- run: |
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 --ignore-engines
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 memfs@4.14.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
|
||||
|
||||
|
|
|
@ -284,6 +284,7 @@
|
|||
"url's",
|
||||
"valign",
|
||||
"valtype",
|
||||
"walltime",
|
||||
"wasi",
|
||||
"wasm",
|
||||
"watchings",
|
||||
|
@ -304,7 +305,6 @@
|
|||
"commithash",
|
||||
"formaters",
|
||||
"akait",
|
||||
"Akait",
|
||||
"evenstensberg",
|
||||
"Stensberg",
|
||||
"ovflowd",
|
||||
|
|
|
@ -15,59 +15,46 @@ const browserslist = require("browserslist");
|
|||
// [[C:]/path/to/config][:env]
|
||||
const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
|
||||
|
||||
/**
|
||||
* @typedef {object} BrowserslistHandlerConfig
|
||||
* @property {string=} configPath
|
||||
* @property {string=} env
|
||||
* @property {string=} query
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string | null | undefined} input input string
|
||||
* @param {string} context the context directory
|
||||
* @returns {BrowserslistHandlerConfig} config
|
||||
*/
|
||||
const parse = (input, context) => {
|
||||
if (!input) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (path.isAbsolute(input)) {
|
||||
const [, configPath, env] = inputRx.exec(input) || [];
|
||||
return { configPath, env };
|
||||
}
|
||||
|
||||
const config = browserslist.findConfig(context);
|
||||
|
||||
if (config && Object.keys(config).includes(input)) {
|
||||
return { env: input };
|
||||
}
|
||||
|
||||
return { query: input };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string | null | undefined} input input string
|
||||
* @param {string} context the context directory
|
||||
* @returns {string[] | undefined} selected browsers
|
||||
*/
|
||||
const load = (input, context) => {
|
||||
const { configPath, env, query } = parse(input, context);
|
||||
// browserslist:path-to-config
|
||||
// browserslist:path-to-config:env
|
||||
if (input && path.isAbsolute(input)) {
|
||||
const [, configPath, env] = inputRx.exec(input) || [];
|
||||
|
||||
// if a query is specified, then use it, else
|
||||
// if a path to a config is specified then load it, else
|
||||
// find a nearest config
|
||||
const config =
|
||||
query ||
|
||||
(configPath
|
||||
? browserslist.loadConfig({
|
||||
config: configPath,
|
||||
env
|
||||
})
|
||||
: browserslist.loadConfig({ path: context, env }));
|
||||
const config = browserslist.loadConfig({
|
||||
config: configPath,
|
||||
env
|
||||
});
|
||||
|
||||
if (!config) return;
|
||||
return browserslist(config);
|
||||
return browserslist(config, { env });
|
||||
}
|
||||
|
||||
const env = input || undefined;
|
||||
|
||||
const config = browserslist.loadConfig({
|
||||
path: context,
|
||||
env
|
||||
});
|
||||
|
||||
// browserslist
|
||||
// browserslist:env
|
||||
if (config) {
|
||||
try {
|
||||
return browserslist(config, { env, throwOnMissing: true });
|
||||
} catch (_err) {
|
||||
// Nothing, no `env` was found in browserslist, maybe input is `queries`
|
||||
}
|
||||
}
|
||||
|
||||
// browserslist:query
|
||||
if (env) {
|
||||
return browserslist(env);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1326,8 +1326,13 @@ const applyOutputDefaults = (
|
|||
if (tp.importScripts) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default script chunk format available:\n" +
|
||||
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
`CommonJs exports can be chosen when 'require' or node builtins are available.\n${
|
||||
`${
|
||||
tp.module
|
||||
? "Module ('module') can be chosen when ES modules are available (please set 'experiments.outputModule' and 'output.module' to `true`)"
|
||||
: ""
|
||||
}\n` +
|
||||
"JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
`CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${
|
||||
helpMessage
|
||||
}`
|
||||
);
|
||||
|
|
|
@ -16,7 +16,7 @@ const getBrowserslistTargetHandler = memoize(() =>
|
|||
* @returns {string} default target
|
||||
*/
|
||||
const getDefaultTarget = (context) => {
|
||||
const browsers = getBrowserslistTargetHandler().load(null, context);
|
||||
const browsers = getBrowserslistTargetHandler().load(undefined, context);
|
||||
return browsers ? "browserslist" : "web";
|
||||
};
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ class ImportMetaPlugin {
|
|||
new ModuleDependencyWarning(
|
||||
parser.state.module,
|
||||
new CriticalDependencyWarning(
|
||||
"Accessing import.meta directly is unsupported (only property access or destructuring is supported)"
|
||||
"'import.meta' cannot be used as a standalone expression. For static analysis, its properties must be accessed directly (e.g., 'import.meta.url') or through destructuring."
|
||||
),
|
||||
/** @type {DependencyLocation} */ (metaProperty.loc)
|
||||
)
|
||||
|
|
26
package.json
26
package.json
|
@ -89,7 +89,7 @@
|
|||
"@webassemblyjs/wasm-parser": "^1.14.1",
|
||||
"acorn": "^8.15.0",
|
||||
"acorn-import-phases": "^1.0.3",
|
||||
"browserslist": "^4.24.5",
|
||||
"browserslist": "^4.26.3",
|
||||
"chrome-trace-event": "^1.0.2",
|
||||
"enhanced-resolve": "^5.17.3",
|
||||
"es-module-lexer": "^1.2.1",
|
||||
|
@ -111,16 +111,16 @@
|
|||
"@babel/core": "^7.27.1",
|
||||
"@babel/preset-react": "^7.27.1",
|
||||
"@codspeed/core": "^4.0.1",
|
||||
"@eslint/js": "^9.29.0",
|
||||
"@eslint/markdown": "^7.1.0",
|
||||
"@stylistic/eslint-plugin": "^5.2.2",
|
||||
"@eslint/js": "^9.36.0",
|
||||
"@eslint/markdown": "^7.3.0",
|
||||
"@stylistic/eslint-plugin": "^5.4.0",
|
||||
"@types/glob-to-regexp": "^0.4.4",
|
||||
"@types/graceful-fs": "^4.1.9",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^24.1.0",
|
||||
"@types/node": "^24.5.2",
|
||||
"@types/xxhashjs": "^0.2.4",
|
||||
"assemblyscript": "^0.28.5",
|
||||
"assemblyscript": "^0.28.8",
|
||||
"babel-loader": "^10.0.0",
|
||||
"bundle-loader": "^0.5.6",
|
||||
"coffee-loader": "^5.0.0",
|
||||
|
@ -131,13 +131,13 @@
|
|||
"date-fns": "^4.0.0",
|
||||
"es5-ext": "^0.10.53",
|
||||
"es6-promise-polyfill": "^1.2.0",
|
||||
"eslint": "^9.29.0",
|
||||
"eslint": "^9.36.0",
|
||||
"eslint-config-prettier": "^10.1.1",
|
||||
"eslint-config-webpack": "^4.5.1",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jest": "^29.0.1",
|
||||
"eslint-plugin-jsdoc": "^51.2.3",
|
||||
"eslint-plugin-n": "^17.21.0",
|
||||
"eslint-plugin-n": "^17.23.1",
|
||||
"eslint-plugin-prettier": "^5.5.0",
|
||||
"eslint-plugin-unicorn": "^61.0.1",
|
||||
"file-loader": "^6.0.0",
|
||||
|
@ -146,11 +146,11 @@
|
|||
"hash-wasm": "^4.9.0",
|
||||
"husky": "^9.0.11",
|
||||
"istanbul": "^0.4.5",
|
||||
"jest": "^30.1.2",
|
||||
"jest-circus": "^30.1.2",
|
||||
"jest-cli": "^30.1.2",
|
||||
"jest-diff": "^30.1.2",
|
||||
"jest-environment-node": "^30.1.2",
|
||||
"jest": "^30.2.0",
|
||||
"jest-circus": "^30.2.0",
|
||||
"jest-cli": "^30.2.0",
|
||||
"jest-diff": "^30.2.0",
|
||||
"jest-environment-node": "^30.2.0",
|
||||
"jest-junit": "^16.0.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"json5": "^2.1.3",
|
||||
|
|
|
@ -3,6 +3,16 @@ import fs from "fs/promises";
|
|||
import { Session } from "inspector";
|
||||
import path from "path";
|
||||
import { fileURLToPath, pathToFileURL } from "url";
|
||||
import {
|
||||
InstrumentHooks,
|
||||
getCodspeedRunnerMode,
|
||||
getGitDir,
|
||||
getV8Flags,
|
||||
mongoMeasurement,
|
||||
optimizeFunction,
|
||||
setupCore,
|
||||
teardownCore
|
||||
} from "@codspeed/core";
|
||||
import { simpleGit } from "simple-git";
|
||||
import { Bench, hrtimeNow } from "tinybench";
|
||||
|
||||
|
@ -12,32 +22,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 +232,8 @@ for (const baselineInfo of baselineRevisions) {
|
|||
}
|
||||
}
|
||||
|
||||
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
||||
|
||||
function buildConfiguration(
|
||||
test,
|
||||
baseline,
|
||||
|
@ -385,105 +371,299 @@ 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);
|
||||
};
|
||||
|
||||
await bench.opts.teardown?.(task, "run");
|
||||
task.processRunResult({ latencySamples: samples });
|
||||
const wrapWithInstrumentHooksAsync = async (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = await fn();
|
||||
InstrumentHooks.stopBenchmark();
|
||||
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||
return result;
|
||||
};
|
||||
|
||||
function printStatus(fn) {
|
||||
const status = eval("%GetOptimizationStatus(fn)");
|
||||
console.log(status.toString(2).padStart(12, "0"));
|
||||
|
||||
if (status & (1 << 0)) {
|
||||
console.log("is function");
|
||||
}
|
||||
|
||||
if (status & (1 << 1)) {
|
||||
console.log("is never optimized");
|
||||
}
|
||||
|
||||
if (status & (1 << 2)) {
|
||||
console.log("is always optimized");
|
||||
}
|
||||
|
||||
if (status & (1 << 3)) {
|
||||
console.log("is maybe deoptimized");
|
||||
}
|
||||
|
||||
if (status & (1 << 4)) {
|
||||
console.log("is optimized");
|
||||
}
|
||||
|
||||
if (status & (1 << 5)) {
|
||||
console.log("is optimized by TurboFan");
|
||||
}
|
||||
|
||||
if (status & (1 << 6)) {
|
||||
console.log("is interpreted");
|
||||
}
|
||||
|
||||
if (status & (1 << 7)) {
|
||||
console.log("is marked for optimization");
|
||||
}
|
||||
|
||||
if (status & (1 << 8)) {
|
||||
console.log("is marked for concurrent optimization");
|
||||
}
|
||||
|
||||
if (status & (1 << 9)) {
|
||||
console.log("is optimizing concurrently");
|
||||
}
|
||||
|
||||
if (status & (1 << 10)) {
|
||||
console.log("is executing");
|
||||
}
|
||||
|
||||
if (status & (1 << 11)) {
|
||||
console.log("topmost frame is turbo fanned");
|
||||
}
|
||||
}
|
||||
teardownCore();
|
||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||
return bench.tasks;
|
||||
};
|
||||
|
||||
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
|
||||
const samples = [];
|
||||
while (samples.length < bench.opts.iterations - 1) {
|
||||
samples.push(await iterationAsync(task));
|
||||
}
|
||||
|
||||
const toRun = async () => {
|
||||
await fnOpts?.beforeEach?.call(task, "run");
|
||||
await fn();
|
||||
await fnOpts?.afterEach?.call(task, "run");
|
||||
};
|
||||
|
||||
await optimizeFunction(toRun);
|
||||
|
||||
console.log("optimize", printStatus(toRun));
|
||||
|
||||
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");
|
||||
|
||||
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 +675,6 @@ const bench = await withCodSpeed(
|
|||
warmupIterations: 2,
|
||||
iterations: 8,
|
||||
setup(task, mode) {
|
||||
global.gc();
|
||||
console.log(`Setup (${mode} mode): ${task.name}`);
|
||||
},
|
||||
teardown(task, mode) {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = [[/Critical dependency: Accessing import\.meta/]];
|
||||
module.exports = [
|
||||
[
|
||||
/Critical dependency: 'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||
]
|
||||
];
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
module.exports = [
|
||||
[
|
||||
/Accessing import.meta directly is unsupported \(only property access or destructuring is supported\)/
|
||||
/'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||
]
|
||||
];
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
extends browserslist-config-mycompany
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,37 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
production: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: `browserslist:${path.join(__dirname, ".browserslistrc")}:production`,
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
extends browserslist-config-mycompany1
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany1"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
// We are in tests, so 'process.env.NODE_ENV' has the 'test' value (browserslist respects the 'process.env.NODE_ENV' value)
|
||||
test: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,43 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: `browserslist:${path.join(__dirname, ".browserslistrc")}`,
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"browserslist": {
|
||||
"development": [
|
||||
"last 1 version"
|
||||
],
|
||||
"production": [
|
||||
"ie 9"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist:production",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"browserslist": [
|
||||
"extends browserslist-config-mycompany2"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const rootPath = path.resolve(__dirname, "../../../../");
|
||||
const rootNodeModules = path.resolve(rootPath, "./node_modules");
|
||||
const browserslistPackage = path.resolve(
|
||||
rootNodeModules,
|
||||
"browserslist-config-mycompany2"
|
||||
);
|
||||
const content = `
|
||||
module.exports = {
|
||||
development: [
|
||||
'last 1 version'
|
||||
],
|
||||
// We are in tests, so 'process.env.NODE_ENV' has the 'test' value (browserslist respects the 'process.env.NODE_ENV' value)
|
||||
test: [
|
||||
'ie 9',
|
||||
]
|
||||
}
|
||||
`;
|
||||
const browserslistFile = path.resolve(browserslistPackage, "./index.js");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(browserslistPackage);
|
||||
} catch (_err) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
fs.writeFileSync(browserslistFile, content);
|
||||
|
||||
module.exports = {
|
||||
afterExecute() {
|
||||
fs.unlinkSync(browserslistFile);
|
||||
fs.rmdirSync(browserslistPackage);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": false,
|
||||
"asyncFunction": false,
|
||||
"bigIntLiteral": false,
|
||||
"const": false,
|
||||
"destructuring": false,
|
||||
"document": true,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
"nodePrefixForCoreModules": false,
|
||||
"optionalChaining": false,
|
||||
"templateLiteral": false,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": false,
|
||||
"nwjs": false,
|
||||
"web": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"browserslist": {
|
||||
"development": [
|
||||
"last 1 version"
|
||||
],
|
||||
"production": [
|
||||
"ie 9"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
target: "browserslist:maintained node versions",
|
||||
plugins: [
|
||||
(compiler) => {
|
||||
compiler.hooks.compilation.tap("Test", (compilation) => {
|
||||
expect(compilation.outputOptions.environment).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"arrowFunction": true,
|
||||
"asyncFunction": true,
|
||||
"bigIntLiteral": true,
|
||||
"const": true,
|
||||
"destructuring": true,
|
||||
"document": false,
|
||||
"dynamicImport": true,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": true,
|
||||
"globalThis": true,
|
||||
"module": true,
|
||||
"nodePrefixForCoreModules": true,
|
||||
"optionalChaining": true,
|
||||
"templateLiteral": true,
|
||||
}
|
||||
`);
|
||||
expect(compilation.options.externalsPresets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"electron": false,
|
||||
"electronMain": false,
|
||||
"electronPreload": false,
|
||||
"electronRenderer": false,
|
||||
"node": true,
|
||||
"nwjs": false,
|
||||
"web": false,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue