@aalis/plugin-process-local 0.1.0

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @aalis/plugin-process-local
2
+
3
+ `@aalis/plugin-process-api` 的本地实现:使用 `node:child_process` 启动子进程,使用 `@aalis/plugin-storage-api` 的 `tmp:/` 根分配本地临时目录。
@@ -0,0 +1,7 @@
1
+ import type { Context, PluginModule } from '@aalis/core';
2
+ export declare const name = "@aalis/plugin-process-local";
3
+ export declare const provides: string[];
4
+ export declare function apply(ctx: Context): Promise<void>;
5
+ declare const plugin: PluginModule;
6
+ export default plugin;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMzD,eAAO,MAAM,IAAI,gCAAgC,CAAC;AAClD,eAAO,MAAM,QAAQ,UAAc,CAAC;AA0FpC,wBAAsB,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvD;AAED,QAAA,MAAM,MAAM,EAAE,YAA8B,CAAC;AAC7C,eAAe,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ // ============================================================
2
+ // @aalis/plugin-process-local — process-api 的本地实现
3
+ // ============================================================
4
+ import { spawn as nodeSpawn } from 'node:child_process';
5
+ import { readFile as fsReadFile } from 'node:fs/promises';
6
+ import { makeTempDirViaStorage } from '@aalis/plugin-process-api';
7
+ import { createStorageGateway } from '@aalis/plugin-storage-api';
8
+ export const name = '@aalis/plugin-process-local';
9
+ export const provides = ['process'];
10
+ class LocalProcessService {
11
+ storage;
12
+ constructor(storage) {
13
+ this.storage = storage;
14
+ }
15
+ spawn(cmd, args, opts = {}) {
16
+ const stdioMode = opts.stdio ?? 'pipe';
17
+ const child = nodeSpawn(cmd, [...args], {
18
+ cwd: opts.cwd,
19
+ env: { ...process.env, ...(opts.env ?? {}) },
20
+ stdio: stdioMode === 'pipe' ? ['pipe', 'pipe', 'pipe'] : stdioMode,
21
+ detached: opts.detached === true,
22
+ });
23
+ if (opts.input != null && stdioMode === 'pipe') {
24
+ try {
25
+ child.stdin?.end(opts.input);
26
+ }
27
+ catch {
28
+ /* ignore */
29
+ }
30
+ }
31
+ let timer;
32
+ if (opts.timeout && opts.timeout > 0) {
33
+ timer = setTimeout(() => {
34
+ try {
35
+ child.kill('SIGKILL');
36
+ }
37
+ catch {
38
+ /* ignore */
39
+ }
40
+ }, opts.timeout);
41
+ }
42
+ const handle = {
43
+ pid: child.pid,
44
+ stdin: child.stdin,
45
+ stdout: child.stdout,
46
+ stderr: child.stderr,
47
+ kill: signal => child.kill(signal),
48
+ unref: () => {
49
+ try {
50
+ child.unref();
51
+ }
52
+ catch {
53
+ /* ignore */
54
+ }
55
+ },
56
+ wait: () => new Promise((resolve, reject) => {
57
+ const chunksOut = [];
58
+ const chunksErr = [];
59
+ child.stdout?.on('data', d => chunksOut.push(Buffer.from(d)));
60
+ child.stderr?.on('data', d => chunksErr.push(Buffer.from(d)));
61
+ child.on('error', err => {
62
+ if (timer)
63
+ clearTimeout(timer);
64
+ reject(err);
65
+ });
66
+ child.on('close', (code, signal) => {
67
+ if (timer)
68
+ clearTimeout(timer);
69
+ resolve({
70
+ code,
71
+ signal,
72
+ stdout: Buffer.concat(chunksOut).toString('utf-8'),
73
+ stderr: Buffer.concat(chunksErr).toString('utf-8'),
74
+ });
75
+ });
76
+ }),
77
+ };
78
+ return handle;
79
+ }
80
+ async execFile(cmd, args, opts = {}) {
81
+ const handle = this.spawn(cmd, args, opts);
82
+ const res = await handle.wait();
83
+ if (res.code !== 0) {
84
+ const err = new Error(`execFile ${cmd} 退出码 ${res.code ?? 'null'}${res.signal ? ` (signal ${res.signal})` : ''}: ${res.stderr.slice(0, 200)}`);
85
+ err.result = res;
86
+ throw err;
87
+ }
88
+ return res;
89
+ }
90
+ async makeTempDir(prefix) {
91
+ return makeTempDirViaStorage(this.storage, prefix);
92
+ }
93
+ async readExternalFile(path) {
94
+ const realPath = path.startsWith('file://') ? path.slice('file://'.length) : path;
95
+ return fsReadFile(realPath);
96
+ }
97
+ }
98
+ export async function apply(ctx) {
99
+ const logger = ctx.logger.child('process-local');
100
+ const storage = createStorageGateway(ctx);
101
+ const service = new LocalProcessService(storage);
102
+ ctx.provide('process', service);
103
+ logger.info('process-local 就绪');
104
+ }
105
+ const plugin = { name, apply };
106
+ export default plugin;
107
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kDAAkD;AAClD,+DAA+D;AAE/D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,SAAS,CAAC,CAAC;AAEpC,MAAM,mBAAmB;IACM;IAA7B,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD,KAAK,CAAC,GAAW,EAAE,IAAuB,EAAE,OAAqB,EAAE;QACjE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QACvC,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE;YACtC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,GAAG,EAAE,EA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;IAChC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,MAAM,GAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7C,eAAe,MAAM,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@aalis/plugin-process-local",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "keywords": [
6
+ "aalis-plugin"
7
+ ],
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "dependencies": {
14
+ "@aalis/plugin-process-api": "^0.1.0",
15
+ "@aalis/plugin-storage-api": "^0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^22.0.0",
19
+ "typescript": "^5.7.0",
20
+ "@aalis/core": "0.1.0"
21
+ },
22
+ "peerDependencies": {
23
+ "@aalis/core": "^0.1.0"
24
+ },
25
+ "aalis": {
26
+ "service": {
27
+ "provides": [
28
+ "process"
29
+ ]
30
+ }
31
+ },
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "dev": "tsc --watch"
35
+ }
36
+ }