@vitest-agent/sidecar 2.2.14 → 2.2.15

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/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * \@vitest-agent/sidecar
3
3
  *
4
- * Resolves the absolute path of the platform-specific sidecar binary
5
- * by using `require.resolve` on the optional platform package's bin entry.
4
+ * Resolves the absolute path of the platform-specific sidecar binary through
5
+ * `@effected/commands`' `PrebuiltBinary`, anchored at this package so module
6
+ * resolution finds the optional platform packages it declares.
6
7
  *
7
8
  * @packageDocumentation
8
9
  */
@@ -16,25 +17,26 @@ interface ResolveSidecarBinaryPathOptions {
16
17
  readonly platform?: NodeJS.Platform;
17
18
  /** Override the architecture (defaults to `process.arch`). */
18
19
  readonly arch?: string;
19
- /** Override the module resolver (defaults to `createRequire`-backed resolver). */
20
+ /** Override the module resolver (defaults to `require.resolve` anchored at this package). */
20
21
  readonly resolver?: (path: string) => string;
21
22
  }
22
23
  /**
23
24
  * Resolve the absolute path of the platform-specific sidecar binary.
24
25
  *
25
26
  * The four platform packages that ship SEA binaries are:
26
- * - `@vitest-agent/sidecar-darwin-arm64` → `bin/vitest-agent-sidecar`
27
- * - `@vitest-agent/sidecar-linux-arm64` → `bin/vitest-agent-sidecar`
28
- * - `@vitest-agent/sidecar-linux-x64` → `bin/vitest-agent-sidecar`
29
- * - `@vitest-agent/sidecar-win32-x64` → `bin/vitest-agent-sidecar.exe`
27
+ * - `@vitest-agent/sidecar-darwin-arm64`
28
+ * - `@vitest-agent/sidecar-linux-arm64`
29
+ * - `@vitest-agent/sidecar-linux-x64`
30
+ * - `@vitest-agent/sidecar-win32-x64` (an `.exe`)
30
31
  *
31
- * The binary path is resolved via `require.resolve` of the platform package's
32
- * bin entry (not discovered on PATH), so transitive optional dependencies that
33
- * are never hoisted to `node_modules/.bin/` are still found correctly.
32
+ * The binary path is resolved through the platform package's `.` export (not
33
+ * discovered on PATH), so transitive optional dependencies that are never
34
+ * hoisted to `node_modules/.bin/` are still found.
34
35
  *
35
- * Returns `null` when:
36
- * - The platform/arch combination has no matching package (e.g. darwin-x64).
37
- * - The matching optional dependency was not installed (MODULE_NOT_FOUND).
36
+ * Returns `null` when the platform/arch combination has no matching package
37
+ * (e.g. darwin-x64), when the matching optional dependency was not installed,
38
+ * or when it is installed without its binary. Any other resolution failure is
39
+ * a packaging fault and is rethrown as the resolver's own error.
38
40
  *
39
41
  * @param options - Optional overrides for platform, arch, and resolver (for testing).
40
42
  * @returns The absolute path to the binary, or `null` when not resolvable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest-agent/sidecar",
3
- "version": "2.2.14",
3
+ "version": "2.2.15",
4
4
  "private": false,
5
5
  "description": "Fast-path native binary for vitest-agent. Ships a Node SEA executable that handles the per-Bash-call inject-env hot path.",
6
6
  "keywords": [
@@ -34,11 +34,15 @@
34
34
  },
35
35
  "./package.json": "./package.json"
36
36
  },
37
+ "dependencies": {
38
+ "@effected/commands": "^0.17.0",
39
+ "effect": "^4.0.6"
40
+ },
37
41
  "optionalDependencies": {
38
- "@vitest-agent/sidecar-darwin-arm64": "2.2.14",
39
- "@vitest-agent/sidecar-linux-arm64": "2.2.14",
40
- "@vitest-agent/sidecar-linux-x64": "2.2.14",
41
- "@vitest-agent/sidecar-win32-x64": "2.2.14"
42
+ "@vitest-agent/sidecar-darwin-arm64": "2.2.15",
43
+ "@vitest-agent/sidecar-linux-arm64": "2.2.15",
44
+ "@vitest-agent/sidecar-linux-x64": "2.2.15",
45
+ "@vitest-agent/sidecar-win32-x64": "2.2.15"
42
46
  },
43
47
  "engines": {
44
48
  "node": ">=24.11.0"
@@ -1,56 +1,76 @@
1
- import { createRequire } from "node:module";
1
+ import { PrebuiltBinary } from "@effected/commands";
2
+ import { nodePrebuiltHost } from "@effected/commands/node-sync";
3
+ import { Result } from "effect";
2
4
 
3
5
  // src/resolve-sidecar-binary-path.ts
4
6
  /**
5
- * \@vitest-agent/sidecar
6
- *
7
- * Resolves the absolute path of the platform-specific sidecar binary
8
- * by using `require.resolve` on the optional platform package's bin entry.
9
- *
10
- * @packageDocumentation
7
+ * Target key to the platform package carrying its SEA binary. Each package's
8
+ * `.` export is the binary itself (the bundler points it at the suffixed SEA,
9
+ * `.exe` on win32), so the spec names no subpath. darwin-x64 is intentionally
10
+ * absent: there is no such package.
11
11
  */
