acryl 0.2.5 → 0.2.7
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 +51 -8
- package/forward.js +86 -0
- package/launcher.js +7933 -0
- package/package.json +7 -5
- package/release-contract.js +5 -1
- package/runtime.js +29 -0
- package/web-runtime.js +19 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "acryl",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin.js",
|
|
11
|
+
"forward.js",
|
|
12
|
+
"launcher.js",
|
|
11
13
|
"runtime.js",
|
|
12
14
|
"release-contract.js",
|
|
13
15
|
"web-runtime.js",
|
|
@@ -15,10 +17,10 @@
|
|
|
15
17
|
"README.md"
|
|
16
18
|
],
|
|
17
19
|
"optionalDependencies": {
|
|
18
|
-
"acryl-cli-darwin-arm64": "0.2.
|
|
19
|
-
"acryl-cli-linux-arm64": "0.2.
|
|
20
|
-
"acryl-cli-linux-x64": "0.2.
|
|
21
|
-
"acryl-cli-windows-x64": "0.2.
|
|
20
|
+
"acryl-cli-darwin-arm64": "0.2.7",
|
|
21
|
+
"acryl-cli-linux-arm64": "0.2.7",
|
|
22
|
+
"acryl-cli-linux-x64": "0.2.7",
|
|
23
|
+
"acryl-cli-windows-x64": "0.2.7"
|
|
22
24
|
},
|
|
23
25
|
"engines": {
|
|
24
26
|
"node": ">=22.19.0 || >=24.0.0"
|
package/release-contract.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync, readdirSync, statSync } from 'node:fs'
|
|
|
3
3
|
import { join, relative } from 'node:path'
|
|
4
4
|
|
|
5
5
|
export const RECEIPT_SCHEMA_VERSION = 1
|
|
6
|
+
export const RELEASE_MANIFEST_NAME = 'acryl-release-manifest.json'
|
|
6
7
|
|
|
7
8
|
// darwin-x64 is intentionally absent: GitHub's macos-14 runners are arm64 and
|
|
8
9
|
// cannot cross-compile sharp/koffi's native binaries for x64, so the CLI is
|
|
@@ -31,13 +32,16 @@ export function sha256(value) {
|
|
|
31
32
|
return createHash('sha256').update(value).digest('hex')
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** A payload file's name in the receipt: forward slashes on every platform, so a receipt made on one machine validates on another. */
|
|
36
|
+
export function payloadPath(path) { return path.replaceAll('\\', '/') }
|
|
37
|
+
|
|
34
38
|
/** Hash a prepared runtime tree in a stable, receipt-excluding form. */
|
|
35
39
|
export function payloadSha256(directory) {
|
|
36
40
|
const entries = []
|
|
37
41
|
const visit = current => {
|
|
38
42
|
for (const entry of readdirSync(current)) {
|
|
39
43
|
const absolute = join(current, entry)
|
|
40
|
-
const path = relative(directory, absolute)
|
|
44
|
+
const path = payloadPath(relative(directory, absolute))
|
|
41
45
|
if (path === 'receipt.json') continue
|
|
42
46
|
// npm strips .npmignore/.gitignore/.npmrc when packing a vendored
|
|
43
47
|
// node_modules, so exclude them from the payload hash or the installed
|
package/runtime.js
CHANGED
|
@@ -35,3 +35,32 @@ export function runtimeLauncher({ require = createRequire(import.meta.url), plat
|
|
|
35
35
|
}
|
|
36
36
|
return join(root, 'runtime', 'bin', platform === 'win32' ? 'acryl.cmd' : 'acryl')
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* How to start the CLI runtime whose launcher `runtimeLauncher` returned. Elsewhere that is the launcher itself. On Windows the launcher is a
|
|
41
|
+
* `.cmd`, which Node starts only through cmd.exe (CVE-2024-27980), where the user's arguments would be parsed again (`%`, `^`, `"`) and Ctrl-C
|
|
42
|
+
* asks "Terminate batch job (Y/N)?". So what the `.cmd` runs (apps/acryl-cli/scripts/acryl-cli-launcher.cmd) is run directly: this Node, with
|
|
43
|
+
* --expose-internals, on the runtime's lib/bin.js.
|
|
44
|
+
* @returns {{ command: string, args: string[] }}
|
|
45
|
+
*/
|
|
46
|
+
export function runtimeCommand(launcher, args, { platform = process.platform, node = process.execPath } = {}) {
|
|
47
|
+
if (platform !== 'win32') return { command: launcher, args }
|
|
48
|
+
return { command: node, args: ['--expose-internals', join(dirname(dirname(launcher)), 'lib', 'bin.js'), ...args] }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const STOP_SIGNALS = Object.freeze(['SIGINT', 'SIGTERM', 'SIGHUP'])
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pass the stop signals this process receives on to the runtime it started, and stay alive until that runtime exits. A supervisor or `kill`
|
|
55
|
+
* signals this process alone, and the runtime (the Web server, holding its port) outlived it. A terminal's Ctrl-C reaches both, so the runtime
|
|
56
|
+
* gets it twice and must take a repeated signal calmly (apps/acryl-web/src/serve.ts does). On Windows nothing is passed on: the console sends
|
|
57
|
+
* Ctrl-C to both processes itself, Node can only end a child there, not signal it, and the child is in a job that ends with this process.
|
|
58
|
+
* @returns {() => void} removes the handlers
|
|
59
|
+
*/
|
|
60
|
+
export function forwardStopSignals(child, { platform = process.platform, host = process } = {}) {
|
|
61
|
+
const forward = signal => {
|
|
62
|
+
if (platform !== 'win32' && child.exitCode === null && child.signalCode === null) child.kill(signal)
|
|
63
|
+
}
|
|
64
|
+
for (const signal of STOP_SIGNALS) host.on(signal, forward)
|
|
65
|
+
return () => { for (const signal of STOP_SIGNALS) host.off(signal, forward) }
|
|
66
|
+
}
|
package/web-runtime.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from 'node:fs'
|
|
11
11
|
import { homedir } from 'node:os'
|
|
12
12
|
import { dirname, join } from 'node:path'
|
|
13
|
+
import { RELEASE_MANIFEST_NAME } from './release-contract.js'
|
|
13
14
|
|
|
14
15
|
const RECEIPT_NAME = '.acryl-web-runtime.json'
|
|
15
16
|
const DEFAULT_RELEASE = 'https://github.com/acryldev/acryl/releases/download'
|
|
@@ -23,7 +24,7 @@ export function managedWebRoot(env = process.env) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function manifestUrl(version, env = process.env) {
|
|
26
|
-
return env.ACRYL_RELEASE_MANIFEST_URL ?? `${DEFAULT_RELEASE}/v${version}
|
|
27
|
+
return env.ACRYL_RELEASE_MANIFEST_URL ?? `${DEFAULT_RELEASE}/v${version}/${RELEASE_MANIFEST_NAME}`
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export function confirmWebAcquisition({ yes, interactive, confirm }) {
|
|
@@ -66,12 +67,26 @@ export function hasVerifiedWebRuntime(root, { version, target, sha256 }) {
|
|
|
66
67
|
} catch { return false }
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* How to start a verified Web runtime under `root`. On Windows its launcher is a `.cmd`, started by Node only through cmd.exe (see
|
|
72
|
+
* `runtimeCommand` in runtime.js), so what the `.cmd` runs is run directly: the runtime's own node.exe on its lib/bin.js.
|
|
73
|
+
* @returns {{ command: string, args: string[] }}
|
|
74
|
+
*/
|
|
75
|
+
export function webRuntimeCommand(root, args, { platform = process.platform } = {}) {
|
|
76
|
+
if (platform !== 'win32') return { command: join(root, 'runtime', 'bin', 'acryl-web'), args }
|
|
77
|
+
return { command: join(root, 'runtime', 'bin', 'node.exe'), args: [join(root, 'lib', 'bin.js'), ...args] }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Windows' own tar (bsdtar): the first `tar` on a Windows PATH is often Git's GNU tar, which reads `C:\...` as a remote host.
|
|
81
|
+
const TAR = process.platform === 'win32' ? join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'tar.exe') : 'tar'
|
|
82
|
+
|
|
69
83
|
function defaultExtract(archive, destination) {
|
|
70
|
-
execFileSync(
|
|
84
|
+
execFileSync(TAR, ['-xzf', archive, '--no-same-owner', '--no-same-permissions', '--strip-components=1', '-C', destination])
|
|
71
85
|
}
|
|
72
86
|
|
|
73
87
|
async function defaultDownload(url) {
|
|
74
|
-
|
|
88
|
+
// GitHub answers a release download with a redirect to its asset host; the archive is checked against the manifest's SHA-256 either way.
|
|
89
|
+
const response = await fetch(url, { redirect: 'follow' })
|
|
75
90
|
if (!response.ok) fail(`Web artifact download failed: ${response.status} ${response.statusText}`)
|
|
76
91
|
return Buffer.from(await response.arrayBuffer())
|
|
77
92
|
}
|
|
@@ -124,7 +139,7 @@ export async function acquireWebRuntime({
|
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
export async function fetchReleaseManifest(url = manifestUrl('unknown')) {
|
|
127
|
-
const response = await fetch(url, { redirect: '
|
|
142
|
+
const response = await fetch(url, { redirect: 'follow' })
|
|
128
143
|
if (!response.ok) fail(`release manifest lookup failed: ${response.status} ${response.statusText}`)
|
|
129
144
|
try {
|
|
130
145
|
const manifest = await response.json()
|