@temporalio/testing 1.2.0 → 1.3.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.
- package/lib/{test-service-client.d.ts → connection.d.ts} +1 -1
- package/lib/{test-service-client.js → connection.js} +3 -3
- package/lib/connection.js.map +1 -0
- package/lib/index.d.ts +110 -66
- package/lib/index.js +140 -69
- package/lib/index.js.map +1 -1
- package/package.json +8 -21
- package/src/{test-service-client.ts → connection.ts} +1 -1
- package/src/index.ts +209 -135
- package/generated-protos/index.d.ts +0 -4206
- package/generated-protos/index.js +0 -11034
- package/lib/child-process.d.ts +0 -16
- package/lib/child-process.js +0 -57
- package/lib/child-process.js.map +0 -1
- package/lib/index-for-docs.d.ts +0 -1
- package/lib/index-for-docs.js +0 -29
- package/lib/index-for-docs.js.map +0 -1
- package/lib/test-service-client.js.map +0 -1
- package/scripts/common.mjs +0 -18
- package/scripts/compile-proto.mjs +0 -91
- package/scripts/download-test-server.mjs +0 -91
- package/src/child-process.ts +0 -60
- package/src/index-for-docs.ts +0 -2
package/lib/child-process.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { ChildProcess } from 'child_process';
|
|
4
|
-
export declare class ChildProcessError extends Error {
|
|
5
|
-
readonly code: number | null;
|
|
6
|
-
readonly signal: NodeJS.Signals | null;
|
|
7
|
-
readonly name = "ChildProcessError";
|
|
8
|
-
constructor(message: string, code: number | null, signal: NodeJS.Signals | null);
|
|
9
|
-
}
|
|
10
|
-
export interface WaitOptions {
|
|
11
|
-
validReturnCodes: number[];
|
|
12
|
-
}
|
|
13
|
-
export declare function waitOnChild(child: ChildProcess, opts?: WaitOptions): Promise<void>;
|
|
14
|
-
export declare function kill(child: ChildProcess, signal?: NodeJS.Signals, opts?: WaitOptions): Promise<void>;
|
|
15
|
-
export declare function killIfExists(child: ChildProcess, signal?: NodeJS.Signals, opts?: WaitOptions): Promise<void>;
|
|
16
|
-
export declare const shell: boolean;
|
package/lib/child-process.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shell = exports.killIfExists = exports.kill = exports.waitOnChild = exports.ChildProcessError = void 0;
|
|
4
|
-
class ChildProcessError extends Error {
|
|
5
|
-
constructor(message, code, signal) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.code = code;
|
|
8
|
-
this.signal = signal;
|
|
9
|
-
this.name = 'ChildProcessError';
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.ChildProcessError = ChildProcessError;
|
|
13
|
-
async function waitOnChild(child, opts) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
child.on('exit', (code, signal) => {
|
|
16
|
-
if (code !== null && (opts?.validReturnCodes ?? [0]).includes(code)) {
|
|
17
|
-
resolve();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
reject(new ChildProcessError('Process failed', code, signal));
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
child.on('error', reject);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.waitOnChild = waitOnChild;
|
|
27
|
-
async function kill(child, signal = 'SIGINT', opts) {
|
|
28
|
-
if (child.pid === undefined) {
|
|
29
|
-
throw new TypeError('Expected child with pid');
|
|
30
|
-
}
|
|
31
|
-
process.kill(child.pid, signal);
|
|
32
|
-
try {
|
|
33
|
-
await waitOnChild(child, opts);
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
// Should error if the error is not a child process error or it is a child
|
|
37
|
-
// process and either the platform is Windows or the signal matches.
|
|
38
|
-
const shouldError = !(err instanceof ChildProcessError) || (process.platform !== 'win32' && err.signal !== signal);
|
|
39
|
-
if (shouldError) {
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.kill = kill;
|
|
45
|
-
async function killIfExists(child, signal = 'SIGINT', opts) {
|
|
46
|
-
try {
|
|
47
|
-
await kill(child, signal, opts);
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
if (err.code !== 'ESRCH') {
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.killIfExists = killIfExists;
|
|
56
|
-
exports.shell = process.platform === 'win32';
|
|
57
|
-
//# sourceMappingURL=child-process.js.map
|
package/lib/child-process.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"child-process.js","sourceRoot":"","sources":["../src/child-process.ts"],"names":[],"mappings":";;;AAGA,MAAa,iBAAkB,SAAQ,KAAK;IAG1C,YAAY,OAAe,EAAkB,IAAmB,EAAkB,MAA6B;QAC7G,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAe;QAAkB,WAAM,GAAN,MAAM,CAAuB;QAF/F,SAAI,GAAG,mBAAmB,CAAC;IAI3C,CAAC;CACF;AAND,8CAMC;AAMM,KAAK,UAAU,WAAW,CAAC,KAAmB,EAAE,IAAkB;IACvE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YAChC,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,gBAAgB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACnE,OAAO,EAAE,CAAC;aACX;iBAAM;gBACL,MAAM,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;aAC/D;QACH,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC;AAXD,kCAWC;AAEM,KAAK,UAAU,IAAI,CAAC,KAAmB,EAAE,SAAyB,QAAQ,EAAE,IAAkB;IACnG,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE;QAC3B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;KAChD;IACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI;QACF,MAAM,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;KAChC;IAAC,OAAO,GAAG,EAAE;QACZ,0EAA0E;QAC1E,oEAAoE;QACpE,MAAM,WAAW,GAAG,CAAC,CAAC,GAAG,YAAY,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;QACnH,IAAI,WAAW,EAAE;YACf,MAAM,GAAG,CAAC;SACX;KACF;AACH,CAAC;AAfD,oBAeC;AAEM,KAAK,UAAU,YAAY,CAChC,KAAmB,EACnB,SAAyB,QAAQ,EACjC,IAAkB;IAElB,IAAI;QACF,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;KACjC;IAAC,OAAO,GAAQ,EAAE;QACjB,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE;YACxB,MAAM,GAAG,CAAC;SACX;KACF;AACH,CAAC;AAZD,oCAYC;AAEY,QAAA,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC"}
|
package/lib/index-for-docs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as testing from './index';
|
package/lib/index-for-docs.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.testing = void 0;
|
|
27
|
-
// Reexports the contents of this package under the "testing" namespace for better docs generation
|
|
28
|
-
exports.testing = __importStar(require("./index"));
|
|
29
|
-
//# sourceMappingURL=index-for-docs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-for-docs.js","sourceRoot":"","sources":["../src/index-for-docs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAAkG;AAClG,mDAAmC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-service-client.js","sourceRoot":"","sources":["../src/test-service-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,+CAAqF;AAErF,0DAA+C;AAGhC,mBAAW,GAAK,2BAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,aAAC;AAM3D;;GAEG;AACH,MAAa,UAAW,SAAQ,mBAAc;IA2B5C,YAAsB,OAA8B;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;IA1BS,MAAM,CAAC,iBAAiB,CAAC,OAA2B;QAC5D,MAAM,WAAW,GAAG,mBAAc,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,yBAAyB,CAAC;YAC7C,WAAW,EAAE,yCAAyC;YACtD,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,kBAAkB,EAAE,WAAW,CAAC,kBAAkB;YAClD,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,YAAY;SAC/C,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,mBAAW,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,EAAE,GAAG,WAAW,EAAE,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,OAA2B;QACrC,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAA2B;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC,eAAe,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;;AAzBH,gCA+BC;AA9BwB,4BAAiB,GAAG,IAAI,CAAC,4BAA4B,CAAC,EAAE,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC"}
|
package/scripts/common.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import { URL, fileURLToPath } from 'node:url';
|
|
3
|
-
|
|
4
|
-
const platformMapping = { darwin: 'macOS', linux: 'linux', win32: 'windows' };
|
|
5
|
-
const archAlias = { x64: 'amd64', arm64: 'aarch64' };
|
|
6
|
-
|
|
7
|
-
export const systemPlatform = platformMapping[os.platform()];
|
|
8
|
-
if (!systemPlatform) {
|
|
9
|
-
throw new Error(`Unsupported platform ${os.platform()}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const systemArch = archAlias[os.arch()];
|
|
13
|
-
if (!systemArch) {
|
|
14
|
-
throw new Error(`Unsupported architecture ${os.arch()}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ext = systemPlatform === 'windows' ? '.exe' : '';
|
|
18
|
-
export const outputPath = fileURLToPath(new URL(`../test-server${ext}`, import.meta.url));
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { promisify } from 'util';
|
|
5
|
-
import dedent from 'dedent';
|
|
6
|
-
import glob from 'glob';
|
|
7
|
-
import { statSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
8
|
-
import pbjs from 'protobufjs-cli/pbjs.js';
|
|
9
|
-
import pbts from 'protobufjs-cli/pbts.js';
|
|
10
|
-
|
|
11
|
-
const require = createRequire(import.meta.url);
|
|
12
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
const outputDir = resolve(__dirname, '../generated-protos');
|
|
14
|
-
const outputFile = resolve(outputDir, 'index.js');
|
|
15
|
-
const protoBaseDir = resolve(__dirname, '../proto');
|
|
16
|
-
|
|
17
|
-
const serviceProtoPath = resolve(protoBaseDir, 'temporal/api/testservice/v1/service.proto');
|
|
18
|
-
|
|
19
|
-
function mtime(path) {
|
|
20
|
-
try {
|
|
21
|
-
return statSync(path).mtimeMs;
|
|
22
|
-
} catch (err) {
|
|
23
|
-
if (err.code === 'ENOENT') {
|
|
24
|
-
return 0;
|
|
25
|
-
}
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function compileProtos(protoPath, jsOutputFile, dtsOutputFile, ...args) {
|
|
31
|
-
console.log(`Creating protobuf JS definitions from ${protoPath}`);
|
|
32
|
-
|
|
33
|
-
const pbjsArgs = [
|
|
34
|
-
...args,
|
|
35
|
-
'--wrap',
|
|
36
|
-
'commonjs',
|
|
37
|
-
'--target',
|
|
38
|
-
'static-module',
|
|
39
|
-
'--force-long',
|
|
40
|
-
'--no-verify',
|
|
41
|
-
'--root',
|
|
42
|
-
'__temporal_testing',
|
|
43
|
-
'--out',
|
|
44
|
-
jsOutputFile,
|
|
45
|
-
resolve(require.resolve('protobufjs'), '../google/protobuf/descriptor.proto'),
|
|
46
|
-
protoPath,
|
|
47
|
-
];
|
|
48
|
-
await promisify(pbjs.main)(pbjsArgs);
|
|
49
|
-
|
|
50
|
-
// Workaround an issue that prevents protobufjs from loading 'long' in Yarn 3 PnP
|
|
51
|
-
// https://github.com/protobufjs/protobuf.js/issues/1745#issuecomment-1200319399
|
|
52
|
-
const pbjsOutput = readFileSync(jsOutputFile, 'utf8');
|
|
53
|
-
writeFileSync(
|
|
54
|
-
jsOutputFile,
|
|
55
|
-
pbjsOutput.replace(
|
|
56
|
-
/(require\("protobufjs\/minimal"\);)$/m,
|
|
57
|
-
`$1
|
|
58
|
-
$protobuf.util.Long = require('long');
|
|
59
|
-
$protobuf.configure();
|
|
60
|
-
`
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
console.log(`Creating protobuf TS definitions from ${protoPath}`);
|
|
65
|
-
await promisify(pbts.main)(['--out', dtsOutputFile, jsOutputFile]);
|
|
66
|
-
|
|
67
|
-
// Fix issue where Long is not found in TS definitions (https://github.com/protobufjs/protobuf.js/issues/1533)
|
|
68
|
-
const pbtsOutput = readFileSync(dtsOutputFile, 'utf8');
|
|
69
|
-
writeFileSync(
|
|
70
|
-
dtsOutputFile,
|
|
71
|
-
dedent`
|
|
72
|
-
import Long from "long";
|
|
73
|
-
${pbtsOutput}
|
|
74
|
-
`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
mkdirSync(outputDir, { recursive: true });
|
|
79
|
-
|
|
80
|
-
const protoFiles = glob.sync(resolve(protoBaseDir, '**/*.proto'));
|
|
81
|
-
const protosMTime = Math.max(...protoFiles.map(mtime));
|
|
82
|
-
const genMTime = mtime(outputFile);
|
|
83
|
-
|
|
84
|
-
if (protosMTime < genMTime) {
|
|
85
|
-
console.log('Assuming protos are up to date');
|
|
86
|
-
process.exit(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
await compileProtos(serviceProtoPath, outputFile, resolve(outputDir, 'index.d.ts'), '--path', resolve(protoBaseDir));
|
|
90
|
-
|
|
91
|
-
console.log('Done');
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import stream from 'node:stream';
|
|
2
|
-
import util from 'node:util';
|
|
3
|
-
import zlib from 'node:zlib';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import got from 'got';
|
|
6
|
-
import tar from 'tar-stream';
|
|
7
|
-
import unzipper from 'unzipper';
|
|
8
|
-
import { outputPath, systemArch, systemPlatform } from './common.mjs';
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
if (fs.statSync(outputPath).isFile) {
|
|
12
|
-
console.log('Found existing test server executable', { path: outputPath });
|
|
13
|
-
process.exit(0);
|
|
14
|
-
}
|
|
15
|
-
} catch (err) {
|
|
16
|
-
if (err.code !== 'ENOENT') {
|
|
17
|
-
throw err;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const pipeline = util.promisify(stream.pipeline);
|
|
22
|
-
|
|
23
|
-
const defaultHeaders = {
|
|
24
|
-
'User-Agent': '@temporalio/testing installer',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const { GITHUB_TOKEN } = process.env;
|
|
28
|
-
|
|
29
|
-
if (GITHUB_TOKEN) {
|
|
30
|
-
console.log(`Using GITHUB_TOKEN`);
|
|
31
|
-
defaultHeaders['Authorization'] = `Bearer ${GITHUB_TOKEN}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const latestReleaseRes = await got('https://api.github.com/repos/temporalio/sdk-java/releases/latest', {
|
|
35
|
-
headers: {
|
|
36
|
-
...defaultHeaders,
|
|
37
|
-
Accept: 'application/vnd.github.v3+json',
|
|
38
|
-
},
|
|
39
|
-
}).json();
|
|
40
|
-
|
|
41
|
-
function findTestServerAsset(assets) {
|
|
42
|
-
for (const asset of assets) {
|
|
43
|
-
const m = asset.name.match(/^temporal-test-server_[^_]+_([^_]+)_([^.]+)\.(?:zip|tar.gz)$/);
|
|
44
|
-
if (m) {
|
|
45
|
-
const [_, assetPlatform, _assetArch] = m;
|
|
46
|
-
if (assetPlatform === systemPlatform) {
|
|
47
|
-
// TODO: assetArch === systemArch (no arm builds for test server yet)
|
|
48
|
-
return asset;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
throw new Error(`No prebuilt test server for ${systemPlatform}-${systemArch}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const asset = findTestServerAsset(latestReleaseRes.assets);
|
|
56
|
-
console.log('Downloading test server', { asset: asset.name, outputPath });
|
|
57
|
-
|
|
58
|
-
if (asset.content_type === 'application/x-gzip' || asset.content_type === 'application/x-gtar') {
|
|
59
|
-
const extract = tar.extract();
|
|
60
|
-
extract.on('entry', (_headers, stream, next) => {
|
|
61
|
-
stream.pipe(fs.createWriteStream(outputPath));
|
|
62
|
-
next();
|
|
63
|
-
});
|
|
64
|
-
await pipeline(
|
|
65
|
-
got.stream(asset.browser_download_url, {
|
|
66
|
-
headers: {
|
|
67
|
-
...defaultHeaders,
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
zlib.createGunzip(),
|
|
71
|
-
extract
|
|
72
|
-
);
|
|
73
|
-
await fs.promises.chmod(outputPath, 0o755);
|
|
74
|
-
} else if (asset.content_type === 'application/zip') {
|
|
75
|
-
got
|
|
76
|
-
.stream(asset.browser_download_url, {
|
|
77
|
-
headers: {
|
|
78
|
-
...defaultHeaders,
|
|
79
|
-
},
|
|
80
|
-
})
|
|
81
|
-
.pipe(unzipper.Parse())
|
|
82
|
-
.on('entry', (entry) => {
|
|
83
|
-
if (entry.type === 'File') {
|
|
84
|
-
entry.pipe(fs.createWriteStream(outputPath));
|
|
85
|
-
} else {
|
|
86
|
-
entry.autodrain();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} else {
|
|
90
|
-
throw new Error(`Unexpected content type for Test server download: ${asset.content_type}`);
|
|
91
|
-
}
|
package/src/child-process.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// TODO: this code is duplicated in the scripts directory, consider moving to external dependency
|
|
2
|
-
import { ChildProcess } from 'child_process';
|
|
3
|
-
|
|
4
|
-
export class ChildProcessError extends Error {
|
|
5
|
-
public readonly name = 'ChildProcessError';
|
|
6
|
-
|
|
7
|
-
constructor(message: string, public readonly code: number | null, public readonly signal: NodeJS.Signals | null) {
|
|
8
|
-
super(message);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface WaitOptions {
|
|
13
|
-
validReturnCodes: number[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function waitOnChild(child: ChildProcess, opts?: WaitOptions): Promise<void> {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
child.on('exit', (code, signal) => {
|
|
19
|
-
if (code !== null && (opts?.validReturnCodes ?? [0]).includes(code)) {
|
|
20
|
-
resolve();
|
|
21
|
-
} else {
|
|
22
|
-
reject(new ChildProcessError('Process failed', code, signal));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
child.on('error', reject);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function kill(child: ChildProcess, signal: NodeJS.Signals = 'SIGINT', opts?: WaitOptions): Promise<void> {
|
|
30
|
-
if (child.pid === undefined) {
|
|
31
|
-
throw new TypeError('Expected child with pid');
|
|
32
|
-
}
|
|
33
|
-
process.kill(child.pid, signal);
|
|
34
|
-
try {
|
|
35
|
-
await waitOnChild(child, opts);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
// Should error if the error is not a child process error or it is a child
|
|
38
|
-
// process and either the platform is Windows or the signal matches.
|
|
39
|
-
const shouldError = !(err instanceof ChildProcessError) || (process.platform !== 'win32' && err.signal !== signal);
|
|
40
|
-
if (shouldError) {
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function killIfExists(
|
|
47
|
-
child: ChildProcess,
|
|
48
|
-
signal: NodeJS.Signals = 'SIGINT',
|
|
49
|
-
opts?: WaitOptions
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
try {
|
|
52
|
-
await kill(child, signal, opts);
|
|
53
|
-
} catch (err: any) {
|
|
54
|
-
if (err.code !== 'ESRCH') {
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const shell = process.platform === 'win32';
|
package/src/index-for-docs.ts
DELETED