@exodus/stasis-core 1.0.0-beta.14 → 1.0.0-beta.15
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/package.json +1 -1
- package/src/add.js +8 -5
- package/src/config.js +8 -10
- package/src/state-util.js +18 -0
- package/src/state.js +2 -4
- package/src/util.js +5 -0
package/package.json
CHANGED
package/src/add.js
CHANGED
|
@@ -7,7 +7,7 @@ import { Lockfile } from './lockfile.js'
|
|
|
7
7
|
import { compressBundleText, parseBundleBytes } from './brotli.js'
|
|
8
8
|
import { detectRepo, normalizeEntries, packageLookup, packageType, readJson, statStrict } from './bundle-util.js'
|
|
9
9
|
import { diskHost } from './host.js'
|
|
10
|
-
import { canonicalizePath, sha512integrity } from './state-util.js'
|
|
10
|
+
import { canonicalizePath, deferredLockfile, sha512integrity } from './state-util.js'
|
|
11
11
|
import { assertRealPathWithinBase, classifyFormat, fileInBucket, hasNodeModulesSegment, isAutoExcludedDir, isAutoExcludedFile, isBinaryPlist, isBrotliQuality, isExecutableMode, moduleInfo, parseResourcesOption, pathExt, sortPaths, splitNodeModulesPath, toPosix, withMetadataOf } from './util.js'
|
|
12
12
|
|
|
13
13
|
// Snapshotted before `stasis run --fs` patches node:fs: State#includeExtra matches its outputs with
|
|
@@ -317,8 +317,9 @@ function validateFiles({ baseDir, realBase, files, resources, withIntegrity, lab
|
|
|
317
317
|
// scope): those it doesn't carry already (its own record of a file stands), in its buckets where it
|
|
318
318
|
// has them. `outputs` are the project-relative paths the build writes, never swept in. The files
|
|
319
319
|
// are read through `host`, the disk by default.
|
|
320
|
-
// -> { bundle, lockfile } of the `extra` consumer (null when there is nothing to add),
|
|
321
|
-
// `carried`: the files named that `bundle` carries already, the `extra`
|
|
320
|
+
// -> { bundle, lockfile } of the `extra` consumer (null when there is nothing to add), the lockfile
|
|
321
|
+
// built when first read, and `carried`: the files named that `bundle` carries already, the `extra`
|
|
322
|
+
// consumer's too
|
|
322
323
|
export function extraArtifacts({ baseDir, patterns, resources, bundle, outputs = new Set(), host = diskHost }) {
|
|
323
324
|
const named = expandExtra(baseDir, patterns, outputs, host).files
|
|
324
325
|
// Bundle#sources builds its Map afresh on each read: once.
|
|
@@ -326,10 +327,12 @@ export function extraArtifacts({ baseDir, patterns, resources, bundle, outputs =
|
|
|
326
327
|
const carried = [...named.keys()].filter((rel) => bundled.has(rel))
|
|
327
328
|
const files = new Map([...named].filter(([rel]) => !bundled.has(rel)))
|
|
328
329
|
if (files.size === 0) return { bundle: null, lockfile: null, carried }
|
|
329
|
-
const { codeFiles, resourceFiles
|
|
330
|
+
const { codeFiles, resourceFiles } = validateFiles({ baseDir, realBase: host.realpath(baseDir), files, resources, label: 'extra', host })
|
|
330
331
|
const rootPkg = readJson(join(baseDir, 'package.json'), host) ?? {}
|
|
331
332
|
const extra = assembleBundle(baseDir, new Map([...codeFiles, ...resourceFiles]), rootPkg.name ?? 'workspace', rootPkg.version ?? '0.0.0', undefined, { reason: 'extra', buckets: bundle.modules, host })
|
|
332
|
-
|
|
333
|
+
// Hashed from the bundle, which holds the bytes read, once a lockfile is wanted.
|
|
334
|
+
const lockfile = deferredLockfile(extra)
|
|
335
|
+
return { bundle: extra, get lockfile() { return lockfile() }, carried }
|
|
333
336
|
}
|
|
334
337
|
|
|
335
338
|
// GLOB the listed paths, FILTERING the auto-excluded set out of what a sweep finds (see
|
package/src/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
|
|
|
2
2
|
|
|
3
3
|
import { diskHost } from './host.js'
|
|
4
4
|
import { canonicalizePath } from './state-util.js'
|
|
5
|
-
import { extSetsEqual, isBrotliQuality, parseBrotliQuality, parseExtraOption, parseInstallDevDependencies, parseLazyDependencies, parseResourcesOption } from './util.js'
|
|
5
|
+
import { extSetsEqual, isBrotliQuality, parseBrotliQuality, parseExtraOption, parseGeneratePrisma, parseInstallDevDependencies, parseLazyDependencies, parseResourcesOption } from './util.js'
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_LOCK = 'add'
|
|
8
8
|
export const DEFAULT_BUNDLE = 'none'
|
|
@@ -22,8 +22,8 @@ const envList = (value) => value.split(',').map((s) => s.trim()).filter(Boolean)
|
|
|
22
22
|
// option, how a `new Config()` option does. `lockFile` and `bundle` are flag/env-only (never from
|
|
23
23
|
// stasis.config.json), and the file's `lock` can only be CONFIG_FILE_LOCK; `extra` is the reverse,
|
|
24
24
|
// stasis.config.json only (no env var or option), `entries` is `stasis bundle`'s and
|
|
25
|
-
// `installDevDependencies` and `
|
|
26
|
-
// github-bundle`), which a run takes nothing from.
|
|
25
|
+
// `installDevDependencies`, `lazyDependencies` and `generatePrisma` the trees laid out from the
|
|
26
|
+
// lockfile's (`stasis github-bundle`), which a run takes nothing from.
|
|
27
27
|
const OPTIONS = {
|
|
28
28
|
scope: { env: 'EXODUS_STASIS_SCOPE', valid: new Set(['node_modules', 'full']) },
|
|
29
29
|
lock: { env: 'EXODUS_STASIS_LOCK', valid: new Set(['none', 'ignore', 'add', 'replace', 'frozen']) },
|
|
@@ -40,7 +40,9 @@ const OPTIONS = {
|
|
|
40
40
|
resources: { env: 'EXODUS_STASIS_RESOURCES', parse: (name, value) => parseResourcesOption('env', envList(value)), option: (value) => parseResourcesOption('options', value) },
|
|
41
41
|
}
|
|
42
42
|
const OPTION_KEYS = Object.keys(OPTIONS)
|
|
43
|
-
|
|
43
|
+
// The trees laid out from the lockfile's flags (`stasis github-bundle`), by how each is parsed.
|
|
44
|
+
const TREE_FLAGS = { __proto__: null, installDevDependencies: parseInstallDevDependencies, lazyDependencies: parseLazyDependencies, generatePrisma: parseGeneratePrisma }
|
|
45
|
+
const CONFIG_FILE_KEYS = [...OPTION_KEYS.filter((key) => key !== 'lockFile' && key !== 'bundle'), 'extra', 'entries', ...Object.keys(TREE_FLAGS)]
|
|
44
46
|
// The one mode a stasis.config.json can pin: a run that writes, loads or ignores is given its modes
|
|
45
47
|
// explicitly (flags, env, options), never by a file.
|
|
46
48
|
const CONFIG_FILE_LOCK = 'frozen'
|
|
@@ -216,12 +218,8 @@ export class Config {
|
|
|
216
218
|
// `stasis bundle`'s, validated there.
|
|
217
219
|
if (key === 'entries') continue
|
|
218
220
|
// A run takes node_modules as installed, but a value github-bundle would refuse is refused here too.
|
|
219
|
-
if (key
|
|
220
|
-
|
|
221
|
-
continue
|
|
222
|
-
}
|
|
223
|
-
if (key === 'lazyDependencies') {
|
|
224
|
-
parseLazyDependencies('stasis.config.json', config.lazyDependencies)
|
|
221
|
+
if (Object.hasOwn(TREE_FLAGS, key)) {
|
|
222
|
+
TREE_FLAGS[key]('stasis.config.json', config[key])
|
|
225
223
|
continue
|
|
226
224
|
}
|
|
227
225
|
if (key === 'resources') this.#opts.resources = parseResourcesOption('stasis.config.json', config.resources)
|
package/src/state-util.js
CHANGED
|
@@ -5,6 +5,7 @@ import { join, resolve, sep } from 'node:path'
|
|
|
5
5
|
import { pathToFileURL } from 'node:url'
|
|
6
6
|
|
|
7
7
|
import { diskHost } from './host.js'
|
|
8
|
+
import { Lockfile } from './lockfile.js'
|
|
8
9
|
import { isPathWithin } from './util.js'
|
|
9
10
|
|
|
10
11
|
// Genuine fs readers snapshotted off the namespace before any --fs patch. A plain `import { readFileSync }`
|
|
@@ -33,6 +34,23 @@ assert.equal(sep, '/', 'Not tested on Windows')
|
|
|
33
34
|
|
|
34
35
|
export const sha512integrity = (x) => `sha512-${hash('sha512', x, 'base64')}`
|
|
35
36
|
|
|
37
|
+
// A bundled file's integrity from its `content` as a bundle stores it: of the bytes it stands for,
|
|
38
|
+
// a 'resource:base64' payload's decoded ones, else its UTF-8 text's.
|
|
39
|
+
export const bundledIntegrity = (content, format) => sha512integrity(format === 'resource:base64' ? Buffer.from(content, 'base64') : content)
|
|
40
|
+
|
|
41
|
+
// The companion lockfile of `bundle` as it is now (Lockfile.fromBundle's), built on the first call,
|
|
42
|
+
// the same one after: each file's integrity that of the bytes its content stands for
|
|
43
|
+
// (bundledIntegrity), so a file is hashed only once the lockfile is wanted, for a bundle whose
|
|
44
|
+
// content is the bytes read, encoded without loss. Its records are taken now: one the bundle
|
|
45
|
+
// replaces after (a commit pinned onto a module) is not the lockfile's.
|
|
46
|
+
// -> () => Lockfile
|
|
47
|
+
export function deferredLockfile(bundle) {
|
|
48
|
+
const { config, entries, imports, formats, executable } = bundle
|
|
49
|
+
const now = { config, entries, modules: new Map(bundle.modules), imports, formats, executable }
|
|
50
|
+
let lockfile
|
|
51
|
+
return () => (lockfile ??= Lockfile.fromBundle(now, (file, content) => bundledIntegrity(content, formats.get(file))))
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
export function readFileSyncMaybe(dir, file, encoding, host = diskHost) {
|
|
37
55
|
let buf
|
|
38
56
|
try {
|
package/src/state.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Config } from './config.js'
|
|
|
8
8
|
import { Bundle, mergeRepo } from './bundle.js'
|
|
9
9
|
import { Lockfile } from './lockfile.js'
|
|
10
10
|
import { parseShard, serializeShard } from './shard.js'
|
|
11
|
-
import { canonicalizePath, inScope, sha512integrity, readFileSyncMaybe, noupsert, realContained } from './state-util.js'
|
|
11
|
+
import { bundledIntegrity, canonicalizePath, inScope, sha512integrity, readFileSyncMaybe, noupsert, realContained } from './state-util.js'
|
|
12
12
|
import { compressBundleText, parseBundleBytes } from './brotli.js'
|
|
13
13
|
import { CODE_EXTENSIONS, EMPTY_MODULE_PATH, assertRealPathWithinBase, canObserveExecuteBits, classifyFormat, erasedTypeScriptFormat, fileMapToObject, hasNodeModulesSegment, importTargetsEqual, isBinaryPlist, isNativeArtifact, isPackageString, isPathWithin, isPlainObject, isStatFormat, isSubpackage, moduleFileKey, moduleInfo, narrowExecutable, nestedMap, objectToMaps, observeExecutable, pathExt, reconcileFormat, relativeEscapes, sortPaths, splitNodeModulesPath, toPosix, withMetadataOf } from './util.js'
|
|
14
14
|
import { detectRepo, invalidPackageConfig, namedManifestOf, packageJSONStat, packageJSONText, packageRepo, readModuleManifest, scopeManifestOf, vendorDirOf, vendoredPackageOf } from './bundle-util.js'
|
|
@@ -49,9 +49,6 @@ function upsertFormat(map, file, format) {
|
|
|
49
49
|
map.set(file, currentFormat === undefined ? format : reconcileFormat(format, currentFormat, file))
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// A bundled file's integrity as addFile/addFsDir hash it: a 'resource:base64' payload's is its decoded bytes'.
|
|
53
|
-
const bundledIntegrity = (content, format) => sha512integrity(format === 'resource:base64' ? Buffer.from(content, 'base64') : content)
|
|
54
|
-
|
|
55
52
|
// Loader formats the extension alone decides; `.js`/`.ts` follow the nearest package `type`.
|
|
56
53
|
const EXT_FORMATS = { __proto__: null, '.json': 'json', '.mjs': 'module', '.cjs': 'commonjs', '.mts': 'module-typescript', '.cts': 'commonjs-typescript' }
|
|
57
54
|
// With no `type`, Node decides .js/.ts by syntax detection: either variant is possible, the first is the default.
|
|
@@ -63,6 +60,7 @@ const UNTYPED_VARIANTS = { __proto__: null, '.js': ['commonjs', 'module'], '.ts'
|
|
|
63
60
|
// Maintained list: add only a confirmed upstream false positive, with its reason.
|
|
64
61
|
const INCONSISTENT_PACKAGE_JSON_EXCEPTIONS = [
|
|
65
62
|
'node_modules/@redis/client/dist/package.json', // stale build-time copy
|
|
63
|
+
'node_modules/hashids/esm/package.json', // a `type` marker named `hashids-esm`, in every 2.x release
|
|
66
64
|
]
|
|
67
65
|
const isInconsistentPackageJsonException = (file) =>
|
|
68
66
|
INCONSISTENT_PACKAGE_JSON_EXCEPTIONS.some((suffix) => file === suffix || file.endsWith(`/${suffix}`))
|
package/src/util.js
CHANGED
|
@@ -116,6 +116,11 @@ export const parseInstallDevDependencies = configFlag('installDevDependencies')
|
|
|
116
116
|
// (true, the default), or have every package fetched before the build (false).
|
|
117
117
|
export const parseLazyDependencies = configFlag('lazyDependencies')
|
|
118
118
|
|
|
119
|
+
// stasis.config.json's `generatePrisma`: whether `stasis github-bundle` and @exodus/stasis/vfs-bundle's
|
|
120
|
+
// builds, given no `generate`, write the Prisma Client of each project the entries reach whose schema
|
|
121
|
+
// asks for one, as `prisma generate` would (true, the default), or none (false).
|
|
122
|
+
export const parseGeneratePrisma = configFlag('generatePrisma')
|
|
123
|
+
|
|
119
124
|
export const isBrotliQuality = (n) => Number.isInteger(n) && n >= 0 && n <= 11
|
|
120
125
|
|
|
121
126
|
// `${n}` must round-trip to the input, so non-canonical forms ('5.0', '05', ' 5 ') throw.
|