@trim21/personal-pi-extensions 0.0.259 → 0.0.261
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trim21/personal-pi-extensions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.261",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
|
|
6
6
|
"keywords": [
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@types/node": "^24.13.3",
|
|
39
39
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
40
40
|
"@vitest/coverage-v8": "^4.1.10",
|
|
41
|
+
"@vscode/tree-sitter-wasm": "^0.3.1",
|
|
41
42
|
"eslint": "^10.8.1",
|
|
42
43
|
"eslint-config-prettier": "10.1.8",
|
|
43
44
|
"eslint-plugin-erasable-syntax-only": "0.4.2",
|
|
@@ -79,7 +80,6 @@
|
|
|
79
80
|
},
|
|
80
81
|
"packageManager": "pnpm@11.22.0",
|
|
81
82
|
"dependencies": {
|
|
82
|
-
"tree-sitter-bash": "^0.25.1",
|
|
83
83
|
"web-tree-sitter": "^0.26.12"
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -11,12 +11,9 @@
|
|
|
11
11
|
* - opencode packages/opencode/src/tool/shell.ts(tree-sitter 命令提取)
|
|
12
12
|
*/
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
15
14
|
|
|
16
15
|
import type { Node } from "web-tree-sitter";
|
|
17
16
|
|
|
18
|
-
import { resolvePackageWasm } from "../lib/wasm.js";
|
|
19
|
-
|
|
20
17
|
/** 解析后的单个命令:命令名 + 参数 + 原文 + 嵌套命令(命令替换里的)。 */
|
|
21
18
|
export interface BashCommand {
|
|
22
19
|
name: string;
|
|
@@ -48,7 +45,12 @@ interface BashParser {
|
|
|
48
45
|
/**
|
|
49
46
|
* 延迟初始化 tree-sitter bash parser(wasm 加载开销大,只做一次)。
|
|
50
47
|
* Node 环境:主 wasm 由 web-tree-sitter 按自身路径自动加载,
|
|
51
|
-
* bash grammar 的 wasm
|
|
48
|
+
* bash grammar 的 wasm 从仓库内 vendor 的文件读入。
|
|
49
|
+
*
|
|
50
|
+
* 本文件(tree-sitter-bash.wasm)来自 @vscode/tree-sitter-wasm
|
|
51
|
+
* (devDependency,MIT):用 `pnpm up @vscode/tree-sitter-wasm` 升级后,
|
|
52
|
+
* 将 node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter-bash.wasm
|
|
53
|
+
* 覆盖回本文件即可。
|
|
52
54
|
*/
|
|
53
55
|
function createParserLoader(): () => Promise<BashParser> {
|
|
54
56
|
let parserPromise: Promise<BashParser> | undefined;
|
|
@@ -56,9 +58,7 @@ function createParserLoader(): () => Promise<BashParser> {
|
|
|
56
58
|
parserPromise ??= (async () => {
|
|
57
59
|
const { Language, Parser } = await import("web-tree-sitter");
|
|
58
60
|
await Parser.init();
|
|
59
|
-
const bashWasm = readFileSync(
|
|
60
|
-
fileURLToPath(resolvePackageWasm("tree-sitter-bash", "tree-sitter-bash.wasm")),
|
|
61
|
-
);
|
|
61
|
+
const bashWasm = readFileSync(new URL("tree-sitter-bash.wasm", import.meta.url));
|
|
62
62
|
const language = await Language.load(bashWasm);
|
|
63
63
|
const parser = new Parser();
|
|
64
64
|
parser.setLanguage(language);
|
|
Binary file
|
package/src/lib/wasm.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* wasm —— 运行时定位 npm 包内的 wasm 文件。
|
|
3
|
-
* Node ESM 下 `import.meta.resolve` 返回 file URL(受包 exports 约束)。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export function resolvePackageWasm(packageName: string, subpath: string): URL {
|
|
7
|
-
const resolved = import.meta.resolve(`${packageName}/${subpath}`);
|
|
8
|
-
return new URL(resolved);
|
|
9
|
-
}
|