@kujolang/kujo-runtime 1.2.2

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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # `@kujolang/kujo-runtime`
2
+
3
+ This package installs the `kujo` command from a platform-specific optional
4
+ dependency. It performs no network access and runs no npm lifecycle scripts.
5
+
6
+ The package also exports `resolveKujoBinary()` and `getKujoRuntimeInfo()` for
7
+ tools that need to locate the native executable without starting it. Runtime
8
+ information includes the package/runtime versions, binary path, and bundled
9
+ source. TypeScript declarations are included. Typed resolution failures include
10
+ stable `code`, `platform`, and `arch` fields.
11
+
12
+ Supported targets are Linux x64/arm64, macOS x64/arm64, and Windows x64.
13
+ Installing with optional dependencies disabled omits the runtime binary;
14
+ the launcher reports that condition with remediation guidance.
package/bin/kujo.js ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { spawnSync } = require('node:child_process');
5
+ const { resolveKujoBinary } = require('..');
6
+
7
+ function fail(message) {
8
+ process.stderr.write(`kujo: ${message}\n`);
9
+ process.exitCode = 1;
10
+ }
11
+
12
+ let binaryPath;
13
+ try {
14
+ binaryPath = resolveKujoBinary();
15
+ } catch (error) {
16
+ fail(error.message);
17
+ return;
18
+ }
19
+
20
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
21
+ stdio: 'inherit',
22
+ shell: false,
23
+ windowsHide: false
24
+ });
25
+
26
+ if (result.error) {
27
+ fail(`failed to start the bundled runtime: ${result.error.message}`);
28
+ } else if (result.signal) {
29
+ process.kill(process.pid, result.signal);
30
+ } else {
31
+ process.exitCode = result.status === null ? 1 : result.status;
32
+ }
package/index.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ export type KujoRuntimeSource = 'bundled';
2
+ export type KujoRuntimePlatform = 'darwin' | 'linux' | 'win32';
3
+ export type KujoRuntimeArch = 'arm64' | 'x64';
4
+
5
+ export interface KujoRuntimeInfo {
6
+ platform: KujoRuntimePlatform;
7
+ arch: KujoRuntimeArch;
8
+ packageName: string;
9
+ packageVersion: string;
10
+ runtimeVersion: string;
11
+ binaryName: 'kujo' | 'kujo.exe';
12
+ binaryPath: string;
13
+ source: KujoRuntimeSource;
14
+ }
15
+
16
+ export interface KujoRuntimeOptions {
17
+ platform?: KujoRuntimePlatform;
18
+ arch?: KujoRuntimeArch;
19
+ }
20
+
21
+ export class KujoRuntimeError extends Error {
22
+ readonly code: string;
23
+ readonly platform: string;
24
+ readonly arch: string;
25
+ }
26
+
27
+ export class UnsupportedPlatformError extends KujoRuntimeError {}
28
+
29
+ export class MissingPlatformPackageError extends KujoRuntimeError {
30
+ readonly packageName: string;
31
+ }
32
+
33
+ export class BinaryNotFoundError extends KujoRuntimeError {
34
+ readonly packageName: string;
35
+ readonly binaryPath: string;
36
+ }
37
+
38
+ export function getKujoRuntimeInfo(options?: KujoRuntimeOptions): KujoRuntimeInfo;
39
+ export function resolveKujoBinary(options?: KujoRuntimeOptions): string;
package/index.js ADDED
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const RUNTIME_PACKAGE_VERSION = require('./package.json').version;
6
+
7
+ const TARGETS = Object.freeze({
8
+ 'darwin-arm64': Object.freeze({
9
+ packageName: '@kujolang/kujo-darwin-arm64',
10
+ binaryName: 'kujo'
11
+ }),
12
+ 'darwin-x64': Object.freeze({
13
+ packageName: '@kujolang/kujo-darwin-x64',
14
+ binaryName: 'kujo'
15
+ }),
16
+ 'linux-x64': Object.freeze({
17
+ packageName: '@kujolang/kujo-linux-x64',
18
+ binaryName: 'kujo'
19
+ }),
20
+ 'linux-arm64': Object.freeze({
21
+ packageName: '@kujolang/kujo-linux-arm64',
22
+ binaryName: 'kujo'
23
+ }),
24
+ 'win32-x64': Object.freeze({
25
+ packageName: '@kujolang/kujo-win32-x64',
26
+ binaryName: 'kujo.exe'
27
+ })
28
+ });
29
+
30
+ function targetFor(platform = process.platform, arch = process.arch) {
31
+ return TARGETS[`${platform}-${arch}`] || null;
32
+ }
33
+
34
+ class KujoRuntimeError extends Error {
35
+ constructor(message, code, platform, arch, options = {}) {
36
+ super(message, options);
37
+ this.name = this.constructor.name;
38
+ this.code = code;
39
+ this.platform = platform;
40
+ this.arch = arch;
41
+ }
42
+ }
43
+
44
+ class UnsupportedPlatformError extends KujoRuntimeError {
45
+ constructor(platform, arch) {
46
+ const supported = Object.keys(TARGETS).sort().join(', ');
47
+ super(
48
+ `Kujo does not provide an npm runtime for ${platform}-${arch}. Supported targets: ${supported}.`,
49
+ 'KUJO_UNSUPPORTED_PLATFORM',
50
+ platform,
51
+ arch
52
+ );
53
+ }
54
+ }
55
+
56
+ class MissingPlatformPackageError extends KujoRuntimeError {
57
+ constructor(platform, arch, target, cause) {
58
+ super(
59
+ [
60
+ `Kujo's platform package ${target.packageName} is not installed.`,
61
+ 'Reinstall @kujolang/kujo-runtime without --omit=optional or --no-optional,',
62
+ 'and ensure your package manager is allowed to install optional dependencies.'
63
+ ].join(' '),
64
+ 'KUJO_PLATFORM_PACKAGE_MISSING',
65
+ platform,
66
+ arch,
67
+ { cause }
68
+ );
69
+ this.packageName = target.packageName;
70
+ }
71
+ }
72
+
73
+ class BinaryNotFoundError extends KujoRuntimeError {
74
+ constructor(platform, arch, packageName, binaryPath) {
75
+ super(
76
+ `Kujo's platform package ${packageName} does not contain the expected binary at ${binaryPath}. Reinstall the package and verify your npm cache.`,
77
+ 'KUJO_BINARY_MISSING',
78
+ platform,
79
+ arch
80
+ );
81
+ this.packageName = packageName;
82
+ this.binaryPath = binaryPath;
83
+ }
84
+ }
85
+
86
+ function selectedTarget(options = {}) {
87
+ const platform = options.platform || process.platform;
88
+ const arch = options.arch || process.arch;
89
+ const target = targetFor(platform, arch);
90
+
91
+ if (!target) {
92
+ throw new UnsupportedPlatformError(platform, arch);
93
+ }
94
+
95
+ return { platform, arch, ...target };
96
+ }
97
+
98
+ function resolveRuntime(options = {}) {
99
+ const { platform, arch, packageName, binaryName } = selectedTarget(options);
100
+ const resolvePackage = options.resolvePackage || require.resolve;
101
+ const fileExists = options.fileExists || fs.existsSync;
102
+ const readManifest = options.readManifest || ((manifestPath) => JSON.parse(fs.readFileSync(manifestPath, 'utf8')));
103
+
104
+ let manifestPath;
105
+ try {
106
+ manifestPath = resolvePackage(`${packageName}/package.json`);
107
+ } catch (error) {
108
+ throw new MissingPlatformPackageError(platform, arch, { packageName }, error);
109
+ }
110
+
111
+ const binaryPath = path.join(path.dirname(manifestPath), 'bin', binaryName);
112
+ if (!fileExists(binaryPath)) {
113
+ throw new BinaryNotFoundError(platform, arch, packageName, binaryPath);
114
+ }
115
+
116
+ const platformManifest = readManifest(manifestPath);
117
+ return Object.freeze({
118
+ platform,
119
+ arch,
120
+ packageName,
121
+ packageVersion: RUNTIME_PACKAGE_VERSION,
122
+ runtimeVersion: platformManifest.version,
123
+ binaryName,
124
+ binaryPath,
125
+ source: 'bundled'
126
+ });
127
+ }
128
+
129
+ function getKujoRuntimeInfo(options = {}) {
130
+ return resolveRuntime(options);
131
+ }
132
+
133
+ function resolveKujoBinary(options = {}) {
134
+ return resolveRuntime(options).binaryPath;
135
+ }
136
+
137
+ module.exports = {
138
+ BinaryNotFoundError,
139
+ KujoRuntimeError,
140
+ MissingPlatformPackageError,
141
+ TARGETS,
142
+ UnsupportedPlatformError,
143
+ getKujoRuntimeInfo,
144
+ resolveKujoBinary,
145
+ targetFor
146
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@kujolang/kujo-runtime",
3
+ "version": "1.2.2",
4
+ "description": "Kujo programming language runtime",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kujolang/kujo.git",
9
+ "directory": "npm/runtime"
10
+ },
11
+ "homepage": "https://github.com/kujolang/kujo",
12
+ "engines": {
13
+ "node": ">=18"
14
+ },
15
+ "bin": {
16
+ "kujo": "bin/kujo.js"
17
+ },
18
+ "main": "index.js",
19
+ "types": "index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./index.d.ts",
23
+ "require": "./index.js",
24
+ "default": "./index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "bin/kujo.js",
30
+ "index.js",
31
+ "index.d.ts",
32
+ "README.md"
33
+ ],
34
+ "optionalDependencies": {
35
+ "@kujolang/kujo-darwin-arm64": "1.2.2",
36
+ "@kujolang/kujo-darwin-x64": "1.2.2",
37
+ "@kujolang/kujo-linux-arm64": "1.2.2",
38
+ "@kujolang/kujo-linux-x64": "1.2.2",
39
+ "@kujolang/kujo-win32-x64": "1.2.2"
40
+ }
41
+ }