@volcengine/tls-observer-trae-install 0.0.2 → 0.0.3
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/CHANGELOG.md +7 -0
- package/dist/index.js +112 -30
- package/package.json +5 -3
- package/src/installer/installer-runner.ts +12 -22
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,12 +1,105 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { homedir, tmpdir } from "node:os";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
4
|
import promises from "node:readline/promises";
|
|
6
5
|
import { randomInt } from "node:crypto";
|
|
6
|
+
import * as __rspack_external_cross_spawn_96b24ecb from "cross-spawn";
|
|
7
7
|
import * as __rspack_external_node_fs_promises_153e37e0 from "node:fs/promises";
|
|
8
8
|
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
9
|
-
|
|
9
|
+
var __webpack_modules__ = {};
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
__webpack_require__.m = __webpack_modules__;
|
|
21
|
+
(()=>{
|
|
22
|
+
__webpack_require__.add = function(modules) {
|
|
23
|
+
Object.assign(__webpack_require__.m, modules);
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
__webpack_require__.add({
|
|
27
|
+
"cross-spawn" (module) {
|
|
28
|
+
module.exports = __rspack_external_cross_spawn_96b24ecb;
|
|
29
|
+
},
|
|
30
|
+
"../tls-observer-shared/src/cross-platform-spawn.cjs" (__unused_rspack_module, exports, __webpack_require__) {
|
|
31
|
+
const crossSpawnModule = __webpack_require__("cross-spawn");
|
|
32
|
+
const crossSpawn = crossSpawnModule.default ?? crossSpawnModule;
|
|
33
|
+
const DEFAULT_MAX_BUFFER = 1048576;
|
|
34
|
+
function outputTooLargeError(command, maxBuffer) {
|
|
35
|
+
const error = new Error(`${command} output exceeded ${maxBuffer} bytes`);
|
|
36
|
+
error.code = 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';
|
|
37
|
+
return error;
|
|
38
|
+
}
|
|
39
|
+
async function runCommand(command, args, options = {}) {
|
|
40
|
+
return new Promise((resolve, reject)=>{
|
|
41
|
+
const child = crossSpawn(command, args, {
|
|
42
|
+
cwd: options.cwd,
|
|
43
|
+
env: options.env,
|
|
44
|
+
stdio: 'inherit' === options.stdio ? 'inherit' : [
|
|
45
|
+
'ignore',
|
|
46
|
+
'pipe',
|
|
47
|
+
'pipe'
|
|
48
|
+
],
|
|
49
|
+
windowsHide: true
|
|
50
|
+
});
|
|
51
|
+
const maxBuffer = options.maxBuffer ?? DEFAULT_MAX_BUFFER;
|
|
52
|
+
let stdout = '';
|
|
53
|
+
let stderr = '';
|
|
54
|
+
let outputBytes = 0;
|
|
55
|
+
let settled = false;
|
|
56
|
+
let timer;
|
|
57
|
+
const finish = (error)=>{
|
|
58
|
+
if (settled) return;
|
|
59
|
+
settled = true;
|
|
60
|
+
if (timer) clearTimeout(timer);
|
|
61
|
+
if (error) {
|
|
62
|
+
error.stdout ??= stdout;
|
|
63
|
+
error.stderr ??= stderr;
|
|
64
|
+
reject(error);
|
|
65
|
+
} else resolve({
|
|
66
|
+
stdout,
|
|
67
|
+
stderr
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const appendOutput = (target, chunk)=>{
|
|
71
|
+
const text = String(chunk);
|
|
72
|
+
outputBytes += Buffer.byteLength(text);
|
|
73
|
+
if (outputBytes > maxBuffer) {
|
|
74
|
+
child.kill();
|
|
75
|
+
finish(outputTooLargeError(command, maxBuffer));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if ('stdout' === target) stdout += text;
|
|
79
|
+
else stderr += text;
|
|
80
|
+
};
|
|
81
|
+
child.stdout?.on('data', (chunk)=>appendOutput('stdout', chunk));
|
|
82
|
+
child.stderr?.on('data', (chunk)=>appendOutput('stderr', chunk));
|
|
83
|
+
child.once('error', finish);
|
|
84
|
+
child.once('close', (code, signal)=>{
|
|
85
|
+
if (0 === code) return void finish();
|
|
86
|
+
const detail = signal ? `signal ${signal}` : `code ${code}`;
|
|
87
|
+
const error = new Error(`${command} exited with ${detail}`);
|
|
88
|
+
error.code = code;
|
|
89
|
+
finish(error);
|
|
90
|
+
});
|
|
91
|
+
if (options.timeoutMs && options.timeoutMs > 0) timer = setTimeout(()=>{
|
|
92
|
+
child.kill();
|
|
93
|
+
const error = new Error(`${command} timed out after ${options.timeoutMs}ms`);
|
|
94
|
+
error.code = 'ETIMEDOUT';
|
|
95
|
+
finish(error);
|
|
96
|
+
}, options.timeoutMs);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.d = runCommand;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const cross_platform_spawn = __webpack_require__("../tls-observer-shared/src/cross-platform-spawn.cjs");
|
|
10
103
|
const PLUGIN_NAME = 'tls-observer-trae';
|
|
11
104
|
const PLUGIN_PACKAGE_NAME = '@volcengine/tls-observer-trae';
|
|
12
105
|
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
@@ -471,7 +564,6 @@ function pluginPackageSpec(options) {
|
|
|
471
564
|
async function installPluginPackageToTemp(options) {
|
|
472
565
|
const root = await __rspack_external_node_fs_promises_153e37e0.mkdtemp(__rspack_external_node_path_c5b9b54f.join(tmpdir(), 'tls-observer-trae-plugin-'));
|
|
473
566
|
const packageSpec = pluginPackageSpec(options);
|
|
474
|
-
const npm = 'win32' === process.platform ? 'npm.cmd' : 'npm';
|
|
475
567
|
const args = [
|
|
476
568
|
'install',
|
|
477
569
|
'--prefix',
|
|
@@ -484,8 +576,8 @@ async function installPluginPackageToTemp(options) {
|
|
|
484
576
|
options.registry,
|
|
485
577
|
packageSpec
|
|
486
578
|
];
|
|
487
|
-
await
|
|
488
|
-
|
|
579
|
+
await (0, cross_platform_spawn.d)('npm', args, {
|
|
580
|
+
timeoutMs: 120000
|
|
489
581
|
});
|
|
490
582
|
const source = pluginPackagePath(root, options.pluginPackage);
|
|
491
583
|
await assertPluginRuntime(source);
|
|
@@ -535,28 +627,18 @@ async function installPlugin(options) {
|
|
|
535
627
|
])await __rspack_external_node_fs_promises_153e37e0.cp(__rspack_external_node_path_c5b9b54f.join(source, entry), __rspack_external_node_path_c5b9b54f.join(options.pluginTarget, entry), {
|
|
536
628
|
recursive: true
|
|
537
629
|
});
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const timer = setTimeout(()=>{
|
|
551
|
-
child.kill();
|
|
552
|
-
reject(new Error('npm install timed out after 120s'));
|
|
553
|
-
}, 120000);
|
|
554
|
-
child.on('exit', (code)=>{
|
|
555
|
-
clearTimeout(timer);
|
|
556
|
-
if (0 === code) resolve();
|
|
557
|
-
else reject(new Error(`npm install exited with code ${code}`));
|
|
558
|
-
});
|
|
559
|
-
child.on('error', reject);
|
|
630
|
+
await (0, cross_platform_spawn.d)('npm', [
|
|
631
|
+
'install',
|
|
632
|
+
'--omit=dev',
|
|
633
|
+
"--ignore-scripts",
|
|
634
|
+
'--no-audit',
|
|
635
|
+
'--no-fund',
|
|
636
|
+
'--registry',
|
|
637
|
+
options.registry
|
|
638
|
+
], {
|
|
639
|
+
cwd: options.pluginTarget,
|
|
640
|
+
stdio: 'inherit',
|
|
641
|
+
timeoutMs: 120000
|
|
560
642
|
});
|
|
561
643
|
if (tempInstall) await __rspack_external_node_fs_promises_153e37e0.rm(tempInstall.root, {
|
|
562
644
|
recursive: true,
|
|
@@ -688,10 +770,10 @@ async function runHealthCheck(options) {
|
|
|
688
770
|
cfs_transport: process.env.CFS_TRANSPORT || 'ipc'
|
|
689
771
|
};
|
|
690
772
|
try {
|
|
691
|
-
await
|
|
773
|
+
await (0, cross_platform_spawn.d)('ctx-cli', [
|
|
692
774
|
'--help'
|
|
693
775
|
], {
|
|
694
|
-
|
|
776
|
+
timeoutMs: 5000,
|
|
695
777
|
env: {
|
|
696
778
|
...process.env,
|
|
697
779
|
CFS_TRANSPORT: process.env.CFS_TRANSPORT || 'ipc'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcengine/tls-observer-trae-install",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "One-step installer for the TLS Observer Trae runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
"node": ">=18"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@volcengine/openapi": "^1.36.1"
|
|
22
|
+
"@volcengine/openapi": "^1.36.1",
|
|
23
|
+
"cross-spawn": "7.0.6"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@rslib/core": "^0.21.5",
|
|
26
27
|
"@types/node": "^25.9.3",
|
|
27
28
|
"prettier": "^3.4.2",
|
|
28
|
-
"typescript": "^6.0.3"
|
|
29
|
+
"typescript": "^6.0.3",
|
|
30
|
+
"@volcengine/tls-observer-shared": "0.0.1"
|
|
29
31
|
},
|
|
30
32
|
"publishConfig": {
|
|
31
33
|
"access": "public"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import { homedir, tmpdir } from 'node:os';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { promisify } from 'node:util';
|
|
7
6
|
import readline from 'node:readline/promises';
|
|
8
7
|
import { randomInt } from 'node:crypto';
|
|
8
|
+
import { runCommand } from '@volcengine/tls-observer-shared/cross-platform-spawn';
|
|
9
9
|
|
|
10
10
|
type AnyRecord = Record<string, any>;
|
|
11
11
|
|
|
@@ -66,7 +66,6 @@ type PluginInstallResult = {
|
|
|
66
66
|
version?: string;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
const execFileAsync = promisify(execFile);
|
|
70
69
|
const PLUGIN_NAME = 'tls-observer-trae';
|
|
71
70
|
const PLUGIN_PACKAGE_NAME = '@volcengine/tls-observer-trae';
|
|
72
71
|
const DEFAULT_REGISTRY = 'https://registry.npmjs.org';
|
|
@@ -600,7 +599,6 @@ async function installPluginPackageToTemp(options: InstallOptions): Promise<{
|
|
|
600
599
|
}> {
|
|
601
600
|
const root = await fs.mkdtemp(path.join(tmpdir(), 'tls-observer-trae-plugin-'));
|
|
602
601
|
const packageSpec = pluginPackageSpec(options);
|
|
603
|
-
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
604
602
|
const args = [
|
|
605
603
|
'install',
|
|
606
604
|
'--prefix',
|
|
@@ -613,7 +611,7 @@ async function installPluginPackageToTemp(options: InstallOptions): Promise<{
|
|
|
613
611
|
options.registry,
|
|
614
612
|
packageSpec,
|
|
615
613
|
];
|
|
616
|
-
await
|
|
614
|
+
await runCommand('npm', args, { timeoutMs: 120_000 });
|
|
617
615
|
const source = pluginPackagePath(root, options.pluginPackage);
|
|
618
616
|
await assertPluginRuntime(source);
|
|
619
617
|
return { root, source, packageSpec };
|
|
@@ -659,23 +657,15 @@ async function installPlugin(options: InstallOptions): Promise<PluginInstallResu
|
|
|
659
657
|
await fs.cp(path.join(source, entry), path.join(options.pluginTarget, entry), { recursive: true });
|
|
660
658
|
}
|
|
661
659
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
660
|
+
await runCommand(
|
|
661
|
+
'npm',
|
|
662
|
+
['install', '--omit=dev', '--ignore-scripts', '--no-audit', '--no-fund', '--registry', options.registry],
|
|
663
|
+
{
|
|
665
664
|
cwd: options.pluginTarget,
|
|
666
665
|
stdio: 'inherit',
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
reject(new Error('npm install timed out after 120s'));
|
|
671
|
-
}, 120_000);
|
|
672
|
-
child.on('exit', (code) => {
|
|
673
|
-
clearTimeout(timer);
|
|
674
|
-
if (code === 0) resolve();
|
|
675
|
-
else reject(new Error(`npm install exited with code ${code}`));
|
|
676
|
-
});
|
|
677
|
-
child.on('error', reject);
|
|
678
|
-
});
|
|
666
|
+
timeoutMs: 120_000,
|
|
667
|
+
},
|
|
668
|
+
);
|
|
679
669
|
|
|
680
670
|
if (tempInstall) await fs.rm(tempInstall.root, { recursive: true, force: true });
|
|
681
671
|
return {
|
|
@@ -811,8 +801,8 @@ async function runHealthCheck(options: InstallOptions): Promise<Record<string, u
|
|
|
811
801
|
cfs_transport: process.env.CFS_TRANSPORT || 'ipc',
|
|
812
802
|
};
|
|
813
803
|
try {
|
|
814
|
-
await
|
|
815
|
-
|
|
804
|
+
await runCommand('ctx-cli', ['--help'], {
|
|
805
|
+
timeoutMs: 5_000,
|
|
816
806
|
env: {
|
|
817
807
|
...process.env,
|
|
818
808
|
CFS_TRANSPORT: process.env.CFS_TRANSPORT || 'ipc',
|