@runeditrun/rer 0.2.83 → 0.2.84
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/cli/authoring.mjs +1 -0
- package/cli/contract.mjs +1 -1
- package/cli/demo-host.mjs +5 -1
- package/cli/demo.mjs +6 -1
- package/cli/export.mjs +1 -1
- package/cli/parse.mjs +1 -1
- package/edition-authoring/base-copies.mjs +72 -25
- package/edition-authoring/copy-checkout.mjs +7 -120
- package/edition-authoring/edition-migrations.mjs +41 -0
- package/edition-authoring/files.mjs +67 -0
- package/edition-authoring/lock.mjs +2 -2
- package/edition-authoring/module-closure.mjs +232 -0
- package/edition-authoring/module-edges.mjs +100 -0
- package/edition-authoring/module-resolution.mjs +66 -0
- package/edition-authoring/module-syntax.mjs +57 -0
- package/edition-authoring/package-target.mjs +92 -0
- package/edition-authoring/runtime-dependencies.mjs +74 -97
- package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
- package/edition-authoring/vendor/babel-parser/README.md +21 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
- package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
- package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
- package/edition-authoring/vendor/yaml/LICENSE +13 -0
- package/edition-authoring/vendor/yaml/README.md +11 -0
- package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
- package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
- package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
- package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
- package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
- package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
- package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
- package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
- package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
- package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
- package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
- package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
- package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
- package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
- package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
- package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
- package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
- package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
- package/edition-authoring/vendor/yaml/errors.mjs +57 -0
- package/edition-authoring/vendor/yaml/index.mjs +17 -0
- package/edition-authoring/vendor/yaml/log.mjs +11 -0
- package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
- package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
- package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
- package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
- package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
- package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
- package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
- package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
- package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
- package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
- package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
- package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
- package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
- package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
- package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
- package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
- package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
- package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
- package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
- package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
- package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
- package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
- package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
- package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
- package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
- package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
- package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
- package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
- package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
- package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
- package/edition-authoring/vendor/yaml/util.mjs +11 -0
- package/edition-authoring/vendor/yaml/visit.mjs +233 -0
- package/edition-authoring/workflow-copies.mjs +125 -0
- package/edition-authoring/workflow-scripts.mjs +112 -0
- package/foundation/runtime/contract-docs.mjs +753 -0
- package/global/CHANGELOG.md +22 -3
- package/modules/demo/declaration.mjs +1 -4
- package/modules/demo/vite.mjs +1 -1
- package/modules/deploy-kit/README.md +1 -1
- package/modules/deploy-kit/templates.mjs +3 -3
- package/onboarding/operator-installer.mjs +2 -2
- package/package.json +1 -1
- package/scripts/publish-check/README.md +6 -0
- package/scripts/publish-check/history_scan.py +5 -3
- package/scripts/publish-check/hygiene_config.py +2 -1
- package/scripts/publish-check/report.py +9 -3
- package/scripts/publish-check/third-party-notices.json +13 -0
- package/scripts/publish-check/third_party_notices.py +38 -0
- package/scripts/publish-check/tree_scan.py +6 -0
- package/scripts/publish-check.mjs +1 -1
package/cli/authoring.mjs
CHANGED
|
@@ -7,6 +7,7 @@ export function authoringCommand(options) {
|
|
|
7
7
|
if (options.verb === 'refresh-base' && !options.ref) throw invalid('Provide --ref with the full immutable Base commit. Run rer refresh-base --help.');
|
|
8
8
|
try {
|
|
9
9
|
return options.verb === 'adopt-edition' ? adoptEdition(options.cwd) : refreshCopies(options.cwd, copyOptions([
|
|
10
|
+
...(options.editionMigration ? options.editionMigration.split(',').flatMap(id => ['--edition-migration', id]) : []),
|
|
10
11
|
options.ref, '--record', options.record ?? 'base-copies.json',
|
|
11
12
|
...(options.base ? ['--base', resolve(options.cwd, options.base)] : []), ...(options.offline ? ['--offline'] : []),
|
|
12
13
|
], 1));
|
package/cli/contract.mjs
CHANGED
|
@@ -29,7 +29,7 @@ export const signinVerb = Object.freeze({ bootstrap: 'before', flags: [...common
|
|
|
29
29
|
// Their project-package bootstrap uses the same contract as every checkout verb.
|
|
30
30
|
export const authoringVerbs = Object.freeze({
|
|
31
31
|
'adopt-edition': {bootstrap: 'before', flags: [...commonFlags], effects: 'Add edition.json and sources.lock.json for the existing tracked local source, preserving declared project identity and existing copy/composition records. Create an empty base-copies.json only when none exists. Review and stage the new authoring inputs; no source regeneration, install setup or commit.'},
|
|
32
|
-
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--record', '--offline'], effects: 'Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or use --base CHECKOUT. --offline requires --base and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
32
|
+
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--record', '--offline', '--edition-migration'], effects: 'Consent to each declared edition edit with repeatable --edition-migration ID; refresh leaves the edit owed. Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Deliver invoked workflow helpers atomically; adopt tracked known historical Verify templates and preserve divergent workflows with adoption notices. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or use --base CHECKOUT. --offline requires --base and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
33
33
|
});
|
|
34
34
|
export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
|
|
35
35
|
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--scan-timeout-seconds', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
package/cli/demo-host.mjs
CHANGED
|
@@ -19,7 +19,11 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
19
19
|
if (process.env.RER_DEMO_OPERATOR_TOKEN && (process.env.RER_DEMO_OPERATOR_TOKEN.length < 32 || process.env.RER_DEMO_OPERATOR_TOKEN.length > 512)) throw invalid('RER_DEMO_OPERATOR_TOKEN must contain 32 to 512 characters.');
|
|
20
20
|
const supplied = process.env.RER_DEMO_MEASUREMENT_TOKEN?.trim();
|
|
21
21
|
if (supplied && (supplied.length < 32 || supplied.length > 512 || /[\s;,]/.test(supplied))) throw invalid('RER_DEMO_MEASUREMENT_TOKEN must contain 32 to 512 characters, with no spaces, semicolons or commas.');
|
|
22
|
-
|
|
22
|
+
// The Vite build is a child of this operation; pass the already resolved exit.
|
|
23
|
+
const previousRunUrl = process.env.RER_DEMO_RUN_URL;
|
|
24
|
+
process.env.RER_DEMO_RUN_URL = plan.wrangler.vars.DEMO_RUN_URL;
|
|
25
|
+
try { return await (await import('./demo-native.mjs')).nativeDemoCommand(project, options, store, signal, out, operation, app, plan); }
|
|
26
|
+
finally { if (previousRunUrl === undefined) delete process.env.RER_DEMO_RUN_URL; else process.env.RER_DEMO_RUN_URL = previousRunUrl; }
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
async function removeDemo(plan, store, signal) {
|
package/cli/demo.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
4
4
|
import { missing, refuse } from './errors.mjs';
|
|
5
5
|
import { shared } from './shared.mjs';
|
|
6
6
|
import { requiredLocalSettings } from './settings.mjs';
|
|
7
|
+
import { contained } from './project.mjs';
|
|
8
|
+
import { demoRunDeclaration } from '../modules/demo/declaration.mjs';
|
|
9
|
+
import { demoRunUrl } from '../modules/demo/run-url.mjs';
|
|
7
10
|
|
|
8
11
|
// `rer demo` (dev --demo) state and its two adoption checks (export/DEMO.md).
|
|
9
12
|
const adopt = 'See DEMO.md: a seed adopts demo mode with src/demo.ts, withDemo as the first import of its Worker entry, and three vite.config changes.';
|
|
@@ -15,7 +18,9 @@ const adopt = 'See DEMO.md: a seed adopts demo mode with src/demo.ts, withDemo a
|
|
|
15
18
|
export async function demoPreflight(project, vars, seconds) {
|
|
16
19
|
if (requiredLocalSettings(project, vars).length) throw missing('Private owner settings are missing. Run rer setup first.');
|
|
17
20
|
await demoAdopted(project.root);
|
|
18
|
-
|
|
21
|
+
const declaration = JSON.parse(await readFile(await contained(project.root, 'deploy-demo.json'), 'utf8'));
|
|
22
|
+
const resolved = await demoRunDeclaration(declaration, {root: project.root, adapter: project.adapter});
|
|
23
|
+
return {...await demoState(project.root, seconds), runUrl: demoRunUrl(resolved.runUrl === undefined ? `https://${resolved.domain}/run` : resolved.runUrl)};
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
// Before anything starts: the seed's Vite persists where rer says, so the
|
package/cli/export.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { cliVersion } from './version.mjs';
|
|
|
6
6
|
|
|
7
7
|
// Copy whole maintained source/tooling directories. Python publication scans
|
|
8
8
|
// load sibling modules and data dynamically; they belong in the inventory too.
|
|
9
|
-
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs'];
|
|
9
|
+
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/module-closure.mjs', 'edition-authoring/edition-migrations.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/module-resolution.mjs', 'edition-authoring/package-target.mjs', 'edition-authoring/module-syntax.mjs', 'edition-authoring/module-edges.mjs', 'edition-authoring/vendor/babel-parser', 'edition-authoring/workflow-copies.mjs', 'edition-authoring/workflow-scripts.mjs', 'edition-authoring/vendor/yaml', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs', 'foundation/runtime/contract-docs.mjs'];
|
|
10
10
|
export async function inventory(base, roots = sourceRoots) {
|
|
11
11
|
const files = [];
|
|
12
12
|
async function walk(path) {
|
package/cli/parse.mjs
CHANGED
|
@@ -40,7 +40,7 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
40
40
|
throw invalid(`Unsupported flag ${/^--[a-zA-Z-]{1,40}$/.test(flag)?flag:'(invalid)'} for ${verb}.${suggestion?` Did you mean ${suggestion}?`:''} Run rer ${verb} --help.`);
|
|
41
41
|
}
|
|
42
42
|
// Several secrets change in one deploy: --set-secret A --set-secret B is --set-secret A,B.
|
|
43
|
-
const listed = ['--set-secret', '--unset-secret'].includes(flag);
|
|
43
|
+
const listed = ['--set-secret', '--unset-secret', '--edition-migration'].includes(flag);
|
|
44
44
|
if (options.supplied.has(flag) && !listed) throw invalid(`Repeated flag ${flag} for ${verb}. Run rer ${verb} --help.`);
|
|
45
45
|
options.supplied.add(flag);
|
|
46
46
|
const key = flag.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
@@ -10,10 +10,12 @@ import os from 'node:os';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import crypto from 'node:crypto';
|
|
12
12
|
import {execFileSync} from 'node:child_process';
|
|
13
|
-
import {hash, json, git, raw, gitReader, safe, noLinks, testSource} from './files.mjs';
|
|
13
|
+
import {hash, json, git, raw, gitReader, safe, noLinks, requirePhysical, testSource} from './files.mjs';
|
|
14
14
|
import {snapshot, acknowledgementDrift} from './base-acknowledgements.mjs';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import {requireMaterializedCopies, preflightRefresh} from './copy-checkout.mjs';
|
|
16
|
+
import {completeModuleCopies} from './module-closure.mjs';
|
|
17
|
+
import {editionMigrations} from './edition-migrations.mjs';
|
|
18
|
+
import {adoptWorkflowTemplates, completeWorkflowHelpers} from './workflow-copies.mjs';
|
|
17
19
|
|
|
18
20
|
export const RECORD = 'base-copies.json';
|
|
19
21
|
const commit = /^[a-f0-9]{40}$/, sha256 = /^[a-f0-9]{64}$/;
|
|
@@ -56,10 +58,14 @@ function open(record, base, root, offline = false) {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
export function options(args, count) {
|
|
59
|
-
const result = {positional: [], record: RECORD, base: null, offline: false};
|
|
61
|
+
const result = {positional: [], record: RECORD, base: null, offline: false, editionMigration: []};
|
|
60
62
|
for (let i = 0; i < args.length; i++) {
|
|
61
63
|
const arg = args[i];
|
|
62
64
|
if (arg === '--offline') result.offline = true;
|
|
65
|
+
else if (arg === '--edition-migration') {
|
|
66
|
+
if (!args[i + 1] || args[i + 1].startsWith('--')) throw Error(`${arg} requires a value`);
|
|
67
|
+
result.editionMigration.push(args[++i]);
|
|
68
|
+
}
|
|
63
69
|
else if (arg === '--record' || arg === '--base') {
|
|
64
70
|
if (!args[i + 1]) throw Error(`${arg} requires a value`);
|
|
65
71
|
result[arg.slice(2)] = args[++i];
|
|
@@ -177,12 +183,21 @@ function reader(origin) {
|
|
|
177
183
|
digests(objects) {
|
|
178
184
|
return new Map([...this.blobs(objects)].map(([object, bytes]) => [object, hash(bytes)]));
|
|
179
185
|
},
|
|
186
|
+
contains(revision, introduced) {
|
|
187
|
+
this.tree(revision); this.tree(introduced);
|
|
188
|
+
try { return source.git('merge-base', revision, introduced) === introduced; }
|
|
189
|
+
catch { throw Error(`Cannot compare Base history for ${revision} and ${introduced}; fetch full Base history, then repeat refresh-base; no files were refreshed.`); }
|
|
190
|
+
},
|
|
191
|
+
history(revision, name) {
|
|
192
|
+
return source.git('log', '--format=%H', revision, '--', name).split('\n').filter(Boolean)
|
|
193
|
+
.flatMap(pin => { const entry = this.tree(pin).get(name); return entry ? [{revision: pin, ...entry}] : []; });
|
|
194
|
+
},
|
|
180
195
|
};
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
// The record is edition input: never read or write it through a link, and only as a regular file.
|
|
184
199
|
function recordFile(root, recordPath) {
|
|
185
|
-
|
|
200
|
+
requirePhysical(root, recordPath);
|
|
186
201
|
const filename = path.join(root, recordPath);
|
|
187
202
|
let stat;
|
|
188
203
|
try { stat = fs.lstatSync(filename); }
|
|
@@ -202,7 +217,9 @@ export function verifyCopies(root, {record: recordPath, base, offline}) {
|
|
|
202
217
|
for (const [name, file] of files) {
|
|
203
218
|
if (!within(name, copy.path)) continue;
|
|
204
219
|
if (!file.regular) drift.push({kind: 'not-a-file', path: name, copy: copy.path});
|
|
205
|
-
else if (!Object.hasOwn(copy.files, name))
|
|
220
|
+
else if (!Object.hasOwn(copy.files, name)) {
|
|
221
|
+
if (!(record.ignore || []).some(p => within(name, p))) drift.push({kind: 'unrecorded', path: name, copy: copy.path});
|
|
222
|
+
}
|
|
206
223
|
else if (Object.hasOwn(copy.adapted || {}, name)) {
|
|
207
224
|
noLinks(root, name);
|
|
208
225
|
drift.push(...acknowledgementDrift(root, copy, name, file, recordPath));
|
|
@@ -323,7 +340,7 @@ export function adaptCopy(root, {positional: [name], record: recordPath}) {
|
|
|
323
340
|
// entirely, just as absent files are dropped from directory copies. Local edits
|
|
324
341
|
// are refused, never overwritten, as is any change to an existing file under a
|
|
325
342
|
// migrations folder.
|
|
326
|
-
export function refreshCopies(root, {positional: [revision], record: recordPath, base, offline}) {
|
|
343
|
+
export function refreshCopies(root, {positional: [revision], record: recordPath, base, offline, editionMigration = []}) {
|
|
327
344
|
if (!commit.test(revision)) throw Error('Refresh requires an immutable full 40-character Base commit. Resolve the release tag with git -C <base-checkout> rev-parse <tag>^{commit}, then repeat with --ref <commit> --base <base-checkout>.');
|
|
328
345
|
if (offline && !base) throw Error('Offline refresh needs a Base checkout. Repeat rer refresh-base --ref <commit> --offline --base <checkout> containing that commit.');
|
|
329
346
|
const filename = recordFile(root, recordPath);
|
|
@@ -332,9 +349,13 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
332
349
|
const files = seedFiles(root);
|
|
333
350
|
requireMaterializedCopies(root, record, files);
|
|
334
351
|
const origin = open(record, base, root, offline);
|
|
352
|
+
let writing = false, notices = [];
|
|
335
353
|
try {
|
|
336
354
|
const read = reader(origin);
|
|
337
355
|
const next = read.tree(revision);
|
|
356
|
+
const migrations = editionMigrations(record, {tree: next, read, revision, base: base ? origin.repository : null, recordPath, offline, consent: editionMigration});
|
|
357
|
+
const index = new Set(raw(root, 'ls-files', '-z').toString('utf8').split('\0').filter(Boolean));
|
|
358
|
+
for (const name of record.copies.flatMap(copy => Object.keys(copy.files))) requirePhysical(root, name);
|
|
338
359
|
const upstream = read.digests([...next.values()].map(({object}) => object));
|
|
339
360
|
const local = name => files.get(name)?.regular ? hash(files.get(name).read()) : null;
|
|
340
361
|
const edited = [], unacknowledged = [];
|
|
@@ -360,6 +381,7 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
360
381
|
...(conflict ? {note: 'Upstream changed or removed this seed-owned adaptation; review and reconcile explicitly.',
|
|
361
382
|
diffHint: `git -C <base> diff ${baseline} ${revision} -- ${JSON.stringify(originPath)}`} : {})};
|
|
362
383
|
}));
|
|
384
|
+
const ownerSources = new Map();
|
|
363
385
|
const plans = record.copies.map(copy => {
|
|
364
386
|
// Absence is the existing directory-copy removal signal; there is no
|
|
365
387
|
// separate deletion-intent marker. Only an absent, unadapted singleton
|
|
@@ -370,51 +392,58 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
370
392
|
const pinned = read.tree(copy.revision);
|
|
371
393
|
if (retired) return {copy, sources: [], retired, removed: [copy.path]};
|
|
372
394
|
const tests = Object.keys(copy.files).some(name => testSource(mapped(name, copy.path, copy.originPath)));
|
|
373
|
-
const sources = [...next].filter(([name
|
|
395
|
+
const sources = [...next].filter(([name]) => {
|
|
374
396
|
if (!within(name, copy.originPath)) return false;
|
|
375
397
|
const target = mapped(name, copy.originPath, copy.path), actual = local(target);
|
|
376
398
|
if (Object.hasOwn(copy.adapted || {}, target)) return false;
|
|
377
399
|
if (Object.hasOwn(copy.files, target)) {
|
|
378
400
|
return Boolean(actual);
|
|
379
401
|
}
|
|
380
|
-
if (actual)
|
|
402
|
+
if (actual) {
|
|
403
|
+
if (index.has(target)) ownerSources.set(target, name);
|
|
404
|
+
return false; // Existing unrecorded source is edition-owned.
|
|
405
|
+
}
|
|
381
406
|
return !pinned.has(name) && (tests || !testSource(name));
|
|
382
407
|
});
|
|
383
408
|
if (!sources.length && !Object.keys(copy.adapted || {}).length) throw Error(`No Base source at ${copy.originPath} in ${revision}`);
|
|
384
409
|
return {copy, sources, retired, removed: Object.keys(copy.files).filter(name => !Object.hasOwn(copy.adapted || {}, name) && !sources.some(([source]) => mapped(source, copy.originPath, copy.path) === name))};
|
|
385
410
|
});
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}});
|
|
411
|
+
const templates = adoptWorkflowTemplates(root, plans, {tree: next, read, revision, files});
|
|
412
|
+
notices = templates.notices;
|
|
413
|
+
completeWorkflowHelpers(root, plans, {tree: next, read, revision});
|
|
414
|
+
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, ownerSources,
|
|
415
|
+
deliveries: migrations.flatMap(step => step.deliver.map(source => ({source, origin: step.origin, importers: step.copies})))});
|
|
392
416
|
// Closure may add individually recorded siblings when the seed originally
|
|
393
417
|
// selected runtime files one at a time instead of copying the directory.
|
|
394
|
-
record.copies = plans.map(plan => plan.copy).sort((a, b) => a.path.localeCompare(b.path));
|
|
395
418
|
// A migration a database may already have applied is never rewritten in place:
|
|
396
419
|
// the schema change it brings belongs in a new migration of the seed's own.
|
|
397
420
|
const applied = plans.flatMap(({copy, sources}) => sources.map(([source, {object}]) => [mapped(source, copy.originPath, copy.path), object])
|
|
398
421
|
.filter(([name, object]) => name.split('/').slice(0, -1).includes('migrations') && local(name) && local(name) !== upstream.get(object)).map(([name]) => name));
|
|
399
422
|
if (applied.length) throw Error(`Refusing to rewrite migrations that may already be applied: ${applied.join(', ')}. Base changed these files after they were copied; keep them as they are, drop them from ${recordPath}, and add a new migration for the change instead.`);
|
|
423
|
+
// A file already owned by the edition can become byte-equal when Base adds
|
|
424
|
+
// its own implementation. Preserve ownership explicitly for discovery; it
|
|
425
|
+
// must never enter the copy write plan merely because the bytes now match.
|
|
426
|
+
const ownedMatches = [...ownerSources].filter(([target, source]) => {
|
|
427
|
+
const entry = next.get(source);
|
|
428
|
+
return entry && local(target) === upstream.get(entry.object);
|
|
429
|
+
}).map(([target]) => target);
|
|
430
|
+
if (ownedMatches.length) record.ignore = [...new Set([...(record.ignore || []), ...ownedMatches])].sort();
|
|
400
431
|
const bytes = read.blobs(plans.flatMap(plan => plan.sources.map(([, {object}]) => object)));
|
|
401
|
-
|
|
432
|
+
const writes = plans.flatMap(({copy, sources}) => sources.map(([source, entry]) => ({
|
|
433
|
+
name: safe(mapped(source, copy.originPath, copy.path)), ...entry,
|
|
434
|
+
})));
|
|
435
|
+
const byName = new Map(writes.map(entry => [entry.name, entry]));
|
|
402
436
|
const changes = [];
|
|
403
437
|
for (const {copy, sources, removed} of plans) {
|
|
404
|
-
for (const name of removed) { noLinks(root, name); fs.rmSync(path.join(root, name), {force: true}); }
|
|
405
438
|
const recorded = {}, modes = {}, added = [];
|
|
406
439
|
for (const name of Object.keys(copy.adapted || {})) {
|
|
407
440
|
recorded[name] = copy.files[name];
|
|
408
441
|
if (copy.modes?.[name]) modes[name] = copy.modes[name];
|
|
409
442
|
}
|
|
410
|
-
for (const [source
|
|
443
|
+
for (const [source] of sources.sort(([a], [b]) => a.localeCompare(b))) {
|
|
411
444
|
const name = safe(mapped(source, copy.originPath, copy.path));
|
|
412
|
-
|
|
445
|
+
const {object, mode} = byName.get(name);
|
|
413
446
|
if (!Object.hasOwn(copy.files, name)) added.push(name);
|
|
414
|
-
const target = path.join(root, name);
|
|
415
|
-
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
416
|
-
fs.writeFileSync(target, bytes.get(object));
|
|
417
|
-
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
418
447
|
recorded[name] = upstream.get(object); modes[name] = mode;
|
|
419
448
|
}
|
|
420
449
|
changes.push({path: copy.path, from: copy.revision, files: sources.length, added, removed});
|
|
@@ -423,7 +452,25 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
423
452
|
record.copies = plans.filter(plan => !plan.retired).map(plan => plan.copy);
|
|
424
453
|
delete record.repository;
|
|
425
454
|
validate(record);
|
|
455
|
+
preflightRefresh(root, plans, recordPath, files);
|
|
456
|
+
writing = true;
|
|
457
|
+
for (const {copy, sources, removed} of plans) {
|
|
458
|
+
for (const name of removed) { noLinks(root, name); fs.rmSync(path.join(root, name), {force: true}); }
|
|
459
|
+
for (const [source] of sources) {
|
|
460
|
+
const name = safe(mapped(source, copy.originPath, copy.path));
|
|
461
|
+
const {object, mode} = byName.get(name);
|
|
462
|
+
noLinks(root, name);
|
|
463
|
+
const target = path.join(root, name);
|
|
464
|
+
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
465
|
+
fs.writeFileSync(target, bytes.get(object));
|
|
466
|
+
fs.chmodSync(target, mode === '100755' ? 0o755 : 0o644);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
426
469
|
fs.writeFileSync(filename, json(record));
|
|
427
|
-
return {refreshed: revision, record: recordPath, copies: changes, retired: plans.filter(plan => plan.retired).map(plan => plan.copy.path), adapted, next: 'Run verify-base, then the edition tests, and commit the copied files with the record.'};
|
|
470
|
+
return {refreshed: revision, record: recordPath, copies: changes, retired: plans.filter(plan => plan.retired).map(plan => plan.copy.path), adapted, withheld, editionMigrations: migrations.map(({id, guide, edit, copies}) => ({id, guide, edit, copies})), ...templates, next: 'Run verify-base, then the edition tests, and commit the copied files with the record.'};
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (!writing && !/no files were refreshed/i.test(error.message)) error.message += ' No files were refreshed.';
|
|
473
|
+
if (!writing && notices.length) error.message += '\n' + notices.join('\n');
|
|
474
|
+
throw error;
|
|
428
475
|
} finally { origin.close(); }
|
|
429
476
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {git, raw, safe, noLinks,
|
|
4
|
-
import {specifiers} from './runtime-dependencies.mjs';
|
|
3
|
+
import {git, raw, safe, noLinks, requirePhysical, freedEntries} from './files.mjs';
|
|
5
4
|
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
6
5
|
|
|
7
6
|
// -v marks assume-unchanged; -f marks fsmonitor-valid. Read them separately
|
|
@@ -45,7 +44,7 @@ export function requireMaterializedCopies(root, record, files) {
|
|
|
45
44
|
const prefix = path.relative(root, path.join(directory, link[0])).split(path.sep).join('/');
|
|
46
45
|
const child = path.join(root, prefix);
|
|
47
46
|
let initialized = false;
|
|
48
|
-
try { initialized = fs.realpathSync(git(child, 'rev-parse', '--show-toplevel')) === fs.realpathSync(child); } catch {}
|
|
47
|
+
try { initialized = fs.realpathSync(git(child, 'rev-parse', '--show-toplevel')) === fs.realpathSync(child); } catch { initialized = false; }
|
|
49
48
|
if (!initialized) throw Error(`Base copy ${name} is beneath the uninitialized Git submodule ${prefix}. Run git -C ${quote(directory)} submodule update --init -- ${quote(link[0])}, then repeat refresh-base. No copy record was changed.`);
|
|
50
49
|
relative = relative.slice(link[0].length + 1);
|
|
51
50
|
directory = child;
|
|
@@ -69,131 +68,19 @@ export function requireMaterializedCopies(root, record, files) {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
// Every recorded authoring module is a root, including exported mirrors and
|
|
73
|
-
// local adaptations. Edition-owned tracked siblings end traversal at that edge.
|
|
74
|
-
export function completeAuthoringImports(root, plans, {tree, read, revision, base}) {
|
|
75
|
-
const mapped = (name, copy) => copy.path + name.slice(copy.originPath.length);
|
|
76
|
-
const authoring = name => path.posix.basename(path.posix.dirname(name)) === 'edition-authoring' && name.endsWith('.mjs') && !testSource(name);
|
|
77
|
-
const tracked = index(root), planned = new Map(), recorded = new Map(), queue = [];
|
|
78
|
-
for (const plan of plans) {
|
|
79
|
-
for (const name of Object.keys(plan.copy.files)) recorded.set(name, plan);
|
|
80
|
-
for (const [source, entry] of plan.sources) {
|
|
81
|
-
const target = mapped(source, plan.copy);
|
|
82
|
-
planned.set(target, plan);
|
|
83
|
-
if (authoring(source)) queue.push({source, target, entry});
|
|
84
|
-
}
|
|
85
|
-
for (const target of Object.keys(plan.copy.adapted || {})) {
|
|
86
|
-
const source = plan.copy.originPath + target.slice(plan.copy.path.length);
|
|
87
|
-
if (authoring(source)) queue.push({source, target, adapted: true});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const refuse = (target, reason, command) => {
|
|
91
|
-
throw Error(`Cannot refresh authoring import ${target}: ${reason}. Run ${command}, then repeat refresh-base; no files were refreshed.`);
|
|
92
|
-
};
|
|
93
|
-
const move = target => `mv -i -- ${quote(target)} ${quote(target + '.refresh-backup')}`;
|
|
94
|
-
// Unlike the write preflight, closure must also validate files it only relies
|
|
95
|
-
// on. Read actual directory entries to reject aliases, never infer volume case.
|
|
96
|
-
function inspect(target) {
|
|
97
|
-
const parts = safe(target).split('/');
|
|
98
|
-
let parent = root;
|
|
99
|
-
for (const [i, part] of parts.entries()) {
|
|
100
|
-
const absolute = path.join(parent, part), name = parts.slice(0, i + 1).join('/');
|
|
101
|
-
let stat;
|
|
102
|
-
try { stat = fs.lstatSync(absolute); }
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (error.code === 'ENOENT') return null;
|
|
105
|
-
refuse(name, error.message, move(name));
|
|
106
|
-
}
|
|
107
|
-
if (!fs.readdirSync(parent).includes(part)) refuse(name, 'the volume resolves a differently spelled entry', move(name));
|
|
108
|
-
if (stat.isSymbolicLink()) refuse(name, 'symlink in import path', move(name));
|
|
109
|
-
if (i < parts.length - 1 && !stat.isDirectory()) refuse(name, 'import parent is not a directory', move(name));
|
|
110
|
-
if (i === parts.length - 1) {
|
|
111
|
-
if (!stat.isFile()) refuse(name, 'import is not a regular file', move(name));
|
|
112
|
-
return stat;
|
|
113
|
-
}
|
|
114
|
-
parent = absolute;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const blobs = new Map(), seen = new Set();
|
|
118
|
-
for (let i = 0; i < queue.length; i++) {
|
|
119
|
-
const {source, target, entry, adapted} = queue[i];
|
|
120
|
-
if (seen.has(target)) continue;
|
|
121
|
-
seen.add(target);
|
|
122
|
-
inspect(target);
|
|
123
|
-
let bytes;
|
|
124
|
-
if (adapted) bytes = fs.readFileSync(path.join(root, target), 'utf8');
|
|
125
|
-
else {
|
|
126
|
-
if (!blobs.has(entry.object)) blobs.set(entry.object, read.blobs([entry.object]).get(entry.object).toString('utf8'));
|
|
127
|
-
bytes = blobs.get(entry.object);
|
|
128
|
-
}
|
|
129
|
-
for (const specifier of specifiers(bytes)) {
|
|
130
|
-
const directory = path.posix.dirname(source);
|
|
131
|
-
const dependency = path.posix.normalize(path.posix.join(directory, specifier));
|
|
132
|
-
const destination = path.posix.normalize(path.posix.join(path.posix.dirname(target), specifier));
|
|
133
|
-
if (path.posix.dirname(dependency) !== directory) {
|
|
134
|
-
refuse(target, `import ${specifier} leaves its directory`, `\${EDITOR:-vi} ${quote(target)}`);
|
|
135
|
-
}
|
|
136
|
-
const exists = inspect(destination), owner = recorded.get(destination);
|
|
137
|
-
if (owner?.removed.includes(destination)) {
|
|
138
|
-
const original = owner.copy.originPath + destination.slice(owner.copy.path.length);
|
|
139
|
-
const restore = tracked.has(destination) ? `git restore -- ${quote(destination)}` :
|
|
140
|
-
`git -C ${quote(base)} show ${quote(owner.copy.revision + ':' + original)} > ${quote(destination)}`;
|
|
141
|
-
refuse(destination, 'recorded file was removed but is still imported', restore);
|
|
142
|
-
}
|
|
143
|
-
if (planned.has(destination) || owner) continue;
|
|
144
|
-
if (tracked.has(destination)) {
|
|
145
|
-
if (!exists) refuse(destination, 'tracked edition source is missing', `git restore -- ${quote(destination)}`);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (exists) refuse(destination, 'existing file has no Base copy record or Git index entry', `git add -f -- ${quote(destination)}`);
|
|
149
|
-
const value = tree.get(dependency);
|
|
150
|
-
if (!value) refuse(destination, `no source at ${dependency} in ${revision}`, `\${EDITOR:-vi} ${quote(target)}`);
|
|
151
|
-
// A directory copy can already own this destination's namespace. Extend
|
|
152
|
-
// that record; otherwise the dependency is a new singleton copy.
|
|
153
|
-
let plan = plans.find(plan => destination.startsWith(plan.copy.path + '/'));
|
|
154
|
-
if (plan && mapped(dependency, plan.copy) !== destination) {
|
|
155
|
-
refuse(destination, 'source cannot fit its enclosing copy record', `\${EDITOR:-vi} base-copies.json`);
|
|
156
|
-
}
|
|
157
|
-
if (!plan) {
|
|
158
|
-
if (plans.some(plan => plan.copy.path.startsWith(destination + '/'))) refuse(destination, 'overlaps a copy directory', `\${EDITOR:-vi} base-copies.json`);
|
|
159
|
-
plan = {copy: {path: destination, originPath: dependency, revision, files: {}, modes: {}}, sources: [], removed: []};
|
|
160
|
-
plans.push(plan);
|
|
161
|
-
}
|
|
162
|
-
plan.sources.push([dependency, value]);
|
|
163
|
-
planned.set(destination, plan);
|
|
164
|
-
queue.push({source: dependency, target: destination, entry: value});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
71
|
// Inspect real filesystem facts in apply order without opening or changing any
|
|
170
72
|
// file. This cannot see later races, disk-space or I/O failures, umask on newly
|
|
171
73
|
// created directories, or two new names differing only in case on an insensitive
|
|
172
74
|
// volume. Only earlier removals are remembered; no future directory is modelled.
|
|
173
75
|
export function preflightRefresh(root, plans, recordPath, seedFiles) {
|
|
174
|
-
const uid = process.geteuid?.(), freed =
|
|
175
|
-
const identity = (name, stat) => stat.nlink > 1 ? name : `${stat.dev}:${stat.ino}`;
|
|
76
|
+
const uid = process.geteuid?.(), freed = freedEntries(root);
|
|
176
77
|
const writable = (target, stat, directory = false) => {
|
|
177
78
|
if (uid === 0 && !(stat.mode & 0o222)) throw Error('no write permission bits');
|
|
178
79
|
fs.accessSync(target, fs.constants.W_OK | (directory ? fs.constants.X_OK : 0));
|
|
179
80
|
};
|
|
81
|
+
const cache = new Map();
|
|
180
82
|
function inspect(name) {
|
|
181
|
-
|
|
182
|
-
if (!parentStat.isDirectory()) throw Error('checkout root is not a directory');
|
|
183
|
-
const parts = safe(name).split('/');
|
|
184
|
-
for (const [i, part] of parts.entries()) {
|
|
185
|
-
const target = path.join(parent, part), relative = parts.slice(0, i + 1).join('/');
|
|
186
|
-
let stat;
|
|
187
|
-
try { stat = fs.lstatSync(target); }
|
|
188
|
-
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
189
|
-
if (!stat || (stat.isFile() && freed.has(identity(relative, stat)))) return {parent, parentStat};
|
|
190
|
-
if (i === parts.length - 1) {
|
|
191
|
-
if (!stat.isFile()) throw Error('destination is not a regular file');
|
|
192
|
-
return {parent, parentStat, target, stat};
|
|
193
|
-
}
|
|
194
|
-
if (!stat.isDirectory()) throw Error(`directory required at ${relative}`);
|
|
195
|
-
parent = target; parentStat = stat;
|
|
196
|
-
}
|
|
83
|
+
return requirePhysical(root, name, {cache, freed: freed.has});
|
|
197
84
|
}
|
|
198
85
|
function check(name, operation) {
|
|
199
86
|
try {
|
|
@@ -202,9 +89,9 @@ export function preflightRefresh(root, plans, recordPath, seedFiles) {
|
|
|
202
89
|
if (!stat) return;
|
|
203
90
|
writable(parent, parentStat, true);
|
|
204
91
|
if (uid !== undefined && uid !== 0 && (parentStat.mode & 0o1000) && uid !== parentStat.uid && uid !== stat.uid) throw Error('sticky parent and file are owned by another user');
|
|
205
|
-
freed.add(
|
|
92
|
+
freed.add(name, stat);
|
|
206
93
|
} else if (stat) {
|
|
207
|
-
if (operation !== 'record' && !seedFiles.has(name)) throw Error('existing destination is ignored
|
|
94
|
+
if (operation !== 'record' && !seedFiles.has(name)) throw Error('existing destination is ignored');
|
|
208
95
|
writable(target, stat);
|
|
209
96
|
if (operation !== 'record' && uid !== undefined && uid !== 0 && uid !== stat.uid) throw Error('file is owned by another user; cannot set its mode');
|
|
210
97
|
} else writable(parent, parentStat, true);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Base declares edition edits; consent permits refresh, never edits seed data.
|
|
2
|
+
import {safe} from './files.mjs';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
const dataPath = 'foundation/edition-migrations.json';
|
|
5
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
6
|
+
export function editionMigrations(record, {tree, read, revision, base, recordPath, offline, consent = []}) {
|
|
7
|
+
let migrations = [];
|
|
8
|
+
const fail = reason => { throw Error(`Base edition migration data error: ${reason}. Repair ${dataPath} in Base and commit it, then refresh to that commit; no files were refreshed.`); };
|
|
9
|
+
if (tree.has(dataPath)) {
|
|
10
|
+
try {
|
|
11
|
+
const data = JSON.parse(read.blobs([tree.get(dataPath).object]).get(tree.get(dataPath).object));
|
|
12
|
+
if (data.schemaVersion !== 1 || !Array.isArray(data.migrations)) fail('invalid schema');
|
|
13
|
+
const ids = new Set();
|
|
14
|
+
for (const step of data.migrations) {
|
|
15
|
+
if (!step || !/^[a-z][a-z0-9-]+$/.test(step.id) || ids.has(step.id) || !/^[a-f0-9]{40}$/.test(step.introduced) ||
|
|
16
|
+
typeof step.guide !== 'string' || !step.guide || typeof step.edit !== 'string' || !step.edit ||
|
|
17
|
+
!Array.isArray(step.deliver) || step.deliver.some(name => typeof name !== 'string')) fail('invalid entry');
|
|
18
|
+
safe(step.origin); safe(step.guide); step.deliver.forEach(safe);
|
|
19
|
+
read.tree(step.introduced);
|
|
20
|
+
for (const name of step.deliver) if (!tree.has(name)) fail(`missing delivery ${name}`);
|
|
21
|
+
ids.add(step.id);
|
|
22
|
+
}
|
|
23
|
+
migrations = data.migrations;
|
|
24
|
+
} catch (error) { fail(error.message); }
|
|
25
|
+
}
|
|
26
|
+
for (const id of consent) if (!migrations.some(step => step.id === id)) throw Error(`Unknown edition migration ${id} at Base ${revision}. Use only ids declared in ${dataPath} at that commit; no files were refreshed.`);
|
|
27
|
+
const applicable = migrations.flatMap(step => {
|
|
28
|
+
if (!read.contains(revision, step.introduced)) return [];
|
|
29
|
+
const copies = record.copies.flatMap(copy => Object.keys(copy.files).filter(name =>
|
|
30
|
+
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin && !read.contains(copy.revision, step.introduced)));
|
|
31
|
+
return copies.length ? [{...step, copies}] : [];
|
|
32
|
+
});
|
|
33
|
+
const missing = applicable.filter(step => !consent.includes(step.id));
|
|
34
|
+
if (missing.length) {
|
|
35
|
+
const cli = fileURLToPath(new URL('./cli.mjs', import.meta.url));
|
|
36
|
+
// Keep automatic acquisition automatic: its temporary checkout closes on refusal.
|
|
37
|
+
const command = `${quote(process.execPath)} ${quote(cli)} refresh-base ${revision}${base ? ' --base ' + quote(base) : ''} --record ${quote(recordPath)}${offline ? ' --offline' : ''}${applicable.map(step => ' --edition-migration ' + step.id).join('')}`;
|
|
38
|
+
throw Error(`Edition migrations require consent before planning:\n${missing.map(step => `${step.id}: ${step.copies.join(', ')}; ${step.guide}: ${step.edit}`).join('\n')}\nReview the guides and repeat exactly: ${command}\nRefresh will leave these edition-owned edits owed; no files were refreshed.`);
|
|
39
|
+
}
|
|
40
|
+
return applicable;
|
|
41
|
+
}
|
|
@@ -38,6 +38,63 @@ export function safe(name) {
|
|
|
38
38
|
}
|
|
39
39
|
return name;
|
|
40
40
|
}
|
|
41
|
+
// One physical spelling/type check for refresh writes and dependencies. Cache
|
|
42
|
+
// directory entries only for one read-only planning pass; removals take priority.
|
|
43
|
+
export function freedEntries(root) {
|
|
44
|
+
const removed = new Set();
|
|
45
|
+
const identity = (name, stat) => stat.nlink > 1 ? name : `${stat.dev}:${stat.ino}`;
|
|
46
|
+
return {
|
|
47
|
+
add: (name, stat) => removed.add(identity(name, stat)),
|
|
48
|
+
has(relative, stat, parent) {
|
|
49
|
+
if (stat.isFile()) return removed.has(identity(relative, stat));
|
|
50
|
+
if (!parent || !stat.isDirectory() || !removed.size) return false;
|
|
51
|
+
let found = false;
|
|
52
|
+
const empty = directory => fs.readdirSync(directory).every(name => {
|
|
53
|
+
const absolute = path.join(directory, name), child = fs.lstatSync(absolute);
|
|
54
|
+
if (child.isDirectory()) return empty(absolute);
|
|
55
|
+
const freed = child.isFile() && removed.has(identity(path.relative(root, absolute), child));
|
|
56
|
+
found ||= freed;
|
|
57
|
+
return freed;
|
|
58
|
+
});
|
|
59
|
+
return empty(path.join(root, relative)) && found;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function physicalEntry(root, name, {cache = new Map(), freed = () => false} = {}) {
|
|
64
|
+
let parent = root, parentStat = fs.lstatSync(root);
|
|
65
|
+
const parts = safe(name).split('/');
|
|
66
|
+
for (const [i, part] of parts.entries()) {
|
|
67
|
+
const target = path.join(parent, part), relative = parts.slice(0, i + 1).join('/');
|
|
68
|
+
let stat;
|
|
69
|
+
try { stat = fs.lstatSync(target); }
|
|
70
|
+
catch (error) { if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') throw error; }
|
|
71
|
+
if (!stat || freed(relative, stat, i < parts.length - 1)) return {absent: true, parent, parentStat};
|
|
72
|
+
if (!cache.has(parent)) cache.set(parent, fs.readdirSync(parent));
|
|
73
|
+
const entries = cache.get(parent);
|
|
74
|
+
if (!entries.includes(part)) {
|
|
75
|
+
const physical = entries.find(entry => {
|
|
76
|
+
const other = fs.lstatSync(path.join(parent, entry));
|
|
77
|
+
return other.dev === stat.dev && other.ino === stat.ino;
|
|
78
|
+
});
|
|
79
|
+
return {kind: 'alias', path: relative, physical: path.relative(root, path.join(parent, physical ?? part))};
|
|
80
|
+
}
|
|
81
|
+
if (stat.isSymbolicLink()) return {kind: 'symlink', path: relative};
|
|
82
|
+
if (i < parts.length - 1 && !stat.isDirectory()) return {kind: 'non-directory parent', path: relative};
|
|
83
|
+
if (i === parts.length - 1) return stat.isFile() ? {stat, target, parent, parentStat} : {kind: 'non-regular', path: relative};
|
|
84
|
+
parent = target; parentStat = stat;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function requirePhysical(root, name, options) {
|
|
88
|
+
const entry = physicalEntry(root, name, options);
|
|
89
|
+
if (entry.kind) {
|
|
90
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
91
|
+
const indexed = raw(root, '--literal-pathspecs', 'ls-files', '--', entry.path).length > 0;
|
|
92
|
+
const command = `backup=$(mktemp -d) && mv -- ${quote(entry.physical ?? entry.path)} "$backup/"${indexed ? ' && git restore -- ' + quote(entry.path) : ''}`;
|
|
93
|
+
const reason = entry.kind === 'symlink' ? 'Symlink in destination path' : entry.kind === 'non-regular' ? 'destination is not a regular file' : entry.kind;
|
|
94
|
+
throw Error(`Cannot refresh ${name}: ${reason} at ${entry.physical ?? entry.path}. Run ${command}, then repeat refresh-base; no files were refreshed.`);
|
|
95
|
+
}
|
|
96
|
+
return entry;
|
|
97
|
+
}
|
|
41
98
|
export function noLinks(root, relative) {
|
|
42
99
|
let current = root;
|
|
43
100
|
for (const part of relative.split('/')) {
|
|
@@ -62,6 +119,16 @@ export function tracked(root, allowMissing = false) {
|
|
|
62
119
|
return result;
|
|
63
120
|
}
|
|
64
121
|
export const digest = files => hash(json(files));
|
|
122
|
+
// The complete tool in `dir`, as sorted relative paths: its non-test modules and
|
|
123
|
+
// every vendored parser file with its licence. Copies and the lock identity use it.
|
|
124
|
+
export function toolFiles(dir) {
|
|
125
|
+
const modules = fs.readdirSync(dir).filter(p => p.endsWith('.mjs') && !p.endsWith('.test.mjs'));
|
|
126
|
+
const vendored = fs.readdirSync(path.join(dir, 'vendor'), {recursive: true, withFileTypes: true}).filter(entry => {
|
|
127
|
+
if (!entry.isFile() && !entry.isDirectory()) throw Error(`Unsupported vendored tool entry: ${entry.name}`);
|
|
128
|
+
return entry.isFile();
|
|
129
|
+
}).map(entry => path.relative(dir, path.join(entry.parentPath, entry.name)).split(path.sep).join('/'));
|
|
130
|
+
return [...modules, ...vendored].sort();
|
|
131
|
+
}
|
|
65
132
|
// Base's test, fixture and browser-check sources, which portable copies leave out.
|
|
66
133
|
// Composition pins its tooling alone, so composition/git-source.mjs keeps its own copy.
|
|
67
134
|
export function testSource(path) {
|
|
@@ -3,11 +3,11 @@ import path from 'node:path';
|
|
|
3
3
|
import {fileURLToPath} from 'node:url';
|
|
4
4
|
import {manifest, VERSION} from './manifest.mjs';
|
|
5
5
|
import {snapshot, merge} from './sources.mjs';
|
|
6
|
-
import {hash, json, tracked} from './files.mjs';
|
|
6
|
+
import {hash, json, tracked, toolFiles} from './files.mjs';
|
|
7
7
|
|
|
8
8
|
function toolsIdentity() {
|
|
9
9
|
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const names =
|
|
10
|
+
const names = toolFiles(dir);
|
|
11
11
|
const bytes = names.map(p => p + '\0' + fs.readFileSync(path.join(dir, p), 'utf8')).join('\0');
|
|
12
12
|
return {id: 'runeditrun/edition-authoring', version: VERSION, sha256: hash(bytes)};
|
|
13
13
|
}
|