@runeditrun/rer 0.2.79 → 0.2.80
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 +17 -3
- package/cli/README.md +25 -13
- package/cli/authoring.mjs +14 -0
- package/cli/contract.mjs +25 -5
- package/cli/demo-host.mjs +4 -2
- package/cli/dev-identity.mjs +2 -2
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +38 -2
- package/cli/main.mjs +8 -2
- package/cli/managed-server.mjs +1 -1
- package/cli/parse.mjs +7 -6
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +6 -2
- package/cli/production-auth.mjs +2 -1
- package/cli/production-mail.mjs +36 -9
- package/cli/project.mjs +5 -14
- package/cli/release.mjs +2 -1
- package/cli/site-preview.mjs +4 -1
- package/cli/site.mjs +3 -2
- package/edition-authoring/adopt.mjs +39 -0
- package/edition-authoring/base-acknowledgements.mjs +24 -0
- package/edition-authoring/base-copies.mjs +418 -0
- package/edition-authoring/cli.mjs +85 -0
- package/edition-authoring/copy-checkout.mjs +69 -0
- package/edition-authoring/files.mjs +15 -2
- package/edition-authoring/lock.mjs +48 -0
- package/edition-authoring/offline-git.mjs +28 -0
- package/edition-authoring/parent-comparison.mjs +77 -0
- package/edition-authoring/projection-lock.mjs +38 -0
- package/edition-authoring/release.mjs +48 -0
- package/edition-authoring/sources.mjs +114 -0
- package/edition-authoring/updates.mjs +105 -0
- package/global/CHANGELOG.md +12 -0
- package/global/README.md +17 -3
- package/global/cli/install.mjs +3 -1
- package/global/main.mjs +9 -12
- package/modules/container/build.mjs +1 -1
- package/modules/d1-transport/index.mjs +68 -21
- package/modules/demo/README.md +8 -2
- package/modules/demo/declaration.mjs +21 -0
- package/modules/demo/input-path.mjs +18 -0
- package/modules/demo/label.d.mts +1 -1
- package/modules/demo/label.mjs +10 -5
- package/modules/demo/navigation.mjs +32 -0
- package/modules/demo/run-url.mjs +9 -0
- package/modules/demo/vite.d.mts +7 -2
- package/modules/demo/vite.mjs +17 -2
- package/modules/demo-host/README.md +5 -3
- package/modules/demo-host/page-style.mjs +2 -2
- package/modules/demo-host/pages.mjs +3 -3
- package/modules/demo-host/plan.mjs +6 -4
- package/modules/demo-host/theme.mjs +5 -2
- package/modules/deploy-kit/README.md +19 -15
- package/modules/deploy-kit/owner-cli.mjs +1 -1
- package/modules/deploy-kit/readiness-window.mjs +3 -3
- package/modules/erasure/README.md +10 -5
- package/modules/import-kit/src/d1/README.md +15 -9
- package/modules/import-kit/src/d1/apply.ts +10 -6
- package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
- package/modules/import-kit/src/d1/budget.ts +48 -26
- package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
- package/modules/import-kit/src/d1/database.ts +2 -1
- package/modules/import-kit/src/d1/jobs.ts +2 -1
- package/modules/import-kit/src/d1/plans.ts +4 -2
- package/modules/import-kit/src/d1/verified-plan.ts +63 -0
- package/modules/integrations/core/README.md +2 -2
- package/modules/mail/README.md +4 -3
- package/modules/mail/pnpm-lock.yaml +16 -0
- package/modules/operator-auth/accounts/native.mjs +3 -1
- package/modules/operator-auth/accounts/provider-control.mjs +7 -4
- package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
- package/modules/operator-auth/accounts/settings-page.mjs +13 -4
- package/modules/operator-auth/conformance/README.md +1 -1
- package/modules/operator-auth/dev/index.mjs +22 -4
- package/modules/operator-auth/dev/refusal.mjs +19 -0
- package/modules/operator-auth/docs/README.md +6 -5
- package/modules/operator-auth/docs/tanstack-start.md +1 -1
- package/modules/operator-auth/docs/vite-spa.md +5 -6
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/operator-auth/page.mjs +14 -0
- package/modules/operator-auth/representation.mjs +83 -0
- package/modules/operator-auth/routes.mjs +25 -2
- package/modules/portability/README.md +91 -14
- package/modules/portability/bookkeeping.mjs +3 -3
- package/modules/portability/bridge.mjs +5 -4
- package/modules/portability/catalogue.mjs +12 -8
- package/modules/portability/cli.mjs +5 -1
- package/modules/portability/export.mjs +5 -11
- package/modules/portability/format.mjs +7 -1
- package/modules/portability/http-errors.mjs +51 -0
- package/modules/portability/http.mjs +4 -1
- package/modules/portability/import-lease.mjs +13 -2
- package/modules/portability/import.mjs +10 -0
- package/modules/portability/index.d.mts +3 -0
- package/modules/portability/references.mjs +20 -0
- package/modules/portability/schema-identity.mjs +13 -0
- package/modules/portability/schema-legacy.mjs +21 -0
- package/modules/portability/sqlite-tokens.mjs +121 -0
- package/modules/release/README.md +20 -9
- package/modules/release/github-verify.mjs +30 -9
- package/modules/site/docs-search/search.css +1 -1
- package/onboarding/README.md +16 -4
- package/onboarding/adapter.mjs +5 -1
- package/onboarding/schema/SETUP.schema.json +26 -1
- package/onboarding/schema/business-field-inputs.mjs +37 -0
- package/onboarding/schema/json-schema.mjs +6 -2
- package/onboarding/schema/setup-validation.mjs +20 -3
- package/onboarding/server.mjs +1 -1
- package/onboarding/setup-manifest.mjs +2 -0
- package/onboarding/start-origin-diagnostic.mjs +24 -0
- package/onboarding/ui/style.css +9 -9
- package/package.json +1 -1
- package/scripts/publish-check/README.md +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {release, verifyReceipt} from './release.mjs';
|
|
5
|
+
import {changes, extract, compare} from './updates.mjs';
|
|
6
|
+
import {manifest} from './manifest.mjs';
|
|
7
|
+
import {snapshot, source, merge} from './sources.mjs';
|
|
8
|
+
import {options, adaptCopy, recordCopy, refreshCopies, verifyCopies} from './base-copies.mjs';
|
|
9
|
+
import {json, tracked, writeTree, fresh} from './files.mjs';
|
|
10
|
+
|
|
11
|
+
import {resolveSources} from './lock.mjs';
|
|
12
|
+
import {adoptEdition} from './adopt.mjs';
|
|
13
|
+
|
|
14
|
+
const root = process.cwd();
|
|
15
|
+
const resolve = (retain = false, diagnostics = false) => resolveSources(root, retain, diagnostics);
|
|
16
|
+
function check() {
|
|
17
|
+
const expected = JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json'), 'utf8'));
|
|
18
|
+
const actual = resolve();
|
|
19
|
+
if (json(expected) !== json(actual)) throw Error('Stale lock or source/tool integrity mismatch; run changes to inspect intentional edits before lock');
|
|
20
|
+
return actual;
|
|
21
|
+
}
|
|
22
|
+
function materialize(destination) {
|
|
23
|
+
const output = fresh(destination, root);
|
|
24
|
+
const recipe = manifest(root);
|
|
25
|
+
const files = tracked(root);
|
|
26
|
+
for (const component of recipe.components) {
|
|
27
|
+
if (component.source.kind === 'git') merge(files, component.source.destination, source(root, component.source, true));
|
|
28
|
+
}
|
|
29
|
+
fs.mkdirSync(output, {recursive: true});
|
|
30
|
+
writeTree(output, files);
|
|
31
|
+
return {output, development: true};
|
|
32
|
+
}
|
|
33
|
+
function promote(id) {
|
|
34
|
+
const recipe = manifest(root);
|
|
35
|
+
const component = recipe.components.find(c => c.id === id);
|
|
36
|
+
if (!component || component.source.kind !== 'git') throw Error('Select a Git component');
|
|
37
|
+
const selected = component.source;
|
|
38
|
+
const destinationExisted = fs.existsSync(path.join(root, selected.destination));
|
|
39
|
+
const files = source(root, selected, true);
|
|
40
|
+
snapshot(root, selected, true);
|
|
41
|
+
merge(tracked(root), selected.destination, files);
|
|
42
|
+
const retained = Object.fromEntries(Object.entries(files).map(([name, value]) => [selected.destination + '/' + name, value]));
|
|
43
|
+
writeTree(root, retained);
|
|
44
|
+
component.source = {
|
|
45
|
+
kind: 'local', paths: destinationExisted ? Object.keys(retained) : [selected.destination],
|
|
46
|
+
origin: {
|
|
47
|
+
repository: selected.repository, ...(selected.projection ? {projection: selected.projection} : {revision: selected.revision}), path: selected.path || '.',
|
|
48
|
+
...(selected.paths ? {paths: selected.paths} : {}),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
fs.writeFileSync(path.join(root, 'edition.json'), json(recipe));
|
|
52
|
+
return {promoted: id, destination: selected.destination, next: 'git add the retained source and recipe, then lock and commit'};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const args = process.argv.slice(2);
|
|
57
|
+
// Package scripts may forward their argument separator after the command.
|
|
58
|
+
if (args[1] === '--') args.splice(1, 1);
|
|
59
|
+
const [command, argument, candidate, current] = args;
|
|
60
|
+
let result;
|
|
61
|
+
if (command === 'adopt') result = adoptEdition(root);
|
|
62
|
+
else if (command === 'inspect') result = manifest(root);
|
|
63
|
+
else if (command === 'lock') {
|
|
64
|
+
result = resolve(true);
|
|
65
|
+
fs.writeFileSync(path.join(root, 'sources.lock.json'), json(result));
|
|
66
|
+
} else if (command === 'check') result = {ok: true, ...check()};
|
|
67
|
+
else if (command === 'materialize' && argument) result = materialize(argument);
|
|
68
|
+
else if (command === 'promote' && argument) result = promote(argument);
|
|
69
|
+
else if (command === 'release' && argument) result = release(root, argument, check);
|
|
70
|
+
else if (command === 'receipt' && argument) result = verifyReceipt(root, argument, check);
|
|
71
|
+
else if (command === 'changes') result = changes(JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json'))), resolve(false, true));
|
|
72
|
+
else if (command === 'extract' && argument && candidate) result = extract(root, argument, candidate);
|
|
73
|
+
else if (command === 'compare' && argument && candidate) result = compare(root, argument, candidate, current);
|
|
74
|
+
else if (command === 'verify-base') {
|
|
75
|
+
result = verifyCopies(root, options(args.slice(1), 0));
|
|
76
|
+
if (!result.ok) process.exitCode = 1;
|
|
77
|
+
} else if (command === 'record-base') result = recordCopy(root, options(args.slice(1), 3));
|
|
78
|
+
else if (command === 'adapt-base') result = adaptCopy(root, options(args.slice(1), 1));
|
|
79
|
+
else if (command === 'refresh-base') result = refreshCopies(root, options(args.slice(1), 1));
|
|
80
|
+
else throw Error('Usage: cli.mjs adopt|inspect|lock|check|receipt <sidecar-json>|changes|extract <id|parent> <new-output>|compare <id|parent> <candidate-checkout> [current-parent-checkout]|materialize <new-output>|promote <id>|release <new-local-git-repository>|verify-base [--record <file>] [--base <checkout>] [--offline]|record-base <path> <origin-path> <revision> [--record <file>] [--base <checkout>]|adapt-base <file> [--record <file>]|refresh-base <revision> [--record <file>] [--base <checkout>]');
|
|
81
|
+
console.log(json(result));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(error.message);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {git, raw, safe, noLinks} from './files.mjs';
|
|
4
|
+
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
5
|
+
|
|
6
|
+
// -v marks assume-unchanged; -f marks fsmonitor-valid. Read them separately
|
|
7
|
+
// because either option can lowercase the normal checkout-state tag.
|
|
8
|
+
function index(root) {
|
|
9
|
+
try {
|
|
10
|
+
const read = flag => new Map(raw(root, 'ls-files', '--stage', flag, '-z').toString('utf8').split('\0').filter(Boolean).map(line => {
|
|
11
|
+
const match = /^([HSMRCK?hsmrck]) ([0-7]{6}) ([a-f0-9]{40,64}) 0\t(.+)$/.exec(line);
|
|
12
|
+
if (!match) throw Error('Unsupported index entry');
|
|
13
|
+
return [safe(match[4]), {tag: match[1], mode: match[2], object: match[3]}];
|
|
14
|
+
}));
|
|
15
|
+
const entries = read('-v'), monitor = read('-f');
|
|
16
|
+
if (entries.size !== monitor.size) throw Error('Index changed');
|
|
17
|
+
for (const [name, entry] of entries) {
|
|
18
|
+
const other = monitor.get(name);
|
|
19
|
+
if (!other || entry.mode !== other.mode || entry.object !== other.object) throw Error('Index changed');
|
|
20
|
+
entry.monitor = other.tag;
|
|
21
|
+
}
|
|
22
|
+
return entries;
|
|
23
|
+
} catch {
|
|
24
|
+
throw Error('Cannot read or interpret the Git index to decide whether Base copies were removed. Run git status and repair the checkout, then repeat refresh-base. No copy record was changed.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Absence alone is a removal signal only in a complete checkout. For a
|
|
29
|
+
// materialized submodule, inspect its own index and read the recorded child;
|
|
30
|
+
// the parent index lists the gitlink, never the child's files.
|
|
31
|
+
export function requireMaterializedCopies(root, record, files) {
|
|
32
|
+
const indexes = new Map();
|
|
33
|
+
const entriesAt = directory => {
|
|
34
|
+
if (!indexes.has(directory)) indexes.set(directory, index(directory));
|
|
35
|
+
return indexes.get(directory);
|
|
36
|
+
};
|
|
37
|
+
entriesAt(root);
|
|
38
|
+
for (const name of record.copies.flatMap(copy => Object.keys(copy.files))) {
|
|
39
|
+
let directory = root, relative = name;
|
|
40
|
+
for (;;) {
|
|
41
|
+
const entries = entriesAt(directory), entry = entries.get(relative);
|
|
42
|
+
const link = [...entries].find(([prefix, value]) => value.mode === '160000' && relative.startsWith(prefix + '/'));
|
|
43
|
+
if (link) {
|
|
44
|
+
const prefix = path.relative(root, path.join(directory, link[0])).split(path.sep).join('/');
|
|
45
|
+
const child = path.join(root, prefix);
|
|
46
|
+
let initialized = false;
|
|
47
|
+
try { initialized = fs.realpathSync(git(child, 'rev-parse', '--show-toplevel')) === fs.realpathSync(child); } catch {}
|
|
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.`);
|
|
49
|
+
relative = relative.slice(link[0].length + 1);
|
|
50
|
+
directory = child;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const target = path.join(root, name);
|
|
54
|
+
if (!fs.existsSync(target)) {
|
|
55
|
+
const repairs = [];
|
|
56
|
+
if (entry?.tag.toUpperCase() === 'S') repairs.push('git sparse-checkout disable');
|
|
57
|
+
if (entry && entry.tag === entry.tag.toLowerCase()) repairs.push(`git update-index --no-assume-unchanged -- ${quote(relative)}`);
|
|
58
|
+
if (entry && entry.monitor === entry.monitor.toLowerCase()) repairs.push(`git update-index --no-fsmonitor-valid -- ${quote(relative)}`);
|
|
59
|
+
if (directory !== root) repairs.push(`git restore -- ${quote(relative)}`);
|
|
60
|
+
if (repairs.length) throw Error(`Base copy ${name} has incomplete Git checkout evidence, not a confirmed removal. In ${directory}, run ${repairs.join(', then ')}, restore the file if absent, then repeat refresh-base. No copy record was changed.`);
|
|
61
|
+
} else if (directory !== root) {
|
|
62
|
+
noLinks(root, name);
|
|
63
|
+
const stat = fs.lstatSync(target);
|
|
64
|
+
files.set(name, {regular: stat.isFile(), executable: !!(stat.mode & 0o100), read: () => fs.readFileSync(target)});
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import {execFileSync} from 'node:child_process';
|
|
5
|
+
import {offlineRepository} from './offline-git.mjs';
|
|
5
6
|
export const hash = value => crypto.createHash('sha256').update(value).digest('hex');
|
|
6
7
|
export const json = value => JSON.stringify(value, null, 2) + '\n';
|
|
7
8
|
const environment = {...process.env, GIT_NO_REPLACE_OBJECTS: '1'};
|
|
@@ -9,9 +10,9 @@ export function git(root, ...args) {
|
|
|
9
10
|
return execFileSync('git', ['-C', root, ...args], {env: environment, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']}).trim();
|
|
10
11
|
}
|
|
11
12
|
// Raw Git output, for committed source bytes. The limit fails explicitly rather than truncating.
|
|
12
|
-
function output(root, args, input) {
|
|
13
|
+
function output(root, args, input, env = environment) {
|
|
13
14
|
try {
|
|
14
|
-
return execFileSync('git', ['-C', root, ...args], {env
|
|
15
|
+
return execFileSync('git', ['-C', root, ...args], {env, input, maxBuffer: 64 * 1024 * 1024, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe']});
|
|
15
16
|
} catch (error) {
|
|
16
17
|
if (error.code === 'ENOBUFS') throw Error('Git source output exceeds the 64 MiB acquisition limit');
|
|
17
18
|
throw error;
|
|
@@ -19,6 +20,18 @@ function output(root, args, input) {
|
|
|
19
20
|
}
|
|
20
21
|
export const raw = (root, ...args) => output(root, args);
|
|
21
22
|
export const batch = (root, input, ...args) => output(root, args, input);
|
|
23
|
+
// Scope offline object access to this repository reader, never global state.
|
|
24
|
+
export function gitReader(root, offline = false) {
|
|
25
|
+
const repository = offline ? offlineRepository(root) : {root, env: environment, close() {}};
|
|
26
|
+
const read = (args, input) => {
|
|
27
|
+
try { return output(repository.root, args, input, repository.env); }
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (offline && typeof error.status === 'number') throw Error('Cannot read required Base objects offline. Run git -C <base-checkout> fsck to diagnose missing or corrupt local objects. If objects are missing locally, run rer refresh-base --ref <commit> --base <base-checkout> without --offline while online to acquire them, then retry offline. Repair corrupt objects before retrying. No copy record was changed.');
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return {git: (...args) => read(args).toString('utf8').trim(), raw: (...args) => read(args), batch: (input, ...args) => read(args, input), close: repository.close};
|
|
34
|
+
}
|
|
22
35
|
export function safe(name) {
|
|
23
36
|
if (typeof name !== 'string' || !name || name.includes('\\') || /[\x00-\x1f\x7f]/.test(name) || path.posix.isAbsolute(name) || name.split('/').some(p => !p || p === '.' || p === '..' || p === '.git')) {
|
|
24
37
|
throw Error(`Unsafe path: ${name}`);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
import {manifest, VERSION} from './manifest.mjs';
|
|
5
|
+
import {snapshot, merge} from './sources.mjs';
|
|
6
|
+
import {hash, json, tracked} from './files.mjs';
|
|
7
|
+
|
|
8
|
+
function toolsIdentity() {
|
|
9
|
+
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const names = fs.readdirSync(dir).filter(p => p.endsWith('.mjs') && !p.endsWith('.test.mjs')).sort();
|
|
11
|
+
const bytes = names.map(p => p + '\0' + fs.readFileSync(path.join(dir, p), 'utf8')).join('\0');
|
|
12
|
+
return {id: 'runeditrun/edition-authoring', version: VERSION, sha256: hash(bytes)};
|
|
13
|
+
}
|
|
14
|
+
function includes(files, selected) {
|
|
15
|
+
return Object.keys(files).some(p => p === selected || p.startsWith(selected + '/'));
|
|
16
|
+
}
|
|
17
|
+
export function resolveSources(root, retain = false, diagnostics = false, additionalFiles = {}) {
|
|
18
|
+
const recipe = manifest(root);
|
|
19
|
+
const files = Object.assign(tracked(root, diagnostics), additionalFiles);
|
|
20
|
+
// The recipe is input even before initial adoption has staged it.
|
|
21
|
+
files['edition.json'] ??= {data: fs.readFileSync(path.join(root, 'edition.json')).toString('base64'), executable: false};
|
|
22
|
+
const components = [];
|
|
23
|
+
for (const component of recipe.components) {
|
|
24
|
+
const selected = component.source;
|
|
25
|
+
if (selected.workspace) throw Error('Retain workspace edits by promotion or commit and exact revision selection before locking/release');
|
|
26
|
+
const reference = selected.kind === 'git' ? selected : selected.origin;
|
|
27
|
+
const baseline = reference ? snapshot(root, reference, retain) : null;
|
|
28
|
+
if (selected.kind === 'git') merge(files, selected.destination, baseline.files);
|
|
29
|
+
else for (const name of selected.paths) {
|
|
30
|
+
if (!diagnostics && !includes(files, name)) throw Error(`Local source missing or untracked: ${name}`);
|
|
31
|
+
}
|
|
32
|
+
for (const mapping of selected.mappings || []) {
|
|
33
|
+
if ((!diagnostics && !includes(files, mapping.path)) || !baseline || !includes(baseline.files, mapping.originPath)) {
|
|
34
|
+
throw Error('Mapping names missing local or retained origin source');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
components.push({id: component.id, source: selected, baseline: baseline ? {key: baseline.key, digest: baseline.digest, sha256: hash(json(baseline))} : null});
|
|
38
|
+
}
|
|
39
|
+
const parent = recipe.parent ? snapshot(root, {...recipe.parent, excludeSnapshots: true}, retain) : null;
|
|
40
|
+
const identities = Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([name, value]) => [name, {
|
|
41
|
+
sha256: hash(Buffer.from(value.data, 'base64')), executable: value.executable,
|
|
42
|
+
}]);
|
|
43
|
+
return {
|
|
44
|
+
schemaVersion: 1, parent: parent ? {key: parent.key, digest: parent.digest, sha256: hash(json(parent))} : null,
|
|
45
|
+
edition: recipe.id, manifest: hash(json(recipe)), toolchain: toolsIdentity(),
|
|
46
|
+
components, files: Object.fromEntries(identities),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
// Older Git ignores GIT_NO_LAZY_FETCH. Read the real object store through a
|
|
7
|
+
// repository with no remotes instead: even missing promisor objects cannot
|
|
8
|
+
// launch a fetch. Never load the source's config into this repository.
|
|
9
|
+
export function offlineRepository(root) {
|
|
10
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) =>
|
|
11
|
+
!/^GIT_(?:CONFIG|DIR$|COMMON_DIR$|WORK_TREE$|INDEX_FILE$|OBJECT_DIRECTORY$|ALTERNATE_OBJECT_DIRECTORIES$|SHALLOW_FILE$|NAMESPACE$|QUARANTINE_PATH$|REPLACE_REF_BASE$)/.test(name)));
|
|
12
|
+
Object.assign(env, {GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: os.devNull, GIT_NO_REPLACE_OBJECTS: '1', GIT_NO_LAZY_FETCH: '1', GIT_OPTIONAL_LOCKS: '0'});
|
|
13
|
+
const metadata = (...args) => execFileSync('git', ['-C', root, 'rev-parse', ...args], {env, encoding: 'utf8', stdio: 'pipe'}).trim();
|
|
14
|
+
let temporary;
|
|
15
|
+
try {
|
|
16
|
+
// These queries read repository metadata and refs, never object contents.
|
|
17
|
+
const objects = metadata('--path-format=absolute', '--git-path', 'objects');
|
|
18
|
+
const format = metadata('--show-object-format');
|
|
19
|
+
const head = metadata('--verify', 'HEAD');
|
|
20
|
+
temporary = fs.mkdtempSync(path.join(os.tmpdir(), 'base-offline-'));
|
|
21
|
+
execFileSync('git', ['init', '--bare', '--quiet', '--template=', `--object-format=${format}`, temporary], {env, stdio: 'pipe'});
|
|
22
|
+
fs.writeFileSync(path.join(temporary, 'HEAD'), head + '\n');
|
|
23
|
+
return {root: temporary, env: {...env, GIT_OBJECT_DIRECTORY: objects}, close: () => fs.rmSync(temporary, {recursive: true, force: true})};
|
|
24
|
+
} catch {
|
|
25
|
+
if (temporary) fs.rmSync(temporary, {recursive: true, force: true});
|
|
26
|
+
throw Error('Cannot prepare the local Base object reader. Ensure Git is installed, the Base checkout and its HEAD are readable, and temporary storage is writable, then retry offline. No copy record was changed.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {hash, json, git, safe, noLinks} from './files.mjs';
|
|
4
|
+
|
|
5
|
+
// A retained parent baseline may be a reviewed public projection of a private
|
|
6
|
+
// original. Its plan and receipt sit at this conventional location and are bound
|
|
7
|
+
// by the edition's source lock.
|
|
8
|
+
export const PROJECTION_PLAN = 'scripts/public-projections/plan.json';
|
|
9
|
+
export const PROJECTION_RECEIPT = 'scripts/public-projections/receipt.json';
|
|
10
|
+
|
|
11
|
+
// Match the whole-parent snapshot's archive-only exclusion. In particular, keep
|
|
12
|
+
// source locks and other .edition files visible, and observe tracked deletions.
|
|
13
|
+
export function parentFiles(root) {
|
|
14
|
+
if (fs.realpathSync(git(root, 'rev-parse', '--show-toplevel')) !== fs.realpathSync(root)) throw Error('Current source must be a Git repository root');
|
|
15
|
+
const files = {};
|
|
16
|
+
for (const name of git(root, 'ls-files', '-z').split('\0').filter(Boolean)) {
|
|
17
|
+
safe(name);
|
|
18
|
+
if (name.startsWith('.edition/sources/')) continue;
|
|
19
|
+
noLinks(root, name);
|
|
20
|
+
let stat;
|
|
21
|
+
try { stat = fs.lstatSync(path.join(root, name)); }
|
|
22
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error; }
|
|
23
|
+
if (!stat.isFile()) throw Error('Unsupported current parent source');
|
|
24
|
+
files[name] = {data: fs.readFileSync(path.join(root, name)).toString('base64'), executable: !!(stat.mode & 0o111)};
|
|
25
|
+
}
|
|
26
|
+
return files;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Members whose exact original bytes the projection plan replaces or omits.
|
|
30
|
+
function projectedMembers(root, saved) {
|
|
31
|
+
if (!fs.existsSync(path.join(root, PROJECTION_RECEIPT))) {
|
|
32
|
+
if (saved.origin.projection) throw Error('Missing parent projection receipt');
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
const receiptBytes = fs.readFileSync(path.join(root, PROJECTION_RECEIPT));
|
|
36
|
+
const receipt = JSON.parse(receiptBytes);
|
|
37
|
+
const selected = receipt.archives.find(item => item.selector === 'parent' &&
|
|
38
|
+
(item.key === saved.key || item.originalKey === saved.key));
|
|
39
|
+
if (!selected) {
|
|
40
|
+
if (saved.origin.projection) throw Error('Unaccounted parent projection');
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const planBytes = fs.readFileSync(path.join(root, PROJECTION_PLAN));
|
|
44
|
+
const lock = JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json')));
|
|
45
|
+
if (lock.files[PROJECTION_RECEIPT]?.sha256 !== hash(receiptBytes) || lock.files[PROJECTION_PLAN]?.sha256 !== hash(planBytes) || receipt.recipeSha256 !== hash(planBytes)) throw Error('Parent comparison policy differs from source lock');
|
|
46
|
+
const planned = JSON.parse(planBytes).archives.find(item => item.originalKey === selected.originalKey);
|
|
47
|
+
const isOriginal = selected.originalKey === saved.key;
|
|
48
|
+
if (!planned || planned.originalSha256 !== selected.originalSha256 || hash(json(saved)) !== (isOriginal ? selected.originalSha256 : selected.sha256)) throw Error('Parent comparison identity mismatch');
|
|
49
|
+
if (!isOriginal && (saved.origin.projection.originalSha256 !== selected.originalSha256 || saved.origin.projection.recipeSha256 !== receipt.recipeSha256)) throw Error('Parent comparison derivation mismatch');
|
|
50
|
+
const result = [];
|
|
51
|
+
for (const [name, rule] of Object.entries(planned.members)) {
|
|
52
|
+
const member = selected.members.find(item => item.path === name);
|
|
53
|
+
if (!member || rule.originalSha256 !== member.originalSha256 || (member.projectedSha256 === null) !== !!rule.omit) throw Error('Parent member policy mismatch');
|
|
54
|
+
// Every omission is planned member by member, with the reason it is safe.
|
|
55
|
+
if (rule.omit && (typeof rule.reason !== 'string' || !rule.reason.trim())) throw Error('Only planned omissions with a recorded reason may be omitted');
|
|
56
|
+
const value = saved.files[name], expected = isOriginal ? member.originalSha256 : member.projectedSha256;
|
|
57
|
+
if (expected === null ? value !== undefined : !value || hash(Buffer.from(value.data, 'base64')) !== expected || value.executable !== member.executable) throw Error('Parent member identity mismatch');
|
|
58
|
+
result.push(member);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Normalize only exact planned original bytes to their projected identity; every
|
|
64
|
+
// other byte, mode, addition and removal stays visible.
|
|
65
|
+
export function parentIdentities(root, saved) {
|
|
66
|
+
const members = new Map(projectedMembers(root, saved).map(member => [member.path, member]));
|
|
67
|
+
return files => Object.fromEntries(Object.entries(files).flatMap(([name, file]) => {
|
|
68
|
+
const identity = {sha256: hash(Buffer.from(file.data, 'base64')), executable: file.executable};
|
|
69
|
+
const member = members.get(name);
|
|
70
|
+
if (member && identity.sha256 === member.originalSha256) {
|
|
71
|
+
if (member.projectedSha256 === null) {
|
|
72
|
+
if (identity.executable === member.executable) return [];
|
|
73
|
+
} else identity.sha256 = member.projectedSha256;
|
|
74
|
+
}
|
|
75
|
+
return [[name, identity]];
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {manifest} from './manifest.mjs';
|
|
4
|
+
import {hash, json, noLinks} from './files.mjs';
|
|
5
|
+
|
|
6
|
+
export function snapshotOrigin(ref) {
|
|
7
|
+
return {repository: ref.repository, ...(ref.projection ? {projection: ref.projection} : {revision: ref.revision}), path: ref.path || '.', paths: ref.paths || null, excludeSnapshots: !!ref.excludeSnapshots};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function verifyProjectionLock(root, origin, saved, bytes) {
|
|
11
|
+
noLinks(root, 'edition.json');
|
|
12
|
+
noLinks(root, 'sources.lock.json');
|
|
13
|
+
if (!fs.existsSync(path.join(root, 'sources.lock.json'))) throw Error('Public projection requires a selected source-lock binding');
|
|
14
|
+
for (const name of ['edition.json', 'sources.lock.json']) {
|
|
15
|
+
if (!fs.lstatSync(path.join(root, name)).isFile()) throw Error('Public projection selection and lock must be regular files');
|
|
16
|
+
}
|
|
17
|
+
const recipe = manifest(root);
|
|
18
|
+
const lock = JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json')));
|
|
19
|
+
if (lock.schemaVersion !== 1 || lock.edition !== recipe.id) throw Error('Public projection source lock identifies a different edition');
|
|
20
|
+
const pins = [];
|
|
21
|
+
const matches = ref => ref?.projection && json(snapshotOrigin(ref)) === json(origin);
|
|
22
|
+
if (recipe.parent && matches({...recipe.parent, excludeSnapshots: true})) pins.push(lock.parent);
|
|
23
|
+
for (const component of recipe.components) {
|
|
24
|
+
const ref = component.source.kind === 'git' ? component.source : component.source.origin;
|
|
25
|
+
if (!matches(ref)) continue;
|
|
26
|
+
const locked = lock.components?.find(entry => entry.id === component.id);
|
|
27
|
+
const lockedRef = locked?.source?.kind === 'git' ? locked.source : locked?.source?.origin;
|
|
28
|
+
if (!matches(lockedRef)) throw Error('Public projection selection differs from source lock');
|
|
29
|
+
pins.push(locked.baseline);
|
|
30
|
+
}
|
|
31
|
+
if (!pins.length) throw Error('Public projection is not selected by this edition');
|
|
32
|
+
const rawSha256 = hash(bytes);
|
|
33
|
+
for (const expected of pins) {
|
|
34
|
+
if (!expected || expected.key !== saved.key || expected.digest !== saved.digest || expected.sha256 !== rawSha256) {
|
|
35
|
+
throw Error('Public projection artifact differs from source lock');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {execFileSync} from 'node:child_process';
|
|
4
|
+
import {fresh, git, hash, json} from './files.mjs';
|
|
5
|
+
|
|
6
|
+
export function release(root, destination, check) {
|
|
7
|
+
const output = fresh(destination, root);
|
|
8
|
+
const receiptPath = fresh(output + '.release.json', root);
|
|
9
|
+
if (git(root, 'status', '--porcelain', '--untracked-files=all')) throw Error('Release requires a clean committed edition');
|
|
10
|
+
const lock = check();
|
|
11
|
+
const comparisons = [...lock.components, ...(lock.parent ? [{baseline: lock.parent}] : [])];
|
|
12
|
+
const pending = comparisons.filter(c => c.baseline).map(c => c.baseline);
|
|
13
|
+
const checked = new Set();
|
|
14
|
+
while (pending.length) {
|
|
15
|
+
const baseline = pending.pop();
|
|
16
|
+
if (checked.has(baseline.key)) continue;
|
|
17
|
+
checked.add(baseline.key);
|
|
18
|
+
const filename = '.edition/sources/' + baseline.key + '.json';
|
|
19
|
+
if (!git(root, 'ls-files', '--', filename)) throw Error('Comparison source snapshot must be tracked');
|
|
20
|
+
const archive = JSON.parse(fs.readFileSync(path.join(root, filename)));
|
|
21
|
+
pending.push(...(archive.dependencies || []));
|
|
22
|
+
}
|
|
23
|
+
const commit = git(root, 'rev-parse', 'HEAD');
|
|
24
|
+
const tree = git(root, 'rev-parse', 'HEAD^{tree}');
|
|
25
|
+
execFileSync('git', ['clone', '--no-hardlinks', '--', root, output], {stdio: 'pipe'});
|
|
26
|
+
git(output, 'remote', 'remove', 'origin');
|
|
27
|
+
const receipt = {
|
|
28
|
+
schemaVersion: 1, edition: lock.edition, source: {commit, tree},
|
|
29
|
+
lockSha256: hash(fs.readFileSync(path.join(root, 'sources.lock.json'))), toolchain: lock.toolchain,
|
|
30
|
+
verification: 'source integrity only; no product build or deployment asserted',
|
|
31
|
+
};
|
|
32
|
+
// Outside the author tree: publication preserves the exact authoritative commit.
|
|
33
|
+
fs.writeFileSync(receiptPath, json(receipt), {flag: 'wx'});
|
|
34
|
+
return {output, receiptPath, ...receipt};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function verifyReceipt(root, filename, check) {
|
|
38
|
+
const receipt = JSON.parse(fs.readFileSync(filename, 'utf8'));
|
|
39
|
+
const lock = check();
|
|
40
|
+
if (receipt.schemaVersion !== 1 || receipt.edition !== lock.edition ||
|
|
41
|
+
receipt.source?.commit !== git(root, 'rev-parse', 'HEAD') ||
|
|
42
|
+
receipt.source?.tree !== git(root, 'rev-parse', 'HEAD^{tree}') ||
|
|
43
|
+
receipt.lockSha256 !== hash(fs.readFileSync(path.join(root, 'sources.lock.json'))) ||
|
|
44
|
+
json(receipt.toolchain) !== json(lock.toolchain) || git(root, 'status', '--porcelain', '--untracked-files=all')) {
|
|
45
|
+
throw Error('Receipt does not identify this clean source checkout');
|
|
46
|
+
}
|
|
47
|
+
return {ok: true, ...receipt, verification: 'source integrity only; receipt is not publisher authentication or product acceptance'};
|
|
48
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {execFileSync} from 'node:child_process';
|
|
5
|
+
import {hash, json, git, raw, safe, digest, noLinks} from './files.mjs';
|
|
6
|
+
import {snapshotOrigin, verifyProjectionLock} from './projection-lock.mjs';
|
|
7
|
+
|
|
8
|
+
const environment = {...process.env, GIT_NO_REPLACE_OBJECTS: '1'};
|
|
9
|
+
function selected(name, ref) {
|
|
10
|
+
const prefix = ref.path && ref.path !== '.' ? ref.path : '';
|
|
11
|
+
if (prefix && name !== prefix && !name.startsWith(prefix + '/')) return false;
|
|
12
|
+
const relative = prefix ? (name === prefix ? path.basename(name) : name.slice(prefix.length + 1)) : name;
|
|
13
|
+
if (ref.excludeSnapshots && relative.startsWith('.edition/sources/')) return false;
|
|
14
|
+
if (ref.paths && !ref.paths.some(p => relative === p || relative.startsWith(p + '/'))) return false;
|
|
15
|
+
return relative;
|
|
16
|
+
}
|
|
17
|
+
function committed(root, ref, archives) {
|
|
18
|
+
const files = Object.create(null);
|
|
19
|
+
const entries = raw(root, 'ls-tree', '-rz', '--full-tree', ref.revision).toString('utf8').split('\0').filter(Boolean);
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const tab = entry.indexOf('\t');
|
|
22
|
+
const [mode, type, object] = entry.slice(0, tab).split(' ');
|
|
23
|
+
const name = entry.slice(tab + 1);
|
|
24
|
+
if (ref.excludeSnapshots && name.startsWith('.edition/sources/') && /^\.edition\/sources\/[a-f0-9]{64}\.json$/.test(name)) {
|
|
25
|
+
if (type !== 'blob' || mode !== '100644') throw Error('Unsupported comparison archive');
|
|
26
|
+
const archived = JSON.parse(raw(root, 'cat-file', 'blob', object));
|
|
27
|
+
if (archived.key !== path.basename(name, '.json') || archived.key !== hash(json(archived.origin)) || archived.digest !== digest(archived.files)) throw Error('Corrupt ancestor comparison archive');
|
|
28
|
+
archives[archived.key] = archived;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const relative = selected(name, ref);
|
|
32
|
+
if (relative === false) continue;
|
|
33
|
+
safe(relative);
|
|
34
|
+
if (type !== 'blob' || !['100644', '100755'].includes(mode)) throw Error(`Unsupported committed source: ${name}`);
|
|
35
|
+
files[relative] = {data: raw(root, 'cat-file', 'blob', object).toString('base64'), executable: mode === '100755'};
|
|
36
|
+
}
|
|
37
|
+
return files;
|
|
38
|
+
}
|
|
39
|
+
export function snapshot(root, ref, retain = false) {
|
|
40
|
+
if (ref.projection && ref.workspace) throw Error('Public projections cannot select workspace source');
|
|
41
|
+
const origin = snapshotOrigin(ref);
|
|
42
|
+
const key = hash(json(origin));
|
|
43
|
+
noLinks(root, '.edition/sources/' + key + '.json');
|
|
44
|
+
const filename = path.join(root, '.edition/sources', key + '.json');
|
|
45
|
+
if (fs.existsSync(filename)) {
|
|
46
|
+
if (!fs.lstatSync(filename).isFile()) throw Error('Retained source snapshot must be a regular file');
|
|
47
|
+
const bytes = fs.readFileSync(filename);
|
|
48
|
+
const saved = JSON.parse(bytes);
|
|
49
|
+
if (saved.key !== key || json(saved.origin) !== json(origin) || saved.digest !== digest(saved.files)) throw Error('Corrupt retained source snapshot');
|
|
50
|
+
if (ref.projection) verifyProjectionLock(root, origin, saved, bytes);
|
|
51
|
+
for (const dependency of saved.dependencies || []) {
|
|
52
|
+
noLinks(root, '.edition/sources/' + dependency.key + '.json');
|
|
53
|
+
const ancestor = JSON.parse(fs.readFileSync(path.join(root, '.edition/sources', dependency.key + '.json')));
|
|
54
|
+
if (ancestor.digest !== dependency.digest || digest(ancestor.files) !== dependency.digest || hash(json(ancestor)) !== dependency.sha256) {
|
|
55
|
+
throw Error('Missing or corrupt ancestor comparison archive');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return saved;
|
|
59
|
+
}
|
|
60
|
+
// A projection has no fetchable revision; it exists only as a reviewed retained archive.
|
|
61
|
+
if (ref.projection) throw Error('Missing retained public projection; regenerate from the pinned private original outside the public tree');
|
|
62
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'edition-source-'));
|
|
63
|
+
try {
|
|
64
|
+
execFileSync('git', ['clone', '--no-checkout', '--', ref.repository, temp], {env: environment, stdio: 'pipe'});
|
|
65
|
+
if (git(temp, 'rev-parse', `${ref.revision}^{commit}`) !== ref.revision) throw Error('Source revision is not exact commit');
|
|
66
|
+
const archives = Object.create(null);
|
|
67
|
+
const files = committed(temp, ref, archives);
|
|
68
|
+
if (!Object.keys(files).length) throw Error('Empty source export');
|
|
69
|
+
const dependencies = Object.values(archives).map(a => ({key: a.key, digest: a.digest, sha256: hash(json(a))}));
|
|
70
|
+
const saved = {key, origin, digest: digest(files), files, dependencies};
|
|
71
|
+
if (retain) {
|
|
72
|
+
fs.mkdirSync(path.dirname(filename), {recursive: true});
|
|
73
|
+
for (const archive of Object.values(archives)) {
|
|
74
|
+
noLinks(root, '.edition/sources/' + archive.key + '.json');
|
|
75
|
+
fs.writeFileSync(path.join(root, '.edition/sources', archive.key + '.json'), json(archive));
|
|
76
|
+
}
|
|
77
|
+
fs.writeFileSync(filename, json(saved));
|
|
78
|
+
}
|
|
79
|
+
return saved;
|
|
80
|
+
} finally {
|
|
81
|
+
fs.rmSync(temp, {recursive: true, force: true});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function source(root, ref, dev = false, retain = false) {
|
|
85
|
+
if (ref.projection && ref.workspace) throw Error('Public projections cannot select workspace source');
|
|
86
|
+
if (!dev || !ref.workspace) return snapshot(root, ref, retain).files;
|
|
87
|
+
if (fs.realpathSync(git(ref.workspace, 'rev-parse', '--show-toplevel')) !== fs.realpathSync(ref.workspace)) throw Error('Workspace must name the repository root');
|
|
88
|
+
const files = Object.create(null);
|
|
89
|
+
const index = raw(ref.workspace, 'ls-files', '--stage', '-z').toString('utf8').split('\0').filter(Boolean);
|
|
90
|
+
for (const entry of index) {
|
|
91
|
+
const [header, name] = entry.split('\t');
|
|
92
|
+
if (selected(name, ref) !== false && header.startsWith('160000 ')) throw Error('Submodules are not source files');
|
|
93
|
+
}
|
|
94
|
+
const names = raw(ref.workspace, 'ls-files', '--cached', '--others', '--exclude-standard', '-z').toString('utf8').split('\0').filter(Boolean);
|
|
95
|
+
for (const name of [...new Set(names)].sort()) {
|
|
96
|
+
const relative = selected(name, ref);
|
|
97
|
+
if (relative === false) continue;
|
|
98
|
+
safe(name); safe(relative); noLinks(ref.workspace, name);
|
|
99
|
+
const absolute = path.join(ref.workspace, name);
|
|
100
|
+
if (!fs.existsSync(absolute)) continue; // A tracked deletion is a real workspace edit.
|
|
101
|
+
const stat = fs.lstatSync(absolute);
|
|
102
|
+
if (!stat.isFile()) throw Error(`Unsupported workspace source: ${name}`);
|
|
103
|
+
files[relative] = {data: fs.readFileSync(absolute).toString('base64'), executable: !!(stat.mode & 0o111)};
|
|
104
|
+
}
|
|
105
|
+
if (!Object.keys(files).length) throw Error('Empty workspace source export');
|
|
106
|
+
return files;
|
|
107
|
+
}
|
|
108
|
+
export function merge(files, destination, ingredient) {
|
|
109
|
+
for (const [name, value] of Object.entries(ingredient)) {
|
|
110
|
+
const target = destination + '/' + safe(name);
|
|
111
|
+
if (Object.keys(files).some(p => p === target || p.startsWith(target + '/') || target.startsWith(p + '/'))) throw Error(`Source collision: ${target}`);
|
|
112
|
+
files[target] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|