12
+ const SIDECAR_PACKAGES = { packages: {
13
+ "darwin-arm64": "@vitest-agent/sidecar-darwin-arm64",
14
+ "linux-arm64": "@vitest-agent/sidecar-linux-arm64",
15
+ "linux-x64": "@vitest-agent/sidecar-linux-x64",
16
+ "win32-x64": "@vitest-agent/sidecar-win32-x64"
17
+ } };
12
18
  /**
13
- * The four platform/arch combinations that have a matching sidecar package.
14
- * darwin-x64 is intentionally absent — there is no such package.
19
+ * The host the resolution runs against. The anchor MUST be a module of this
20
+ * package: `require.resolve` finds an optional dependency only from inside the
21
+ * package that declares it. The node host is built only when an override
22
+ * leaves something for it to supply; an overridden platform drops the host's
23
+ * libc, which describes the real Linux host, not the requested target.
15
24
  */
16
- const SUPPORTED_PLATFORMS = /* @__PURE__ */ new Map([
17
- ["darwin-arm64", "@vitest-agent/sidecar-darwin-arm64"],
18
- ["linux-arm64", "@vitest-agent/sidecar-linux-arm64"],
19
- ["linux-x64", "@vitest-agent/sidecar-linux-x64"],
20
- ["win32-x64", "@vitest-agent/sidecar-win32-x64"]
21
- ]);
25
+ function makeHost(options) {
26
+ const { platform, arch, resolver } = options;
27
+ if (platform !== void 0 && arch !== void 0 && resolver !== void 0) return {
28
+ target: {
29
+ platform,
30
+ arch
31
+ },
32
+ resolve: resolver
33
+ };
34
+ const node = nodePrebuiltHost(import.meta.url);
35
+ return {
36
+ target: platform === void 0 ? {
37
+ ...node.target,
38
+ ...arch !== void 0 ? { arch } : {}
39
+ } : {
40
+ platform,
41
+ arch: arch ?? node.target.arch
42
+ },
43
+ resolve: resolver ?? node.resolve
44
+ };
45
+ }
22
46
  /**
23
47
  * Resolve the absolute path of the platform-specific sidecar binary.
24
48
  *
25
49
  * The four platform packages that ship SEA binaries are:
26
- * - `@vitest-agent/sidecar-darwin-arm64` → `bin/vitest-agent-sidecar`
27
- * - `@vitest-agent/sidecar-linux-arm64` → `bin/vitest-agent-sidecar`
28
- * - `@vitest-agent/sidecar-linux-x64` → `bin/vitest-agent-sidecar`
29
- * - `@vitest-agent/sidecar-win32-x64` → `bin/vitest-agent-sidecar.exe`
50
+ * - `@vitest-agent/sidecar-darwin-arm64`
51
+ * - `@vitest-agent/sidecar-linux-arm64`
52
+ * - `@vitest-agent/sidecar-linux-x64`
53
+ * - `@vitest-agent/sidecar-win32-x64` (an `.exe`)
30
54
  *
31
- * The binary path is resolved via `require.resolve` of the platform package's
32
- * bin entry (not discovered on PATH), so transitive optional dependencies that
33
- * are never hoisted to `node_modules/.bin/` are still found correctly.
55
+ * The binary path is resolved through the platform package's `.` export (not
56
+ * discovered on PATH), so transitive optional dependencies that are never
57
+ * hoisted to `node_modules/.bin/` are still found.
34
58
  *
35
- * Returns `null` when:
36
- * - The platform/arch combination has no matching package (e.g. darwin-x64).
37
- * - The matching optional dependency was not installed (MODULE_NOT_FOUND).
59
+ * Returns `null` when the platform/arch combination has no matching package
60
+ * (e.g. darwin-x64), when the matching optional dependency was not installed,
61
+ * or when it is installed without its binary. Any other resolution failure is
62
+ * a packaging fault and is rethrown as the resolver's own error.
38
63
  *
39
64
  * @param options - Optional overrides for platform, arch, and resolver (for testing).
40
65
  * @returns The absolute path to the binary, or `null` when not resolvable.
41
66
  * @public
42
67
  */
43
68
  function resolveSidecarBinaryPath(options = {}) {
44
- const key = `${options.platform ?? process.platform}-${options.arch ?? process.arch}`;
45
- const packageName = SUPPORTED_PLATFORMS.get(key);
46
- if (packageName === void 0) return null;
47
- const resolve = options.resolver ?? createRequire(import.meta.url).resolve;
48
- try {
49
- return resolve(packageName);
50
- } catch (err) {
51
- if (err.code === "MODULE_NOT_FOUND") return null;
52
- throw err;
53
- }
69
+ const resolved = PrebuiltBinary.resolveSync(SIDECAR_PACKAGES, makeHost(options));
70
+ if (Result.isSuccess(resolved)) return resolved.success.path;
71
+ const error = resolved.failure;
72
+ if (error.reason === "unresolvable") throw error.cause ?? error;
73
+ return null;
54
74
  }
55
75
 
56
76
  export { resolveSidecarBinaryPath };
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.1"
8
+ "packageVersion": "7.59.4"
9
9
  }
10
10
  ]
11
11
  }