@jini-ai/devops 0.6.15-rc.2 → 0.6.16
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 +2 -2
- package/dist/agent-jobs/jobs.js +3 -2
- package/dist/checks/hardwiring-node.js +16 -6
- package/dist/checks/hardwiring.js +38 -16
- package/dist/checks/memory-soak.js +2 -1
- package/dist/checks/node.d.ts +0 -1
- package/dist/checks/node.js +7 -1
- package/dist/checks/published-types/index.js +5 -2
- package/dist/core/deploy-types.d.ts +8 -0
- package/dist/deploy/naming.js +4 -5
- package/dist/deploy/node.js +4 -2
- package/dist/deploy/reachability.js +26 -23
- package/dist/dns/plan.js +2 -1
- package/dist/dns/records.js +7 -3
- package/dist/dns/registry.js +4 -2
- package/dist/local-dev/index.js +7 -3
- package/dist/packaging/electron/entry.d.ts +3 -0
- package/dist/packaging/electron/entry.js +3 -0
- package/dist/packaging/electron/imports.js +5 -3
- package/dist/packaging/electron/node.js +7 -1
- package/dist/packaging/electron/optional-peers.d.ts +22 -0
- package/dist/packaging/electron/optional-peers.js +16 -0
- package/dist/packaging/electron/ports.d.ts +16 -0
- package/dist/packaging/electron/staged-closure-node.d.ts +7 -0
- package/dist/packaging/electron/staged-closure-node.js +17 -0
- package/dist/packaging/electron/staged-closure.d.ts +27 -0
- package/dist/packaging/electron/staged-closure.js +128 -0
- package/dist/packaging/electron/staging.d.ts +28 -4
- package/dist/packaging/electron/staging.js +69 -27
- package/dist/packaging/electron/typescript.d.ts +15 -2
- package/dist/packaging/electron/typescript.js +101 -16
- package/dist/source-control/commit.js +23 -5
- package/dist/source-control/contracts.d.ts +11 -1
- package/dist/source-control/entry.d.ts +1 -0
- package/dist/source-control/entry.js +1 -0
- package/dist/source-control/kit.js +2 -0
- package/dist/source-control/registry.d.ts +5 -0
- package/dist/source-control/registry.js +5 -2
- package/dist/source-control/repository-path.d.ts +28 -0
- package/dist/source-control/repository-path.js +52 -0
- package/dist/source-control/repository-target.js +6 -3
- package/dist/static-export/contracts.d.ts +4 -5
- package/dist/static-export/css-urls.d.ts +16 -0
- package/dist/static-export/css-urls.js +66 -0
- package/dist/static-export/html-url-locations.d.ts +2 -1
- package/dist/static-export/html-url-locations.js +23 -3
- package/dist/static-export/node-adapters.js +8 -3
- package/dist/static-export/runner.js +47 -30
- package/dist/static-export/transforms.js +45 -29
- package/package.json +12 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PackagingFilesystemPort, ImportReaderPort, RuntimeResolverPort } from './ports.js';
|
|
2
|
+
export interface StagedClosureInput {
|
|
3
|
+
root: string;
|
|
4
|
+
/** Host runtime entry files or directories. All installed Jini dist files are also audited. */
|
|
5
|
+
scan: readonly string[];
|
|
6
|
+
/** Package roots sharing this resource tree, e.g. an extracted app.asar directory. */
|
|
7
|
+
packageRoots?: readonly string[];
|
|
8
|
+
fs: PackagingFilesystemPort;
|
|
9
|
+
imports: ImportReaderPort;
|
|
10
|
+
resolver: RuntimeResolverPort;
|
|
11
|
+
/** Native host modules supplied by the executable, e.g. Electron. Never package exceptions. */
|
|
12
|
+
hostModules?: ReadonlySet<string>;
|
|
13
|
+
}
|
|
14
|
+
export interface StagedClosureAudit {
|
|
15
|
+
problems: string[];
|
|
16
|
+
optIns: string[];
|
|
17
|
+
checked: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Audit literal runtime references from the staged tree only. All Jini dist files are roots,
|
|
21
|
+
* so deferred loads cannot disappear behind an unexercised feature or a try/catch.
|
|
22
|
+
* Missing peers are exempt only by their owning package's valid opt-in manifest contract.
|
|
23
|
+
* @throws on an invalid scan root, escaping package link, or a parser without runtime references.
|
|
24
|
+
* @complexity O(files + edges × Node resolution cost); each reached file is parsed once.
|
|
25
|
+
*/
|
|
26
|
+
export declare function auditStagedClosure(input: StagedClosureInput, _options?: Record<string, never>): StagedClosureAudit;
|
|
27
|
+
//# sourceMappingURL=staged-closure.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isBuiltin } from 'node:module';
|
|
3
|
+
import { optionalPeerClassification } from './optional-peers.js';
|
|
4
|
+
const codeFile = (file) => /\.[cm]?[jt]sx?$/.test(file) && !/\.d\.[cm]?ts$/.test(file) && !/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(file);
|
|
5
|
+
const inside = (root, target) => target === root || target.startsWith(root + path.sep);
|
|
6
|
+
const packageName = (specifier) => specifier.split('/').slice(0, specifier.startsWith('@') ? 2 : 1).join('/');
|
|
7
|
+
/** Scan trees once, never following a symlink outside the stage. O(files), O(files) output. */
|
|
8
|
+
function codeFiles(required) {
|
|
9
|
+
const { directory, root, fs } = required;
|
|
10
|
+
if (!fs.exists({ path: directory }))
|
|
11
|
+
return [];
|
|
12
|
+
if (!inside(root, fs.realpath({ path: directory })))
|
|
13
|
+
throw new Error(`staged scan escapes root: ${directory}`);
|
|
14
|
+
if (fs.stat({ path: directory }).kind === 'file')
|
|
15
|
+
return codeFile(directory) ? [fs.realpath({ path: directory })] : [];
|
|
16
|
+
return fs.entries({ path: directory }).flatMap(name => codeFiles({ directory: path.join(directory, name), root, fs }));
|
|
17
|
+
}
|
|
18
|
+
/** Enumerate nested production package trees, including nested versions and self-contained bundles. */
|
|
19
|
+
function jiniFiles(required) {
|
|
20
|
+
const { directory, root, fs } = required;
|
|
21
|
+
const modules = path.join(directory, 'node_modules');
|
|
22
|
+
if (!fs.exists({ path: modules }))
|
|
23
|
+
return [];
|
|
24
|
+
const packages = fs.entries({ path: modules }).filter(name => !name.startsWith('.')).flatMap(name => {
|
|
25
|
+
const entry = path.join(modules, name);
|
|
26
|
+
return name.startsWith('@') ? fs.entries({ path: entry }).map(child => path.join(entry, child)) : [entry];
|
|
27
|
+
});
|
|
28
|
+
return packages.flatMap(directory => {
|
|
29
|
+
if (!inside(root, fs.realpath({ path: directory })))
|
|
30
|
+
throw new Error(`staged package escapes root: ${directory}`);
|
|
31
|
+
const own = path.basename(path.dirname(directory)) === '@jini-ai'
|
|
32
|
+
? codeFiles({ directory: path.join(directory, 'dist'), root, fs }) : [];
|
|
33
|
+
return [...own, ...jiniFiles({ directory, root, fs })];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function manifestOwner(required) {
|
|
37
|
+
const { file, root, fs } = required;
|
|
38
|
+
let directory = path.dirname(file);
|
|
39
|
+
while (inside(root, directory)) {
|
|
40
|
+
const manifest = path.join(directory, 'package.json');
|
|
41
|
+
if (fs.exists({ path: manifest }))
|
|
42
|
+
return JSON.parse(Buffer.from(fs.read({ path: manifest })).toString('utf8'));
|
|
43
|
+
if (directory === root)
|
|
44
|
+
break;
|
|
45
|
+
directory = path.dirname(directory);
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
function exemption(required) {
|
|
50
|
+
const { specifier } = required;
|
|
51
|
+
if (specifier.startsWith('.') || specifier.startsWith('#') || path.isAbsolute(specifier))
|
|
52
|
+
return undefined;
|
|
53
|
+
const manifest = manifestOwner(required);
|
|
54
|
+
if (!manifest?.name?.startsWith('@jini-ai/'))
|
|
55
|
+
return undefined;
|
|
56
|
+
return optionalPeerClassification({ manifest, name: packageName(specifier) });
|
|
57
|
+
}
|
|
58
|
+
/** Check one edge using Node's actual import/require conditions; ancestor resolution is rejected. */
|
|
59
|
+
function resolveEdge(required) {
|
|
60
|
+
const { input, file, specifier, kind } = required;
|
|
61
|
+
const target = input.resolver.resolve({ fromFile: file, specifier, kind });
|
|
62
|
+
const root = input.fs.realpath({ path: input.root });
|
|
63
|
+
if (!inside(root, target))
|
|
64
|
+
throw new Error('resolved outside the staged tree');
|
|
65
|
+
if (!input.fs.exists({ path: target }))
|
|
66
|
+
throw new Error('resolved target does not exist');
|
|
67
|
+
if (!inside(root, input.fs.realpath({ path: target })))
|
|
68
|
+
throw new Error('resolved symlink escapes the staged tree');
|
|
69
|
+
if (input.fs.stat({ path: target }).kind !== 'file')
|
|
70
|
+
throw new Error('resolved target is not a file');
|
|
71
|
+
return target;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Audit literal runtime references from the staged tree only. All Jini dist files are roots,
|
|
75
|
+
* so deferred loads cannot disappear behind an unexercised feature or a try/catch.
|
|
76
|
+
* Missing peers are exempt only by their owning package's valid opt-in manifest contract.
|
|
77
|
+
* @throws on an invalid scan root, escaping package link, or a parser without runtime references.
|
|
78
|
+
* @complexity O(files + edges × Node resolution cost); each reached file is parsed once.
|
|
79
|
+
*/
|
|
80
|
+
export function auditStagedClosure(input, _options = {}) {
|
|
81
|
+
if (!input.imports.references)
|
|
82
|
+
throw new Error('staged closure requires an AST runtime-reference reader');
|
|
83
|
+
const root = input.fs.realpath({ path: input.root });
|
|
84
|
+
const queue = [...new Set([...input.scan.flatMap(directory => codeFiles({ directory, root, fs: input.fs })),
|
|
85
|
+
...(input.packageRoots ?? [root]).flatMap(directory => jiniFiles({ directory, root, fs: input.fs }))])];
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
const problems = [];
|
|
88
|
+
const optIns = [];
|
|
89
|
+
const stagedInput = { ...input, root };
|
|
90
|
+
function failure(file, specifier, location, error) {
|
|
91
|
+
const optIn = exemption({ file, specifier, root, fs: input.fs });
|
|
92
|
+
if (optIn)
|
|
93
|
+
optIns.push(`${location} (${optIn})`);
|
|
94
|
+
else
|
|
95
|
+
problems.push(`${location}: ${error instanceof Error ? error.message : String(error)}`);
|
|
96
|
+
}
|
|
97
|
+
function checkReference(file, ref) {
|
|
98
|
+
if (isBuiltin(ref.specifier) || input.hostModules?.has(ref.specifier))
|
|
99
|
+
return;
|
|
100
|
+
const location = `${path.relative(root, file)}:${ref.line} -> ${ref.specifier}`;
|
|
101
|
+
try {
|
|
102
|
+
const target = resolveEdge({ file, ...ref, input: stagedInput });
|
|
103
|
+
// Third-party packages own their optional internals. This contract audits Jini and host files.
|
|
104
|
+
const relative = path.relative(root, target).split(path.sep).join('/');
|
|
105
|
+
const lastModules = relative.lastIndexOf('node_modules/');
|
|
106
|
+
const owned = lastModules < 0 || /^@jini-ai\/[^/]+\/dist\//.test(relative.slice(lastModules + 'node_modules/'.length));
|
|
107
|
+
if (codeFile(target) && owned)
|
|
108
|
+
queue.push(target);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
failure(file, ref.specifier, location, error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function scan(file) {
|
|
115
|
+
const source = Buffer.from(input.fs.read({ path: file })).toString('utf8');
|
|
116
|
+
for (const ref of input.imports.references({ file, source }))
|
|
117
|
+
checkReference(file, ref);
|
|
118
|
+
}
|
|
119
|
+
while (queue.length) {
|
|
120
|
+
const file = queue.pop();
|
|
121
|
+
if (seen.has(file))
|
|
122
|
+
continue;
|
|
123
|
+
seen.add(file);
|
|
124
|
+
scan(file);
|
|
125
|
+
}
|
|
126
|
+
return { problems, optIns, checked: seen.size };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=staged-closure.js.map
|
|
@@ -15,25 +15,48 @@ export declare function stageDir(required: {
|
|
|
15
15
|
}, optional?: {
|
|
16
16
|
dropNestedModules?: boolean;
|
|
17
17
|
}): void;
|
|
18
|
-
/**
|
|
18
|
+
/** Host policy selects runtime edges; the planner still owns resolution/version safety. */
|
|
19
|
+
interface DependencyOptions {
|
|
20
|
+
dependencies?: (required: {
|
|
21
|
+
packageDir: string;
|
|
22
|
+
fs: PackagingFilesystemPort;
|
|
23
|
+
}) => readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Plan selected runtime edges before copying; unresolved/conflicting versions throw atomically.
|
|
26
|
+
* Supplied roots are already owned by the caller and are never copied through a back edge.
|
|
27
|
+
* @complexity O(packages + edges × ancestor depth) filesystem reads, O(packages) plan memory.
|
|
28
|
+
* @example stageTransitiveDependencies({ roots, outDir, excluded, fs, resolver });
|
|
29
|
+
*/
|
|
19
30
|
export declare function stageTransitiveDependencies(required: {
|
|
20
31
|
roots: readonly string[];
|
|
21
32
|
outDir: string;
|
|
22
33
|
excluded: ReadonlySet<string>;
|
|
23
34
|
fs: PackagingFilesystemPort;
|
|
24
35
|
resolver: PackageResolverPort;
|
|
25
|
-
}): number;
|
|
36
|
+
}, optional?: DependencyOptions): number;
|
|
26
37
|
/** Enumerate real package roots, treating scoped directories as containers. */
|
|
27
38
|
export declare function stagedPackageDirs({ modulesDir, fs }: {
|
|
28
39
|
modulesDir: string;
|
|
29
40
|
fs: PackagingFilesystemPort;
|
|
30
41
|
}): string[];
|
|
31
|
-
/**
|
|
42
|
+
/** Inventory every staged package, including nested scopes, and report missing declared edges.
|
|
43
|
+
* Hosts may select peers/optionals through the same policy seam as the staging planner.
|
|
44
|
+
* @returns Ordered package-to-dependency diagnostics, suitable for host-specific refusal messages.
|
|
45
|
+
* @throws Error if the staged modules tree is missing.
|
|
46
|
+
* @complexity O(packages + edges × ancestor depth) filesystem probes; O(packages + gaps) memory.
|
|
47
|
+
* @example missingClosureDependencies({ outDir, excluded, fs });
|
|
48
|
+
*/
|
|
49
|
+
export declare function missingClosureDependencies(required: {
|
|
50
|
+
outDir: string;
|
|
51
|
+
excluded: ReadonlySet<string>;
|
|
52
|
+
fs: PackagingFilesystemPort;
|
|
53
|
+
}, optional?: DependencyOptions): string[];
|
|
54
|
+
/** Refuse incomplete nested/hoisted closures; checkout ancestors cannot fill shipped gaps. */
|
|
32
55
|
export declare function assertClosureComplete(required: {
|
|
33
56
|
outDir: string;
|
|
34
57
|
excluded: ReadonlySet<string>;
|
|
35
58
|
fs: PackagingFilesystemPort;
|
|
36
|
-
}): void;
|
|
59
|
+
}, optional?: DependencyOptions): void;
|
|
37
60
|
/** Share the existing workspace build/pack/rewritten-tarball implementation via a host binding. */
|
|
38
61
|
export declare function stagePackedWorkspace(required: {
|
|
39
62
|
repoRoot: string;
|
|
@@ -105,4 +128,5 @@ export declare function stageBundledNpm(required: {
|
|
|
105
128
|
fileCount: number;
|
|
106
129
|
bytes: number;
|
|
107
130
|
};
|
|
131
|
+
export {};
|
|
108
132
|
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { isBundleInput, prebuildTarget, strippableReason } from './policies.js';
|
|
3
|
+
const PACKAGE_JSON = 'package.json';
|
|
3
4
|
function manifest(directory, fs) {
|
|
4
|
-
const file = path.join(directory,
|
|
5
|
+
const file = path.join(directory, PACKAGE_JSON);
|
|
5
6
|
return fs.exists({ path: file }) ? JSON.parse(Buffer.from(fs.read({ path: file })).toString('utf8')) : {};
|
|
6
7
|
}
|
|
7
8
|
function safePackageName(name) {
|
|
@@ -32,7 +33,7 @@ function resolveDependency(required) {
|
|
|
32
33
|
*/
|
|
33
34
|
function assertFlattenable(required) {
|
|
34
35
|
const { name, planned: { directory, version }, existing, destination, fs } = required;
|
|
35
|
-
const destinationVersion = fs.exists({ path: path.join(destination,
|
|
36
|
+
const destinationVersion = fs.exists({ path: path.join(destination, PACKAGE_JSON) }) ? manifest(destination, fs).version : undefined;
|
|
36
37
|
const plannedConflict = existing !== undefined && existing.directory !== directory && (!version || existing.version !== version);
|
|
37
38
|
const stagedConflict = fs.exists({ path: destination }) && (!version || destinationVersion !== version);
|
|
38
39
|
if (plannedConflict || stagedConflict)
|
|
@@ -46,6 +47,8 @@ function planDependency(plan, required) {
|
|
|
46
47
|
if (isExcluded({ name, excluded }))
|
|
47
48
|
return;
|
|
48
49
|
const directory = resolveDependency({ from, name, fs, resolver });
|
|
50
|
+
if (plan.roots.has(directory))
|
|
51
|
+
return;
|
|
49
52
|
const planned = { directory, version: manifest(directory, fs).version };
|
|
50
53
|
const existing = staged.get(name);
|
|
51
54
|
assertFlattenable({ name, planned, existing, destination: stagedPath(outDir, name), fs });
|
|
@@ -56,14 +59,18 @@ function planDependency(plan, required) {
|
|
|
56
59
|
queue.push(directory);
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
|
-
/** Plan
|
|
60
|
-
|
|
62
|
+
/** Plan selected runtime edges before copying; unresolved/conflicting versions throw atomically.
|
|
63
|
+
* Supplied roots are already owned by the caller and are never copied through a back edge.
|
|
64
|
+
* @complexity O(packages + edges × ancestor depth) filesystem reads, O(packages) plan memory.
|
|
65
|
+
* @example stageTransitiveDependencies({ roots, outDir, excluded, fs, resolver });
|
|
66
|
+
*/
|
|
67
|
+
export function stageTransitiveDependencies(required, optional = {}) {
|
|
61
68
|
const { roots, outDir, fs } = required;
|
|
62
69
|
const visited = new Set(roots.map(root => fs.realpath({ path: root })));
|
|
63
|
-
const plan = { ...required, staged: new Map(), visited, queue: [...visited] };
|
|
70
|
+
const plan = { ...required, staged: new Map(), roots: new Set(visited), visited, queue: [...visited] };
|
|
64
71
|
for (let index = 0; index < plan.queue.length; index++) {
|
|
65
72
|
const from = plan.queue[index];
|
|
66
|
-
for (const name of declaredDependencies({ packageDir: from, fs }))
|
|
73
|
+
for (const name of (optional.dependencies ?? declaredDependencies)({ packageDir: from, fs }))
|
|
67
74
|
planDependency(plan, { from, name });
|
|
68
75
|
}
|
|
69
76
|
let count = 0;
|
|
@@ -83,26 +90,55 @@ export function stagedPackageDirs({ modulesDir, fs }) {
|
|
|
83
90
|
return fs.entries({ path: modulesDir }).filter(entry => !entry.startsWith('.')).flatMap(entry => {
|
|
84
91
|
const full = path.join(modulesDir, entry);
|
|
85
92
|
if (!entry.startsWith('@'))
|
|
86
|
-
return fs.exists({ path: path.join(full,
|
|
87
|
-
return fs.entries({ path: full }).map(scoped => path.join(full, scoped)).filter(dir => fs.exists({ path: path.join(dir,
|
|
93
|
+
return fs.exists({ path: path.join(full, PACKAGE_JSON) }) ? [full] : [];
|
|
94
|
+
return fs.entries({ path: full }).map(scoped => path.join(full, scoped)).filter(dir => fs.exists({ path: path.join(dir, PACKAGE_JSON) }));
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
|
-
/**
|
|
91
|
-
|
|
97
|
+
/** Resolve a dependency using Node's ancestor search, bounded to the shipped modules tree.
|
|
98
|
+
* Symlinks escaping the payload cannot satisfy an edge. O(ancestor depth) filesystem probes.
|
|
99
|
+
*/
|
|
100
|
+
function shippedDependency({ directory, name, modulesDir, fs }, _optional = {}) {
|
|
101
|
+
const candidates = [];
|
|
102
|
+
for (let current = directory; current.startsWith(modulesDir + path.sep); current = path.dirname(current))
|
|
103
|
+
candidates.push(path.join(current, 'node_modules', name));
|
|
104
|
+
const found = [...candidates, path.join(modulesDir, name)].find(candidate => fs.exists({ path: path.join(candidate, PACKAGE_JSON) }));
|
|
105
|
+
if (!found)
|
|
106
|
+
return false;
|
|
107
|
+
const relative = path.relative(fs.realpath({ path: modulesDir }), fs.realpath({ path: found }));
|
|
108
|
+
return relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative);
|
|
109
|
+
}
|
|
110
|
+
/** Inventory every staged package, including nested scopes, and report missing declared edges.
|
|
111
|
+
* Hosts may select peers/optionals through the same policy seam as the staging planner.
|
|
112
|
+
* @returns Ordered package-to-dependency diagnostics, suitable for host-specific refusal messages.
|
|
113
|
+
* @throws Error if the staged modules tree is missing.
|
|
114
|
+
* @complexity O(packages + edges × ancestor depth) filesystem probes; O(packages + gaps) memory.
|
|
115
|
+
* @example missingClosureDependencies({ outDir, excluded, fs });
|
|
116
|
+
*/
|
|
117
|
+
export function missingClosureDependencies(required, optional = {}) {
|
|
92
118
|
const { outDir, excluded, fs } = required;
|
|
93
119
|
const modulesDir = path.join(outDir, 'node_modules');
|
|
94
|
-
const missing = [];
|
|
95
120
|
if (!fs.exists({ path: modulesDir }))
|
|
96
121
|
throw new Error('staged node_modules tree is missing');
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
const packages = stagedPackageDirs({ modulesDir, fs });
|
|
123
|
+
const missing = [], visited = new Set();
|
|
124
|
+
// Inventory nested packages even when no top-level dependency happens to reference them.
|
|
125
|
+
for (const directory of packages) {
|
|
126
|
+
const real = fs.realpath({ path: directory });
|
|
127
|
+
if (visited.has(real))
|
|
128
|
+
continue;
|
|
129
|
+
visited.add(real);
|
|
130
|
+
packages.push(...stagedPackageDirs({ modulesDir: path.join(directory, 'node_modules'), fs }));
|
|
131
|
+
for (const name of (optional.dependencies ?? declaredDependencies)({ packageDir: directory, fs })) {
|
|
101
132
|
safePackageName(name);
|
|
102
|
-
if (!isExcluded({ name, excluded }) && !
|
|
133
|
+
if (!isExcluded({ name, excluded }) && !shippedDependency({ directory, name, modulesDir, fs }))
|
|
103
134
|
missing.push(`${path.relative(modulesDir, directory)} -> ${name}`);
|
|
104
135
|
}
|
|
105
136
|
}
|
|
137
|
+
return missing;
|
|
138
|
+
}
|
|
139
|
+
/** Refuse incomplete nested/hoisted closures; checkout ancestors cannot fill shipped gaps. */
|
|
140
|
+
export function assertClosureComplete(required, optional = {}) {
|
|
141
|
+
const missing = missingClosureDependencies(required, optional);
|
|
106
142
|
if (missing.length)
|
|
107
143
|
throw new Error(`staged tree is missing ${missing.length} declared dependencies:\n ${missing.join('\n ')}`);
|
|
108
144
|
}
|
|
@@ -153,20 +189,22 @@ export function stripNonRuntimeFiles(required) {
|
|
|
153
189
|
tally.coverage++;
|
|
154
190
|
fs.remove({ path: coverage });
|
|
155
191
|
}
|
|
192
|
+
function stripFile(full, diskBytes) {
|
|
193
|
+
const reason = strippableReason({ relPath: path.relative(modulesDir, full).split(path.sep).join('/'), keepScopes });
|
|
194
|
+
if (!reason)
|
|
195
|
+
return;
|
|
196
|
+
tally.bytes += diskBytes;
|
|
197
|
+
tally[reason]++;
|
|
198
|
+
fs.remove({ path: full });
|
|
199
|
+
}
|
|
156
200
|
function walk(directory) {
|
|
157
201
|
for (const name of fs.entries({ path: directory })) {
|
|
158
202
|
const full = path.join(directory, name);
|
|
159
203
|
const info = fs.stat({ path: full });
|
|
160
|
-
if (info.kind === 'directory')
|
|
204
|
+
if (info.kind === 'directory')
|
|
161
205
|
walk(full);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const reason = strippableReason({ relPath: path.relative(modulesDir, full).split(path.sep).join('/'), keepScopes });
|
|
165
|
-
if (!reason)
|
|
166
|
-
continue;
|
|
167
|
-
tally.bytes += info.diskBytes;
|
|
168
|
-
tally[reason]++;
|
|
169
|
-
fs.remove({ path: full });
|
|
206
|
+
else
|
|
207
|
+
stripFile(full, info.diskBytes);
|
|
170
208
|
}
|
|
171
209
|
}
|
|
172
210
|
walk(modulesDir);
|
|
@@ -237,6 +275,10 @@ export function stageBundledNpm(required) {
|
|
|
237
275
|
throw new Error('stageBundledNpm: bounded prefix-read port is required');
|
|
238
276
|
const readPrefix = fs.readPrefix.bind(fs);
|
|
239
277
|
const excluded = ({ path: full, directory }) => directory ? droppedDirectoryNames.has(path.basename(full)) : droppedFileSuffixes.some(suffix => full.endsWith(suffix));
|
|
278
|
+
function assertNotNativeBinary(full) {
|
|
279
|
+
if (hasNativeBinaryMagic({ bytes: readPrefix({ path: full, maxBytes: 4 }) }))
|
|
280
|
+
throw new Error(`stageBundledNpm: ${path.relative(source, full)} starts with native-binary magic bytes`);
|
|
281
|
+
}
|
|
240
282
|
function inspect(directory) {
|
|
241
283
|
for (const entry of fs.entries({ path: directory })) {
|
|
242
284
|
const full = path.join(directory, entry);
|
|
@@ -247,8 +289,8 @@ export function stageBundledNpm(required) {
|
|
|
247
289
|
continue;
|
|
248
290
|
if (info.kind === 'directory')
|
|
249
291
|
inspect(full);
|
|
250
|
-
else
|
|
251
|
-
|
|
292
|
+
else
|
|
293
|
+
assertNotNativeBinary(full);
|
|
252
294
|
}
|
|
253
295
|
}
|
|
254
296
|
inspect(source);
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import type ts from 'typescript';
|
|
2
2
|
import type { ImportReaderPort } from './ports.js';
|
|
3
|
-
|
|
3
|
+
export interface RuntimeImportRef {
|
|
4
|
+
specifier: string;
|
|
5
|
+
kind: 'import' | 'require';
|
|
6
|
+
line: number;
|
|
7
|
+
deferred: boolean;
|
|
8
|
+
typeOnly?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Read syntax with the host's maintained parser. No module is executed. O(source length). */
|
|
11
|
+
export declare function runtimeImportReferences({ compiler: c, file, source }: {
|
|
12
|
+
compiler: typeof ts;
|
|
13
|
+
file: string;
|
|
14
|
+
source: string;
|
|
15
|
+
}, _options?: Record<string, never>): RuntimeImportRef[];
|
|
16
|
+
/** Bind one parser owner for static, dynamic, CommonJS and createRequire references. */
|
|
4
17
|
export declare function createTypeScriptImportReader({ compiler }: {
|
|
5
18
|
compiler: typeof ts;
|
|
6
|
-
}): ImportReaderPort;
|
|
19
|
+
}, _options?: Record<string, never>): ImportReaderPort;
|
|
7
20
|
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -1,18 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/** Read syntax with the host's maintained parser. No module is executed. O(source length). */
|
|
2
|
+
export function runtimeImportReferences({ compiler: c, file, source }, _options = {}) {
|
|
3
|
+
const tree = c.createSourceFile(file, source, c.ScriptTarget.Latest, true, file.endsWith('.tsx') ? c.ScriptKind.TSX : c.ScriptKind.TS);
|
|
4
|
+
const scopes = new Map();
|
|
5
|
+
const found = [];
|
|
6
|
+
function scopeOf(node) {
|
|
7
|
+
let parent = node.parent;
|
|
8
|
+
while (parent && !c.isBlock(parent) && !c.isFunctionLike(parent) && !c.isSourceFile(parent))
|
|
9
|
+
parent = parent.parent;
|
|
10
|
+
return parent ?? tree;
|
|
11
|
+
}
|
|
12
|
+
function lookup(node) {
|
|
13
|
+
let scope = scopeOf(node);
|
|
14
|
+
while (scope) {
|
|
15
|
+
const value = scopes.get(scope)?.get(node.text);
|
|
16
|
+
if (value)
|
|
17
|
+
return value;
|
|
18
|
+
scope = scope === tree ? undefined : scopeOf(scope);
|
|
19
|
+
}
|
|
20
|
+
if (node.text === 'require')
|
|
21
|
+
return 'require';
|
|
22
|
+
return node.text === 'createRequire' ? 'creator' : undefined;
|
|
23
|
+
}
|
|
24
|
+
function isCreator(node) {
|
|
25
|
+
if (c.isIdentifier(node))
|
|
26
|
+
return lookup(node) === 'creator';
|
|
27
|
+
return c.isPropertyAccessExpression(node) && node.name.text === 'createRequire';
|
|
28
|
+
}
|
|
29
|
+
function bind(node, name, value) {
|
|
30
|
+
const scope = scopeOf(node);
|
|
31
|
+
const values = scopes.get(scope) ?? new Map();
|
|
32
|
+
values.set(name, value);
|
|
33
|
+
scopes.set(scope, values);
|
|
34
|
+
}
|
|
35
|
+
function variableBinding(node) {
|
|
36
|
+
if (!c.isVariableDeclaration(node) || !c.isIdentifier(node.name))
|
|
37
|
+
return;
|
|
38
|
+
const init = node.initializer;
|
|
39
|
+
const value = init && c.isCallExpression(init) && isCreator(init.expression) ? 'require' : 'other';
|
|
40
|
+
bind(node, node.name.text, value);
|
|
41
|
+
}
|
|
42
|
+
function bindings(node) {
|
|
43
|
+
if (c.isImportSpecifier(node) && (node.propertyName ?? node.name).text === 'createRequire')
|
|
44
|
+
bind(node, node.name.text, 'creator');
|
|
45
|
+
if (c.isParameter(node) && c.isIdentifier(node.name))
|
|
46
|
+
bind(node, node.name.text, 'other');
|
|
47
|
+
variableBinding(node);
|
|
48
|
+
c.forEachChild(node, bindings);
|
|
49
|
+
}
|
|
50
|
+
bindings(tree);
|
|
51
|
+
function isRequire(node) {
|
|
52
|
+
if (c.isIdentifier(node))
|
|
53
|
+
return lookup(node) === 'require';
|
|
54
|
+
return c.isCallExpression(node) && isCreator(node.expression);
|
|
55
|
+
}
|
|
56
|
+
function inlineTypes(clause) {
|
|
57
|
+
if (!clause)
|
|
58
|
+
return false;
|
|
59
|
+
if (!c.isNamedImports(clause) && !c.isNamedExports(clause))
|
|
60
|
+
return false;
|
|
61
|
+
return clause.elements.length > 0 && clause.elements.every(e => e.isTypeOnly);
|
|
62
|
+
}
|
|
63
|
+
function erased(node) {
|
|
64
|
+
if (c.isImportDeclaration(node)) {
|
|
65
|
+
const clause = node.importClause;
|
|
66
|
+
return Boolean(clause?.isTypeOnly || (!clause?.name && inlineTypes(clause?.namedBindings)));
|
|
67
|
+
}
|
|
68
|
+
return node.isTypeOnly || inlineTypes(node.exportClause);
|
|
69
|
+
}
|
|
70
|
+
function callReference(node) {
|
|
71
|
+
if (node.expression.kind === c.SyntaxKind.ImportKeyword)
|
|
72
|
+
return { literal: node.arguments[0], kind: 'import' };
|
|
73
|
+
const call = node.expression;
|
|
74
|
+
if (isRequire(call))
|
|
75
|
+
return { literal: node.arguments[0], kind: 'require' };
|
|
76
|
+
if (c.isPropertyAccessExpression(call) && call.name.text === 'resolve' && isRequire(call.expression))
|
|
77
|
+
return { literal: node.arguments[0], kind: 'require' };
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function reference(node) {
|
|
81
|
+
if (c.isImportDeclaration(node) || c.isExportDeclaration(node))
|
|
82
|
+
return { literal: node.moduleSpecifier, kind: 'import', typeOnly: erased(node) };
|
|
83
|
+
if (c.isImportEqualsDeclaration(node) && c.isExternalModuleReference(node.moduleReference))
|
|
84
|
+
return { literal: node.moduleReference.expression, kind: 'require', typeOnly: node.isTypeOnly };
|
|
85
|
+
return c.isCallExpression(node) ? callReference(node) : undefined;
|
|
86
|
+
}
|
|
87
|
+
function visit(node, deferred = false) {
|
|
88
|
+
const ref = reference(node);
|
|
89
|
+
if (ref?.literal && c.isStringLiteralLike(ref.literal))
|
|
90
|
+
found.push({ specifier: ref.literal.text, kind: ref.kind,
|
|
91
|
+
typeOnly: ref.typeOnly ?? false, line: tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1, deferred });
|
|
92
|
+
const nested = deferred || c.isFunctionLike(node);
|
|
93
|
+
c.forEachChild(node, child => visit(child, nested));
|
|
94
|
+
}
|
|
95
|
+
visit(tree);
|
|
96
|
+
return found;
|
|
97
|
+
}
|
|
98
|
+
/** Bind one parser owner for static, dynamic, CommonJS and createRequire references. */
|
|
99
|
+
export function createTypeScriptImportReader({ compiler }, _options = {}) {
|
|
100
|
+
const references = ({ file, source }) => runtimeImportReferences({ compiler, file, source }).filter(ref => !ref.typeOnly);
|
|
101
|
+
return { references, imports: required => references(required).map(ref => ref.specifier) };
|
|
17
102
|
}
|
|
18
103
|
//# sourceMappingURL=typescript.js.map
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { firstExportFailure } from '../core/export-failure-summary.js';
|
|
2
2
|
import { validateCommitTarget } from './repository-target.js';
|
|
3
|
+
import { normalizeRepositoryFolder, prefixRepositoryPath } from './repository-path.js';
|
|
4
|
+
/** Folder validation precedes credentials, rendering and all provider effects. */
|
|
5
|
+
function folderError(required, optional = {}) {
|
|
6
|
+
try {
|
|
7
|
+
const folder = normalizeRepositoryFolder(required);
|
|
8
|
+
if (folder && optional.committing && required.supportsFolder !== true)
|
|
9
|
+
return 'This provider does not support folder commits.';
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return error.message;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
3
16
|
/** Normalize platform separators without changing the retained byte payload. */
|
|
4
17
|
export function toCommitFile(required) {
|
|
5
18
|
return { path: required.outputFile.replace(/\\/g, '/'), data: required.data };
|
|
@@ -13,7 +26,11 @@ async function exportIntoRunDirectory(input, claim) {
|
|
|
13
26
|
const failure = firstExportFailure({ report });
|
|
14
27
|
if (failure)
|
|
15
28
|
return { ok: false, code: 'EXPORT_FAILED', message: `refused to commit: ${failure.count} ${failure.kind}(s) failed to export (first: '${failure.identifier}' — ${failure.reason})` };
|
|
16
|
-
|
|
29
|
+
const files = [...report.routes.succeeded.map(toCommitFile), ...report.assets.succeeded.map(toCommitFile)];
|
|
30
|
+
// Validate every folder-relative path while export failures still use the safe outcome channel.
|
|
31
|
+
for (const file of files)
|
|
32
|
+
prefixRepositoryPath({ folder: input.folder, path: file.path });
|
|
33
|
+
return { ok: true, files };
|
|
17
34
|
}
|
|
18
35
|
catch (error) {
|
|
19
36
|
return { ok: false, code: 'EXPORT_FAILED', message: `export failed before committing could start: ${input.describeError({ error })}` };
|
|
@@ -36,13 +53,13 @@ async function exportForCommit(input) {
|
|
|
36
53
|
}
|
|
37
54
|
/** Run a real fresh export, without credentials or repository I/O. */
|
|
38
55
|
export async function previewCommitExport(required, optional = {}) {
|
|
39
|
-
const error = validateCommitTarget(required, optional);
|
|
56
|
+
const error = validateCommitTarget(required, optional) ?? folderError(required);
|
|
40
57
|
if (error)
|
|
41
58
|
return { ok: false, code: 'INVALID_CONFIG', message: error };
|
|
42
59
|
const exported = await exportForCommit(required);
|
|
43
60
|
if (!exported.ok)
|
|
44
61
|
return exported;
|
|
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) };
|
|
62
|
+
return { ok: true, fileCount: exported.files.length, totalBytes: exported.files.reduce((sum, file) => sum + Buffer.byteLength(file.data), 0), paths: exported.files.map(file => prefixRepositoryPath({ folder: required.folder, path: file.path })).sort().slice(0, 50) };
|
|
46
63
|
}
|
|
47
64
|
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
65
|
/** The credential must exist and belong to the requested provider; failures never reveal the token. */
|
|
@@ -64,7 +81,8 @@ async function resolveProviderCredential(required) {
|
|
|
64
81
|
async function commitExportedFiles(required, optional) {
|
|
65
82
|
const { args, token, files } = required;
|
|
66
83
|
try {
|
|
67
|
-
const
|
|
84
|
+
const folder = normalizeRepositoryFolder(args);
|
|
85
|
+
const result = await args.adapter.commitSite({ token, owner: args.owner, repo: args.repo, commitMessage: args.commitMessage, files, ...(folder ? { folder } : {}) }, optional.branch !== undefined ? { branch: optional.branch } : {});
|
|
68
86
|
if (!result.ok)
|
|
69
87
|
return { ok: false, code: PROVIDER_FAILURE_CODES[result.code], message: result.message };
|
|
70
88
|
return { ...result, owner: args.owner, repo: args.repo, divergedPaths: result.divergedPaths ?? [] };
|
|
@@ -75,7 +93,7 @@ async function commitExportedFiles(required, optional) {
|
|
|
75
93
|
}
|
|
76
94
|
/** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
|
|
77
95
|
export async function commitSiteToSourceControl(required, optional = {}) {
|
|
78
|
-
const configError = validateCommitTarget(required, optional);
|
|
96
|
+
const configError = validateCommitTarget(required, optional) ?? folderError(required, { committing: true });
|
|
79
97
|
if (configError)
|
|
80
98
|
return { ok: false, code: 'INVALID_CONFIG', message: configError };
|
|
81
99
|
const resolved = await resolveProviderCredential(required);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
2
2
|
import type { ExportReport } from '../static-export/contracts.js';
|
|
3
|
-
/**
|
|
3
|
+
/** Folder-relative bytes; the provider applies the destination prefix once. */
|
|
4
4
|
export interface CommitFile {
|
|
5
5
|
readonly path: string;
|
|
6
6
|
readonly data: string | Buffer;
|
|
@@ -23,6 +23,7 @@ export interface CommitSiteInput {
|
|
|
23
23
|
readonly token: string;
|
|
24
24
|
readonly owner: string;
|
|
25
25
|
readonly repo: string;
|
|
26
|
+
readonly folder?: string;
|
|
26
27
|
readonly commitMessage: string;
|
|
27
28
|
readonly files: readonly CommitFile[];
|
|
28
29
|
}
|
|
@@ -152,6 +153,7 @@ export interface RepositoryTarget {
|
|
|
152
153
|
}
|
|
153
154
|
export type RepositoryTargetValidator = (required: RepositoryTarget) => string | null;
|
|
154
155
|
export type SourceControlProvider = SourceControlProviderOperations & SourceControlHostFacts & {
|
|
156
|
+
readonly supportsFolder?: boolean;
|
|
155
157
|
readonly validateTarget?: RepositoryTargetValidator;
|
|
156
158
|
};
|
|
157
159
|
export interface DescribedTransportError {
|
|
@@ -167,6 +169,11 @@ export type SourceControlFetchPort = (required: {
|
|
|
167
169
|
init?: RequestInit;
|
|
168
170
|
}) => Promise<Response>;
|
|
169
171
|
export interface SourceControlProviderKit {
|
|
172
|
+
readonly repositoryPaths: {
|
|
173
|
+
normalizeFolder: typeof import('./repository-path.js').normalizeRepositoryFolder;
|
|
174
|
+
prefixPath: typeof import('./repository-path.js').prefixRepositoryPath;
|
|
175
|
+
contains: typeof import('./repository-path.js').repositoryPathContained;
|
|
176
|
+
};
|
|
170
177
|
fetch(required: {
|
|
171
178
|
url: string;
|
|
172
179
|
init: RequestInit;
|
|
@@ -191,6 +198,7 @@ export interface SourceControlProviderModule {
|
|
|
191
198
|
kit: SourceControlProviderKit;
|
|
192
199
|
}): SourceControlProviderOperations;
|
|
193
200
|
validateTarget?: RepositoryTargetValidator;
|
|
201
|
+
readonly supportsFolder?: boolean;
|
|
194
202
|
}
|
|
195
203
|
export interface SourceControlProviderDescriptor extends SourceControlHostFacts {
|
|
196
204
|
readonly module: string;
|
|
@@ -274,6 +282,7 @@ export interface CommitLayoutPort {
|
|
|
274
282
|
}): Promise<void>;
|
|
275
283
|
}
|
|
276
284
|
export interface CommitExportArgs {
|
|
285
|
+
folder?: string;
|
|
277
286
|
workspaceId: string;
|
|
278
287
|
owner: string;
|
|
279
288
|
repo: string;
|
|
@@ -290,6 +299,7 @@ export interface CommitExportArgs {
|
|
|
290
299
|
}): string;
|
|
291
300
|
}
|
|
292
301
|
export interface CommitOrchestrationArgs extends CommitExportArgs {
|
|
302
|
+
supportsFolder?: boolean;
|
|
293
303
|
credentials: CredentialResolverPort;
|
|
294
304
|
adapter: Pick<SourceControlProviderOperations, 'commitSite'>;
|
|
295
305
|
}
|