@volcengine/tls-observer-trae 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.
Files changed (2) hide show
  1. package/dist/index.js +97 -5
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -2,11 +2,103 @@ import { homedir, hostname, networkInterfaces, userInfo } from "node:os";
2
2
  import { tlsOpenapi } from "@volcengine/openapi";
3
3
  import { createHash as external_node_crypto_createHash, randomUUID } from "node:crypto";
4
4
  import "node:url";
5
- import { execFile } from "node:child_process";
6
- import { promisify } from "node:util";
5
+ import * as __rspack_external_cross_spawn_96b24ecb from "cross-spawn";
7
6
  import * as __rspack_external_node_fs_promises_153e37e0 from "node:fs/promises";
8
7
  import * as __rspack_external_node_path_c5b9b54f from "node:path";
9
8
  import * as __rspack_external_node_fs_5ea92f0c from "node:fs";
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
+ });
10
102
  const TLS_ANONYMOUS_IDENTITY_HEADER = 'x-tls-anonymous-identity';
11
103
  const DEFAULT_FILE_NAME = 'agent-trace';
12
104
  const NO_RETRY_STATUS_CODES = [
@@ -1825,7 +1917,7 @@ async function appendBoundedJsonlFile(filePath, values, maxBytes, options = {})
1825
1917
  await pruneRotatedJsonlFiles(filePath, maxFiles);
1826
1918
  });
1827
1919
  }
1828
- const execFileAsync = promisify(execFile);
1920
+ const cross_platform_spawn = __webpack_require__("../tls-observer-shared/src/cross-platform-spawn.cjs");
1829
1921
  const REQUIRED_CFS_ENV = [
1830
1922
  'CFS_TOKEN',
1831
1923
  'CFS_IPC_NAME'
@@ -1880,8 +1972,8 @@ function errorMessage(error) {
1880
1972
  return error instanceof Error ? error.message : String(error);
1881
1973
  }
1882
1974
  async function ctxCli(config, args, env) {
1883
- const { stdout } = await execFileAsync(config.ctxCli, args, {
1884
- timeout: config.ctxCliTimeoutMs,
1975
+ const { stdout } = await (0, cross_platform_spawn.d)(config.ctxCli, args, {
1976
+ timeoutMs: config.ctxCliTimeoutMs,
1885
1977
  env: contextFsChildEnv(env),
1886
1978
  maxBuffer: 20971520
1887
1979
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volcengine/tls-observer-trae",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Export Trae hook telemetry to Volcengine TLS with OTLP traces.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,6 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@volcengine/openapi": "^1.36.1"
28
+ "@volcengine/openapi": "^1.36.1",
29
+ "cross-spawn": "7.0.6"
29
30
  }
30
31
  }