Socket
Socket
Sign inDemoInstall

@codspeed/tinybench-plugin

Package Overview
Dependencies
10
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.3.0

135

dist/index.cjs.js
'use strict';
var core = require('@codspeed/core');
var path = require('node:path');
var node_url = require('node:url');
var process = require('node:process');
var fs = require('node:fs');
var path$1 = require('path');
var path = require('path');
var url = require('url');
const typeMappings = {
directory: 'isDirectory',
file: 'isFile',
};
function checkType(type) {
if (Object.hasOwnProperty.call(typeMappings, type)) {
return;
}
throw new Error(`Invalid type specified: ${type}`);
}
const matchType = (type, stat) => stat[typeMappings[type]]();
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
function locatePathSync(
paths,
{
cwd = process.cwd(),
type = 'file',
allowSymlinks = true,
} = {},
) {
checkType(type);
cwd = toPath$1(cwd);
const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
for (const path_ of paths) {
try {
const stat = statFunction(path.resolve(cwd, path_), {
throwIfNoEntry: false,
});
if (!stat) {
continue;
}
if (matchType(type, stat)) {
return path_;
}
} catch {}
}
}
const toPath = urlOrPath => urlOrPath instanceof URL ? node_url.fileURLToPath(urlOrPath) : urlOrPath;
const findUpStop = Symbol('findUpStop');
function findUpMultipleSync(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) || '');
const {root} = path.parse(directory);
const stopAt = options.stopAt || root;
const limit = options.limit || Number.POSITIVE_INFINITY;
const paths = [name].flat();
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePathSync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePathSync([foundPath], locateOptions);
}
return foundPath;
};
const matches = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const foundPath = runMatcher({...options, cwd: directory});
if (foundPath === findUpStop) {
break;
}
if (foundPath) {
matches.push(path.resolve(directory, foundPath));
}
if (directory === stopAt || matches.length >= limit) {
break;
}
directory = path.dirname(directory);
}
return matches;
}
function findUpSync(name, options = {}) {
const matches = findUpMultipleSync(name, {...options, limit: 1});
return matches[0];
}
function get(belowFn) {

@@ -168,2 +65,3 @@ const oldLimit = Error.stackTraceLimit;

core.tryIntrospect();
function isCodSpeedBenchOptions(options) {

@@ -187,3 +85,3 @@ return "uri" in options;

const uri = `${callingFile}::${name}`;
const options = Object.assign({}, opts != null ? opts : {}, { uri });
const options = Object.assign({}, opts ?? {}, { uri });
return rawAdd.bind(bench)(name, fn, options);

@@ -193,15 +91,13 @@ };

bench.run = async () => {
var _a, _b, _c, _d;
console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.2.0"}`);
console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.3.0"}`);
core.setupCore();
for (const task of bench.tasks) {
const uri = isCodSpeedBenchOptions(task.opts) ? task.opts.uri : `${rootCallingFile}::${task.name}`;
await ((_a = task.opts.beforeAll) == null ? void 0 : _a.call(task));
await task.opts.beforeAll?.call(task);
await core.optimizeFunction(async () => {
var _a2, _b2;
await ((_a2 = task.opts.beforeEach) == null ? void 0 : _a2.call(task));
await task.opts.beforeEach?.call(task);
await task.fn();
await ((_b2 = task.opts.afterEach) == null ? void 0 : _b2.call(task));
await task.opts.afterEach?.call(task);
});
await ((_b = task.opts.beforeEach) == null ? void 0 : _b.call(task));
await task.opts.beforeEach?.call(task);
await async function __codspeed_root_frame__() {

@@ -212,4 +108,4 @@ core.Measurement.startInstrumentation();

}();
await ((_c = task.opts.afterEach) == null ? void 0 : _c.call(task));
await ((_d = task.opts.afterAll) == null ? void 0 : _d.call(task));
await task.opts.afterEach?.call(task);
await task.opts.afterAll?.call(task);
console.log(` \u2714 Measured ${uri}`);

@@ -226,3 +122,3 @@ }

let callingFile = stack[2].getFileName();
const gitDir = getGitDir(callingFile);
const gitDir = core.getGitDir(callingFile);
if (gitDir === void 0) {

@@ -234,13 +130,6 @@ throw new Error("Could not find a git repository");

}
return path$1.relative(gitDir, callingFile);
return path.relative(gitDir, callingFile);
}
function getGitDir(path2) {
const dotGitPath = findUpSync(".git", {
cwd: path2,
type: "directory"
});
return dotGitPath ? path$1.dirname(dotGitPath) : void 0;
}
exports.withCodSpeed = withCodSpeed;
//# sourceMappingURL=index.cjs.js.map

@@ -1,108 +0,5 @@

import { Measurement, setupCore, optimizeFunction, teardownCore } from '@codspeed/core';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import process from 'node:process';
import fs from 'node:fs';
import path$1, { dirname } from 'path';
import { fileURLToPath as fileURLToPath$1 } from 'url';
import { tryIntrospect, Measurement, setupCore, optimizeFunction, teardownCore, getGitDir } from '@codspeed/core';
import path from 'path';
import { fileURLToPath } from 'url';
const typeMappings = {
directory: 'isDirectory',
file: 'isFile',
};
function checkType(type) {
if (Object.hasOwnProperty.call(typeMappings, type)) {
return;
}
throw new Error(`Invalid type specified: ${type}`);
}
const matchType = (type, stat) => stat[typeMappings[type]]();
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
function locatePathSync(
paths,
{
cwd = process.cwd(),
type = 'file',
allowSymlinks = true,
} = {},
) {
checkType(type);
cwd = toPath$1(cwd);
const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
for (const path_ of paths) {
try {
const stat = statFunction(path.resolve(cwd, path_), {
throwIfNoEntry: false,
});
if (!stat) {
continue;
}
if (matchType(type, stat)) {
return path_;
}
} catch {}
}
}
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
const findUpStop = Symbol('findUpStop');
function findUpMultipleSync(name, options = {}) {
let directory = path.resolve(toPath(options.cwd) || '');
const {root} = path.parse(directory);
const stopAt = options.stopAt || root;
const limit = options.limit || Number.POSITIVE_INFINITY;
const paths = [name].flat();
const runMatcher = locateOptions => {
if (typeof name !== 'function') {
return locatePathSync(paths, locateOptions);
}
const foundPath = name(locateOptions.cwd);
if (typeof foundPath === 'string') {
return locatePathSync([foundPath], locateOptions);
}
return foundPath;
};
const matches = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const foundPath = runMatcher({...options, cwd: directory});
if (foundPath === findUpStop) {
break;
}
if (foundPath) {
matches.push(path.resolve(directory, foundPath));
}
if (directory === stopAt || matches.length >= limit) {
break;
}
directory = path.dirname(directory);
}
return matches;
}
function findUpSync(name, options = {}) {
const matches = findUpMultipleSync(name, {...options, limit: 1});
return matches[0];
}
function get(belowFn) {

@@ -166,2 +63,3 @@ const oldLimit = Error.stackTraceLimit;

tryIntrospect();
function isCodSpeedBenchOptions(options) {

@@ -185,3 +83,3 @@ return "uri" in options;

const uri = `${callingFile}::${name}`;
const options = Object.assign({}, opts != null ? opts : {}, { uri });
const options = Object.assign({}, opts ?? {}, { uri });
return rawAdd.bind(bench)(name, fn, options);

@@ -191,15 +89,13 @@ };

bench.run = async () => {
var _a, _b, _c, _d;
console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.2.0"}`);
console.log(`[CodSpeed] running with @codspeed/tinybench v${"2.3.0"}`);
setupCore();
for (const task of bench.tasks) {
const uri = isCodSpeedBenchOptions(task.opts) ? task.opts.uri : `${rootCallingFile}::${task.name}`;
await ((_a = task.opts.beforeAll) == null ? void 0 : _a.call(task));
await task.opts.beforeAll?.call(task);
await optimizeFunction(async () => {
var _a2, _b2;
await ((_a2 = task.opts.beforeEach) == null ? void 0 : _a2.call(task));
await task.opts.beforeEach?.call(task);
await task.fn();
await ((_b2 = task.opts.afterEach) == null ? void 0 : _b2.call(task));
await task.opts.afterEach?.call(task);
});
await ((_b = task.opts.beforeEach) == null ? void 0 : _b.call(task));
await task.opts.beforeEach?.call(task);
await async function __codspeed_root_frame__() {

@@ -210,4 +106,4 @@ Measurement.startInstrumentation();

}();
await ((_c = task.opts.afterEach) == null ? void 0 : _c.call(task));
await ((_d = task.opts.afterAll) == null ? void 0 : _d.call(task));
await task.opts.afterEach?.call(task);
await task.opts.afterAll?.call(task);
console.log(` \u2714 Measured ${uri}`);

@@ -229,15 +125,8 @@ }

if (callingFile.startsWith("file://")) {
callingFile = fileURLToPath$1(callingFile);
callingFile = fileURLToPath(callingFile);
}
return path$1.relative(gitDir, callingFile);
return path.relative(gitDir, callingFile);
}
function getGitDir(path2) {
const dotGitPath = findUpSync(".git", {
cwd: path2,
type: "directory"
});
return dotGitPath ? dirname(dotGitPath) : void 0;
}
export { withCodSpeed };
//# sourceMappingURL=index.es5.js.map

6

package.json
{
"name": "@codspeed/tinybench-plugin",
"version": "2.2.0",
"version": "2.3.0",
"description": "tinybench compatibility layer for CodSpeed",

@@ -22,3 +22,2 @@ "keywords": [

"devDependencies": {
"@types/find-up": "^4.0.0",
"@types/stack-trace": "^0.0.30",

@@ -29,4 +28,3 @@ "jest-mock-extended": "^3.0.4",

"dependencies": {
"@codspeed/core": "^2.2.0",
"find-up": "^6.3.0",
"@codspeed/core": "^2.3.0",
"stack-trace": "1.0.0-pre2"

@@ -33,0 +31,0 @@ },

@@ -9,2 +9,3 @@ <div align="center">

[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/codspeed-node)

@@ -11,0 +12,0 @@ </div>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc