@exodus/stasis-core 1.0.0-beta.0 → 1.0.0-beta.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/bin/stasis-core.js +21 -5
- package/package.json +1 -1
- package/src/brotli.js +17 -10
- package/src/bundle.js +15 -6
- package/src/config.js +67 -11
- package/src/fs.js +86 -15
- package/src/hooks.js +74 -4
- package/src/lockfile.js +7 -1
- package/src/state.js +371 -155
- package/src/util.js +35 -5
package/src/util.js
CHANGED
|
@@ -19,7 +19,11 @@ const sep = '/'
|
|
|
19
19
|
// Source languages (analysis-only, not runnable by Node) — solidity, php, bash, rust
|
|
20
20
|
// Resources (asset payloads) — resource (raw UTF-8), resource:base64 (binary)
|
|
21
21
|
// Filesystem captures (`stasis run --fs`) — directory (a JSON-serialized,
|
|
22
|
-
// sorted `fs.readdirSync` listing; a resource-like raw-UTF-8 payload)
|
|
22
|
+
// sorted `fs.readdirSync` listing; a resource-like raw-UTF-8 payload), and the
|
|
23
|
+
// payload-free stat records stat:file / stat:directory (an `fs.lstatSync`/
|
|
24
|
+
// `fs.statSync` capture: attests only that the path existed with that KIND —
|
|
25
|
+
// no bytes, no hash, no module-files entry — so isFile()/isDirectory() answer
|
|
26
|
+
// from the bundle at load; see isStatFormat below)
|
|
23
27
|
// Adding a new format is a deliberate schema change: list it here AND extend
|
|
24
28
|
// hooks.js's executable allowlist if Node should serve it from a bundle.
|
|
25
29
|
export const KNOWN_FORMATS = new Set([
|
|
@@ -35,6 +39,8 @@ export const KNOWN_FORMATS = new Set([
|
|
|
35
39
|
'resource',
|
|
36
40
|
'resource:base64',
|
|
37
41
|
'directory',
|
|
42
|
+
'stat:file',
|
|
43
|
+
'stat:directory',
|
|
38
44
|
])
|
|
39
45
|
|
|
40
46
|
// File extensions whose bytes are JS-shaped code -- Node's loader and the
|
|
@@ -50,6 +56,14 @@ export const KNOWN_FORMATS = new Set([
|
|
|
50
56
|
// own set, so an fs-read tagged a `.jsx` 'resource' while the import tagged it code.
|
|
51
57
|
export const CODE_EXTENSIONS = new Set(['js', 'mjs', 'cjs', 'ts', 'jsx', 'tsx', 'json', 'mts', 'cts'])
|
|
52
58
|
|
|
59
|
+
// The payload-free stat-record formats (`stasis run --fs` lstatSync/statSync captures).
|
|
60
|
+
// A stat record attests a path's KIND (file vs directory) without any content, so it
|
|
61
|
+
// lives ONLY in the `formats` maps — never in a module's hashed `files`, never as a
|
|
62
|
+
// bundle payload. It is deliberately WEAK: real content recorded for the same path (a
|
|
63
|
+
// read, a readdir listing, an import) supersedes it — see State's addFile/addFsDir
|
|
64
|
+
// stale-record drop and #mergedFormats' upgrade rule.
|
|
65
|
+
export const isStatFormat = (format) => format === 'stat:file' || format === 'stat:directory'
|
|
66
|
+
|
|
53
67
|
// Lowercased, dot-less extension of a path, or '' if none.
|
|
54
68
|
export function pathExt(filePath) {
|
|
55
69
|
const m = /\.([^./\\]+)$/.exec(filePath)
|
|
@@ -87,6 +101,20 @@ export function parseResourcesOption(label, resources) {
|
|
|
87
101
|
return out
|
|
88
102
|
}
|
|
89
103
|
|
|
104
|
+
export const isBrotliQuality = (n) => Number.isInteger(n) && n >= 0 && n <= 11
|
|
105
|
+
|
|
106
|
+
// Parse an EXODUS_STASIS_BROTLI_QUALITY / --brotli-quality string into a brotli quality
|
|
107
|
+
// (integer 0..11). `${n}` must round-trip back to the input, so Number()-coercible
|
|
108
|
+
// non-canonical forms ('5.0', '05', ' 5 ', whitespace -> 0) throw instead of silently
|
|
109
|
+
// selecting an unintended quality. The single parser for the env var and both CLIs.
|
|
110
|
+
export function parseBrotliQuality(name, value) {
|
|
111
|
+
const n = Number(value)
|
|
112
|
+
if (`${n}` !== value || !isBrotliQuality(n)) {
|
|
113
|
+
throw new RangeError(`${name} must be an integer 0..11 (got '${value}')`)
|
|
114
|
+
}
|
|
115
|
+
return n
|
|
116
|
+
}
|
|
117
|
+
|
|
90
118
|
// Classifies a file against the code set + a parsed resources allowlist. Returns 'code'
|
|
91
119
|
// (track with its loader format), 'resource' (track with a 'resource'/'resource:base64'
|
|
92
120
|
// format -- the encoding is chosen from content), or 'unknown' (caller must reject). A
|
|
@@ -116,12 +144,14 @@ export function extSetsEqual(a, b) {
|
|
|
116
144
|
// the bucketing State/Bundle apply. The `rel === ''` branch is reached only by a
|
|
117
145
|
// `directory` capture whose path IS a module root (e.g. `fs.readdirSync` of a
|
|
118
146
|
// package dir, or of the project root): the listing is keyed at the bucket itself,
|
|
119
|
-
// so the flat key is the dir
|
|
120
|
-
//
|
|
121
|
-
//
|
|
147
|
+
// so the flat key is the dir — never `${dir}/`, which a trailing-slash join would
|
|
148
|
+
// wrongly produce and break the round-trip. The workspace root keys at '.' (the
|
|
149
|
+
// '.' bucket's own dir), NOT '': join('.', '') === '.' is what lockfile re-absorb
|
|
150
|
+
// derives, so a '' key would be written but never found again on load. For every
|
|
151
|
+
// ordinary file `rel` is a real basename, so this matches the historical
|
|
122
152
|
// `dir === '.' ? rel : `${dir}/${rel}`` exactly.
|
|
123
153
|
export function moduleFileKey(dir, rel) {
|
|
124
|
-
if (rel === '') return dir
|
|
154
|
+
if (rel === '') return dir
|
|
125
155
|
return dir === '.' ? rel : `${dir}/${rel}`
|
|
126
156
|
}
|
|
127
157
|
|