@jini-ai/devops 0.5.5 → 0.6.10
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/CHANGELOG.md +17 -0
- package/dist/agent-jobs/jobs.js +33 -26
- package/dist/agent-jobs/node.d.ts +14 -0
- package/dist/agent-jobs/node.js +8 -3
- package/dist/checks/coverage/diff.js +21 -10
- package/dist/checks/coverage/disk.js +20 -13
- package/dist/checks/coverage/integrity.js +44 -39
- package/dist/checks/hardwiring-node.js +89 -73
- package/dist/checks/hardwiring.d.ts +5 -0
- package/dist/checks/hardwiring.js +75 -48
- package/dist/checks/node.js +6 -1
- package/dist/checks/published-types/index.js +30 -15
- package/dist/core/artifact-store.d.ts +35 -0
- package/dist/core/artifact-store.js +2 -0
- package/dist/deploy/host-kit.d.ts +3 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/node.d.ts +10 -0
- package/dist/deploy/node.js +11 -3
- package/dist/deploy/reachability.d.ts +2 -2
- package/dist/deploy/reachability.js +164 -117
- package/dist/dns/approval.d.ts +61 -0
- package/dist/dns/approval.js +48 -0
- package/dist/dns/contract.d.ts +206 -0
- package/dist/dns/contract.js +30 -0
- package/dist/dns/delegation.d.ts +36 -0
- package/dist/dns/delegation.js +44 -0
- package/dist/dns/index.d.ts +15 -0
- package/dist/dns/index.js +15 -0
- package/dist/dns/manual.d.ts +28 -0
- package/dist/dns/manual.js +140 -0
- package/dist/dns/node/index.d.ts +8 -0
- package/dist/dns/node/index.js +8 -0
- package/dist/dns/node/resolver.d.ts +35 -0
- package/dist/dns/node/resolver.js +155 -0
- package/dist/dns/node/udp.d.ts +27 -0
- package/dist/dns/node/udp.js +39 -0
- package/dist/dns/node/wire.d.ts +36 -0
- package/dist/dns/node/wire.js +90 -0
- package/dist/dns/plan.d.ts +34 -0
- package/dist/dns/plan.js +242 -0
- package/dist/dns/records.d.ts +67 -0
- package/dist/dns/records.js +144 -0
- package/dist/dns/registry.d.ts +26 -0
- package/dist/dns/registry.js +59 -0
- package/dist/dns/spf.d.ts +23 -0
- package/dist/dns/spf.js +35 -0
- package/dist/dns/verify.d.ts +61 -0
- package/dist/dns/verify.js +109 -0
- package/dist/local-dev/index.js +36 -20
- package/dist/packaging/electron/archive.d.ts +7 -4
- package/dist/packaging/electron/archive.js +32 -25
- package/dist/packaging/electron/imports.d.ts +1 -1
- package/dist/packaging/electron/imports.js +39 -23
- package/dist/packaging/electron/staging.js +68 -47
- package/dist/source-control/commit.js +36 -18
- package/dist/source-control/registry.js +95 -59
- package/dist/static-export/node-adapters.js +26 -17
- package/dist/static-export/runner.js +185 -103
- package/dist/static-export/transforms.js +26 -23
- package/package.json +19 -7
|
@@ -62,9 +62,37 @@ export function toArchiveEntryPath({ relPath, separator }) {
|
|
|
62
62
|
safeEntry(relPath);
|
|
63
63
|
return relPath.split('/').join(separator);
|
|
64
64
|
}
|
|
65
|
+
function sameBytes(left, right) {
|
|
66
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
67
|
+
}
|
|
68
|
+
/** One shipped entry against its source file: the mismatch reason, or undefined when identical. */
|
|
69
|
+
function entryMismatch(required, optional) {
|
|
70
|
+
const { archivePath, sourceRoot, separator, fs, archive, relPath } = required;
|
|
71
|
+
let source;
|
|
72
|
+
try {
|
|
73
|
+
source = fs.read({ path: path.join(sourceRoot, relPath) });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return 'shipped in app.asar but missing from the source tree';
|
|
77
|
+
}
|
|
78
|
+
// No leading slash: `extractFile`'s path argument is resolved relative to the archive root by
|
|
79
|
+
// splitting on the OS path separator (`filesystem.js`'s `searchNodeFromDirectory`), and a
|
|
80
|
+
// leading "/" produces a spurious empty first segment that walks into a fresh, empty directory
|
|
81
|
+
// node instead of the real root — silently "not found" for every nested path. This is the
|
|
82
|
+
// opposite convention from `listPackage()`'s OUTPUT, which prefixes every entry with "/" for
|
|
83
|
+
// display; that display format is not the input format `extractFile` expects.
|
|
84
|
+
let shipped;
|
|
85
|
+
try {
|
|
86
|
+
shipped = archive.read({ archivePath, entryPath: toArchiveEntryPath({ relPath, separator }) });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return optional.readFailureMessage?.({ error }) ?? `present in the asar header but could not read it (${String(error)})`;
|
|
90
|
+
}
|
|
91
|
+
return sameBytes(source, shipped) ? undefined : optional.contentMismatchMessage ?? 'content differs from source (compared byte-for-byte, never by length alone)';
|
|
92
|
+
}
|
|
65
93
|
/** Compare actual content: equal sizes and an archive's own hash cannot detect shifted offsets. */
|
|
66
94
|
export function verifyAsarAgainstSource(required, optional = {}) {
|
|
67
|
-
const { archivePath,
|
|
95
|
+
const { archivePath, prefixes, archive } = required;
|
|
68
96
|
if (!prefixes.length)
|
|
69
97
|
return { checkedCount: 0, mismatches: [{ relPath: '', reason: 'no checked archive prefixes supplied' }] };
|
|
70
98
|
const { files: headerFiles } = archive.header({ archivePath });
|
|
@@ -73,30 +101,9 @@ export function verifyAsarAgainstSource(required, optional = {}) {
|
|
|
73
101
|
const mismatches = prefixes.filter(prefix => !filesUnderPrefixes({ headerFiles, prefixes: [prefix] }).length)
|
|
74
102
|
.map(relPath => ({ relPath, reason: 'nothing under this checked prefix is in app.asar' }));
|
|
75
103
|
for (const relPath of relPaths) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
mismatches.push({ relPath, reason: 'shipped in app.asar but missing from the source tree' });
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
// No leading slash: `extractFile`'s path argument is resolved relative to the archive root by
|
|
85
|
-
// splitting on the OS path separator (`filesystem.js`'s `searchNodeFromDirectory`), and a
|
|
86
|
-
// leading "/" produces a spurious empty first segment that walks into a fresh, empty directory
|
|
87
|
-
// node instead of the real root — silently "not found" for every nested path. This is the
|
|
88
|
-
// opposite convention from `listPackage()`'s OUTPUT, which prefixes every entry with "/" for
|
|
89
|
-
// display; that display format is not the input format `extractFile` expects.
|
|
90
|
-
let shipped;
|
|
91
|
-
try {
|
|
92
|
-
shipped = archive.read({ archivePath, entryPath: toArchiveEntryPath({ relPath, separator }) });
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
mismatches.push({ relPath, reason: optional.readFailureMessage?.({ error }) ?? `present in the asar header but could not read it (${String(error)})` });
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (source.length !== shipped.length || !source.every((byte, index) => byte === shipped[index]))
|
|
99
|
-
mismatches.push({ relPath, reason: optional.contentMismatchMessage ?? 'content differs from source (compared byte-for-byte, never by length alone)' });
|
|
104
|
+
const reason = entryMismatch({ ...required, relPath }, optional);
|
|
105
|
+
if (reason !== undefined)
|
|
106
|
+
mismatches.push({ relPath, reason });
|
|
100
107
|
}
|
|
101
108
|
return { checkedCount: relPaths.length, mismatches };
|
|
102
109
|
}
|
|
@@ -10,11 +10,11 @@ export interface DistImportInput {
|
|
|
10
10
|
imports: ImportReaderPort;
|
|
11
11
|
aliases: ImportAliasPort;
|
|
12
12
|
}
|
|
13
|
-
/** Walk reachable files once. The injected AST parser owns import syntax and comment handling. */
|
|
14
13
|
/**
|
|
15
14
|
* Every bare import reachable from `entry` that is neither a builtin nor in `declared`, as
|
|
16
15
|
* `"<package> (<file relative to distDir>)"`, in walk order. A relative import whose target file
|
|
17
16
|
* does not exist is reported too, so a broken walk can never read as a clean one.
|
|
17
|
+
* Walk reachable files once. The injected AST parser owns import syntax and comment handling.
|
|
18
18
|
*
|
|
19
19
|
* @complexity O(files + imports) reachable from `entry`; each file is read once.
|
|
20
20
|
*/
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { builtinModules } from 'node:module';
|
|
3
3
|
const builtins = new Set(builtinModules);
|
|
4
|
-
/**
|
|
4
|
+
/** The file a specifier points at (host alias first, then relative/absolute paths), or undefined for a bare package. */
|
|
5
|
+
function localTarget(required) {
|
|
6
|
+
const { specifier, file, distDir, aliases } = required;
|
|
7
|
+
return aliases.resolve({ specifier, fromFile: file, distDir })
|
|
8
|
+
?? (specifier.startsWith('.') || path.isAbsolute(specifier) ? path.resolve(path.dirname(file), specifier) : undefined);
|
|
9
|
+
}
|
|
10
|
+
/** The package a bare specifier names, unless it is a builtin or declared. */
|
|
11
|
+
function undeclaredPackage(required) {
|
|
12
|
+
const { specifier, declared } = required;
|
|
13
|
+
const name = specifier.split('/').slice(0, specifier.startsWith('@') ? 2 : 1).join('/');
|
|
14
|
+
return specifier.startsWith('node:') || builtins.has(name) || declared.has(name) ? undefined : name;
|
|
15
|
+
}
|
|
5
16
|
/**
|
|
6
17
|
* Every bare import reachable from `entry` that is neither a builtin nor in `declared`, as
|
|
7
18
|
* `"<package> (<file relative to distDir>)"`, in walk order. A relative import whose target file
|
|
8
19
|
* does not exist is reported too, so a broken walk can never read as a clean one.
|
|
20
|
+
* Walk reachable files once. The injected AST parser owns import syntax and comment handling.
|
|
9
21
|
*
|
|
10
22
|
* @complexity O(files + imports) reachable from `entry`; each file is read once.
|
|
11
23
|
*/
|
|
@@ -14,32 +26,36 @@ export function undeclaredDistImports(required) {
|
|
|
14
26
|
const queue = [path.resolve(entry)];
|
|
15
27
|
const seen = new Set(queue);
|
|
16
28
|
const problems = [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
/** Queue an unseen local target once; a missing one is reported once, against its first importer. */
|
|
30
|
+
const visit = (target, specifier, relative) => {
|
|
31
|
+
const absolute = path.resolve(target);
|
|
32
|
+
if (seen.has(absolute))
|
|
33
|
+
return;
|
|
34
|
+
seen.add(absolute);
|
|
35
|
+
if (fs.exists({ path: absolute }))
|
|
36
|
+
queue.push(absolute);
|
|
37
|
+
else
|
|
38
|
+
problems.push(`${specifier} (${relative}: file not found)`);
|
|
39
|
+
};
|
|
40
|
+
/** Check one reachable file's imports: follow local targets, report undeclared packages. */
|
|
41
|
+
const scan = (file, relative) => {
|
|
23
42
|
const source = Buffer.from(fs.read({ path: file })).toString('utf8');
|
|
24
43
|
for (const specifier of imports.imports({ file, source })) {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (seen.has(absolute))
|
|
31
|
-
continue;
|
|
32
|
-
seen.add(absolute);
|
|
33
|
-
if (fs.exists({ path: absolute }))
|
|
34
|
-
queue.push(absolute);
|
|
35
|
-
else
|
|
36
|
-
problems.push(`${specifier} (${relative}: file not found)`);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const name = specifier.split('/').slice(0, specifier.startsWith('@') ? 2 : 1).join('/');
|
|
40
|
-
if (!specifier.startsWith('node:') && !builtins.has(name) && !declared.has(name))
|
|
44
|
+
const target = localTarget({ specifier, file, distDir, aliases });
|
|
45
|
+
const name = target === undefined ? undeclaredPackage({ specifier, declared }) : undefined;
|
|
46
|
+
if (target !== undefined)
|
|
47
|
+
visit(target, specifier, relative);
|
|
48
|
+
else if (name !== undefined)
|
|
41
49
|
problems.push(`${name} (${relative})`);
|
|
42
50
|
}
|
|
51
|
+
};
|
|
52
|
+
for (let index = 0; index < queue.length; index++) {
|
|
53
|
+
const file = queue[index];
|
|
54
|
+
const relative = path.relative(distDir, file);
|
|
55
|
+
if (fs.exists({ path: file }))
|
|
56
|
+
scan(file, relative);
|
|
57
|
+
else
|
|
58
|
+
problems.push(`${relative} (entry file not found)`);
|
|
43
59
|
}
|
|
44
60
|
return problems;
|
|
45
61
|
}
|
|
@@ -17,39 +17,58 @@ export function declaredDependencies({ packageDir, fs }) {
|
|
|
17
17
|
export function stageDir(required, optional = {}) {
|
|
18
18
|
required.fs.copy({ from: required.source, to: required.destination }, optional);
|
|
19
19
|
}
|
|
20
|
+
function stagedPath(outDir, name) { return path.join(outDir, 'node_modules', name); }
|
|
21
|
+
function resolveDependency(required) {
|
|
22
|
+
const { from, name, fs, resolver } = required;
|
|
23
|
+
const resolved = resolver.resolve({ fromDirectory: from, packageName: name });
|
|
24
|
+
if (!resolved)
|
|
25
|
+
throw new Error(`Unresolved production dependency: ${from} -> ${name}`);
|
|
26
|
+
return fs.realpath({ path: resolved });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Flattening `name` from `directory` conflicts with an already planned copy from another directory
|
|
30
|
+
* unless both carry the same known version, and with an already staged destination unless that
|
|
31
|
+
* destination carries the same known version. Unversioned packages never count as the same.
|
|
32
|
+
*/
|
|
33
|
+
function assertFlattenable(required) {
|
|
34
|
+
const { name, planned: { directory, version }, existing, destination, fs } = required;
|
|
35
|
+
const destinationVersion = fs.exists({ path: path.join(destination, 'package.json') }) ? manifest(destination, fs).version : undefined;
|
|
36
|
+
const plannedConflict = existing !== undefined && existing.directory !== directory && (!version || existing.version !== version);
|
|
37
|
+
const stagedConflict = fs.exists({ path: destination }) && (!version || destinationVersion !== version);
|
|
38
|
+
if (plannedConflict || stagedConflict)
|
|
39
|
+
throw new Error(`Package version conflict while flattening ${name}`);
|
|
40
|
+
}
|
|
41
|
+
/** Add one declared dependency of `from` to the plan (validated, resolved, conflict-checked) and queue its directory once. */
|
|
42
|
+
function planDependency(plan, required) {
|
|
43
|
+
const { outDir, excluded, fs, resolver, staged, visited, queue } = plan;
|
|
44
|
+
const { from, name } = required;
|
|
45
|
+
safePackageName(name);
|
|
46
|
+
if (isExcluded({ name, excluded }))
|
|
47
|
+
return;
|
|
48
|
+
const directory = resolveDependency({ from, name, fs, resolver });
|
|
49
|
+
const planned = { directory, version: manifest(directory, fs).version };
|
|
50
|
+
const existing = staged.get(name);
|
|
51
|
+
assertFlattenable({ name, planned, existing, destination: stagedPath(outDir, name), fs });
|
|
52
|
+
if (!existing)
|
|
53
|
+
staged.set(name, planned);
|
|
54
|
+
if (!visited.has(directory)) {
|
|
55
|
+
visited.add(directory);
|
|
56
|
+
queue.push(directory);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
20
59
|
/** Plan the production closure first. Fail unresolved/conflicting versions before copying anything. */
|
|
21
60
|
export function stageTransitiveDependencies(required) {
|
|
22
|
-
const { roots, outDir,
|
|
61
|
+
const { roots, outDir, fs } = required;
|
|
23
62
|
const visited = new Set(roots.map(root => fs.realpath({ path: root })));
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const from
|
|
28
|
-
|
|
29
|
-
safePackageName(name);
|
|
30
|
-
if (isExcluded({ name, excluded }))
|
|
31
|
-
continue;
|
|
32
|
-
const resolved = resolver.resolve({ fromDirectory: from, packageName: name });
|
|
33
|
-
if (!resolved)
|
|
34
|
-
throw new Error(`Unresolved production dependency: ${from} -> ${name}`);
|
|
35
|
-
const directory = fs.realpath({ path: resolved });
|
|
36
|
-
const version = manifest(directory, fs).version;
|
|
37
|
-
const existing = staged.get(name);
|
|
38
|
-
const destination = path.join(outDir, 'node_modules', name);
|
|
39
|
-
const destinationVersion = fs.exists({ path: path.join(destination, 'package.json') }) ? manifest(destination, fs).version : undefined;
|
|
40
|
-
if ((existing && existing.directory !== directory && (!version || existing.version !== version)) || (fs.exists({ path: destination }) && (!version || destinationVersion !== version)))
|
|
41
|
-
throw new Error(`Package version conflict while flattening ${name}`);
|
|
42
|
-
if (!existing)
|
|
43
|
-
staged.set(name, { directory, version });
|
|
44
|
-
if (!visited.has(directory)) {
|
|
45
|
-
visited.add(directory);
|
|
46
|
-
queue.push(directory);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
63
|
+
const plan = { ...required, staged: new Map(), visited, queue: [...visited] };
|
|
64
|
+
for (let index = 0; index < plan.queue.length; index++) {
|
|
65
|
+
const from = plan.queue[index];
|
|
66
|
+
for (const name of declaredDependencies({ packageDir: from, fs }))
|
|
67
|
+
planDependency(plan, { from, name });
|
|
49
68
|
}
|
|
50
69
|
let count = 0;
|
|
51
|
-
for (const [name, entry] of staged) {
|
|
52
|
-
const destination =
|
|
70
|
+
for (const [name, entry] of plan.staged) {
|
|
71
|
+
const destination = stagedPath(outDir, name);
|
|
53
72
|
if (fs.exists({ path: destination }))
|
|
54
73
|
continue;
|
|
55
74
|
stageDir({ source: entry.directory, destination, fs }, { dropNestedModules: true });
|
|
@@ -75,12 +94,12 @@ export function assertClosureComplete(required) {
|
|
|
75
94
|
const missing = [];
|
|
76
95
|
if (!fs.exists({ path: modulesDir }))
|
|
77
96
|
throw new Error('staged node_modules tree is missing');
|
|
97
|
+
// Hoisted beside the package, or nested inside it: the only two places a shipped require can land.
|
|
98
|
+
const shipped = (directory, name) => fs.exists({ path: path.join(modulesDir, name, 'package.json') }) || fs.exists({ path: path.join(directory, 'node_modules', name, 'package.json') });
|
|
78
99
|
for (const directory of stagedPackageDirs({ modulesDir, fs })) {
|
|
79
100
|
for (const name of declaredDependencies({ packageDir: directory, fs })) {
|
|
80
101
|
safePackageName(name);
|
|
81
|
-
if (isExcluded({ name, excluded }))
|
|
82
|
-
continue;
|
|
83
|
-
if (!fs.exists({ path: path.join(modulesDir, name, 'package.json') }) && !fs.exists({ path: path.join(directory, 'node_modules', name, 'package.json') }))
|
|
102
|
+
if (!isExcluded({ name, excluded }) && !shipped(directory, name))
|
|
84
103
|
missing.push(`${path.relative(modulesDir, directory)} -> ${name}`);
|
|
85
104
|
}
|
|
86
105
|
}
|
|
@@ -153,6 +172,23 @@ export function stripNonRuntimeFiles(required) {
|
|
|
153
172
|
walk(modulesDir);
|
|
154
173
|
return tally;
|
|
155
174
|
}
|
|
175
|
+
function serves(built, target) {
|
|
176
|
+
return built.architectures.includes(target.arch) && (target.platform === built.platform || (target.platform === 'linux' && built.platform === 'linuxmusl'));
|
|
177
|
+
}
|
|
178
|
+
/** One staged package's removals; throws when its prebuilds cannot serve every target, before anything is removed. */
|
|
179
|
+
function packagePruneRemovals(required) {
|
|
180
|
+
const { directory, modulesDir, targets, fs } = required;
|
|
181
|
+
const prebuilds = path.join(directory, 'prebuilds');
|
|
182
|
+
if (!fs.exists({ path: prebuilds }))
|
|
183
|
+
return [];
|
|
184
|
+
const entries = fs.entries({ path: prebuilds }).map(name => ({ name, built: prebuildTarget({ entryName: name }) }));
|
|
185
|
+
const known = entries.filter((entry) => entry.built !== undefined);
|
|
186
|
+
if (!targets.every(target => known.some(entry => serves(entry.built, target))))
|
|
187
|
+
throw new Error(`${path.relative(modulesDir, directory)} ships no prebuild for every requested target: ${targets.map(x => x.platform + '-' + x.arch).join(', ')}`);
|
|
188
|
+
const foreign = known.filter(entry => !targets.some(target => serves(entry.built, target))).map(entry => ({ full: path.join(prebuilds, entry.name), reason: 'prebuilds' }));
|
|
189
|
+
const buildInputs = ['deps', 'binding.gyp'].map(input => path.join(directory, input)).filter(full => fs.exists({ path: full })).map(full => ({ full, reason: 'buildInputs' }));
|
|
190
|
+
return [...foreign, ...buildInputs];
|
|
191
|
+
}
|
|
156
192
|
/** Verify every target before removing foreign prebuilds or source build inputs. */
|
|
157
193
|
export function pruneNativePrebuilds(required) {
|
|
158
194
|
const { outDir, targets, fs } = required;
|
|
@@ -160,22 +196,7 @@ export function pruneNativePrebuilds(required) {
|
|
|
160
196
|
throw new Error('at least one native target is required');
|
|
161
197
|
const modulesDir = path.join(outDir, 'node_modules');
|
|
162
198
|
const tally = { prebuilds: 0, buildInputs: 0, bytes: 0 };
|
|
163
|
-
const removals =
|
|
164
|
-
for (const directory of stagedPackageDirs({ modulesDir, fs })) {
|
|
165
|
-
const prebuilds = path.join(directory, 'prebuilds');
|
|
166
|
-
if (!fs.exists({ path: prebuilds }))
|
|
167
|
-
continue;
|
|
168
|
-
const entries = fs.entries({ path: prebuilds }).map(name => ({ name, built: prebuildTarget({ entryName: name }) }));
|
|
169
|
-
const serves = (built, target) => built.architectures.includes(target.arch) && (target.platform === built.platform || (target.platform === 'linux' && built.platform === 'linuxmusl'));
|
|
170
|
-
if (!targets.every(target => entries.some(entry => entry.built && serves(entry.built, target))))
|
|
171
|
-
throw new Error(`${path.relative(modulesDir, directory)} ships no prebuild for every requested target: ${targets.map(x => x.platform + '-' + x.arch).join(', ')}`);
|
|
172
|
-
for (const entry of entries)
|
|
173
|
-
if (entry.built && !targets.some(target => serves(entry.built, target)))
|
|
174
|
-
removals.push({ full: path.join(prebuilds, entry.name), reason: 'prebuilds' });
|
|
175
|
-
for (const input of ['deps', 'binding.gyp'])
|
|
176
|
-
if (fs.exists({ path: path.join(directory, input) }))
|
|
177
|
-
removals.push({ full: path.join(directory, input), reason: 'buildInputs' });
|
|
178
|
-
}
|
|
199
|
+
const removals = stagedPackageDirs({ modulesDir, fs }).flatMap(directory => packagePruneRemovals({ directory, modulesDir, targets, fs }));
|
|
179
200
|
for (const { full, reason } of removals) {
|
|
180
201
|
tally.bytes += diskBytes({ absolutePath: full, fs });
|
|
181
202
|
tally[reason]++;
|
|
@@ -4,10 +4,11 @@ import { validateCommitTarget } from './repository-target.js';
|
|
|
4
4
|
export function toCommitFile(required) {
|
|
5
5
|
return { path: required.outputFile.replace(/\\/g, '/'), data: required.data };
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/** Export into a fresh run directory, reporting it through `claim` before any export I/O starts. */
|
|
8
|
+
async function exportIntoRunDirectory(input, claim) {
|
|
9
9
|
try {
|
|
10
|
-
outputDir = input.layout.outputDirectory({ workspaceId: input.workspaceId, providerId: input.providerId, runId: input.ids.next({}) });
|
|
10
|
+
const outputDir = input.layout.outputDirectory({ workspaceId: input.workspaceId, providerId: input.providerId, runId: input.ids.next({}) });
|
|
11
|
+
claim(outputDir);
|
|
11
12
|
const report = await input.files.export({ outputDir }, { clean: true });
|
|
12
13
|
const failure = firstExportFailure({ report });
|
|
13
14
|
if (failure)
|
|
@@ -17,6 +18,12 @@ async function exportForCommit(input) {
|
|
|
17
18
|
catch (error) {
|
|
18
19
|
return { ok: false, code: 'EXPORT_FAILED', message: `export failed before committing could start: ${input.describeError({ error })}` };
|
|
19
20
|
}
|
|
21
|
+
}
|
|
22
|
+
async function exportForCommit(input) {
|
|
23
|
+
let outputDir;
|
|
24
|
+
try {
|
|
25
|
+
return await exportIntoRunDirectory(input, claimed => { outputDir = claimed; });
|
|
26
|
+
}
|
|
20
27
|
finally {
|
|
21
28
|
if (outputDir !== undefined) {
|
|
22
29
|
// Byte payloads are retained by the report; cleanup cannot invalidate the commit.
|
|
@@ -37,11 +44,9 @@ export async function previewCommitExport(required, optional = {}) {
|
|
|
37
44
|
return exported;
|
|
38
45
|
return { ok: true, fileCount: exported.files.length, totalBytes: exported.files.reduce((sum, file) => sum + Buffer.byteLength(file.data), 0), paths: exported.files.map(file => file.path).sort().slice(0, 50) };
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (configError)
|
|
44
|
-
return { ok: false, code: 'INVALID_CONFIG', message: configError };
|
|
47
|
+
const PROVIDER_FAILURE_CODES = { 'repository-not-found': 'REPOSITORY_NOT_FOUND', 'no-changes': 'NO_CHANGES', diverged: 'DIVERGED_BRANCH', 'network-unreachable': 'NETWORK_UNREACHABLE', 'provider-error': 'PROVIDER_ERROR' };
|
|
48
|
+
/** The credential must exist and belong to the requested provider; failures never reveal the token. */
|
|
49
|
+
async function resolveProviderCredential(required) {
|
|
45
50
|
let credential;
|
|
46
51
|
try {
|
|
47
52
|
credential = await required.credentials.resolve({ workspaceId: required.workspaceId, providerId: required.providerId });
|
|
@@ -53,19 +58,32 @@ export async function commitSiteToSourceControl(required, optional = {}) {
|
|
|
53
58
|
return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `No source control credential is configured for '${required.providerId}'.` };
|
|
54
59
|
if (credential.providerId !== required.providerId)
|
|
55
60
|
return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `The resolved default credential is not a '${required.providerId}' connection.` };
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
return { ok: true, credential };
|
|
62
|
+
}
|
|
63
|
+
/** One provider call; the adapter's failure codes map onto the host-facing outcome codes. */
|
|
64
|
+
async function commitExportedFiles(required, optional) {
|
|
65
|
+
const { args, token, files } = required;
|
|
59
66
|
try {
|
|
60
|
-
const result = await
|
|
61
|
-
if (!result.ok)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return { ...result, owner: required.owner, repo: required.repo, divergedPaths: result.divergedPaths ?? [] };
|
|
67
|
+
const result = await args.adapter.commitSite({ token, owner: args.owner, repo: args.repo, commitMessage: args.commitMessage, files }, optional.branch !== undefined ? { branch: optional.branch } : {});
|
|
68
|
+
if (!result.ok)
|
|
69
|
+
return { ok: false, code: PROVIDER_FAILURE_CODES[result.code], message: result.message };
|
|
70
|
+
return { ...result, owner: args.owner, repo: args.repo, divergedPaths: result.divergedPaths ?? [] };
|
|
66
71
|
}
|
|
67
72
|
catch (error) {
|
|
68
|
-
return { ok: false, code: 'PROVIDER_ERROR', message:
|
|
73
|
+
return { ok: false, code: 'PROVIDER_ERROR', message: args.describeError({ error }) };
|
|
69
74
|
}
|
|
70
75
|
}
|
|
76
|
+
/** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
|
|
77
|
+
export async function commitSiteToSourceControl(required, optional = {}) {
|
|
78
|
+
const configError = validateCommitTarget(required, optional);
|
|
79
|
+
if (configError)
|
|
80
|
+
return { ok: false, code: 'INVALID_CONFIG', message: configError };
|
|
81
|
+
const resolved = await resolveProviderCredential(required);
|
|
82
|
+
if (!resolved.ok)
|
|
83
|
+
return resolved;
|
|
84
|
+
const exported = await exportForCommit(required);
|
|
85
|
+
if (!exported.ok)
|
|
86
|
+
return exported;
|
|
87
|
+
return commitExportedFiles({ args: required, token: resolved.credential.token, files: exported.files }, optional);
|
|
88
|
+
}
|
|
71
89
|
//# sourceMappingURL=commit.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
function object(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/** Shared relative-path rule: no backslash, colon or control character; no empty, `.` or `..` segment. */
|
|
3
|
+
function safeRelativePath(value) {
|
|
4
|
+
return !/[\\\x00-\x1f\x7f:]/.test(value) && value.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..');
|
|
4
5
|
}
|
|
5
6
|
/** True for `https://host[:port]` exactly — what `new URL(x).origin` gives back. @complexity O(1). */
|
|
6
7
|
function httpsOrigin(value) {
|
|
@@ -14,30 +15,52 @@ function httpsOrigin(value) {
|
|
|
14
15
|
return false;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
function folderPathAllowed(entry, policy) {
|
|
19
|
+
if (typeof entry !== 'string' || entry.length > 200)
|
|
20
|
+
return false;
|
|
21
|
+
return policy.folderPath ? policy.folderPath({ path: entry }) : safeRelativePath(entry);
|
|
22
|
+
}
|
|
17
23
|
function pathList(value, policy = {}) {
|
|
18
|
-
return Array.isArray(value) && value.length <= 20 && value.every(entry =>
|
|
24
|
+
return Array.isArray(value) && value.length <= 20 && value.every(entry => folderPathAllowed(entry, policy));
|
|
25
|
+
}
|
|
26
|
+
function providerId(value) {
|
|
27
|
+
return typeof value === 'string' && value.length <= 64 && !/\s/.test(value) && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value);
|
|
28
|
+
}
|
|
29
|
+
function providerLabel(value) {
|
|
30
|
+
return typeof value === 'string' && value.trim() !== '' && value.length <= 100;
|
|
31
|
+
}
|
|
32
|
+
function optionalPositiveInteger(value) {
|
|
33
|
+
return value === undefined || (typeof value === 'number' && Number.isSafeInteger(value) && value > 0);
|
|
34
|
+
}
|
|
35
|
+
function moduleAllowed(value, policy) {
|
|
36
|
+
// The `.mjs` rule holds even when a trusted policy replaces the relative-path rule.
|
|
37
|
+
if (typeof value !== 'string' || !value.endsWith('.mjs'))
|
|
38
|
+
return false;
|
|
39
|
+
return policy.modulePath ? policy.modulePath({ path: value }) : safeRelativePath(value);
|
|
40
|
+
}
|
|
41
|
+
/** Field checks in declaration order; each runs only after every earlier one passed. */
|
|
42
|
+
function descriptorFieldError(entry, at, policy) {
|
|
43
|
+
const checks = [
|
|
44
|
+
[() => providerId(entry.id), `${at}.id must be a lowercase hyphenated id`],
|
|
45
|
+
[() => providerLabel(entry.label), `${at}.label must be a non-empty string`],
|
|
46
|
+
[() => httpsOrigin(entry.apiOrigin), `${at}.apiOrigin must be an https origin with no path`],
|
|
47
|
+
[() => optionalPositiveInteger(entry.maxFileBytes), `${at}.maxFileBytes must be a positive integer`],
|
|
48
|
+
[() => entry.reservedPaths === undefined || pathList(entry.reservedPaths, policy), `${at}.reservedPaths must be a list of at most 20 relative folder paths`],
|
|
49
|
+
[() => entry.workflowPaths === undefined || pathList(entry.workflowPaths, policy), `${at}.workflowPaths must be a list of at most 20 relative folder paths`],
|
|
50
|
+
[() => moduleAllowed(entry.module, policy), `${at}.module must be a relative path ending in .mjs`],
|
|
51
|
+
];
|
|
52
|
+
return checks.find(([passes]) => !passes())?.[1];
|
|
19
53
|
}
|
|
20
54
|
function parseDescriptor(entry, at, readExtensions, policy) {
|
|
21
55
|
if (!object(entry))
|
|
22
56
|
return `${at} must be an object`;
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
if (typeof label !== 'string' || label.trim() === '' || label.length > 100)
|
|
27
|
-
return `${at}.label must be a non-empty string`;
|
|
28
|
-
if (!httpsOrigin(apiOrigin))
|
|
29
|
-
return `${at}.apiOrigin must be an https origin with no path`;
|
|
30
|
-
if (maxFileBytes !== undefined && (typeof maxFileBytes !== 'number' || !Number.isSafeInteger(maxFileBytes) || maxFileBytes <= 0))
|
|
31
|
-
return `${at}.maxFileBytes must be a positive integer`;
|
|
32
|
-
if (reservedPaths !== undefined && !pathList(reservedPaths, policy))
|
|
33
|
-
return `${at}.reservedPaths must be a list of at most 20 relative folder paths`;
|
|
34
|
-
if (workflowPaths !== undefined && !pathList(workflowPaths, policy))
|
|
35
|
-
return `${at}.workflowPaths must be a list of at most 20 relative folder paths`;
|
|
36
|
-
if (!(typeof module === "string" && module.endsWith(".mjs") && (policy.modulePath ? policy.modulePath({ path: module }) : relativeModule(module))))
|
|
37
|
-
return `${at}.module must be a relative path ending in .mjs`;
|
|
57
|
+
const fieldError = descriptorFieldError(entry, at, policy);
|
|
58
|
+
if (fieldError !== undefined)
|
|
59
|
+
return fieldError;
|
|
38
60
|
const extras = readExtensions({ entry, at });
|
|
39
61
|
if (!extras.ok)
|
|
40
62
|
return extras.reason;
|
|
63
|
+
const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths, module } = entry;
|
|
41
64
|
return { ...extras.extensions, id, label, apiOrigin, module, ...(typeof maxFileBytes === 'number' ? { maxFileBytes } : {}), ...(pathList(reservedPaths, policy) ? { reservedPaths } : {}), ...(pathList(workflowPaths, policy) ? { workflowPaths } : {}) };
|
|
42
65
|
}
|
|
43
66
|
/** Parse generic host facts; the caller validates credential/i18n extensions. Unknown keys are ignored. */
|
|
@@ -71,52 +94,65 @@ export function sourceControlProviderModuleError({ value }, _optional = {}) {
|
|
|
71
94
|
return "its module's validateTarget is not a function";
|
|
72
95
|
return null;
|
|
73
96
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
function byPluginId(a, b) {
|
|
98
|
+
if (a.pluginId < b.pluginId)
|
|
99
|
+
return -1;
|
|
100
|
+
return a.pluginId > b.pluginId ? 1 : 0;
|
|
101
|
+
}
|
|
102
|
+
/** Parse one catalog descriptor file; a throwing extension reader is that plugin's refusal only. */
|
|
103
|
+
function parseCatalogDescriptors(required) {
|
|
104
|
+
try {
|
|
105
|
+
return parseSourceControlProvidersFile({ raw: required.descriptorText, readExtensions: required.args.readExtensions });
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return { ok: false, reason: required.args.describeError({ error }) };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Import each declared module through the catalog's gate, isolating every provider's fault. */
|
|
112
|
+
async function importTrustedProviders(required) {
|
|
113
|
+
const { item, args, into } = required;
|
|
114
|
+
for (const descriptor of required.descriptors) {
|
|
86
115
|
try {
|
|
87
|
-
|
|
116
|
+
const candidate = await item.importModule({ relativePath: descriptor.module });
|
|
117
|
+
const reason = sourceControlProviderModuleError({ value: candidate });
|
|
118
|
+
if (reason)
|
|
119
|
+
into.refusals.push(`${item.pluginId}/${descriptor.id}: ${reason}`);
|
|
120
|
+
else
|
|
121
|
+
into.providers.push({ descriptor, pluginId: item.pluginId, module: candidate });
|
|
88
122
|
}
|
|
89
123
|
catch (error) {
|
|
90
|
-
refusals.push(`${item.pluginId}: ${
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (!parsed.ok) {
|
|
94
|
-
refusals.push(`${item.pluginId}: ${parsed.reason}`);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (item.state === 'inactive') {
|
|
98
|
-
for (const descriptor of parsed.descriptors)
|
|
99
|
-
if (!switchedOff.has(descriptor.id))
|
|
100
|
-
switchedOff.set(descriptor.id, item.pluginId);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
for (const descriptor of parsed.descriptors) {
|
|
104
|
-
try {
|
|
105
|
-
const candidate = await item.importModule({ relativePath: descriptor.module });
|
|
106
|
-
const reason = sourceControlProviderModuleError({ value: candidate });
|
|
107
|
-
if (reason) {
|
|
108
|
-
refusals.push(`${item.pluginId}/${descriptor.id}: ${reason}`);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
providers.push({ descriptor, pluginId: item.pluginId, module: candidate });
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
refusals.push(`${item.pluginId}/${descriptor.id}: ${required.describeError({ error })}`);
|
|
115
|
-
}
|
|
124
|
+
into.refusals.push(`${item.pluginId}/${descriptor.id}: ${args.describeError({ error })}`);
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
}
|
|
128
|
+
async function loadCatalogItem(required) {
|
|
129
|
+
const { item, into } = required;
|
|
130
|
+
if (item.state === 'refused') {
|
|
131
|
+
into.refusals.push(`${item.pluginId}: ${item.reason}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const parsed = parseCatalogDescriptors({ descriptorText: item.descriptorText, args: required.args });
|
|
135
|
+
if (!parsed.ok) {
|
|
136
|
+
into.refusals.push(`${item.pluginId}: ${parsed.reason}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (item.state === 'inactive') {
|
|
140
|
+
// Inactive plugins never import; the first plugin in id order owns each switched-off id.
|
|
141
|
+
for (const descriptor of parsed.descriptors)
|
|
142
|
+
if (!into.switchedOff.has(descriptor.id))
|
|
143
|
+
into.switchedOff.set(descriptor.id, item.pluginId);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await importTrustedProviders({ item, descriptors: parsed.descriptors, args: required.args, into });
|
|
147
|
+
}
|
|
148
|
+
/** Fresh instance-local registry; only the catalog can grant the ability to import trusted modules. */
|
|
149
|
+
export async function loadSourceControlProviderRegistry(required) {
|
|
150
|
+
const packages = [...await required.catalog.list({ workspaceId: required.workspaceId, descriptorFileName: required.descriptorFileName })].sort(byPluginId);
|
|
151
|
+
const into = { providers: [], refusals: [], switchedOff: new Map() };
|
|
152
|
+
for (const item of packages)
|
|
153
|
+
await loadCatalogItem({ item, args: required, into });
|
|
154
|
+
const frozen = Object.freeze(into.providers.slice());
|
|
155
|
+
return { list: () => frozen, get: ({ providerId }) => frozen.find(provider => provider.descriptor.id === providerId), refusals: Object.freeze(into.refusals.slice()), switchedOff: into.switchedOff };
|
|
120
156
|
}
|
|
121
157
|
export function buildLoadedSourceControlProvider(required, _optional = {}) {
|
|
122
158
|
const { loaded, kit } = required;
|