@dekaruntime/deka 0.0.0 → 0.53.4
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.js +53 -0
- package/launcher-core.js +150 -0
- package/package.json +32 -5
- package/README.md +0 -1
package/bin.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// @dekaruntime/deka: a thin wrapper that resolves and execs the platform
|
|
5
|
+
// binary installed via optionalDependencies. It ships both the `deka` and
|
|
6
|
+
// `dsc` commands (package.json's "bin" field points both names at this same
|
|
7
|
+
// file) -- which one to run is decided by how the file was invoked.
|
|
8
|
+
//
|
|
9
|
+
// Kept intentionally requireable-without-side-effects (guarded by the
|
|
10
|
+
// require.main check below) so tests can exercise resolveBinaryName,
|
|
11
|
+
// makeExtraEnv and main() directly.
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const core = require('./launcher-core');
|
|
15
|
+
|
|
16
|
+
function resolveBinaryName(argv1) {
|
|
17
|
+
const invokedAs = path.basename(argv1 || 'deka');
|
|
18
|
+
return invokedAs === 'dsc' ? 'dsc' : 'deka';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// When running the `deka` command, point DEKA_DSC at the dsc bundled
|
|
22
|
+
// alongside this platform's deka binary. This is belt-and-braces for
|
|
23
|
+
// find_cli_dsc() (deka check/fmt/transpile/lsp), which does consult the
|
|
24
|
+
// environment; the runtime's own find_dsc() is sibling-only and does not
|
|
25
|
+
// read DEKA_DSC, so correctness never depends on this.
|
|
26
|
+
function makeExtraEnv(binaryName) {
|
|
27
|
+
return function extraEnv(pkgDir, env) {
|
|
28
|
+
if (binaryName !== 'deka') return env;
|
|
29
|
+
const dscPath = path.join(pkgDir, 'bin', 'dsc');
|
|
30
|
+
if (!fs.existsSync(dscPath)) return env;
|
|
31
|
+
return Object.assign({}, env, { DEKA_DSC: dscPath });
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function main(argv = process.argv) {
|
|
36
|
+
const binaryName = resolveBinaryName(argv[1]);
|
|
37
|
+
return core.run({
|
|
38
|
+
family: 'deka',
|
|
39
|
+
platformPackagePrefix: '@dekaruntime/deka',
|
|
40
|
+
binaryName,
|
|
41
|
+
launcherDir: __dirname,
|
|
42
|
+
extraEnv: makeExtraEnv(binaryName),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (require.main === module) {
|
|
47
|
+
main().catch((err) => {
|
|
48
|
+
console.error(`deka: ${err.message}`);
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { resolveBinaryName, makeExtraEnv, main };
|
package/launcher-core.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Shared launcher logic for the @dekaruntime/deka and @dekaruntime/dsc
|
|
4
|
+
// wrappers. This exact file is duplicated byte-for-byte at
|
|
5
|
+
// npm/dsc/launcher-core.js -- see test/launcher-core-parity.test.js, which
|
|
6
|
+
// fails the build if the two copies drift. It is duplicated rather than
|
|
7
|
+
// imported because each package must be self-contained once published: npm
|
|
8
|
+
// only packs files inside a package's own directory, so a launcher cannot
|
|
9
|
+
// `require('../deka/launcher-core')` after install.
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const { spawn } = require('child_process');
|
|
14
|
+
|
|
15
|
+
// Platforms deka and dsc publish prebuilt binaries for today. Anything else
|
|
16
|
+
// (Windows included) gets a clear message instead of a stack trace --
|
|
17
|
+
// see https://github.com/dekaruntime/deka/issues/1092.
|
|
18
|
+
const SUPPORTED_PLATFORMS = new Set(['darwin-arm64', 'darwin-x64', 'linux-x64']);
|
|
19
|
+
|
|
20
|
+
function platformKey(platform = os.platform(), arch = os.arch()) {
|
|
21
|
+
return `${platform}-${arch}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isSupportedPlatform(key) {
|
|
25
|
+
return SUPPORTED_PLATFORMS.has(key);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function unsupportedPlatformMessage(family, key) {
|
|
29
|
+
return [
|
|
30
|
+
`${family}: unsupported platform "${key}".`,
|
|
31
|
+
'Prebuilt binaries are published for darwin-arm64, darwin-x64 and linux-x64 only.',
|
|
32
|
+
'Windows support is tracked at https://github.com/dekaruntime/deka/issues/1092.',
|
|
33
|
+
].join('\n');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Resolve the installed directory of a platform package (e.g.
|
|
37
|
+
// @dekaruntime/deka-darwin-arm64). Tries standard module resolution first --
|
|
38
|
+
// this covers both local installs and the common global-install layout,
|
|
39
|
+
// where npm links the platform package as a sibling of the launcher. Falls
|
|
40
|
+
// back to a manual check under the launcher's own node_modules, because npm
|
|
41
|
+
// sometimes nests optionalDependencies there instead (the case tana's
|
|
42
|
+
// bin.js was written to handle).
|
|
43
|
+
function resolvePlatformPackageDir(pkgName, launcherDir, overrides = {}) {
|
|
44
|
+
const resolve = overrides.resolve || require.resolve;
|
|
45
|
+
const existsSync = overrides.existsSync || fs.existsSync;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
return path.dirname(resolve(`${pkgName}/package.json`));
|
|
49
|
+
} catch {
|
|
50
|
+
// Fall through to the nesting fallback below.
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const nested = path.join(launcherDir, 'node_modules', pkgName);
|
|
54
|
+
if (existsSync(path.join(nested, 'package.json'))) {
|
|
55
|
+
return nested;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Run the resolved platform binary, forwarding argv, stdio, SIGINT/SIGTERM
|
|
62
|
+
// and the exit code. Returns a promise that resolves once the child has
|
|
63
|
+
// exited (or could not be started), after process.exitCode has been set --
|
|
64
|
+
// callers should not call process.exit() themselves, so stdio has a chance
|
|
65
|
+
// to flush.
|
|
66
|
+
function run(opts) {
|
|
67
|
+
const {
|
|
68
|
+
family,
|
|
69
|
+
platformPackagePrefix,
|
|
70
|
+
binaryName,
|
|
71
|
+
launcherDir,
|
|
72
|
+
platform,
|
|
73
|
+
arch,
|
|
74
|
+
argv = process.argv.slice(2),
|
|
75
|
+
extraEnv,
|
|
76
|
+
resolveDir,
|
|
77
|
+
} = opts;
|
|
78
|
+
|
|
79
|
+
const key = platformKey(platform, arch);
|
|
80
|
+
|
|
81
|
+
if (!isSupportedPlatform(key)) {
|
|
82
|
+
console.error(unsupportedPlatformMessage(family, key));
|
|
83
|
+
process.exitCode = 1;
|
|
84
|
+
return Promise.resolve({ code: 1, signal: null });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const pkgName = `${platformPackagePrefix}-${key}`;
|
|
88
|
+
const pkgDir = resolveDir
|
|
89
|
+
? resolveDir(pkgName, launcherDir)
|
|
90
|
+
: resolvePlatformPackageDir(pkgName, launcherDir);
|
|
91
|
+
|
|
92
|
+
if (!pkgDir) {
|
|
93
|
+
console.error(`${family}: could not locate ${pkgName}. Try reinstalling ${family}.`);
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
return Promise.resolve({ code: 1, signal: null });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const binaryPath = path.join(pkgDir, 'bin', binaryName);
|
|
99
|
+
if (!fs.existsSync(binaryPath)) {
|
|
100
|
+
console.error(`${family}: ${binaryPath} is missing. Try reinstalling ${family}.`);
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
return Promise.resolve({ code: 1, signal: null });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const env = extraEnv ? extraEnv(pkgDir, process.env) : process.env;
|
|
106
|
+
|
|
107
|
+
return new Promise((resolvePromise) => {
|
|
108
|
+
const child = spawn(binaryPath, argv, { stdio: 'inherit', env });
|
|
109
|
+
|
|
110
|
+
const forward = (signal) => {
|
|
111
|
+
child.kill(signal);
|
|
112
|
+
};
|
|
113
|
+
process.on('SIGINT', forward);
|
|
114
|
+
process.on('SIGTERM', forward);
|
|
115
|
+
|
|
116
|
+
const cleanup = () => {
|
|
117
|
+
process.removeListener('SIGINT', forward);
|
|
118
|
+
process.removeListener('SIGTERM', forward);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
child.on('error', (err) => {
|
|
122
|
+
cleanup();
|
|
123
|
+
console.error(`${family}: failed to launch ${binaryPath}: ${err.message}`);
|
|
124
|
+
process.exitCode = 1;
|
|
125
|
+
resolvePromise({ code: 1, signal: null });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
child.on('exit', (code, signal) => {
|
|
129
|
+
cleanup();
|
|
130
|
+
if (signal) {
|
|
131
|
+
// POSIX/bash convention: 128 + signal number. Deterministic and
|
|
132
|
+
// matches what a shell reports for a signal-terminated process.
|
|
133
|
+
const signalNumber = os.constants.signals[signal];
|
|
134
|
+
process.exitCode = signalNumber ? 128 + signalNumber : 1;
|
|
135
|
+
} else {
|
|
136
|
+
process.exitCode = code === null ? 1 : code;
|
|
137
|
+
}
|
|
138
|
+
resolvePromise({ code: process.exitCode, signal });
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = {
|
|
144
|
+
SUPPORTED_PLATFORMS,
|
|
145
|
+
platformKey,
|
|
146
|
+
isSupportedPlatform,
|
|
147
|
+
unsupportedPlatformMessage,
|
|
148
|
+
resolvePlatformPackageDir,
|
|
149
|
+
run,
|
|
150
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dekaruntime/deka",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.53.4",
|
|
4
|
+
"description": "deka runtime launcher. Resolves and execs the platform binary installed via optionalDependencies; ships both the deka and dsc commands.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"deka": "bin.js",
|
|
7
|
+
"dsc": "bin.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin.js",
|
|
11
|
+
"launcher-core.js"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@dekaruntime/dsc": "0.53.4"
|
|
15
|
+
},
|
|
16
|
+
"optionalDependencies": {
|
|
17
|
+
"@dekaruntime/deka-darwin-arm64": "0.53.4",
|
|
18
|
+
"@dekaruntime/deka-darwin-x64": "0.53.4",
|
|
19
|
+
"@dekaruntime/deka-linux-x64": "0.53.4"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
6
24
|
"repository": {
|
|
7
25
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/dekaruntime/create-deka-app.git"
|
|
26
|
+
"url": "git+https://github.com/dekaruntime/create-deka-app.git",
|
|
27
|
+
"directory": "npm/deka"
|
|
9
28
|
},
|
|
10
|
-
"homepage": "https://deka.gg"
|
|
29
|
+
"homepage": "https://deka.gg",
|
|
30
|
+
"bugs": "https://github.com/dekaruntime/deka/issues",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"keywords": [
|
|
33
|
+
"deka",
|
|
34
|
+
"dekascript",
|
|
35
|
+
"runtime",
|
|
36
|
+
"cli"
|
|
37
|
+
]
|
|
11
38
|
}
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Placeholder. Real contents are published by CI from dekaruntime/create-deka-app.
|