vitest-spock 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/binary.d.ts +1 -1
- package/dist/node/binary.js +31 -10
- package/dist/node/binary.js.map +1 -1
- package/package.json +12 -1
package/dist/node/binary.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type FindBinaryOptions = Readonly<{
|
|
|
10
10
|
* Resolution order:
|
|
11
11
|
* 1. `options.spockBin`
|
|
12
12
|
* 2. `process.env.SPOCK_BIN`
|
|
13
|
-
* 3.
|
|
13
|
+
* 3. Bundled binary inside `spock-cli` (or legacy `@leostera/spock-<platform>-<arch>`)
|
|
14
14
|
* 4. Nearest `node_modules/.bin/spock` walking up from `options.rootDir` / `process.cwd()`
|
|
15
15
|
* 5. `~/.cargo/bin/spock`
|
|
16
16
|
* 6. `spock` on `PATH`
|
package/dist/node/binary.js
CHANGED
|
@@ -3,7 +3,14 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
|
-
const
|
|
6
|
+
const BUNDLED_TARGETS = {
|
|
7
|
+
"darwin:arm64": "darwin-arm64/spock",
|
|
8
|
+
"darwin:x64": "darwin-x64/spock",
|
|
9
|
+
"linux:x64": "linux-x64/spock",
|
|
10
|
+
"linux:arm64": "linux-arm64/spock",
|
|
11
|
+
"win32:x64": "win32-x64/spock.exe",
|
|
12
|
+
};
|
|
13
|
+
const LEGACY_PLATFORM_PACKAGES = {
|
|
7
14
|
"darwin:arm64": "@leostera/spock-darwin-arm64/bin/spock",
|
|
8
15
|
"darwin:x64": "@leostera/spock-darwin-x64/bin/spock",
|
|
9
16
|
"linux:x64": "@leostera/spock-linux-x64/bin/spock",
|
|
@@ -35,13 +42,27 @@ function walkNodeModulesBins(startDir) {
|
|
|
35
42
|
}
|
|
36
43
|
return found;
|
|
37
44
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
|
|
45
|
+
function resolveSpockCliBinary(startDir) {
|
|
46
|
+
const key = `${process.platform}:${process.arch}`;
|
|
47
|
+
const req = createRequire(join(resolve(startDir), "package.json"));
|
|
48
|
+
const bundledRel = BUNDLED_TARGETS[key];
|
|
49
|
+
if (bundledRel !== undefined) {
|
|
50
|
+
try {
|
|
51
|
+
const cliPkg = req.resolve("spock-cli/package.json");
|
|
52
|
+
const candidate = join(dirname(cliPkg), "vendor", bundledRel);
|
|
53
|
+
if (existsSync(candidate)) {
|
|
54
|
+
return candidate;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Fall through to legacy platform package / PATH lookup.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const legacyTarget = LEGACY_PLATFORM_PACKAGES[key];
|
|
62
|
+
if (legacyTarget === undefined)
|
|
41
63
|
return null;
|
|
42
64
|
try {
|
|
43
|
-
|
|
44
|
-
return req.resolve(target);
|
|
65
|
+
return req.resolve(legacyTarget);
|
|
45
66
|
}
|
|
46
67
|
catch {
|
|
47
68
|
return null;
|
|
@@ -54,7 +75,7 @@ const binaryCache = new Map();
|
|
|
54
75
|
* Resolution order:
|
|
55
76
|
* 1. `options.spockBin`
|
|
56
77
|
* 2. `process.env.SPOCK_BIN`
|
|
57
|
-
* 3.
|
|
78
|
+
* 3. Bundled binary inside `spock-cli` (or legacy `@leostera/spock-<platform>-<arch>`)
|
|
58
79
|
* 4. Nearest `node_modules/.bin/spock` walking up from `options.rootDir` / `process.cwd()`
|
|
59
80
|
* 5. `~/.cargo/bin/spock`
|
|
60
81
|
* 6. `spock` on `PATH`
|
|
@@ -70,9 +91,9 @@ export function findSpockBinary(options) {
|
|
|
70
91
|
candidates.push(options.spockBin);
|
|
71
92
|
if (process.env["SPOCK_BIN"])
|
|
72
93
|
candidates.push(process.env["SPOCK_BIN"]);
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
candidates.push(
|
|
94
|
+
const cliBin = resolveSpockCliBinary(startDir);
|
|
95
|
+
if (cliBin)
|
|
96
|
+
candidates.push(cliBin);
|
|
76
97
|
candidates.push(...walkNodeModulesBins(startDir));
|
|
77
98
|
candidates.push(resolve(homedir(), ".cargo", "bin", process.platform === "win32" ? "spock.exe" : "spock"));
|
|
78
99
|
candidates.push("spock");
|
package/dist/node/binary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary.js","sourceRoot":"","sources":["../../src/node/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASnD,MAAM,iBAAiB,GAAqC;
|
|
1
|
+
{"version":3,"file":"binary.js","sourceRoot":"","sources":["../../src/node/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASnD,MAAM,eAAe,GAAqC;IACxD,cAAc,EAAE,oBAAoB;IACpC,YAAY,EAAE,kBAAkB;IAChC,WAAW,EAAE,iBAAiB;IAC9B,aAAa,EAAE,mBAAmB;IAClC,WAAW,EAAE,qBAAqB;CACnC,CAAC;AAEF,MAAM,wBAAwB,GAAqC;IACjE,cAAc,EAAE,wC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Q,CAAC,IAAI,IAAI,CAAC;IAC3C,CAAC;IAED,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,OAAO,EAAE,QAAQ;QAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,MAAM;QAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,UAAU,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClD,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3G,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEzB,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACtB,QAAQ,GAAG,SAAS,CAAC;YACrB,MAAM;QACR,CAAC;IACH,CAAC;IACD,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,qBAAqB;IACnC,WAAW,CAAC,KAAK,EAAE,CAAC;AACtB,CAAC","sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { homedir } from \"node:os\";\nimport { dirname, join, resolve } from \"node:path\";\n\nexport type FindBinaryOptions = Readonly<{\n /** Explicit path to the `spock` executable. */\n spockBin?: string | undefined;\n /** Starting directory when searching `node_modules/.bin/spock`. Defaults to `process.cwd()`. */\n rootDir?: string | undefined;\n}>;\n\nconst BUNDLED_TARGETS: Readonly<Record<string, string>> = {\n \"darwin:arm64\": \"darwin-arm64/spock\",\n \"darwin:x64\": \"darwin-x64/spock\",\n \"linux:x64\": \"linux-x64/spock\",\n \"linux:arm64\": \"linux-arm64/spock\",\n \"win32:x64\": \"win32-x64/spock.exe\",\n};\n\nconst LEGACY_PLATFORM_PACKAGES: Readonly<Record<string, string>> = {\n \"darwin:arm64\": \"@leostera/spock-darwin-arm64/bin/spock\",\n \"darwin:x64\": \"@leostera/spock-darwin-x64/bin/spock\",\n \"linux:x64\": \"@leostera/spock-linux-x64/bin/spock\",\n \"linux:arm64\": \"@leostera/spock-linux-arm64/bin/spock\",\n \"win32:x64\": \"@leostera/spock-win32-x64/bin/spock.exe\",\n};\n\nfunction canRun(bin: string): boolean {\n if ((bin.includes(\"/\") || bin.includes(\"\\\\\")) && !existsSync(bin)) {\n return false;\n }\n try {\n execFileSync(bin, [\"--version\"], { stdio: \"pipe\", timeout: 5_000 });\n return true;\n } catch {\n return false;\n }\n}\n\nfunction walkNodeModulesBins(startDir: string): string[] {\n const found: string[] = [];\n const exe = process.platform === \"win32\" ? \"spock.cmd\" : \"spock\";\n let cur = resolve(startDir);\n while (true) {\n found.push(join(cur, \"node_modules\", \".bin\", exe));\n const parent = dirname(cur);\n if (parent === cur) break;\n cur = parent;\n }\n return found;\n}\n\nfunction resolveSpockCliBinary(startDir: string): string | null {\n const key = `${process.platform}:${process.arch}`;\n const req = createRequire(join(resolve(startDir), \"package.json\"));\n\n const bundledRel = BUNDLED_TARGETS[key];\n if (bundledRel !== undefined) {\n try {\n const cliPkg = req.resolve(\"spock-cli/package.json\");\n const candidate = join(dirname(cliPkg), \"vendor\", bundledRel);\n if (existsSync(candidate)) {\n return candidate;\n }\n } catch {\n // Fall through to legacy platform package / PATH lookup.\n }\n }\n\n const legacyTarget = LEGACY_PLATFORM_PACKAGES[key];\n if (legacyTarget === undefined) return null;\n try {\n return req.resolve(legacyTarget);\n } catch {\n return null;\n }\n}\n\nconst binaryCache = new Map<string, string | null>();\n\n/**\n * Locate the `spock` binary.\n *\n * Resolution order:\n * 1. `options.spockBin`\n * 2. `process.env.SPOCK_BIN`\n * 3. Bundled binary inside `spock-cli` (or legacy `@leostera/spock-<platform>-<arch>`)\n * 4. Nearest `node_modules/.bin/spock` walking up from `options.rootDir` / `process.cwd()`\n * 5. `~/.cargo/bin/spock`\n * 6. `spock` on `PATH`\n */\nexport function findSpockBinary(options?: FindBinaryOptions | undefined): string | null {\n const startDir = options?.rootDir ?? process.cwd();\n const cacheKey = `${options?.spockBin ?? \"\"}\\0${process.env[\"SPOCK_BIN\"] ?? \"\"}\\0${startDir}`;\n if (binaryCache.has(cacheKey)) {\n return binaryCache.get(cacheKey) ?? null;\n }\n\n const candidates: string[] = [];\n if (options?.spockBin) candidates.push(options.spockBin);\n if (process.env[\"SPOCK_BIN\"]) candidates.push(process.env[\"SPOCK_BIN\"]);\n const cliBin = resolveSpockCliBinary(startDir);\n if (cliBin) candidates.push(cliBin);\n candidates.push(...walkNodeModulesBins(startDir));\n candidates.push(resolve(homedir(), \".cargo\", \"bin\", process.platform === \"win32\" ? \"spock.exe\" : \"spock\"));\n candidates.push(\"spock\");\n\n let resolved: string | null = null;\n for (const candidate of candidates) {\n if (canRun(candidate)) {\n resolved = candidate;\n break;\n }\n }\n binaryCache.set(cacheKey, resolved);\n return resolved;\n}\n\n/** Clear the cached binary resolution result (primarily for tests). */\nexport function resetSpockBinaryCache(): void {\n binaryCache.clear();\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-spock",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Vitest matchers, trace recorder, and Cloudflare Workers / Durable Objects bridge for spock trace conformance",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -54,6 +54,17 @@
|
|
|
54
54
|
"README.md",
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsc -p tsconfig.json",
|
|
59
|
+
"prepack": "npm run build",
|
|
60
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
61
|
+
"test": "npm run build && vitest run"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": "^22.0.0",
|
|
65
|
+
"typescript": "^5.8.0",
|
|
66
|
+
"vitest": "^4.1.0"
|
|
67
|
+
},
|
|
57
68
|
"peerDependencies": {
|
|
58
69
|
"vitest": ">=2.0.0"
|
|
59
70
|
},
|