@fadhilp/lantern 0.0.0-stage → 0.4.0-bootstrap.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/bin/binary.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const { platform, arch } = process;
7
+
8
+ /** Platform directory names to try, best first. A static musl binary also runs on glibc. */
9
+ function candidates() {
10
+ const base = `${platform}-${arch}`;
11
+ if (platform === "win32") return [`${base}-msvc`];
12
+ if (platform !== "linux") return [base];
13
+ const glibc = process.report?.getReport?.().header?.glibcVersionRuntime;
14
+ return glibc ? [`${base}-gnu`, `${base}-musl`] : [`${base}-musl`];
15
+ }
16
+
17
+ // The package holds one directory per platform next to this file.
18
+ function findBinary() {
19
+ const exe = platform === "win32" ? "lantern.exe" : "lantern";
20
+ return candidates()
21
+ .map((directory) => path.join(__dirname, directory, exe))
22
+ .find((binary) => fs.existsSync(binary));
23
+ }
24
+
25
+ module.exports = { findBinary };
package/bin/lantern.js ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawnSync } = require("node:child_process");
5
+ const { findBinary } = require("./binary.js");
6
+
7
+ const binary = findBinary();
8
+ if (!binary) {
9
+ console.error(
10
+ `lantern: no prebuilt binary for ${process.platform}-${process.arch}; ` +
11
+ "install from source with `cargo install --git https://github.com/fadhilp/lantern lantern-cli`",
12
+ );
13
+ process.exit(1);
14
+ }
15
+
16
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
17
+ if (result.error) {
18
+ console.error(`lantern: ${result.error.message}`);
19
+ process.exit(1);
20
+ }
21
+ if (result.signal) {
22
+ process.kill(process.pid, result.signal);
23
+ }
24
+ process.exit(result.status ?? 1);
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ // On a global npm install, npm's `lantern` command starts Node, which then starts the binary.
4
+ // This script points the command at the binary. If it does nothing or fails, bin/lantern.js still works.
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+ const { findBinary } = require("./binary.js");
8
+
9
+ function relinkUnix(prefix, binary) {
10
+ // The binary path is a real path, so the link directory must be one too, or the relative link is wrong.
11
+ const directory = fs.realpathSync(path.join(prefix, "bin"));
12
+ const link = path.join(directory, "lantern");
13
+ if (!fs.lstatSync(link).isSymbolicLink()) return;
14
+ const replacement = `${link}.${process.pid}.tmp`;
15
+ fs.symlinkSync(path.relative(directory, fs.realpathSync(binary)), replacement);
16
+ // A rename replaces the old link in one step, so the command never goes missing.
17
+ fs.renameSync(replacement, link);
18
+ }
19
+
20
+ function rewriteWindowsShims(prefix, binary) {
21
+ if (!fs.existsSync(path.join(prefix, "lantern.cmd"))) return;
22
+ const relative = path.relative(prefix, binary);
23
+ const posixRelative = relative.replaceAll("\\", "/");
24
+ // npm reads the target back from these files to check that they belong to this package
25
+ // (read-cmd-shim), so each keeps the shape npm writes: "%~dp0\<path>" %*, "$basedir/<path>" $args,
26
+ // and "$basedir/<path>" "$@".
27
+ const shims = {
28
+ "lantern.cmd": `@ECHO off\r\n"%~dp0\\${relative}" %*\r\n`,
29
+ // A script in a pipeline gets the piped text in $input; the binary needs it on stdin.
30
+ "lantern.ps1": [
31
+ "#!/usr/bin/env pwsh",
32
+ "$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent",
33
+ `if ($MyInvocation.ExpectingInput) { $input | & "$basedir/${posixRelative}" $args } else { & "$basedir/${posixRelative}" $args }`,
34
+ "exit $LASTEXITCODE",
35
+ "",
36
+ ].join("\r\n"),
37
+ // Git Bash and MSYS run this file, not lantern.cmd. ${0%/*} avoids a dirname process, which is slow on Windows.
38
+ lantern: [
39
+ "#!/bin/sh",
40
+ 'case "$0" in */*) basedir="${0%/*}" ;; *) basedir=. ;; esac',
41
+ `exec "$basedir/${posixRelative}" "$@"`,
42
+ "",
43
+ ].join("\n"),
44
+ };
45
+ for (const [name, content] of Object.entries(shims)) {
46
+ fs.writeFileSync(path.join(prefix, name), content);
47
+ }
48
+ }
49
+
50
+ const prefix = process.env.npm_config_global_prefix;
51
+ const binary = findBinary();
52
+ const globalNpmInstall = process.env.npm_config_global === "true" && Boolean(prefix);
53
+
54
+ if (globalNpmInstall && binary) {
55
+ try {
56
+ if (process.platform === "win32") rewriteWindowsShims(prefix, binary);
57
+ else relinkUnix(prefix, binary);
58
+ } catch (error) {
59
+ console.error(`lantern: the command will start through Node (${error.message}).`);
60
+ }
61
+ }
package/package.json CHANGED
@@ -1,6 +1,23 @@
1
- {
2
- "name": "@fadhilp/lantern",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@fadhilp/lantern",
3
+ "version": "0.4.0-bootstrap.0",
4
+ "description": "Read-only code discovery for large codebases",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/fadhilp/lantern.git"
9
+ },
10
+ "bin": {
11
+ "lantern": "bin/lantern.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "skills"
16
+ ],
17
+ "scripts": {
18
+ "postinstall": "node bin/postinstall.js"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ }
23
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.