@vilan-lang/vilan 0.18.1

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.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // npm's `bin` entry for the language server — the compiler's twin, and the
3
+ // reason resolution lives in a module both stubs share rather than in either
4
+ // of them. See ../lib/launch.js.
5
+ "use strict";
6
+
7
+ process.exitCode = require("../lib/launch.js").launch("vilan-lsp");
package/bin/vilan.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ // npm's `bin` entry for the compiler. The whole stub is one hand-off: see
3
+ // ../lib/launch.js.
4
+ //
5
+ // `process.exitCode` rather than `process.exit()`: an error message written to
6
+ // a piped stderr may still be in flight, and exiting outright would truncate
7
+ // it. Nothing else is pending — `spawnSync` has already returned.
8
+ "use strict";
9
+
10
+ process.exitCode = require("../lib/launch.js").launch("vilan");
package/lib/launch.js ADDED
@@ -0,0 +1,96 @@
1
+ // The only part of vilan that ships as JavaScript: it finds the binary npm
2
+ // installed for this machine and hands the process over to it.
3
+ //
4
+ // Deliberately not a shim (proposal/distribution.md §2 — "no shim logic beyond
5
+ // resolution"). It does not read, rewrite or interpret an argument, does not
6
+ // touch the streams, and adds no behaviour of its own: `vilan` installed from
7
+ // npm must be indistinguishable from `vilan` unpacked from a release archive,
8
+ // down to the bytes on stdout and the exit code. Every line below is either
9
+ // resolution, hand-off, or an error message for the two ways resolution can
10
+ // fail.
11
+
12
+ "use strict";
13
+
14
+ const { spawnSync } = require("node:child_process");
15
+ const os = require("node:os");
16
+
17
+ // node's own platform+arch spelling → the package carrying that build. These
18
+ // five keys are exactly the release matrix's five targets; the release
19
+ // workflow maps the rust triples onto these names, and
20
+ // crates/vilan-cli/tests/npm_stub.rs pins the two lists against each other.
21
+ const PACKAGES = {
22
+ "linux-x64": "@vilan-lang/linux-x64",
23
+ "linux-arm64": "@vilan-lang/linux-arm64",
24
+ "darwin-x64": "@vilan-lang/darwin-x64",
25
+ "darwin-arm64": "@vilan-lang/darwin-arm64",
26
+ "win32-x64": "@vilan-lang/win32-x64",
27
+ };
28
+
29
+ const RELEASES = "https://github.com/vilan-lang/vilan/releases";
30
+
31
+ // The absolute path of `name`'s executable inside this machine's platform
32
+ // package. Throws with the whole story when there is none — the two failure
33
+ // classes are genuinely different problems, so they get different messages:
34
+ // an unsupported platform can only be solved by a source build, a missing
35
+ // package by reinstalling.
36
+ function binaryPath(name) {
37
+ const key = `${process.platform}-${process.arch}`;
38
+ const packageName = PACKAGES[key];
39
+ if (packageName === undefined) {
40
+ throw new Error(
41
+ `no prebuilt binary for ${key}; see ${RELEASES}\n` +
42
+ ` prebuilt binaries exist for: ${Object.keys(PACKAGES).join(", ")}`,
43
+ );
44
+ }
45
+ const suffix = process.platform === "win32" ? ".exe" : "";
46
+ try {
47
+ // No `exports` field in the platform packages, so the subpath resolves
48
+ // directly — and require.resolve only locates the file, it never loads
49
+ // it.
50
+ return require.resolve(`${packageName}/bin/${name}${suffix}`);
51
+ } catch (error) {
52
+ if (error.code !== "MODULE_NOT_FOUND") {
53
+ throw error;
54
+ }
55
+ throw new Error(
56
+ `no prebuilt binary for ${key}: the package ${packageName} is not installed.\n` +
57
+ " It is an optional dependency of @vilan-lang/vilan — reinstall with\n" +
58
+ " `npm install -g @vilan-lang/vilan` (and without --omit=optional),\n" +
59
+ ` or take a release archive from ${RELEASES}`,
60
+ );
61
+ }
62
+ }
63
+
64
+ // Run `name` with this process's arguments and streams; answer the exit code
65
+ // the caller should exit with.
66
+ function launch(name) {
67
+ let binary;
68
+ try {
69
+ binary = binaryPath(name);
70
+ } catch (error) {
71
+ process.stderr.write(`${name}: ${error.message}\n`);
72
+ return 1;
73
+ }
74
+
75
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
76
+ if (result.error) {
77
+ process.stderr.write(`${name}: cannot run ${binary}: ${result.error.message}\n`);
78
+ return 1;
79
+ }
80
+ if (result.status !== null) {
81
+ return result.status;
82
+ }
83
+
84
+ // Killed by a signal: report it the way a shell reports a signalled child,
85
+ // 128 + the signal number, so `$?` means the same thing whether vilan was
86
+ // started through npm or directly (a Ctrl-C'd `vilan run` is the everyday
87
+ // case).
88
+ const number = os.constants.signals[result.signal];
89
+ if (number === undefined) {
90
+ process.stderr.write(`${name}: killed by ${result.signal}\n`);
91
+ return 1;
92
+ }
93
+ return 128 + number;
94
+ }
95
+
96
+ module.exports = { PACKAGES, binaryPath, launch };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@vilan-lang/vilan",
3
+ "version": "0.18.1",
4
+ "description": "The vilan toolchain — the vilan compiler and the vilan-lsp language server",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/vilan-lang/vilan"
9
+ },
10
+ "homepage": "https://vilan-lang.org/docs/",
11
+ "bugs": "https://github.com/vilan-lang/vilan/issues",
12
+ "keywords": [
13
+ "vilan",
14
+ "compiler",
15
+ "language",
16
+ "cli",
17
+ "language-server"
18
+ ],
19
+ "bin": {
20
+ "vilan": "bin/vilan.js",
21
+ "vilan-lsp": "bin/vilan-lsp.js"
22
+ },
23
+ "files": [
24
+ "bin/",
25
+ "lib/",
26
+ "LICENSE-MIT",
27
+ "LICENSE-APACHE",
28
+ "THIRD-PARTY-NOTICES.txt"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "optionalDependencies": {
34
+ "@vilan-lang/darwin-arm64": "0.18.1",
35
+ "@vilan-lang/darwin-x64": "0.18.1",
36
+ "@vilan-lang/linux-arm64": "0.18.1",
37
+ "@vilan-lang/linux-x64": "0.18.1",
38
+ "@vilan-lang/win32-x64": "0.18.1"
39
+ }
40
+ }