@exodus/stasis-core 1.0.0-beta.1 → 1.0.0-beta.11
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 +1 -1
- package/bin/stasis-core.js +74 -42
- package/package.json +14 -4
- package/src/add.js +317 -0
- package/src/artifact-util.js +679 -0
- package/src/brotli.js +15 -16
- package/src/bundle-util.js +379 -0
- package/src/bundle.js +216 -163
- package/src/config.js +198 -284
- package/src/extract.js +151 -0
- package/src/fs.js +224 -530
- package/src/hooks.js +327 -527
- package/src/host.js +45 -0
- package/src/loader.js +1 -3
- package/src/lockfile.js +69 -97
- package/src/prune.js +90 -272
- package/src/shard.js +68 -0
- package/src/state-util.js +13 -31
- package/src/state.js +1003 -1520
- package/src/util.js +299 -161
package/src/state-util.js
CHANGED
|
@@ -3,37 +3,28 @@ import { hash } from 'node:crypto'
|
|
|
3
3
|
import * as fs from 'node:fs'
|
|
4
4
|
import { join, resolve, sep } from 'node:path'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// esbuild.js / metro.js; esbuild uses the async realReadFile for its async onLoad). A
|
|
11
|
-
// plugin's capture read is stasis-internal bookkeeping, NOT a program fs
|
|
12
|
-
// read, so routing it through the patched fs would re-record the bundler's module graph
|
|
13
|
-
// into the preload/main bundle -- duplicating into main what the plugin captured into
|
|
14
|
-
// its own sidecar. `import { readFileSync } from 'node:fs'` would NOT do: `stasis run
|
|
15
|
-
// --fs` monkey-patches fs.readFileSync then calls module.syncBuiltinESMExports(), which
|
|
16
|
-
// rebinds that named import to the patched fn -- and a plugin loads AFTER the patch.
|
|
17
|
-
// Snapshotting off the namespace dodges that. state-util.js is the lowest-level module
|
|
18
|
-
// (a leaf with no internal imports), evaluated during the `--import` preload before any
|
|
19
|
-
// patch, so these are always the real builtins -- and the snapshot is taken as early as
|
|
20
|
-
// possible. (`fs.promises` IS node:fs/promises, the same object, so realReadFile also
|
|
21
|
-
// covers `import { readFile } from 'node:fs/promises'`.)
|
|
6
|
+
import { diskHost } from './host.js'
|
|
7
|
+
|
|
8
|
+
// Genuine fs readers snapshotted off the namespace before any --fs patch. A plain `import { readFileSync }`
|
|
9
|
+
// won't do: --fs monkey-patches fs then syncBuiltinESMExports() rebinds named imports, so snapshotting dodges that.
|
|
22
10
|
export const realReadFileSync = fs.readFileSync
|
|
23
11
|
export const realReadFile = fs.promises.readFile
|
|
24
|
-
const
|
|
12
|
+
export const realReaddirSync = fs.readdirSync
|
|
13
|
+
export const realExistsSync = fs.existsSync
|
|
25
14
|
|
|
26
15
|
assert.equal(sep, '/', 'Not tested on Windows')
|
|
27
16
|
|
|
28
17
|
export const sha512integrity = (x) => `sha512-${hash('sha512', x, 'base64')}`
|
|
29
18
|
|
|
30
|
-
export function readFileSyncMaybe(dir, file, encoding) {
|
|
19
|
+
export function readFileSyncMaybe(dir, file, encoding, host = diskHost) {
|
|
20
|
+
let buf
|
|
31
21
|
try {
|
|
32
|
-
|
|
22
|
+
buf = host.readFile(join(dir, file))
|
|
33
23
|
} catch (err) {
|
|
34
24
|
if (err.code === 'ENOENT') return null
|
|
35
25
|
throw err
|
|
36
26
|
}
|
|
27
|
+
return encoding === undefined ? buf : buf.toString(encoding)
|
|
37
28
|
}
|
|
38
29
|
|
|
39
30
|
export function noupsert(map, key, value) {
|
|
@@ -44,20 +35,11 @@ export function noupsert(map, key, value) {
|
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
37
|
|
|
47
|
-
// Canonicalize
|
|
48
|
-
|
|
49
|
-
// different symlink chains that ultimately name the same inode would compare as
|
|
50
|
-
// distinct strings, letting a "is this the same target?" check silently fork
|
|
51
|
-
// (the resourcesBundleFile/lockFile/bundleFile claim sets). `realpathSync`
|
|
52
|
-
// closes that hole when the file already exists;
|
|
53
|
-
// for not-yet-written targets (the common case for a fresh capture's write
|
|
54
|
-
// path), fall back to the lexical `resolve()` -- there's no symlink to follow,
|
|
55
|
-
// and a later writer claiming the realpath of the same target will canonicalize
|
|
56
|
-
// to the same string the first writer's resolve() produced.
|
|
57
|
-
export function canonicalizePath(p) {
|
|
38
|
+
// Canonicalize for write-target collision detection: the host's realpath catches symlink aliases resolve() would miss; lexical fallback for not-yet-written targets.
|
|
39
|
+
export function canonicalizePath(p, host = diskHost) {
|
|
58
40
|
const abs = resolve(p)
|
|
59
41
|
try {
|
|
60
|
-
return
|
|
42
|
+
return host.realpath(abs)
|
|
61
43
|
} catch {
|
|
62
44
|
return abs
|
|
63
45
|
}
|