@codspeed/core
Advanced tools
Comparing version 1.1.0 to 2.0.0
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
const getV8Flags = (nodeVersionMajor) => { | ||
const flags = [ | ||
"--hash-seed=1", | ||
"--random-seed=1", | ||
"--no-opt", | ||
"--predictable", | ||
"--predictable-gc-schedule", | ||
"--interpreted-frames-native-stack" | ||
]; | ||
if (nodeVersionMajor < 18) { | ||
flags.push("--no-randomize-hashes"); | ||
} | ||
if (nodeVersionMajor < 20) { | ||
flags.push("--no-scavenge-task"); | ||
} | ||
return flags; | ||
}; | ||
const tryIntrospect = () => { | ||
if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== void 0) { | ||
const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); | ||
const introspectionMetadata = { | ||
flags: getV8Flags(nodeVersionMajor) | ||
}; | ||
fs.writeFileSync( | ||
process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__, | ||
JSON.stringify(introspectionMetadata) | ||
); | ||
process.exit(0); | ||
} | ||
}; | ||
var __defProp = Object.defineProperty; | ||
@@ -24,14 +56,28 @@ var __defProps = Object.defineProperties; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
let m; | ||
let native_core; | ||
try { | ||
m = __spreadProps(__spreadValues({}, require("node-gyp-build")(path.dirname(__dirname))), { | ||
const nativeCore = require("node-gyp-build")( | ||
path.dirname(__dirname) | ||
); | ||
native_core = __spreadProps(__spreadValues({}, nativeCore), { | ||
isBound: true | ||
}); | ||
} catch (e) { | ||
m = { | ||
isInstrumented: () => false, | ||
startInstrumentation: () => { | ||
native_core = { | ||
Measurement: { | ||
isInstrumented: () => false, | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
startInstrumentation: () => { | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function | ||
stopInstrumentation: (at) => { | ||
} | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
stopInstrumentation: (at) => { | ||
LinuxPerf: class LinuxPerf { | ||
start() { | ||
return false; | ||
} | ||
stop() { | ||
return false; | ||
} | ||
}, | ||
@@ -41,12 +87,13 @@ isBound: false | ||
} | ||
var native_core$1 = native_core; | ||
const skipOptimization = process.env.CODSPEED_FORCE_OPTIMIZATION !== "true"; | ||
const measurement = m; | ||
const initCore = () => { | ||
const initOptimization = () => { | ||
if (!skipOptimization) { | ||
require("v8").setFlagsFromString("--allow-natives-syntax"); | ||
} | ||
measurement.stopInstrumentation(`Metadata: codspeed-node ${"1.0.2"}`); | ||
}; | ||
const optimizeFunction = async (fn) => { | ||
if (skipOptimization) { | ||
await fn(); | ||
return; | ||
@@ -61,2 +108,3 @@ } | ||
if (skipOptimization) { | ||
fn(); | ||
return; | ||
@@ -70,6 +118,23 @@ } | ||
exports.initCore = initCore; | ||
exports.measurement = measurement; | ||
tryIntrospect(); | ||
const linuxPerf = new native_core$1.LinuxPerf(); | ||
const isBound = native_core$1.isBound; | ||
const setupCore = () => { | ||
initOptimization(); | ||
native_core$1.Measurement.stopInstrumentation( | ||
`Metadata: codspeed-node ${"2.0.0"}` | ||
); | ||
linuxPerf.start(); | ||
}; | ||
const teardownCore = () => { | ||
linuxPerf.stop(); | ||
}; | ||
const Measurement = native_core$1.Measurement; | ||
exports.Measurement = Measurement; | ||
exports.isBound = isBound; | ||
exports.optimizeFunction = optimizeFunction; | ||
exports.optimizeFunctionSync = optimizeFunctionSync; | ||
exports.setupCore = setupCore; | ||
exports.teardownCore = teardownCore; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,13 +0,17 @@ | ||
interface Measurement { | ||
isInstrumented(): boolean; | ||
startInstrumentation(): void; | ||
stopInstrumentation(at: string): void; | ||
isBound: boolean; | ||
interface Measurement$1 { | ||
isInstrumented: () => boolean; | ||
startInstrumentation: () => void; | ||
stopInstrumentation: (pos: string) => void; | ||
} | ||
declare const measurement: Measurement; | ||
declare const initCore: () => void; | ||
declare const optimizeFunction: (fn: CallableFunction) => Promise<void>; | ||
declare const optimizeFunctionSync: (fn: CallableFunction) => void; | ||
export { Measurement, initCore, measurement, optimizeFunction, optimizeFunctionSync }; | ||
declare const isBound: boolean; | ||
declare const setupCore: () => void; | ||
declare const teardownCore: () => void; | ||
declare const Measurement: Measurement$1; | ||
export { Measurement, isBound, optimizeFunction, optimizeFunctionSync, setupCore, teardownCore }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,3 +1,35 @@ | ||
import { writeFileSync } from 'fs'; | ||
import path from 'path'; | ||
const getV8Flags = (nodeVersionMajor) => { | ||
const flags = [ | ||
"--hash-seed=1", | ||
"--random-seed=1", | ||
"--no-opt", | ||
"--predictable", | ||
"--predictable-gc-schedule", | ||
"--interpreted-frames-native-stack" | ||
]; | ||
if (nodeVersionMajor < 18) { | ||
flags.push("--no-randomize-hashes"); | ||
} | ||
if (nodeVersionMajor < 20) { | ||
flags.push("--no-scavenge-task"); | ||
} | ||
return flags; | ||
}; | ||
const tryIntrospect = () => { | ||
if (process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__ !== void 0) { | ||
const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); | ||
const introspectionMetadata = { | ||
flags: getV8Flags(nodeVersionMajor) | ||
}; | ||
writeFileSync( | ||
process.env.__CODSPEED_NODE_CORE_INTROSPECTION_PATH__, | ||
JSON.stringify(introspectionMetadata) | ||
); | ||
process.exit(0); | ||
} | ||
}; | ||
var __defProp = Object.defineProperty; | ||
@@ -22,14 +54,28 @@ var __defProps = Object.defineProperties; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
let m; | ||
let native_core; | ||
try { | ||
m = __spreadProps(__spreadValues({}, require("node-gyp-build")(path.dirname(__dirname))), { | ||
const nativeCore = require("node-gyp-build")( | ||
path.dirname(__dirname) | ||
); | ||
native_core = __spreadProps(__spreadValues({}, nativeCore), { | ||
isBound: true | ||
}); | ||
} catch (e) { | ||
m = { | ||
isInstrumented: () => false, | ||
startInstrumentation: () => { | ||
native_core = { | ||
Measurement: { | ||
isInstrumented: () => false, | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
startInstrumentation: () => { | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function | ||
stopInstrumentation: (at) => { | ||
} | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
stopInstrumentation: (at) => { | ||
LinuxPerf: class LinuxPerf { | ||
start() { | ||
return false; | ||
} | ||
stop() { | ||
return false; | ||
} | ||
}, | ||
@@ -39,12 +85,13 @@ isBound: false | ||
} | ||
var native_core$1 = native_core; | ||
const skipOptimization = process.env.CODSPEED_FORCE_OPTIMIZATION !== "true"; | ||
const measurement = m; | ||
const initCore = () => { | ||
const initOptimization = () => { | ||
if (!skipOptimization) { | ||
require("v8").setFlagsFromString("--allow-natives-syntax"); | ||
} | ||
measurement.stopInstrumentation(`Metadata: codspeed-node ${"1.0.2"}`); | ||
}; | ||
const optimizeFunction = async (fn) => { | ||
if (skipOptimization) { | ||
await fn(); | ||
return; | ||
@@ -59,2 +106,3 @@ } | ||
if (skipOptimization) { | ||
fn(); | ||
return; | ||
@@ -68,3 +116,18 @@ } | ||
export { initCore, measurement, optimizeFunction, optimizeFunctionSync }; | ||
tryIntrospect(); | ||
const linuxPerf = new native_core$1.LinuxPerf(); | ||
const isBound = native_core$1.isBound; | ||
const setupCore = () => { | ||
initOptimization(); | ||
native_core$1.Measurement.stopInstrumentation( | ||
`Metadata: codspeed-node ${"2.0.0"}` | ||
); | ||
linuxPerf.start(); | ||
}; | ||
const teardownCore = () => { | ||
linuxPerf.stop(); | ||
}; | ||
const Measurement = native_core$1.Measurement; | ||
export { Measurement, isBound, optimizeFunction, optimizeFunctionSync, setupCore, teardownCore }; | ||
//# sourceMappingURL=index.es5.js.map |
{ | ||
"name": "@codspeed/core", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "The core Node library used to integrate with Codspeed runners", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
192814
267
10
10