@oh-my-pi/pi-natives 12.17.0 → 12.18.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/native/pi_natives.darwin-arm64.node +0 -0
- package/native/pi_natives.darwin-x64-baseline.node +0 -0
- package/native/pi_natives.darwin-x64-modern.node +0 -0
- package/native/pi_natives.linux-arm64.node +0 -0
- package/native/pi_natives.linux-x64-baseline.node +0 -0
- package/native/pi_natives.linux-x64-modern.node +0 -0
- package/native/pi_natives.win32-x64-baseline.node +0 -0
- package/native/pi_natives.win32-x64-modern.node +0 -0
- package/package.json +145 -33
- package/src/native.ts +17 -44
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@oh-my-pi/pi-natives",
|
|
3
|
-
"version": "12.17.0",
|
|
4
|
-
"description": "Native Rust functionality via N-API",
|
|
5
|
-
"keywords": ["napi", "rust", "native", "grep", "text-processing"],
|
|
6
2
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
"name": "@oh-my-pi/pi-natives",
|
|
4
|
+
"version": "12.18.0",
|
|
5
|
+
"description": "Native Rust bindings for grep, clipboard, image processing, syntax highlighting, PTY, and shell operations via N-API",
|
|
6
|
+
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
|
+
"author": "Can Bölük",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/can1357/oh-my-pi.git",
|
|
12
|
+
"directory": "packages/natives"
|
|
14
13
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/can1357/oh-my-pi/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"napi",
|
|
19
|
+
"rust",
|
|
20
|
+
"native",
|
|
21
|
+
"grep",
|
|
22
|
+
"text-processing",
|
|
23
|
+
"clipboard",
|
|
24
|
+
"image",
|
|
25
|
+
"pty",
|
|
26
|
+
"shell",
|
|
27
|
+
"syntax-highlighting"
|
|
18
28
|
],
|
|
29
|
+
"main": "./src/index.ts",
|
|
30
|
+
"types": "./src/index.ts",
|
|
19
31
|
"scripts": {
|
|
20
32
|
"build:native": "bun scripts/build-native.ts",
|
|
21
33
|
"dev:native": "bun scripts/build-native.ts --dev",
|
|
@@ -25,24 +37,124 @@
|
|
|
25
37
|
"test": "bun run build:native && bun test",
|
|
26
38
|
"bench": "bun bench/grep.ts"
|
|
27
39
|
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/can1357/oh-my-pi.git",
|
|
33
|
-
"directory": "packages/natives"
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@oh-my-pi/pi-utils": "12.18.0"
|
|
34
42
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bun": "^1.3.9"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"bun": ">=1.3.7"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"src",
|
|
51
|
+
"native",
|
|
52
|
+
"README.md"
|
|
53
|
+
],
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./src/index.ts",
|
|
57
|
+
"import": "./src/index.ts"
|
|
58
|
+
},
|
|
59
|
+
"./*": {
|
|
60
|
+
"types": "./src/*.ts",
|
|
61
|
+
"import": "./src/*.ts"
|
|
62
|
+
},
|
|
63
|
+
"./clipboard": {
|
|
64
|
+
"types": "./src/clipboard/index.ts",
|
|
65
|
+
"import": "./src/clipboard/index.ts"
|
|
66
|
+
},
|
|
67
|
+
"./clipboard/*": {
|
|
68
|
+
"types": "./src/clipboard/*.ts",
|
|
69
|
+
"import": "./src/clipboard/*.ts"
|
|
70
|
+
},
|
|
71
|
+
"./glob": {
|
|
72
|
+
"types": "./src/glob/index.ts",
|
|
73
|
+
"import": "./src/glob/index.ts"
|
|
74
|
+
},
|
|
75
|
+
"./glob/*": {
|
|
76
|
+
"types": "./src/glob/*.ts",
|
|
77
|
+
"import": "./src/glob/*.ts"
|
|
78
|
+
},
|
|
79
|
+
"./grep": {
|
|
80
|
+
"types": "./src/grep/index.ts",
|
|
81
|
+
"import": "./src/grep/index.ts"
|
|
82
|
+
},
|
|
83
|
+
"./grep/*": {
|
|
84
|
+
"types": "./src/grep/*.ts",
|
|
85
|
+
"import": "./src/grep/*.ts"
|
|
86
|
+
},
|
|
87
|
+
"./highlight": {
|
|
88
|
+
"types": "./src/highlight/index.ts",
|
|
89
|
+
"import": "./src/highlight/index.ts"
|
|
90
|
+
},
|
|
91
|
+
"./highlight/*": {
|
|
92
|
+
"types": "./src/highlight/*.ts",
|
|
93
|
+
"import": "./src/highlight/*.ts"
|
|
94
|
+
},
|
|
95
|
+
"./html": {
|
|
96
|
+
"types": "./src/html/index.ts",
|
|
97
|
+
"import": "./src/html/index.ts"
|
|
98
|
+
},
|
|
99
|
+
"./html/*": {
|
|
100
|
+
"types": "./src/html/*.ts",
|
|
101
|
+
"import": "./src/html/*.ts"
|
|
102
|
+
},
|
|
103
|
+
"./image": {
|
|
104
|
+
"types": "./src/image/index.ts",
|
|
105
|
+
"import": "./src/image/index.ts"
|
|
106
|
+
},
|
|
107
|
+
"./image/*": {
|
|
108
|
+
"types": "./src/image/*.ts",
|
|
109
|
+
"import": "./src/image/*.ts"
|
|
110
|
+
},
|
|
111
|
+
"./keys": {
|
|
112
|
+
"types": "./src/keys/index.ts",
|
|
113
|
+
"import": "./src/keys/index.ts"
|
|
114
|
+
},
|
|
115
|
+
"./keys/*": {
|
|
116
|
+
"types": "./src/keys/*.ts",
|
|
117
|
+
"import": "./src/keys/*.ts"
|
|
118
|
+
},
|
|
119
|
+
"./ps": {
|
|
120
|
+
"types": "./src/ps/index.ts",
|
|
121
|
+
"import": "./src/ps/index.ts"
|
|
122
|
+
},
|
|
123
|
+
"./ps/*": {
|
|
124
|
+
"types": "./src/ps/*.ts",
|
|
125
|
+
"import": "./src/ps/*.ts"
|
|
126
|
+
},
|
|
127
|
+
"./pty": {
|
|
128
|
+
"types": "./src/pty/index.ts",
|
|
129
|
+
"import": "./src/pty/index.ts"
|
|
130
|
+
},
|
|
131
|
+
"./pty/*": {
|
|
132
|
+
"types": "./src/pty/*.ts",
|
|
133
|
+
"import": "./src/pty/*.ts"
|
|
134
|
+
},
|
|
135
|
+
"./shell": {
|
|
136
|
+
"types": "./src/shell/index.ts",
|
|
137
|
+
"import": "./src/shell/index.ts"
|
|
138
|
+
},
|
|
139
|
+
"./shell/*": {
|
|
140
|
+
"types": "./src/shell/*.ts",
|
|
141
|
+
"import": "./src/shell/*.ts"
|
|
142
|
+
},
|
|
143
|
+
"./text": {
|
|
144
|
+
"types": "./src/text/index.ts",
|
|
145
|
+
"import": "./src/text/index.ts"
|
|
146
|
+
},
|
|
147
|
+
"./text/*": {
|
|
148
|
+
"types": "./src/text/*.ts",
|
|
149
|
+
"import": "./src/text/*.ts"
|
|
150
|
+
},
|
|
151
|
+
"./work": {
|
|
152
|
+
"types": "./src/work/index.ts",
|
|
153
|
+
"import": "./src/work/index.ts"
|
|
154
|
+
},
|
|
155
|
+
"./work/*": {
|
|
156
|
+
"types": "./src/work/*.ts",
|
|
157
|
+
"import": "./src/work/*.ts"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
48
160
|
}
|
package/src/native.ts
CHANGED
|
@@ -7,7 +7,7 @@ import * as fs from "node:fs";
|
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import * as os from "node:os";
|
|
9
9
|
import * as path from "node:path";
|
|
10
|
-
import { $env } from "@oh-my-pi/pi-utils";
|
|
10
|
+
import { $env, logger } from "@oh-my-pi/pi-utils";
|
|
11
11
|
import { getNativesDir } from "@oh-my-pi/pi-utils/dirs";
|
|
12
12
|
import packageJson from "../package.json";
|
|
13
13
|
import type { NativeBindings } from "./bindings";
|
|
@@ -27,11 +27,8 @@ import "./work/types";
|
|
|
27
27
|
|
|
28
28
|
export type { NativeBindings, TsFunc } from "./bindings";
|
|
29
29
|
|
|
30
|
-
const debugStartup = $env.PI_DEBUG_STARTUP ? (stage: string) => process.stderr.write(`[startup] ${stage}\n`) : () => {};
|
|
31
|
-
|
|
32
30
|
type CpuVariant = "modern" | "baseline";
|
|
33
31
|
const require = createRequire(import.meta.url);
|
|
34
|
-
const textDecoder = new TextDecoder();
|
|
35
32
|
const platformTag = `${process.platform}-${process.arch}`;
|
|
36
33
|
const packageVersion = (packageJson as { version: string }).version;
|
|
37
34
|
const nativeDir = path.join(import.meta.dir, "..", "native");
|
|
@@ -66,22 +63,17 @@ const releaseCandidates = isCompiledBinary ? [...compiledCandidates, ...baseRele
|
|
|
66
63
|
const candidates = $env.PI_DEV ? [...debugCandidates, ...releaseCandidates] : releaseCandidates;
|
|
67
64
|
const dedupedCandidates = [...new Set(candidates)];
|
|
68
65
|
|
|
69
|
-
function decodeOutput(output: string | ArrayBufferView | ArrayBuffer | null | undefined): string {
|
|
70
|
-
if (!output) return "";
|
|
71
|
-
if (typeof output === "string") return output;
|
|
72
|
-
if (ArrayBuffer.isView(output))
|
|
73
|
-
return textDecoder.decode(new Uint8Array(output.buffer, output.byteOffset, output.byteLength));
|
|
74
|
-
return textDecoder.decode(new Uint8Array(output));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
66
|
function runCommand(command: string, args: string[]): string | null {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
const cmdLine = `${command} '${args.join(" ")}'`;
|
|
68
|
+
return logger.time(`runCommand:${cmdLine}`, () => {
|
|
69
|
+
try {
|
|
70
|
+
const result = Bun.spawnSync([command, ...args], { stdout: "pipe", stderr: "pipe" });
|
|
71
|
+
if (result.exitCode !== 0) return null;
|
|
72
|
+
return result.stdout.toString("utf-8").trim();
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
function getVariantOverride(): CpuVariant | null {
|
|
@@ -92,56 +84,45 @@ function getVariantOverride(): CpuVariant | null {
|
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
function detectAvx2Support(): boolean {
|
|
95
|
-
debugStartup("native:detectAvx2Support:start");
|
|
96
87
|
if (process.arch !== "x64") {
|
|
97
|
-
debugStartup("native:detectAvx2Support:done");
|
|
98
88
|
return false;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
91
|
if (process.platform === "linux") {
|
|
102
92
|
try {
|
|
103
|
-
debugStartup("native:detectAvx2Support:readCpuinfo");
|
|
104
93
|
const cpuInfo = fs.readFileSync("/proc/cpuinfo", "utf8");
|
|
105
|
-
debugStartup("native:detectAvx2Support:done");
|
|
106
94
|
return /\bavx2\b/i.test(cpuInfo);
|
|
107
95
|
} catch {
|
|
108
|
-
debugStartup("native:detectAvx2Support:done");
|
|
109
96
|
return false;
|
|
110
97
|
}
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
if (process.platform === "darwin") {
|
|
114
|
-
debugStartup("native:detectAvx2Support:sysctl");
|
|
115
101
|
const leaf7 = runCommand("sysctl", ["-n", "machdep.cpu.leaf7_features"]);
|
|
116
102
|
if (leaf7 && /\bAVX2\b/i.test(leaf7)) {
|
|
117
|
-
debugStartup("native:detectAvx2Support:done");
|
|
118
103
|
return true;
|
|
119
104
|
}
|
|
120
105
|
const features = runCommand("sysctl", ["-n", "machdep.cpu.features"]);
|
|
121
|
-
debugStartup("native:detectAvx2Support:done");
|
|
122
106
|
return Boolean(features && /\bAVX2\b/i.test(features));
|
|
123
107
|
}
|
|
124
108
|
|
|
125
109
|
if (process.platform === "win32") {
|
|
126
|
-
debugStartup("native:detectAvx2Support:powershell");
|
|
127
110
|
const output = runCommand("powershell.exe", [
|
|
128
111
|
"-NoProfile",
|
|
129
112
|
"-NonInteractive",
|
|
130
113
|
"-Command",
|
|
131
114
|
"[System.Runtime.Intrinsics.X86.Avx2]::IsSupported",
|
|
132
115
|
]);
|
|
133
|
-
debugStartup("native:detectAvx2Support:done");
|
|
134
116
|
return output?.toLowerCase() === "true";
|
|
135
117
|
}
|
|
136
118
|
|
|
137
|
-
debugStartup("native:detectAvx2Support:done");
|
|
138
119
|
return false;
|
|
139
120
|
}
|
|
140
121
|
|
|
141
122
|
function resolveCpuVariant(override: CpuVariant | null): CpuVariant | null {
|
|
142
123
|
if (process.arch !== "x64") return null;
|
|
143
124
|
if (override) return override;
|
|
144
|
-
return detectAvx2Support() ? "modern" : "baseline";
|
|
125
|
+
return logger.time("native:detectAvx2Support", () => detectAvx2Support()) ? "modern" : "baseline";
|
|
145
126
|
}
|
|
146
127
|
|
|
147
128
|
function getAddonFilenames(tag: string, variant: CpuVariant | null): string[] {
|
|
@@ -169,7 +150,6 @@ function selectEmbeddedAddonFile(): { filename: string; filePath: string } | nul
|
|
|
169
150
|
return embeddedAddon.files.find(file => file.variant === "baseline") ?? null;
|
|
170
151
|
}
|
|
171
152
|
function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
172
|
-
debugStartup("native:maybeExtractEmbeddedAddon:start");
|
|
173
153
|
if (!isCompiledBinary || !embeddedAddon) return null;
|
|
174
154
|
if (embeddedAddon.platformTag !== platformTag || embeddedAddon.version !== packageVersion) return null;
|
|
175
155
|
|
|
@@ -178,7 +158,6 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
178
158
|
const targetPath = path.join(versionedDir, selectedEmbeddedFile.filename);
|
|
179
159
|
|
|
180
160
|
try {
|
|
181
|
-
debugStartup("native:maybeExtractEmbeddedAddon:mkdir");
|
|
182
161
|
fs.mkdirSync(versionedDir, { recursive: true });
|
|
183
162
|
} catch (err) {
|
|
184
163
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -186,18 +165,13 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
186
165
|
return null;
|
|
187
166
|
}
|
|
188
167
|
|
|
189
|
-
debugStartup("native:maybeExtractEmbeddedAddon:exists");
|
|
190
168
|
if (fs.existsSync(targetPath)) {
|
|
191
|
-
debugStartup("native:maybeExtractEmbeddedAddon:done");
|
|
192
169
|
return targetPath;
|
|
193
170
|
}
|
|
194
171
|
|
|
195
172
|
try {
|
|
196
|
-
debugStartup("native:maybeExtractEmbeddedAddon:read");
|
|
197
173
|
const buffer = fs.readFileSync(selectedEmbeddedFile.filePath);
|
|
198
|
-
debugStartup("native:maybeExtractEmbeddedAddon:write");
|
|
199
174
|
fs.writeFileSync(targetPath, buffer);
|
|
200
|
-
debugStartup("native:maybeExtractEmbeddedAddon:done");
|
|
201
175
|
return targetPath;
|
|
202
176
|
} catch (err) {
|
|
203
177
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -206,19 +180,18 @@ function maybeExtractEmbeddedAddon(errors: string[]): string | null {
|
|
|
206
180
|
}
|
|
207
181
|
}
|
|
208
182
|
function loadNative(): NativeBindings {
|
|
209
|
-
debugStartup("native:loadNative:start");
|
|
210
183
|
const errors: string[] = [];
|
|
211
|
-
const embeddedCandidate = maybeExtractEmbeddedAddon(errors);
|
|
184
|
+
const embeddedCandidate = logger.time("native:maybeExtractEmbeddedAddon", () => maybeExtractEmbeddedAddon(errors));
|
|
212
185
|
const runtimeCandidates = embeddedCandidate ? [embeddedCandidate, ...dedupedCandidates] : dedupedCandidates;
|
|
213
186
|
for (const candidate of runtimeCandidates) {
|
|
214
187
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
188
|
+
const bindings = logger.time(`native:loadNative:require:${path.basename(candidate)}`, () =>
|
|
189
|
+
require(candidate),
|
|
190
|
+
) as NativeBindings;
|
|
217
191
|
validateNative(bindings, candidate);
|
|
218
192
|
if ($env.PI_DEV) {
|
|
219
193
|
console.log(`Loaded native addon from ${candidate}`);
|
|
220
194
|
}
|
|
221
|
-
debugStartup("native:loadNative:done");
|
|
222
195
|
return bindings;
|
|
223
196
|
} catch (err) {
|
|
224
197
|
if ($env.PI_DEV) {
|
|
@@ -302,4 +275,4 @@ function validateNative(bindings: NativeBindings, source: string): void {
|
|
|
302
275
|
);
|
|
303
276
|
}
|
|
304
277
|
}
|
|
305
|
-
export const native = loadNative();
|
|
278
|
+
export const native = logger.time("native:loadNative", () => loadNative());
|