neoctl 0.2.22 → 0.2.24

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 (38) hide show
  1. package/dist/web/html.js +22 -3
  2. package/dist/web/html.js.map +1 -1
  3. package/dist/web/index.d.ts +24 -1
  4. package/dist/web/index.js +104 -19
  5. package/dist/web/index.js.map +1 -1
  6. package/package.json +4 -4
  7. package/scripts/copy-model-metadata.mjs +4 -4
  8. package/scripts/install-ripgrep.cjs +210 -210
  9. package/scripts/release-local.mjs +190 -190
  10. package/scripts/verify-ripgrep.cjs +87 -82
  11. package/vendor/ripgrep/darwin-arm64/COPYING +3 -3
  12. package/vendor/ripgrep/darwin-arm64/LICENSE-MIT +21 -21
  13. package/vendor/ripgrep/darwin-arm64/UNLICENSE +24 -24
  14. package/vendor/ripgrep/darwin-arm64/manifest.json +7 -7
  15. package/vendor/ripgrep/darwin-arm64/rg +0 -0
  16. package/vendor/ripgrep/darwin-x64/COPYING +3 -3
  17. package/vendor/ripgrep/darwin-x64/LICENSE-MIT +21 -21
  18. package/vendor/ripgrep/darwin-x64/UNLICENSE +24 -24
  19. package/vendor/ripgrep/darwin-x64/manifest.json +7 -7
  20. package/vendor/ripgrep/darwin-x64/rg +0 -0
  21. package/vendor/ripgrep/linux-arm64/COPYING +3 -3
  22. package/vendor/ripgrep/linux-arm64/LICENSE-MIT +21 -21
  23. package/vendor/ripgrep/linux-arm64/UNLICENSE +24 -24
  24. package/vendor/ripgrep/linux-arm64/manifest.json +7 -7
  25. package/vendor/ripgrep/linux-arm64/rg +0 -0
  26. package/vendor/ripgrep/linux-x64/COPYING +3 -3
  27. package/vendor/ripgrep/linux-x64/LICENSE-MIT +21 -21
  28. package/vendor/ripgrep/linux-x64/UNLICENSE +24 -24
  29. package/vendor/ripgrep/linux-x64/manifest.json +7 -7
  30. package/vendor/ripgrep/linux-x64/rg +0 -0
  31. package/vendor/ripgrep/win32-arm64/COPYING +3 -3
  32. package/vendor/ripgrep/win32-arm64/LICENSE-MIT +21 -21
  33. package/vendor/ripgrep/win32-arm64/UNLICENSE +24 -24
  34. package/vendor/ripgrep/win32-arm64/manifest.json +7 -7
  35. package/vendor/ripgrep/win32-x64/COPYING +3 -3
  36. package/vendor/ripgrep/win32-x64/LICENSE-MIT +21 -21
  37. package/vendor/ripgrep/win32-x64/UNLICENSE +24 -24
  38. package/vendor/ripgrep/win32-x64/manifest.json +7 -7
