@exodus/stasis-core 1.0.0-beta.9 → 1.0.0-rc.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.
- package/bin/stasis-core.js +9 -98
- package/package.json +6 -2
- package/src/add.js +161 -157
- package/src/artifact-util.js +319 -221
- package/src/brotli.js +21 -6
- package/src/bundle-util.js +142 -100
- package/src/bundle.js +89 -128
- package/src/cli.js +123 -0
- package/src/config.js +74 -87
- package/src/extract.js +140 -67
- package/src/fs.js +57 -106
- package/src/hooks.js +126 -238
- package/src/host.js +9 -1
- package/src/loader.js +1 -1
- package/src/lockfile.js +58 -74
- package/src/policy.js +222 -0
- package/src/prune.js +60 -114
- package/src/shard.js +10 -25
- package/src/state-util.js +24 -9
- package/src/state.js +722 -865
- package/src/util.js +123 -172
package/bin/stasis-core.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { spawn } from 'node:child_process'
|
|
4
|
-
import { once } from 'node:events'
|
|
5
3
|
import { fileURLToPath } from 'node:url'
|
|
6
|
-
import { basename
|
|
4
|
+
import { basename } from 'node:path'
|
|
7
5
|
import { existsSync, realpathSync } from 'node:fs'
|
|
8
|
-
import { constants as osConstants } from 'node:os'
|
|
9
6
|
import assert from 'node:assert/strict'
|
|
10
|
-
import {
|
|
7
|
+
import { addCli, extractCli, parseRunOptions, pruneCli, runProgram, setRunEnv } from '../src/cli.js'
|
|
11
8
|
import pkg from '../package.json' with { type: 'json' }
|
|
12
9
|
|
|
13
10
|
const argv = [...process.argv]
|
|
@@ -21,7 +18,7 @@ assert(basename(jsname) === 'stasis-core' || pathsEqual(jsname, fileURLToPath(im
|
|
|
21
18
|
const HELP = `Usage:
|
|
22
19
|
stasis-core run --lock=(add|replace|frozen|ignore) [--bundle=(add|replace|load|frozen|ignore)] [--bundle-file=path/to/bundle.br] [--resources-bundle-file=path/to/resources.br] [--dependencies] [--child-process] [--import=module ...] [--fs=(sync|async)] [--resources=ext,ext] [--brotli-quality=0..11] path/to/file.js ...
|
|
23
20
|
stasis-core add path/to/(file|dir) ...
|
|
24
|
-
stasis-core extract [--output=path/to/dir] path/to/bundle.stasis.code.br
|
|
21
|
+
stasis-core extract [--output=path/to/dir] [--lock=(frozen|add|replace|ignore|none)] path/to/bundle.stasis.code.br
|
|
25
22
|
stasis-core prune [path/to/project]
|
|
26
23
|
stasis-core --version
|
|
27
24
|
|
|
@@ -40,12 +37,6 @@ function fail(message) {
|
|
|
40
37
|
process.exit(1)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
function setEnv(name, value) {
|
|
44
|
-
const env = process.env[name]
|
|
45
|
-
if (env && env !== value) throw new Error(`env conflict: ${name}="${env}", effective: "${value}"`)
|
|
46
|
-
process.env[name] = value === undefined ? '' : value
|
|
47
|
-
}
|
|
48
|
-
|
|
49
40
|
const command = argv.shift()
|
|
50
41
|
|
|
51
42
|
if (command === '-v' || command === '--version') {
|
|
@@ -54,95 +45,15 @@ if (command === '-v' || command === '--version') {
|
|
|
54
45
|
} else if (command === '-h' || command === '--help') {
|
|
55
46
|
usage(true)
|
|
56
47
|
} else if (command === 'run') {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'bundle-file': { type: 'string' },
|
|
61
|
-
'resources-bundle-file': { type: 'string' },
|
|
62
|
-
debug: { type: 'boolean' },
|
|
63
|
-
dependencies: { type: 'boolean' },
|
|
64
|
-
'child-process': { type: 'boolean' },
|
|
65
|
-
import: { type: 'string', multiple: true },
|
|
66
|
-
fs: { type: 'string' },
|
|
67
|
-
resources: { type: 'string' },
|
|
68
|
-
'brotli-quality': { type: 'string' },
|
|
69
|
-
}
|
|
70
|
-
const values = parseLeadingOptions(argv, options, {
|
|
71
|
-
valueFlags: ['--bundle', '--bundle-file', '--resources-bundle-file', '--lock', '--import', '--resources', '--brotli-quality'],
|
|
72
|
-
onError: fail,
|
|
73
|
-
})
|
|
74
|
-
if (argv.length === 0) fail('Nothing to run: no path to file given')
|
|
75
|
-
if (!['none', 'ignore', 'add', 'replace', 'frozen'].includes(values.lock)) fail('Error: invalid --lock value')
|
|
76
|
-
const lock = values.lock
|
|
77
|
-
const scope = values.dependencies ? 'node_modules' : 'full'
|
|
78
|
-
const bundle = values.bundle
|
|
79
|
-
const bundleFile = values['bundle-file'] ? resolve(values['bundle-file']) : ''
|
|
80
|
-
const resourcesBundleFile = values['resources-bundle-file'] ? resolve(values['resources-bundle-file']) : ''
|
|
81
|
-
const debug = values.debug ? '1' : ''
|
|
82
|
-
if (!['none', 'ignore', 'add', 'replace', 'load', 'frozen'].includes(bundle)) fail('Error: invalid --bundle value')
|
|
83
|
-
if (bundleFile && bundle === 'none') fail('Error: --bundle-file requires --bundle=(add|replace|load|frozen|ignore)')
|
|
84
|
-
if (resourcesBundleFile && (bundle === 'none' || bundle === 'ignore')) fail('Error: --resources-bundle-file requires --bundle=(add|replace|load|frozen)')
|
|
85
|
-
if (bundle === 'load' && lock !== 'frozen' && lock !== 'none' && lock !== 'ignore') fail('Error: --bundle=load is incompatible with --lock=(add|replace)')
|
|
86
|
-
if (lock === 'none' && bundle === 'none') fail('Error: stasis needs a lockfile or a bundle: set --lock or --bundle')
|
|
87
|
-
if (values.fs !== undefined && !['sync', 'async'].includes(values.fs)) fail("Error: --fs must be 'sync' or 'async'")
|
|
88
|
-
if (values.fs !== undefined && !['add', 'replace', 'load'].includes(bundle)) fail('Error: --fs requires --bundle=(add|replace|load)')
|
|
89
|
-
const captureFs = values.fs ?? ''
|
|
90
|
-
const resources = values.resources ?? ''
|
|
91
|
-
let brotliQuality
|
|
92
|
-
if (values['brotli-quality'] !== undefined) {
|
|
93
|
-
try {
|
|
94
|
-
brotliQuality = parseBrotliQuality('--brotli-quality', values['brotli-quality'])
|
|
95
|
-
} catch (cause) {
|
|
96
|
-
fail(`Error: ${cause.message}`)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const childProcess = values['child-process'] ? '1' : ''
|
|
100
|
-
// --import: extra preload module(s) passed through to the spawned node. Node resolves each
|
|
101
|
-
// against the project cwd; they ride AFTER stasis's own loader import.
|
|
102
|
-
const imports = values.import ?? []
|
|
103
|
-
if (imports.some((s) => s === '')) fail('Error: --import requires a module specifier (e.g. --import=./instrument.mjs)')
|
|
104
|
-
console.warn('[stasis-core] Running stasis with config:', { lock, scope, bundle, ...(bundleFile && { bundleFile }), ...(resourcesBundleFile && { resourcesBundleFile }), ...(childProcess && { childProcess: true }), ...(imports.length > 0 && { import: imports }), ...(values.fs && { fs: values.fs }), ...(resources && { resources }), ...(brotliQuality !== undefined && { brotliQuality }) })
|
|
105
|
-
if (debug) console.warn(`[stasis-core] Warning: stasis debug mode active`)
|
|
106
|
-
setEnv('EXODUS_STASIS_LOCK', lock)
|
|
107
|
-
setEnv('EXODUS_STASIS_SCOPE', scope)
|
|
108
|
-
setEnv('EXODUS_STASIS_BUNDLE', bundle)
|
|
109
|
-
setEnv('EXODUS_STASIS_BUNDLE_FILE', bundleFile)
|
|
110
|
-
setEnv('EXODUS_STASIS_RESOURCES_BUNDLE_FILE', resourcesBundleFile)
|
|
111
|
-
setEnv('EXODUS_STASIS_DEBUG', debug)
|
|
112
|
-
setEnv('EXODUS_STASIS_CHILD_PROCESS', childProcess)
|
|
113
|
-
setEnv('EXODUS_STASIS_FS', captureFs)
|
|
114
|
-
setEnv('EXODUS_STASIS_RESOURCES', resources)
|
|
115
|
-
// Only set when given: an unconditional setEnv('') would reject an ambient EXODUS_STASIS_BROTLI_QUALITY as a conflict.
|
|
116
|
-
if (brotliQuality !== undefined) setEnv('EXODUS_STASIS_BROTLI_QUALITY', String(brotliQuality))
|
|
117
|
-
const nodeArgs = ['--import', import.meta.resolve('../src/loader.js')]
|
|
118
|
-
// Passthrough preloads ride after the loader, so they evaluate under its hooks; their module
|
|
119
|
-
// graphs pass through uncaptured unless the app graph reaches them -- then they're promoted
|
|
120
|
-
// into the capture (see src/hooks.js).
|
|
121
|
-
for (const specifier of imports) nodeArgs.push('--import', specifier)
|
|
122
|
-
const child = spawn(process.execPath, [...nodeArgs, ...argv], { stdio: 'inherit' })
|
|
123
|
-
const [code, signal] = await once(child, 'close')
|
|
124
|
-
// code is null when the child died from a signal; report 128+signo (shell convention) instead of the implicit 0
|
|
125
|
-
process.exitCode = code ?? 128 + (osConstants.signals[signal] ?? 0)
|
|
48
|
+
const run = parseRunOptions(argv, { fail })
|
|
49
|
+
setRunEnv('stasis-core', run)
|
|
50
|
+
await runProgram(argv, { loader: import.meta.resolve('../src/loader.js'), imports: run.imports })
|
|
126
51
|
} else if (command === 'prune') {
|
|
127
|
-
|
|
128
|
-
const root = argv[0] ? resolve(argv[0]) : process.cwd()
|
|
129
|
-
const { prune } = await import('../src/prune.js')
|
|
130
|
-
const { removed, validated, minimized } = prune({ root })
|
|
131
|
-
console.warn(`[stasis-core] prune: validated ${validated.length} file(s), removed ${removed.length} file(s), minimized ${minimized.length} package.json file(s)`)
|
|
52
|
+
await pruneCli(argv, { label: 'stasis-core', fail })
|
|
132
53
|
} else if (command === 'add') {
|
|
133
|
-
|
|
134
|
-
if (argv.some((a) => a.startsWith('-'))) fail('Error: add takes no options; its targets and resource allowlist come from stasis.config.json')
|
|
135
|
-
const { addCommand } = await import('../src/add.js')
|
|
136
|
-
addCommand({ cwd: process.cwd(), entries: argv, logLabel: 'stasis-core' })
|
|
54
|
+
await addCli(argv, { label: 'stasis-core', fail })
|
|
137
55
|
} else if (command === 'extract') {
|
|
138
|
-
|
|
139
|
-
output: { type: 'string', short: 'o' },
|
|
140
|
-
}
|
|
141
|
-
const values = parseLeadingOptions(argv, options, { valueFlags: ['--output', '-o'], onError: fail })
|
|
142
|
-
if (argv.length === 0) fail('Nothing to extract: no bundle file given')
|
|
143
|
-
if (argv.length > 1) fail('Error: extract takes exactly one bundle file')
|
|
144
|
-
const { extractCommand } = await import('../src/extract.js')
|
|
145
|
-
extractCommand({ cwd: process.cwd(), bundleFile: argv[0], output: values.output, logLabel: 'stasis-core' })
|
|
56
|
+
await extractCli(argv, { label: 'stasis-core', fail })
|
|
146
57
|
} else if (command === undefined) {
|
|
147
58
|
usage()
|
|
148
59
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/stasis-core",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"description": "Zero-dependency stasis runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"./util": "./src/util.js",
|
|
18
18
|
"./brotli": "./src/brotli.js",
|
|
19
19
|
"./state-util": "./src/state-util.js",
|
|
20
|
-
"./
|
|
20
|
+
"./policy": "./src/policy.js",
|
|
21
|
+
"./prune": "./src/prune.js",
|
|
22
|
+
"./cli": "./src/cli.js"
|
|
21
23
|
},
|
|
22
24
|
"files": [
|
|
23
25
|
"bin/stasis-core.js",
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
"src/brotli.js",
|
|
27
29
|
"src/bundle.js",
|
|
28
30
|
"src/bundle-util.js",
|
|
31
|
+
"src/cli.js",
|
|
29
32
|
"src/config.js",
|
|
30
33
|
"src/extract.js",
|
|
31
34
|
"src/fs.js",
|
|
@@ -34,6 +37,7 @@
|
|
|
34
37
|
"src/loader.js",
|
|
35
38
|
"src/lockfile.js",
|
|
36
39
|
"src/package.cjs",
|
|
40
|
+
"src/policy.js",
|
|
37
41
|
"src/prune.js",
|
|
38
42
|
"src/shard.js",
|
|
39
43
|
"src/state.js",
|