dirsql 0.4.12 → 0.4.13
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/dist/cli/main.js +68 -16
- package/dist/platforms.d.ts +0 -8
- package/dist/platforms.js +10 -31
- package/package.json +7 -11
- package/dist/cli/platform-key.d.ts +0 -1
- package/dist/cli/platform-key.js +0 -5
- package/dist/cli/resolve-binary.d.ts +0 -5
- package/dist/cli/resolve-binary.js +0 -25
package/dist/cli/main.js
CHANGED
|
@@ -1,23 +1,75 @@
|
|
|
1
|
-
// Launcher entry:
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
1
|
+
// Launcher entry: run the CLI in-process through the napi addon.
|
|
2
|
+
//
|
|
3
|
+
// The launcher is a transparent forwarder — every argv (including any
|
|
4
|
+
// subcommand) goes straight to the core's `runCli`, which owns subcommand
|
|
5
|
+
// dispatch and clap-rejects unknown ones. Nothing is spawned: the same
|
|
6
|
+
// `@dirsql/lib-*` addon the SDK loads carries the CLI, so a package ships one
|
|
7
|
+
// copy of the core instead of two (#739).
|
|
8
|
+
import { mainInProcess } from "bin-shim";
|
|
9
|
+
import { loadNativeCore } from "../load-native-core.js";
|
|
6
10
|
import { die } from "./die.js";
|
|
7
|
-
import { resolveBinary } from "./resolve-binary.js";
|
|
8
11
|
import { withResolvedExtensions } from "./resolve-config-extensions.js";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve `runCli` off the same addon the SDK loads.
|
|
14
|
+
*
|
|
15
|
+
* bin-shim can resolve an addon itself, but its default naming is
|
|
16
|
+
* `@{scope}/lib-{platform}-{arch}`, which cannot express the ABI suffix
|
|
17
|
+
* dirsql's packages carry (`@dirsql/lib-linux-x64-gnu`). Reusing
|
|
18
|
+
* `loadNativeCore` keeps one resolution rule for the SDK and the CLI —
|
|
19
|
+
* including its dev fallback to a locally built `dirsql.node` — so a
|
|
20
|
+
* monorepo checkout and a published install take the same path.
|
|
21
|
+
*/
|
|
22
|
+
function resolveRunCli() {
|
|
23
|
+
const core = loadNativeCore();
|
|
24
|
+
if (typeof core.runCli !== "function") {
|
|
25
|
+
throw new Error("dirsql: the native addon has no callable `runCli` export; " +
|
|
26
|
+
"it was built without the `cli` feature.");
|
|
27
|
+
}
|
|
28
|
+
return core.runCli;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Keep Ctrl-C fatal while the CLI runs in-process.
|
|
32
|
+
*
|
|
33
|
+
* The core installs tokio signal handlers for `dirsql server`, and
|
|
34
|
+
* signal-hook (which tokio uses) *chains*: it runs its own actions and then
|
|
35
|
+
* the handler installed before it. CPython installs `default_int_handler` at
|
|
36
|
+
* startup, so the pip launcher gets a terminating disposition for free —
|
|
37
|
+
* bare Node leaves `SIG_DFL`, which signal-hook does not emulate, so the
|
|
38
|
+
* signal is swallowed and the process becomes SIGKILL-only (measured: a
|
|
39
|
+
* probe ignored SIGTERM for 143 seconds).
|
|
40
|
+
*
|
|
41
|
+
* Registering a JS listener first gives signal-hook a real prior handler to
|
|
42
|
+
* chain to. This cannot be fixed after the fact: `removeAllListeners` only
|
|
43
|
+
* drops JS listeners and cannot touch a disposition installed by native
|
|
44
|
+
* code, and `unregister_signal` leaves the OS handler in place. One listener
|
|
45
|
+
* is the whole remedy — no `unsafe`, no `sigaction`.
|
|
46
|
+
*/
|
|
47
|
+
function keepSignalsFatal() {
|
|
48
|
+
// While the core is running, its own handler drives shutdown and this
|
|
49
|
+
// listener is the tail of the chain; it matters for signals arriving
|
|
50
|
+
// outside that window, where exiting is exactly right.
|
|
51
|
+
process.on("SIGINT", () => process.exit(130));
|
|
52
|
+
process.on("SIGTERM", () => process.exit(143));
|
|
53
|
+
}
|
|
9
54
|
export async function main(argv = process.argv.slice(2)) {
|
|
10
|
-
|
|
11
|
-
// Resolve any package-name extensions in a TOML config here (the
|
|
55
|
+
keepSignalsFatal();
|
|
56
|
+
// Resolve any package-name extensions in a TOML config here (the core
|
|
12
57
|
// can't) and pass them as `--extension` flags; a no-op otherwise.
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
58
|
+
const resolved = await withResolvedExtensions(argv);
|
|
59
|
+
let code;
|
|
60
|
+
try {
|
|
61
|
+
code = await mainInProcess({
|
|
62
|
+
argv: resolved,
|
|
63
|
+
binaryName: "dirsql",
|
|
64
|
+
// Resolution is ours (see `resolveRunCli`), so bin-shim never consults
|
|
65
|
+
// its own naming; `from` only satisfies the shared options type.
|
|
66
|
+
from: import.meta.url,
|
|
67
|
+
runCli: resolveRunCli(),
|
|
68
|
+
});
|
|
18
69
|
}
|
|
19
|
-
|
|
20
|
-
|
|
70
|
+
catch (e) {
|
|
71
|
+
die(e instanceof Error ? e.message : String(e), 1);
|
|
72
|
+
return;
|
|
21
73
|
}
|
|
22
|
-
process.exit(
|
|
74
|
+
process.exit(code);
|
|
23
75
|
}
|
package/dist/platforms.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ export interface Platform {
|
|
|
5
5
|
nodePlatform: NodeJS.Platform;
|
|
6
6
|
/** Node `process.arch` value for this target. */
|
|
7
7
|
nodeArch: NodeJS.Architecture;
|
|
8
|
-
/** CLI sub-package name (`@dirsql/cli-<slug>`). */
|
|
9
|
-
name: string;
|
|
10
8
|
/** napi library sub-package name (`@dirsql/lib-<slug>`). */
|
|
11
9
|
libName: string;
|
|
12
10
|
/** Wheel-style `os` constraint for the sub-package's package.json. */
|
|
@@ -15,14 +13,8 @@ export interface Platform {
|
|
|
15
13
|
cpu: string[];
|
|
16
14
|
/** libc constraint (Linux only). */
|
|
17
15
|
libc?: string[];
|
|
18
|
-
/** Archive extension cargo-dist emits for this target. */
|
|
19
|
-
ext: "tar.xz" | "zip";
|
|
20
|
-
/** Whether the binary has a `.exe` suffix on this platform. */
|
|
21
|
-
exe?: boolean;
|
|
22
16
|
}
|
|
23
17
|
export declare const PLATFORMS: readonly Platform[];
|
|
24
|
-
/** Node `${platform}-${arch}` → `@dirsql/cli-*` sub-package name. */
|
|
25
|
-
export declare function nodeTriples(): Record<string, string>;
|
|
26
18
|
/** Node `${platform}-${arch}` → `@dirsql/lib-*` napi sub-package name. */
|
|
27
19
|
export declare function libTriples(): Record<string, string>;
|
|
28
20
|
/**
|
package/dist/platforms.js
CHANGED
|
@@ -1,82 +1,61 @@
|
|
|
1
1
|
// Single source of truth for the target platforms `dirsql` publishes.
|
|
2
2
|
//
|
|
3
|
-
// Every target triple generates
|
|
3
|
+
// Every target triple generates ONE npm sub-package: `@dirsql/lib-<slug>`,
|
|
4
|
+
// holding the napi-rs `.node` addon. It backs both layers — the TypeScript
|
|
5
|
+
// SDK loads it via `loadNativeCore()`, and since #739 the `dirsql` CLI runs
|
|
6
|
+
// in-process through its `runCli` export rather than spawning a binary. The
|
|
7
|
+
// second family, `@dirsql/cli-<slug>`, shipped a redundant copy of the same
|
|
8
|
+
// core and is gone.
|
|
4
9
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// when a user runs the `dirsql` CLI.
|
|
8
|
-
// 2. `@dirsql/lib-<slug>` — holds the napi-rs `.node` addon used by the
|
|
9
|
-
// TypeScript SDK. Consumed at runtime by `loadNativeCore()` in
|
|
10
|
-
// `src/index.ts` when a user `import`s from `dirsql`.
|
|
10
|
+
// The sub-packages are `optionalDependencies` of the main `dirsql` package,
|
|
11
|
+
// so npm/pnpm install only the one matching the host's OS/arch.
|
|
11
12
|
//
|
|
12
|
-
//
|
|
13
|
-
// package
|
|
14
|
-
//
|
|
15
|
-
// `nodeTriples()` / `libTriples()` return `${process.platform}-${process.arch}`
|
|
16
|
-
// → sub-package-name maps for the respective layer.
|
|
13
|
+
// `libTriples()` returns a `${process.platform}-${process.arch}` →
|
|
14
|
+
// sub-package-name map.
|
|
17
15
|
export const PLATFORMS = [
|
|
18
16
|
{
|
|
19
17
|
triple: "x86_64-unknown-linux-gnu",
|
|
20
18
|
nodePlatform: "linux",
|
|
21
19
|
nodeArch: "x64",
|
|
22
|
-
name: "@dirsql/cli-linux-x64-gnu",
|
|
23
20
|
libName: "@dirsql/lib-linux-x64-gnu",
|
|
24
21
|
os: ["linux"],
|
|
25
22
|
cpu: ["x64"],
|
|
26
23
|
libc: ["glibc"],
|
|
27
|
-
ext: "tar.xz",
|
|
28
24
|
},
|
|
29
25
|
{
|
|
30
26
|
triple: "aarch64-unknown-linux-gnu",
|
|
31
27
|
nodePlatform: "linux",
|
|
32
28
|
nodeArch: "arm64",
|
|
33
|
-
name: "@dirsql/cli-linux-arm64-gnu",
|
|
34
29
|
libName: "@dirsql/lib-linux-arm64-gnu",
|
|
35
30
|
os: ["linux"],
|
|
36
31
|
cpu: ["arm64"],
|
|
37
32
|
libc: ["glibc"],
|
|
38
|
-
ext: "tar.xz",
|
|
39
33
|
},
|
|
40
34
|
{
|
|
41
35
|
triple: "x86_64-apple-darwin",
|
|
42
36
|
nodePlatform: "darwin",
|
|
43
37
|
nodeArch: "x64",
|
|
44
|
-
name: "@dirsql/cli-darwin-x64",
|
|
45
38
|
libName: "@dirsql/lib-darwin-x64",
|
|
46
39
|
os: ["darwin"],
|
|
47
40
|
cpu: ["x64"],
|
|
48
|
-
ext: "tar.xz",
|
|
49
41
|
},
|
|
50
42
|
{
|
|
51
43
|
triple: "aarch64-apple-darwin",
|
|
52
44
|
nodePlatform: "darwin",
|
|
53
45
|
nodeArch: "arm64",
|
|
54
|
-
name: "@dirsql/cli-darwin-arm64",
|
|
55
46
|
libName: "@dirsql/lib-darwin-arm64",
|
|
56
47
|
os: ["darwin"],
|
|
57
48
|
cpu: ["arm64"],
|
|
58
|
-
ext: "tar.xz",
|
|
59
49
|
},
|
|
60
50
|
{
|
|
61
51
|
triple: "x86_64-pc-windows-msvc",
|
|
62
52
|
nodePlatform: "win32",
|
|
63
53
|
nodeArch: "x64",
|
|
64
|
-
name: "@dirsql/cli-win32-x64-msvc",
|
|
65
54
|
libName: "@dirsql/lib-win32-x64-msvc",
|
|
66
55
|
os: ["win32"],
|
|
67
56
|
cpu: ["x64"],
|
|
68
|
-
ext: "zip",
|
|
69
|
-
exe: true,
|
|
70
57
|
},
|
|
71
58
|
];
|
|
72
|
-
/** Node `${platform}-${arch}` → `@dirsql/cli-*` sub-package name. */
|
|
73
|
-
export function nodeTriples() {
|
|
74
|
-
const out = {};
|
|
75
|
-
for (const p of PLATFORMS) {
|
|
76
|
-
out[`${p.nodePlatform}-${p.nodeArch}`] = p.name;
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
59
|
/** Node `${platform}-${arch}` → `@dirsql/lib-*` napi sub-package name. */
|
|
81
60
|
export function libTriples() {
|
|
82
61
|
const out = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"description": "Ephemeral SQL index over a local directory",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/thekevinscott/dirsql",
|
|
@@ -190,6 +190,7 @@
|
|
|
190
190
|
}
|
|
191
191
|
},
|
|
192
192
|
"dependencies": {
|
|
193
|
+
"bin-shim": "^0.2.0",
|
|
193
194
|
"smol-toml": "^1.6.1"
|
|
194
195
|
},
|
|
195
196
|
"devDependencies": {
|
|
@@ -212,15 +213,10 @@
|
|
|
212
213
|
]
|
|
213
214
|
},
|
|
214
215
|
"optionalDependencies": {
|
|
215
|
-
"@dirsql/lib-linux-x64-gnu": "0.4.
|
|
216
|
-
"@dirsql/lib-linux-arm64-gnu": "0.4.
|
|
217
|
-
"@dirsql/lib-darwin-x64": "0.4.
|
|
218
|
-
"@dirsql/lib-darwin-arm64": "0.4.
|
|
219
|
-
"@dirsql/lib-win32-x64-msvc": "0.4.
|
|
220
|
-
"@dirsql/cli-linux-x64-gnu": "0.4.12",
|
|
221
|
-
"@dirsql/cli-linux-arm64-gnu": "0.4.12",
|
|
222
|
-
"@dirsql/cli-darwin-x64": "0.4.12",
|
|
223
|
-
"@dirsql/cli-darwin-arm64": "0.4.12",
|
|
224
|
-
"@dirsql/cli-win32-x64-msvc": "0.4.12"
|
|
216
|
+
"@dirsql/lib-linux-x64-gnu": "0.4.13",
|
|
217
|
+
"@dirsql/lib-linux-arm64-gnu": "0.4.13",
|
|
218
|
+
"@dirsql/lib-darwin-x64": "0.4.13",
|
|
219
|
+
"@dirsql/lib-darwin-arm64": "0.4.13",
|
|
220
|
+
"@dirsql/lib-win32-x64-msvc": "0.4.13"
|
|
225
221
|
}
|
|
226
222
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function platformKey(): string;
|
package/dist/cli/platform-key.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** A minimal `require.resolve`-shaped function. Injectable for tests. */
|
|
2
|
-
export type Resolver = (specifier: string) => string;
|
|
3
|
-
/** Default resolver: a CJS-style `require.resolve` rooted at this ESM module. */
|
|
4
|
-
export declare function defaultResolver(): Resolver;
|
|
5
|
-
export declare function resolveBinary(key?: string, resolver?: Resolver): string;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Resolve the absolute path of the prebuilt `dirsql` binary shipped by
|
|
2
|
-
// whichever `@dirsql/cli-<triple>` optional-dependency package matched
|
|
3
|
-
// the host at `npm install` time.
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import { nodeTriples } from "../platforms.js";
|
|
6
|
-
import { die } from "./die.js";
|
|
7
|
-
import { platformKey } from "./platform-key.js";
|
|
8
|
-
/** Default resolver: a CJS-style `require.resolve` rooted at this ESM module. */
|
|
9
|
-
export function defaultResolver() {
|
|
10
|
-
return createRequire(import.meta.url).resolve;
|
|
11
|
-
}
|
|
12
|
-
export function resolveBinary(key = platformKey(), resolver = defaultResolver()) {
|
|
13
|
-
const triples = nodeTriples();
|
|
14
|
-
const pkg = triples[key];
|
|
15
|
-
if (!pkg) {
|
|
16
|
-
die(`no prebuilt binary for ${key}. Build from source with \`cargo install dirsql --features cli\`.`);
|
|
17
|
-
}
|
|
18
|
-
const bin = process.platform === "win32" ? "dirsql.exe" : "dirsql";
|
|
19
|
-
try {
|
|
20
|
-
return resolver(`${pkg}/${bin}`);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
die(`${pkg} is not installed. If you ran \`npm install --no-optional\` or \`--ignore-optional\`, re-install without that flag.`);
|
|
24
|
-
}
|
|
25
|
-
}
|