@norskvideo/ctl-test-harness 0.1.25 → 0.1.27
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/cli-command.d.ts +10 -0
- package/cli-command.js +45 -17
- package/package.json +5 -1
package/cli-command.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
+
export interface CliCommandDeps {
|
|
2
|
+
env: Record<string, string | undefined>;
|
|
3
|
+
cwd: string;
|
|
4
|
+
/** This module's directory: packages/test-harness/{src,dist}. */
|
|
5
|
+
here: string;
|
|
6
|
+
exists: (path: string) => boolean;
|
|
7
|
+
/** Is `norsk-ctl` executable on PATH? */
|
|
8
|
+
onPath: () => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveCliCommand(d: CliCommandDeps): string[];
|
|
1
11
|
export declare const cliCommand: string[];
|
package/cli-command.js
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 1. NORSK_CTL_BINARY=/path/to/norsk-ctl-<os>-<cpu> — an explicit compiled
|
|
4
4
|
// binary, or "auto" to pick the platform binary under <cwd>/dist.
|
|
5
|
-
// 2.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
5
|
+
// 2. Inside the norsk-ctl monorepo (the cwd is under the checkout this
|
|
6
|
+
// harness sits in): the in-workspace CLI source, run via `bun run` — the
|
|
7
|
+
// monorepo's own tests test the source.
|
|
8
|
+
// 3. `norsk-ctl` on PATH — a consumer of the published harness (the
|
|
9
|
+
// split-repo case), or a product that LINKS the harness from a monorepo
|
|
10
|
+
// checkout: its dev shell's pinned CLI is the one under test, and running
|
|
11
|
+
// the linked source instead costs ~30s per daemon start on a Mac.
|
|
12
|
+
// 4. The in-workspace source anyway, when nothing is on PATH.
|
|
9
13
|
//
|
|
10
14
|
// Spread into spawn args: [...cliCommand, "serve"].
|
|
11
15
|
import { existsSync } from "node:fs";
|
|
12
16
|
import { arch, platform } from "node:os";
|
|
13
|
-
import { dirname, resolve } from "node:path";
|
|
17
|
+
import { delimiter, dirname, join, resolve, sep } from "node:path";
|
|
14
18
|
import { fileURLToPath } from "node:url";
|
|
15
19
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
20
|
function platformBinaryName() {
|
|
@@ -18,28 +22,52 @@ function platformBinaryName() {
|
|
|
18
22
|
const cpu = arch() === "arm64" ? "arm64" : "x64";
|
|
19
23
|
return `norsk-ctl-${os}-${cpu}`;
|
|
20
24
|
}
|
|
21
|
-
function resolveBinary() {
|
|
22
|
-
const env =
|
|
25
|
+
function resolveBinary(d) {
|
|
26
|
+
const env = d.env.NORSK_CTL_BINARY;
|
|
23
27
|
if (!env)
|
|
24
28
|
return null;
|
|
25
|
-
const candidate = env === "auto" ? resolve(
|
|
26
|
-
if (!
|
|
29
|
+
const candidate = env === "auto" ? resolve(d.cwd, "dist", platformBinaryName()) : resolve(env);
|
|
30
|
+
if (!d.exists(candidate)) {
|
|
27
31
|
throw new Error(`NORSK_CTL_BINARY not found: ${candidate}`);
|
|
28
32
|
}
|
|
29
33
|
return candidate;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const source = resolve(here, "../../norsk-ctl/cli/src/index.ts");
|
|
34
|
-
return
|
|
35
|
+
/** packages/test-harness/{src,dist} -> packages/norsk-ctl/cli/src/index.ts. */
|
|
36
|
+
function workspaceSource(d) {
|
|
37
|
+
const source = resolve(d.here, "../../norsk-ctl/cli/src/index.ts");
|
|
38
|
+
return d.exists(source) ? source : null;
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
/** packages/test-harness/{src,dist} -> the monorepo root. */
|
|
41
|
+
function insideMonorepo(d) {
|
|
42
|
+
const root = resolve(d.here, "../../..");
|
|
43
|
+
const cwd = resolve(d.cwd);
|
|
44
|
+
return cwd === root || cwd.startsWith(root + sep);
|
|
45
|
+
}
|
|
46
|
+
export function resolveCliCommand(d) {
|
|
47
|
+
const binary = resolveBinary(d);
|
|
38
48
|
if (binary)
|
|
39
49
|
return [binary];
|
|
40
|
-
const source =
|
|
50
|
+
const source = workspaceSource(d);
|
|
51
|
+
if (source && insideMonorepo(d))
|
|
52
|
+
return ["bun", "run", source];
|
|
53
|
+
if (d.onPath())
|
|
54
|
+
return ["norsk-ctl"];
|
|
41
55
|
if (source)
|
|
42
56
|
return ["bun", "run", source];
|
|
43
57
|
return ["norsk-ctl"];
|
|
44
58
|
}
|
|
45
|
-
|
|
59
|
+
/** A PATH scan rather than Bun.which: the probe doc-guide tier imports this
|
|
60
|
+
* module under Node (Playwright). */
|
|
61
|
+
function norskCtlOnPath() {
|
|
62
|
+
return (process.env.PATH ?? "")
|
|
63
|
+
.split(delimiter)
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.some((dir) => existsSync(join(dir, "norsk-ctl")));
|
|
66
|
+
}
|
|
67
|
+
export const cliCommand = resolveCliCommand({
|
|
68
|
+
env: process.env,
|
|
69
|
+
cwd: process.cwd(),
|
|
70
|
+
here,
|
|
71
|
+
exists: existsSync,
|
|
72
|
+
onPath: norskCtlOnPath,
|
|
73
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@norskvideo/ctl-test-harness",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"default": "./index.js"
|
|
9
9
|
},
|
|
10
|
+
"./cli-command": {
|
|
11
|
+
"types": "./cli-command.d.ts",
|
|
12
|
+
"default": "./cli-command.js"
|
|
13
|
+
},
|
|
10
14
|
"./daemon": {
|
|
11
15
|
"types": "./daemon.d.ts",
|
|
12
16
|
"default": "./daemon.js"
|