@invarn/cibuild 2.0.0 → 2.0.1
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-kind step execution must ride a temp script FILE, never `node -e`.
|
|
3
|
+
*
|
|
4
|
+
* The released `ci` binary is pkg-built. pkg's bootstrap intercepts child
|
|
5
|
+
* spawns of `node` and re-executes the pkg binary itself — and that
|
|
6
|
+
* bootstrap cannot handle `-e`: it resolves it as an entrypoint path and
|
|
7
|
+
* dies with `Cannot find module '<cwd>/-e'` before the script runs. A
|
|
8
|
+
* real file path works under both a system node and the pkg bootstrap,
|
|
9
|
+
* exactly like bash steps already do via their temp-file pattern.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=runner-node-step.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-node-step.test.d.ts","sourceRoot":"","sources":["../../src/runner-node-step.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-kind step execution must ride a temp script FILE, never `node -e`.
|
|
3
|
+
*
|
|
4
|
+
* The released `ci` binary is pkg-built. pkg's bootstrap intercepts child
|
|
5
|
+
* spawns of `node` and re-executes the pkg binary itself — and that
|
|
6
|
+
* bootstrap cannot handle `-e`: it resolves it as an entrypoint path and
|
|
7
|
+
* dies with `Cannot find module '<cwd>/-e'` before the script runs. A
|
|
8
|
+
* real file path works under both a system node and the pkg bootstrap,
|
|
9
|
+
* exactly like bash steps already do via their temp-file pattern.
|
|
10
|
+
*/
|
|
11
|
+
import { describe, test, expect, afterEach } from '@jest/globals';
|
|
12
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { PipelineRunner, StepExecutionError } from './runner.js';
|
|
16
|
+
import { loadConfig } from './config.js';
|
|
17
|
+
function nodeStep(script) {
|
|
18
|
+
return {
|
|
19
|
+
id: 'step_test',
|
|
20
|
+
name: 'node-under-test',
|
|
21
|
+
kind: 'node',
|
|
22
|
+
script,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
describe('PipelineRunner node-kind steps', () => {
|
|
26
|
+
let outDir = null;
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
if (outDir)
|
|
29
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
30
|
+
outDir = null;
|
|
31
|
+
});
|
|
32
|
+
test('executes the script from a file: argv[1] is a real path, never -e', async () => {
|
|
33
|
+
outDir = mkdtempSync(join(tmpdir(), 'cibuild-node-step-'));
|
|
34
|
+
const probePath = join(outDir, 'probe.json');
|
|
35
|
+
const runner = new PipelineRunner(loadConfig('/nonexistent/ci.config.json'));
|
|
36
|
+
await runner.runStep(nodeStep(`require('fs').writeFileSync(${JSON.stringify(probePath)}, JSON.stringify({` +
|
|
37
|
+
`argv1: process.argv[1] ?? null,` +
|
|
38
|
+
`filename: typeof __filename === 'string' ? __filename : null` +
|
|
39
|
+
`}))`));
|
|
40
|
+
const probe = JSON.parse(readFileSync(probePath, 'utf-8'));
|
|
41
|
+
// `node -e` leaves argv[1] undefined and has no __filename; a
|
|
42
|
+
// file-executed script has both, and neither may be the literal '-e'.
|
|
43
|
+
expect(probe.argv1).not.toBeNull();
|
|
44
|
+
expect(probe.argv1).not.toBe('-e');
|
|
45
|
+
expect(probe.filename).not.toBeNull();
|
|
46
|
+
expect(probe.filename).toMatch(/\.cjs$/);
|
|
47
|
+
});
|
|
48
|
+
test('propagates a non-zero exit as StepExecutionError', async () => {
|
|
49
|
+
const runner = new PipelineRunner(loadConfig('/nonexistent/ci.config.json'));
|
|
50
|
+
await expect(runner.runStep(nodeStep('process.exit(3)'))).rejects.toThrow(StepExecutionError);
|
|
51
|
+
});
|
|
52
|
+
test('cleans up the temp script file after the step exits', async () => {
|
|
53
|
+
outDir = mkdtempSync(join(tmpdir(), 'cibuild-node-step-'));
|
|
54
|
+
const probePath = join(outDir, 'probe.json');
|
|
55
|
+
const runner = new PipelineRunner(loadConfig('/nonexistent/ci.config.json'));
|
|
56
|
+
await runner.runStep(nodeStep(`require('fs').writeFileSync(${JSON.stringify(probePath)}, JSON.stringify({ filename: __filename }))`));
|
|
57
|
+
const { filename } = JSON.parse(readFileSync(probePath, 'utf-8'));
|
|
58
|
+
expect(() => readFileSync(filename)).toThrow();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=runner-node-step.test.js.map
|
package/dist/src/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMjE,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;gBAFhB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;CAK1B;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,QAAQ;IAE9B,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/runner.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMjE,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;gBAFhB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;CAK1B;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,QAAQ;IAE9B,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkKhE,OAAO,CAAC,cAAc;IAYtB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAwB7C,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAczD,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA2CpG"}
|
package/dist/src/runner.js
CHANGED
|
@@ -121,8 +121,23 @@ export -f envman
|
|
|
121
121
|
args = ["-e", step.script];
|
|
122
122
|
break;
|
|
123
123
|
case "node":
|
|
124
|
+
// Write the script to a file instead of passing it via -e: the
|
|
125
|
+
// released ci binary is pkg-built, and pkg's bootstrap intercepts
|
|
126
|
+
// child spawns of `node`, re-executing the pkg binary itself —
|
|
127
|
+
// which resolves `-e` as an entrypoint path and dies with
|
|
128
|
+
// `Cannot find module '<cwd>/-e'`. A real file path executes
|
|
129
|
+
// under both a system node and the pkg bootstrap.
|
|
124
130
|
cmd = this.config.interpreters.node;
|
|
125
|
-
|
|
131
|
+
try {
|
|
132
|
+
const tmpDir = mkdtempSync(join(tmpdir(), 'cibuild-script-'));
|
|
133
|
+
tmpScriptPath = join(tmpDir, `step-${step.id || 'script'}.cjs`);
|
|
134
|
+
writeFileSync(tmpScriptPath, step.script, 'utf-8');
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
reject(new Error(`Failed to create temporary script file: ${err}`));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
args = [tmpScriptPath];
|
|
126
141
|
break;
|
|
127
142
|
default:
|
|
128
143
|
reject(new Error(`Unknown step kind: ${step.kind}`));
|