@@ -1,190 +1,190 @@
1
- #!/usr/bin/env node
2
- import { mkdtemp, rm, readFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import path from "node:path";
5
- import { spawn } from "node:child_process";
6
-
7
- const args = process.argv.slice(2);
8
-
9
- if (args.includes("--help") || args.includes("-h")) {
10
- printHelp();
11
- process.exit(0);
12
- }
13
-
14
- const dryRun = takeFlag("--dry-run") || takeFlag("-n") || isTruthy(process.env.npm_config_dry_run);
15
- const skipInstall = takeFlag("--no-install");
16
- const skipPublish = takeFlag("--no-publish");
17
- const registry = takeOption("--registry") ?? "https://registry.npmjs.org/";
18
- const tag = takeOption("--tag") ?? "latest";
19
- const positional = args.filter((arg) => !arg.startsWith("-"));
20
- const bump = positional[0] ?? "patch";
21
-
22
- const root = process.cwd();
23
- const packageJsonPath = path.join(root, "package.json");
24
- const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
25
- const packageName = packageJson.name;
26
- const currentVersion = packageJson.version;
27
- const targetVersion = resolveTargetVersion(currentVersion, bump);
28
-
29
- console.log(`[release-local] package: ${packageName}`);
30
- console.log(`[release-local] current: ${currentVersion}`);
31
- console.log(`[release-local] target: ${targetVersion}`);
32
- console.log(`[release-local] registry: ${registry}`);
33
- console.log(`[release-local] tag: ${tag}`);
34
-
35
- if (dryRun) {
36
- console.log("[release-local] dry run: version files will not be modified, package will not be published, global install will not run");
37
- await run("npm", ["pack", "--dry-run"], { cwd: root });
38
- console.log(`[release-local] dry run complete. Would publish ${packageName}@${targetVersion} and install it globally.`);
39
- process.exit(0);
40
- }
41
-
42
- await run("npm", ["version", targetVersion, "--no-git-tag-version"], { cwd: root });
43
-
44
- let userconfig;
45
- try {
46
- const token = process.env.NODE_AUTH_TOKEN || process.env.NPM_TOKEN;
47
- if (token) {
48
- userconfig = await writeTempNpmrc(registry, token);
49
- }
50
-
51
- if (!skipPublish) {
52
- const publishArgs = ["publish", "--registry", registry, "--tag", tag];
53
- if (userconfig) publishArgs.push("--userconfig", userconfig);
54
- await run("npm", publishArgs, { cwd: root });
55
- } else {
56
- console.log("[release-local] --no-publish: skipping npm publish");
57
- }
58
-
59
- if (!skipPublish) {
60
- await waitForPublishedVersion(packageName, targetVersion, registry, root);
61
- }
62
-
63
- if (!skipInstall) {
64
- await run("npm", ["install", "-g", `${packageName}@${targetVersion}`, "--registry", registry], { cwd: root });
65
- } else {
66
- console.log("[release-local] --no-install: skipping global install");
67
- }
68
-
69
- if (!skipPublish) {
70
- await run("npm", ["view", packageName, "version", "dist-tags", "--registry", registry], { cwd: root });
71
- }
72
- if (!skipInstall) {
73
- await run("npm", ["list", "-g", packageName, "--depth=0"], { cwd: root });
74
- }
75
-
76
- console.log(`[release-local] done: ${packageName}@${targetVersion}`);
77
- } finally {
78
- if (userconfig) await rm(userconfig, { force: true }).catch(() => undefined);
79
- }
80
-
81
- function takeFlag(name) {
82
- const index = args.indexOf(name);
83
- if (index === -1) return false;
84
- args.splice(index, 1);
85
- return true;
86
- }
87
-
88
- function takeOption(name) {
89
- const equalsIndex = args.findIndex((arg) => arg.startsWith(`${name}=`));
90
- if (equalsIndex !== -1) {
91
- const value = args[equalsIndex].slice(name.length + 1);
92
- args.splice(equalsIndex, 1);
93
- return value;
94
- }
95
- const index = args.indexOf(name);
96
- if (index === -1) return undefined;
97
- const value = args[index + 1];
98
- if (!value || value.startsWith("-")) throw new Error(`Missing value for ${name}`);
99
- args.splice(index, 2);
100
- return value;
101
- }
102
-
103
- function isTruthy(value) {
104
- return value === "true" || value === "1" || value === "yes";
105
- }
106
-
107
- function resolveTargetVersion(currentVersion, bump) {
108
- if (/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(bump)) return bump;
109
- const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(currentVersion);
110
- if (!match) throw new Error(`Cannot bump non-standard version: ${currentVersion}`);
111
- const major = Number(match[1]);
112
- const minor = Number(match[2]);
113
- const patch = Number(match[3]);
114
- if (bump === "patch") return `${major}.${minor}.${patch + 1}`;
115
- if (bump === "minor") return `${major}.${minor + 1}.0`;
116
- if (bump === "major") return `${major + 1}.0.0`;
117
- throw new Error(`Unknown bump/version '${bump}'. Use patch, minor, major, or an explicit x.y.z version.`);
118
- }
119
-
120
- async function writeTempNpmrc(registry, token) {
121
- const dir = await mkdtemp(path.join(tmpdir(), "neoctl-release-"));
122
- const file = path.join(dir, ".npmrc");
123
- const registryUrl = new URL(registry);
124
- const fs = await import("node:fs/promises");
125
- await fs.writeFile(file, `//${registryUrl.host}/:_authToken=${token}\nregistry=${registry}\n`, "utf8");
126
- return file;
127
- }
128
-
129
- async function waitForPublishedVersion(packageName, targetVersion, registry, cwd) {
130
- const deadline = Date.now() + 180_000;
131
- console.log(`[release-local] waiting for ${packageName}@${targetVersion} to be visible on ${registry}`);
132
- while (Date.now() < deadline) {
133
- const result = await runCapture("npm", ["view", packageName, "version", "--registry", registry], { cwd });
134
- const version = result.stdout.trim();
135
- if (result.code === 0 && version === targetVersion) {
136
- console.log(`[release-local] registry version visible: ${version}`);
137
- return;
138
- }
139
- console.log(`[release-local] registry version is ${version || "unavailable"}; retrying...`);
140
- await delay(5_000);
141
- }
142
- throw new Error(`Timed out waiting for ${packageName}@${targetVersion} to be visible on ${registry}`);
143
- }
144
-
145
- function delay(ms) {
146
- return new Promise((resolve) => setTimeout(resolve, ms));
147
- }
148
-
149
- function run(command, commandArgs, options = {}) {
150
- console.log(`[release-local] $ ${command} ${commandArgs.map(quoteArg).join(" ")}`);
151
- return new Promise((resolve, reject) => {
152
- const child = spawn(command, commandArgs, {
153
- cwd: options.cwd,
154
- shell: process.platform === "win32",
155
- stdio: "inherit",
156
- env: process.env,
157
- });
158
- child.on("error", reject);
159
- child.on("exit", (code, signal) => {
160
- if (code === 0) resolve();
161
- else reject(new Error(`${command} exited with ${signal ?? code}`));
162
- });
163
- });
164
- }
165
-
166
- function runCapture(command, commandArgs, options = {}) {
167
- console.log(`[release-local] $ ${command} ${commandArgs.map(quoteArg).join(" ")}`);
168
- return new Promise((resolve, reject) => {
169
- const child = spawn(command, commandArgs, {
170
- cwd: options.cwd,
171
- shell: process.platform === "win32",
172
- stdio: ["ignore", "pipe", "pipe"],
173
- env: process.env,
174
- });
175
- let stdout = "";
176
- let stderr = "";
177
- child.stdout.on("data", (chunk) => { stdout += String(chunk); });
178
- child.stderr.on("data", (chunk) => { stderr += String(chunk); });
179
- child.on("error", reject);
180
- child.on("exit", (code, signal) => resolve({ code: code ?? 1, signal, stdout, stderr }));
181
- });
182
- }
183
-
184
- function quoteArg(arg) {
185
- return /\s/.test(arg) ? JSON.stringify(arg) : arg;
186
- }
187
-
188
- function printHelp() {
189
- console.log(`Usage: npm run release:local -- [patch|minor|major|x.y.z] [options]\n\nPublishes a new npm version and updates the local global install to that exact version.\n\nDefault bump is patch. The script updates package.json/package-lock.json using\n'npm version <version> --no-git-tag-version', runs npm publish, then runs\n'npm install -g <name>@<version>'.\n\nOptions:\n --dry-run, -n Run npm pack --dry-run only; do not modify, publish, or install\n --registry <url> Registry to publish/install from (default: https://registry.npmjs.org/)\n --tag <tag> npm dist-tag for publish (default: latest)\n --no-publish Bump version and install, but skip npm publish\n --no-install Bump version and publish, but skip global install\n -h, --help Show this help\n\nAuth:\n Uses NODE_AUTH_TOKEN or NPM_TOKEN when set; otherwise relies on npm login.\n\nExamples:\n npm run release:local\n npm run release:local -- minor\n npm run release:local -- 0.3.0\n NODE_AUTH_TOKEN=... npm run release:local -- patch\n`);
190
- }
1
+ #!/usr/bin/env node
2
+ import { mkdtemp, rm, readFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { spawn } from "node:child_process";
6
+
7
+ const args = process.argv.slice(2);
8
+
9
+ if (args.includes("--help") || args.includes("-h")) {
10
+ printHelp();
11
+ process.exit(0);
12
+ }
13
+
14
+ const dryRun = takeFlag("--dry-run") || takeFlag("-n") || isTruthy(process.env.npm_config_dry_run);
15
+ const skipInstall = takeFlag("--no-install");
16
+ const skipPublish = takeFlag("--no-publish");
17
+ const registry = takeOption("--registry") ?? "https://registry.npmjs.org/";
18
+ const tag = takeOption("--tag") ?? "latest";
19
+ const positional = args.filter((arg) => !arg.startsWith("-"));
20
+ const bump = positional[0] ?? "patch";
21
+
22
+ const root = process.cwd();
23
+ const packageJsonPath = path.join(root, "package.json");
24
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
25
+ const packageName = packageJson.name;
26
+ const currentVersion = packageJson.version;
27
+ const targetVersion = resolveTargetVersion(currentVersion, bump);
28
+
29
+ console.log(`[release-local] package: ${packageName}`);
30
+ console.log(`[release-local] current: ${currentVersion}`);
31
+ console.log(`[release-local] target: ${targetVersion}`);
32
+ console.log(`[release-local] registry: ${registry}`);
33
+ console.log(`[release-local] tag: ${tag}`);
34
+
35
+ if (dryRun) {
36
+ console.log("[release-local] dry run: version files will not be modified, package will not be published, global install will not run");
37
+ await run("npm", ["pack", "--dry-run"], { cwd: root });
38
+ console.log(`[release-local] dry run complete. Would publish ${packageName}@${targetVersion} and install it globally.`);
39
+ process.exit(0);
40
+ }
41
+
42
+ await run("npm", ["version", targetVersion, "--no-git-tag-version"], { cwd: root });
43
+
44
+ let userconfig;
45
+ try {
46
+ const token = process.env.NODE_AUTH_TOKEN || process.env.NPM_TOKEN;
47
+ if (token) {
48
+ userconfig = await writeTempNpmrc(registry, token);
49
+ }
50
+
51
+ if (!skipPublish) {
52
+ const publishArgs = ["publish", "--registry", registry, "--tag", tag];
53
+ if (userconfig) publishArgs.push("--userconfig", userconfig);
54
+ await run("npm", publishArgs, { cwd: root });
55
+ } else {
56
+ console.log("[release-local] --no-publish: skipping npm publish");
57
+ }
58
+
59
+ if (!skipPublish) {
60
+ await waitForPublishedVersion(packageName, targetVersion, registry, root);
61
+ }
62
+
63
+ if (!skipInstall) {
64
+ await run("npm", ["install", "-g", `${packageName}@${targetVersion}`, "--registry", registry], { cwd: root });
65
+ } else {
66
+ console.log("[release-local] --no-install: skipping global install");
67
+ }
68
+
69
+ if (!skipPublish) {
70
+ await run("npm", ["view", packageName, "version", "dist-tags", "--registry", registry], { cwd: root });
71
+ }
72
+ if (!skipInstall) {
73
+ await run("npm", ["list", "-g", packageName, "--depth=0"], { cwd: root });
74
+ }
75
+
76
+ console.log(`[release-local] done: ${packageName}@${targetVersion}`);
77
+ } finally {
78
+ if (userconfig) await rm(userconfig, { force: true }).catch(() => undefined);
79
+ }
80
+
81
+ function takeFlag(name) {
82
+ const index = args.indexOf(name);
83
+ if (index === -1) return false;
84
+ args.splice(index, 1);
85
+ return true;
86
+ }
87
+
88
+ function takeOption(name) {
89
+ const equalsIndex = args.findIndex((arg) => arg.startsWith(`${name}=`));
90
+ if (equalsIndex !== -1) {
91
+ const value = args[equalsIndex].slice(name.length + 1);
92
+ args.splice(equalsIndex, 1);
93
+ return value;
94
+ }
95
+ const index = args.indexOf(name);
96
+ if (index === -1) return undefined;
97
+ const value = args[index + 1];
98
+ if (!value || value.startsWith("-")) throw new Error(`Missing value for ${name}`);
99
+ args.splice(index, 2);
100
+ return value;
101
+ }
102
+
103
+ function isTruthy(value) {
104
+ return value === "true" || value === "1" || value === "yes";
105
+ }
106
+
107
+ function resolveTargetVersion(currentVersion, bump) {
108
+ if (/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(bump)) return bump;
109
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(currentVersion);
110
+ if (!match) throw new Error(`Cannot bump non-standard version: ${currentVersion}`);
111
+ const major = Number(match[1]);
112
+ const minor = Number(match[2]);
113
+ const patch = Number(match[3]);
114
+ if (bump === "patch") return `${major}.${minor}.${patch + 1}`;
115
+ if (bump === "minor") return `${major}.${minor + 1}.0`;
116
+ if (bump === "major") return `${major + 1}.0.0`;
117
+ throw new Error(`Unknown bump/version '${bump}'. Use patch, minor, major, or an explicit x.y.z version.`);
118
+ }
119
+
120
+ async function writeTempNpmrc(registry, token) {
121
+ const dir = await mkdtemp(path.join(tmpdir(), "neoctl-release-"));
122
+ const file = path.join(dir, ".npmrc");
123
+ const registryUrl = new URL(registry);
124
+ const fs = await import("node:fs/promises");
125
+ await fs.writeFile(file, `//${registryUrl.host}/:_authToken=${token}\nregistry=${registry}\n`, "utf8");
126
+ return file;
127
+ }
128
+
129
+ async function waitForPublishedVersion(packageName, targetVersion, registry, cwd) {
130
+ const deadline = Date.now() + 180_000;
131
+ console.log(`[release-local] waiting for ${packageName}@${targetVersion} to be visible on ${registry}`);
132
+ while (Date.now() < deadline) {
133
+ const result = await runCapture("npm", ["view", packageName, "version", "--registry", registry], { cwd });
134
+ const version = result.stdout.trim();
135
+ if (result.code === 0 && version === targetVersion) {
136
+ console.log(`[release-local] registry version visible: ${version}`);
137
+ return;
138
+ }
139
+ console.log(`[release-local] registry version is ${version || "unavailable"}; retrying...`);
140
+ await delay(5_000);
141
+ }
142
+ throw new Error(`Timed out waiting for ${packageName}@${targetVersion} to be visible on ${registry}`);
143
+ }
144
+
145
+ function delay(ms) {
146
+ return new Promise((resolve) => setTimeout(resolve, ms));
147
+ }
148
+
149
+ function run(command, commandArgs, options = {}) {
150
+ console.log(`[release-local] $ ${command} ${commandArgs.map(quoteArg).join(" ")}`);
151
+ return new Promise((resolve, reject) => {
152
+ const child = spawn(command, commandArgs, {
153
+ cwd: options.cwd,
154
+ shell: process.platform === "win32",
155
+ stdio: "inherit",
156
+ env: process.env,
157
+ });
158
+ child.on("error", reject);
159
+ child.on("exit", (code, signal) => {
160
+ if (code === 0) resolve();
161
+ else reject(new Error(`${command} exited with ${signal ?? code}`));
162
+ });
163
+ });
164
+ }
165
+
166
+ function runCapture(command, commandArgs, options = {}) {
167
+ console.log(`[release-local] $ ${command} ${commandArgs.map(quoteArg).join(" ")}`);
168
+ return new Promise((resolve, reject) => {
169
+ const child = spawn(command, commandArgs, {
170
+ cwd: options.cwd,
171
+ shell: process.platform === "win32",
172
+ stdio: ["ignore", "pipe", "pipe"],
173
+ env: process.env,
174
+ });
175
+ let stdout = "";
176
+ let stderr = "";
177
+ child.stdout.on("data", (chunk) => { stdout += String(chunk); });
178
+ child.stderr.on("data", (chunk) => { stderr += String(chunk); });
179
+ child.on("error", reject);
180
+ child.on("exit", (code, signal) => resolve({ code: code ?? 1, signal, stdout, stderr }));
181
+ });
182
+ }
183
+
184
+ function quoteArg(arg) {
185
+ return /\s/.test(arg) ? JSON.stringify(arg) : arg;
186
+ }
187
+
188
+ function printHelp() {
189
+ console.log(`Usage: npm run release:local -- [patch|minor|major|x.y.z] [options]\n\nPublishes a new npm version and updates the local global install to that exact version.\n\nDefault bump is patch. The script updates package.json/package-lock.json using\n'npm version <version> --no-git-tag-version', runs npm publish, then runs\n'npm install -g <name>@<version>'.\n\nOptions:\n --dry-run, -n Run npm pack --dry-run only; do not modify, publish, or install\n --registry <url> Registry to publish/install from (default: https://registry.npmjs.org/)\n --tag <tag> npm dist-tag for publish (default: latest)\n --no-publish Bump version and install, but skip npm publish\n --no-install Bump version and publish, but skip global install\n -h, --help Show this help\n\nAuth:\n Uses NODE_AUTH_TOKEN or NPM_TOKEN when set; otherwise relies on npm login.\n\nExamples:\n npm run release:local\n npm run release:local -- minor\n npm run release:local -- 0.3.0\n NODE_AUTH_TOKEN=... npm run release:local -- patch\n`);
190
+ }
@@ -1,83 +1,88 @@
1
- #!/usr/bin/env node
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
- const { execFileSync } = require("node:child_process");
5
-
6
- const PROJECT_ROOT = path.resolve(__dirname, "..");
7
- const VENDOR_ROOT = path.join(PROJECT_ROOT, "vendor", "ripgrep");
8
- const SKIP_GIT = process.argv.includes("--skip-git");
9
- const TARGETS = [
10
- ["win32-x64", "rg.exe", "pe"],
11
- ["win32-arm64", "rg.exe", "pe"],
12
- ["linux-x64", "rg", "elf"],
13
- ["linux-arm64", "rg", "elf"],
14
- ["darwin-x64", "rg", "macho"],
15
- ["darwin-arm64", "rg", "macho"],
16
- ];
17
- const REQUIRED_SUPPORT_FILES = ["COPYING", "LICENSE-MIT", "UNLICENSE", "manifest.json"];
18
-
19
- for (const [platformKey, executable, format] of TARGETS) {
20
- const relativeFiles = [executable, ...REQUIRED_SUPPORT_FILES]
21
- .map((name) => path.join("vendor", "ripgrep", platformKey, name));
22
-
23
- for (const relativeFile of relativeFiles) {
24
- const absoluteFile = path.join(PROJECT_ROOT, relativeFile);
25
- const stat = requireFile(absoluteFile, relativeFile);
26
- if (stat.size === 0) throw new Error(`Required ripgrep resource is empty: ${relativeFile}`);
27
- if (!SKIP_GIT) assertGitTracked(relativeFile);
1
+ #!/usr/bin/env node
2
+ const fs = require("node:fs");
3
+ const path = require("node:path");
4
+ const { execFileSync } = require("node:child_process");
5
+
6
+ const PROJECT_ROOT = path.resolve(__dirname, "..");
7
+ const VENDOR_ROOT = path.join(PROJECT_ROOT, "vendor", "ripgrep");
8
+ const SKIP_GIT = process.argv.includes("--skip-git");
9
+ const TARGETS = [
10
+ ["win32-x64", "rg.exe", "pe"],
11
+ ["win32-arm64", "rg.exe", "pe"],
12
+ ["linux-x64", "rg", "elf"],
13
+ ["linux-arm64", "rg", "elf"],
14
+ ["darwin-x64", "rg", "macho"],
15
+ ["darwin-arm64", "rg", "macho"],
16
+ ];
17
+ const REQUIRED_SUPPORT_FILES = ["COPYING", "LICENSE-MIT", "UNLICENSE", "manifest.json"];
18
+
19
+ for (const [platformKey, executable, format] of TARGETS) {
20
+ const relativeFiles = [executable, ...REQUIRED_SUPPORT_FILES]
21
+ .map((name) => path.join("vendor", "ripgrep", platformKey, name));
22
+
23
+ for (const relativeFile of relativeFiles) {
24
+ const absoluteFile = path.join(PROJECT_ROOT, relativeFile);
25
+ const stat = requireFile(absoluteFile, relativeFile);
26
+ if (stat.size === 0) throw new Error(`Required ripgrep resource is empty: ${relativeFile}`);
27
+ if (!SKIP_GIT) assertGitTracked(relativeFile);
28
+ }
29
+
30
+ const executablePath = path.join(VENDOR_ROOT, platformKey, executable);
31
+ // Packages published from Windows can lose POSIX executable mode bits in the
32
+ // generated tarball. Restore them during postinstall before validating.
33
+ if (process.platform !== "win32" && format !== "pe" && (fs.statSync(executablePath).mode & 0o111) === 0) {
34
+ fs.chmodSync(executablePath, fs.statSync(executablePath).mode | 0o755);
35
+ if ((fs.statSync(executablePath).mode & 0o111) === 0) {
36
+ throw new Error(`Required ripgrep binary is not executable: ${path.relative(PROJECT_ROOT, executablePath)}`);
37
+ }
28
38
  }
29
-
30
- const executablePath = path.join(VENDOR_ROOT, platformKey, executable);
31
- if (format !== "pe" && (fs.statSync(executablePath).mode & 0o111) === 0) {
32
- throw new Error(`Required ripgrep binary is not executable: ${path.relative(PROJECT_ROOT, executablePath)}`);
33
- }
34
- assertBinaryFormat(executablePath, format, platformKey);
35
- const manifestPath = path.join(VENDOR_ROOT, platformKey, "manifest.json");
36
- const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
37
- if (manifest.name !== "ripgrep" || !manifest.version || !manifest.asset) {
38
- throw new Error(`Invalid ripgrep manifest: ${path.relative(PROJECT_ROOT, manifestPath)}`);
39
- }
40
- }
41
-
42
- console.error(`[ripgrep] verified ${TARGETS.length} required platform bundles${SKIP_GIT ? "" : " and Git tracking"}`);
43
-
44
- function requireFile(file, relativeFile) {
45
- try {
46
- const stat = fs.statSync(file);
47
- if (!stat.isFile()) throw new Error("not a file");
48
- return stat;
49
- } catch {
50
- throw new Error(`Missing required ripgrep resource: ${relativeFile}`);
51
- }
52
- }
53
-
54
- function assertGitTracked(relativeFile) {
55
- try {
56
- execFileSync("git", ["ls-files", "--error-unmatch", "--", relativeFile], {
57
- cwd: PROJECT_ROOT,
58
- stdio: "ignore",
59
- });
60
- } catch {
61
- throw new Error(`Required ripgrep resource is not tracked by Git: ${relativeFile}`);
62
- }
63
- }
64
-
65
- function assertBinaryFormat(file, format, platformKey) {
66
- const header = Buffer.alloc(4);
67
- const fd = fs.openSync(file, "r");
68
- try {
69
- fs.readSync(fd, header, 0, header.length, 0);
70
- } finally {
71
- fs.closeSync(fd);
72
- }
73
-
74
- const valid =
75
- (format === "pe" && header[0] === 0x4d && header[1] === 0x5a) ||
76
- (format === "elf" && header.equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))) ||
77
- (format === "macho" && (
78
- header.equals(Buffer.from([0xcf, 0xfa, 0xed, 0xfe])) ||
79
- header.equals(Buffer.from([0xfe, 0xed, 0xfa, 0xcf]))
80
- ));
81
-
82
- if (!valid) throw new Error(`Unexpected ripgrep binary format for ${platformKey}`);
83
- }
39
+ assertBinaryFormat(executablePath, format, platformKey);
40
+ const manifestPath = path.join(VENDOR_ROOT, platformKey, "manifest.json");
41
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
42
+ if (manifest.name !== "ripgrep" || !manifest.version || !manifest.asset) {
43
+ throw new Error(`Invalid ripgrep manifest: ${path.relative(PROJECT_ROOT, manifestPath)}`);
44
+ }
45
+ }
46
+
47
+ console.error(`[ripgrep] verified ${TARGETS.length} required platform bundles${SKIP_GIT ? "" : " and Git tracking"}`);
48
+
49
+ function requireFile(file, relativeFile) {
50
+ try {
51
+ const stat = fs.statSync(file);
52
+ if (!stat.isFile()) throw new Error("not a file");
53
+ return stat;
54
+ } catch {
55
+ throw new Error(`Missing required ripgrep resource: ${relativeFile}`);
56
+ }
57
+ }
58
+
59
+ function assertGitTracked(relativeFile) {
60
+ try {
61
+ execFileSync("git", ["ls-files", "--error-unmatch", "--", relativeFile], {
62
+ cwd: PROJECT_ROOT,
63
+ stdio: "ignore",
64
+ });
65
+ } catch {
66
+ throw new Error(`Required ripgrep resource is not tracked by Git: ${relativeFile}`);
67
+ }
68
+ }
69
+
70
+ function assertBinaryFormat(file, format, platformKey) {
71
+ const header = Buffer.alloc(4);
72
+ const fd = fs.openSync(file, "r");
73
+ try {
74
+ fs.readSync(fd, header, 0, header.length, 0);
75
+ } finally {
76
+ fs.closeSync(fd);
77
+ }
78
+
79
+ const valid =
80
+ (format === "pe" && header[0] === 0x4d && header[1] === 0x5a) ||
81
+ (format === "elf" && header.equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))) ||
82
+ (format === "macho" && (
83
+ header.equals(Buffer.from([0xcf, 0xfa, 0xed, 0xfe])) ||
84
+ header.equals(Buffer.from([0xfe, 0xed, 0xfa, 0xcf]))
85
+ ));
86
+
87
+ if (!valid) throw new Error(`Unexpected ripgrep binary format for ${platformKey}`);
88
+ }
@@ -1,3 +1,3 @@
1
- This project is dual-licensed under the Unlicense and MIT licenses.
2
-
3
- You may use this code under the terms of either license.
1
+ This project is dual-licensed under the Unlicense and MIT licenses.
2
+
3
+ You may use this code under the terms of either license.
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Andrew Gallant
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrew Gallant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.