@jini-ai/devops 0.4.0 → 0.5.0
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 +120 -0
- package/README.md +62 -2
- package/dist/agent-jobs/entry.d.ts +4 -0
- package/dist/agent-jobs/entry.js +4 -0
- package/dist/agent-jobs/jobs.d.ts +25 -0
- package/dist/agent-jobs/jobs.js +115 -0
- package/dist/agent-jobs/node.d.ts +12 -0
- package/dist/agent-jobs/node.js +53 -0
- package/dist/agent-jobs/ports.d.ts +69 -0
- package/dist/agent-jobs/ports.js +2 -0
- package/dist/checks/coverage/diff.d.ts +57 -0
- package/dist/checks/coverage/diff.js +48 -0
- package/dist/checks/coverage/disk.d.ts +65 -0
- package/dist/checks/coverage/disk.js +136 -0
- package/dist/checks/coverage/floors.d.ts +31 -0
- package/dist/checks/coverage/floors.js +24 -0
- package/dist/checks/coverage/index.d.ts +7 -0
- package/dist/checks/coverage/index.js +6 -0
- package/dist/checks/coverage/integrity.d.ts +79 -0
- package/dist/checks/coverage/integrity.js +140 -0
- package/dist/checks/coverage/lcov.d.ts +65 -0
- package/dist/checks/coverage/lcov.js +64 -0
- package/dist/checks/node.d.ts +19 -0
- package/dist/checks/node.js +40 -0
- package/dist/checks/ports.d.ts +67 -0
- package/dist/checks/ports.js +2 -0
- package/dist/checks/published-types/index.d.ts +77 -0
- package/dist/checks/published-types/index.js +186 -0
- package/dist/deploy/host-kit.d.ts +27 -10
- package/dist/deploy/naming.d.ts +8 -4
- package/dist/deploy/naming.js +4 -5
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +42 -12
- package/dist/deploy/reachability.js +75 -69
- package/dist/deploy/redirect-guard.d.ts +7 -2
- package/dist/deploy/redirect-guard.js +3 -3
- package/dist/deploy/tokens.d.ts +14 -11
- package/dist/deploy/tokens.js +13 -13
- package/dist/deploy/tool.d.ts +9 -5
- package/dist/deploy/tool.js +5 -6
- package/dist/deploy/types.d.ts +22 -10
- package/dist/deploy/types.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-dev/index.d.ts +34 -0
- package/dist/local-dev/index.js +37 -0
- package/dist/packaging/electron/archive.d.ts +41 -0
- package/dist/packaging/electron/archive.js +77 -0
- package/dist/packaging/electron/asar-adapter.d.ts +13 -0
- package/dist/packaging/electron/asar-adapter.js +5 -0
- package/dist/packaging/electron/entry.d.ts +9 -0
- package/dist/packaging/electron/entry.js +9 -0
- package/dist/packaging/electron/imports.d.ts +13 -0
- package/dist/packaging/electron/imports.js +44 -0
- package/dist/packaging/electron/node.d.ts +8 -0
- package/dist/packaging/electron/node.js +51 -0
- package/dist/packaging/electron/policies.d.ts +64 -0
- package/dist/packaging/electron/policies.js +63 -0
- package/dist/packaging/electron/ports.d.ts +113 -0
- package/dist/packaging/electron/ports.js +2 -0
- package/dist/packaging/electron/stability.d.ts +9 -0
- package/dist/packaging/electron/stability.js +12 -0
- package/dist/packaging/electron/staging.d.ts +108 -0
- package/dist/packaging/electron/staging.js +249 -0
- package/dist/packaging/electron/typescript.d.ts +7 -0
- package/dist/packaging/electron/typescript.js +18 -0
- package/dist/source-control/commit.d.ts +11 -0
- package/dist/source-control/commit.js +71 -0
- package/dist/source-control/contracts.d.ts +327 -0
- package/dist/source-control/contracts.js +2 -0
- package/dist/source-control/entry.d.ts +6 -0
- package/dist/source-control/entry.js +6 -0
- package/dist/source-control/kit.d.ts +15 -0
- package/dist/source-control/kit.js +17 -0
- package/dist/source-control/registry.d.ts +100 -0
- package/dist/source-control/registry.js +174 -0
- package/dist/source-control/repository-target.d.ts +13 -0
- package/dist/source-control/repository-target.js +28 -0
- package/dist/static-export/contracts.d.ts +138 -0
- package/dist/static-export/contracts.js +5 -0
- package/dist/static-export/entry.d.ts +6 -0
- package/dist/static-export/entry.js +6 -0
- package/dist/static-export/failure-summary.d.ts +12 -0
- package/dist/static-export/failure-summary.js +12 -0
- package/dist/static-export/fetch-adapter.d.ts +6 -0
- package/dist/static-export/fetch-adapter.js +5 -0
- package/dist/static-export/node-adapters.d.ts +11 -0
- package/dist/static-export/node-adapters.js +111 -0
- package/dist/static-export/runner.d.ts +6 -0
- package/dist/static-export/runner.js +135 -0
- package/dist/static-export/transforms.d.ts +53 -0
- package/dist/static-export/transforms.js +154 -0
- package/package.json +82 -5
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Target } from './policies.js';
|
|
2
|
+
import type { PackagingFilesystemPort, PackageResolverPort, WorkspacePackagePackerPort, ProcessRunnerPort } from './ports.js';
|
|
3
|
+
export declare function isExcluded({ name, excluded }: {
|
|
4
|
+
name: string;
|
|
5
|
+
excluded: ReadonlySet<string>;
|
|
6
|
+
}): boolean;
|
|
7
|
+
export declare function declaredDependencies({ packageDir, fs }: {
|
|
8
|
+
packageDir: string;
|
|
9
|
+
fs: PackagingFilesystemPort;
|
|
10
|
+
}): string[];
|
|
11
|
+
export declare function stageDir(required: {
|
|
12
|
+
source: string;
|
|
13
|
+
destination: string;
|
|
14
|
+
fs: PackagingFilesystemPort;
|
|
15
|
+
}, optional?: {
|
|
16
|
+
dropNestedModules?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
/** Plan the production closure first. Fail unresolved/conflicting versions before copying anything. */
|
|
19
|
+
export declare function stageTransitiveDependencies(required: {
|
|
20
|
+
roots: readonly string[];
|
|
21
|
+
outDir: string;
|
|
22
|
+
excluded: ReadonlySet<string>;
|
|
23
|
+
fs: PackagingFilesystemPort;
|
|
24
|
+
resolver: PackageResolverPort;
|
|
25
|
+
}): number;
|
|
26
|
+
/** Enumerate real package roots, treating scoped directories as containers. */
|
|
27
|
+
export declare function stagedPackageDirs({ modulesDir, fs }: {
|
|
28
|
+
modulesDir: string;
|
|
29
|
+
fs: PackagingFilesystemPort;
|
|
30
|
+
}): string[];
|
|
31
|
+
/** Check nested/hoisted dependencies only inside shipped modules; ancestors cannot fill gaps. */
|
|
32
|
+
export declare function assertClosureComplete(required: {
|
|
33
|
+
outDir: string;
|
|
34
|
+
excluded: ReadonlySet<string>;
|
|
35
|
+
fs: PackagingFilesystemPort;
|
|
36
|
+
}): void;
|
|
37
|
+
/** Share the existing workspace build/pack/rewritten-tarball implementation via a host binding. */
|
|
38
|
+
export declare function stagePackedWorkspace(required: {
|
|
39
|
+
repoRoot: string;
|
|
40
|
+
packagesDir: string;
|
|
41
|
+
rootNames: readonly string[];
|
|
42
|
+
destDir: string;
|
|
43
|
+
packer: WorkspacePackagePackerPort;
|
|
44
|
+
}): ReturnType<WorkspacePackagePackerPort['pack']>;
|
|
45
|
+
/** Run npm's dependency listing through an explicit process port, then parse with parseNpmLsPaths. */
|
|
46
|
+
export declare function productionDependencyOutput(required: {
|
|
47
|
+
command: string;
|
|
48
|
+
args: readonly string[];
|
|
49
|
+
cwd: string;
|
|
50
|
+
shell: boolean;
|
|
51
|
+
runner: ProcessRunnerPort;
|
|
52
|
+
}): string;
|
|
53
|
+
/** Source freshness scan ignores non-bundle inputs, hidden entries and dependency trees. */
|
|
54
|
+
export declare function newestMtime({ absolutePath, fs }: {
|
|
55
|
+
absolutePath: string;
|
|
56
|
+
fs: PackagingFilesystemPort;
|
|
57
|
+
}): number;
|
|
58
|
+
export declare function diskBytes({ absolutePath, fs }: {
|
|
59
|
+
absolutePath: string;
|
|
60
|
+
fs: PackagingFilesystemPort;
|
|
61
|
+
}): number;
|
|
62
|
+
export interface StripTally {
|
|
63
|
+
declaration: number;
|
|
64
|
+
sourceMap: number;
|
|
65
|
+
coverage: number;
|
|
66
|
+
bytes: number;
|
|
67
|
+
}
|
|
68
|
+
/** Only staged roots are accepted; the caller must keep them separate from its source dependency tree. */
|
|
69
|
+
export declare function stripNonRuntimeFiles(required: {
|
|
70
|
+
outDir: string;
|
|
71
|
+
keepScopes: ReadonlySet<string>;
|
|
72
|
+
fs: PackagingFilesystemPort;
|
|
73
|
+
}): StripTally;
|
|
74
|
+
export interface PruneTally {
|
|
75
|
+
prebuilds: number;
|
|
76
|
+
buildInputs: number;
|
|
77
|
+
bytes: number;
|
|
78
|
+
}
|
|
79
|
+
/** Verify every target before removing foreign prebuilds or source build inputs. */
|
|
80
|
+
export declare function pruneNativePrebuilds(required: {
|
|
81
|
+
outDir: string;
|
|
82
|
+
targets: readonly Target[];
|
|
83
|
+
fs: PackagingFilesystemPort;
|
|
84
|
+
}): PruneTally;
|
|
85
|
+
/** Runtime copy inventory is required, so no product shells or payload paths live in this package. */
|
|
86
|
+
export declare function stagePayloadFiles(required: {
|
|
87
|
+
repoRoot: string;
|
|
88
|
+
outDir: string;
|
|
89
|
+
relativePaths: readonly string[];
|
|
90
|
+
fs: PackagingFilesystemPort;
|
|
91
|
+
}): void;
|
|
92
|
+
/** Detect Mach-O/ELF/PE magic from bytes; short files are valid inputs. */
|
|
93
|
+
export declare function hasNativeBinaryMagic({ bytes }: {
|
|
94
|
+
bytes: Uint8Array;
|
|
95
|
+
}): boolean;
|
|
96
|
+
/** Stage npm with an explicit drop policy, refusing unsigned native binaries before any copy. */
|
|
97
|
+
export declare function stageBundledNpm(required: {
|
|
98
|
+
npmSource: string;
|
|
99
|
+
outDir: string;
|
|
100
|
+
marker: string;
|
|
101
|
+
droppedDirectoryNames: ReadonlySet<string>;
|
|
102
|
+
droppedFileSuffixes: readonly string[];
|
|
103
|
+
fs: PackagingFilesystemPort;
|
|
104
|
+
}): {
|
|
105
|
+
fileCount: number;
|
|
106
|
+
bytes: number;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isBundleInput, prebuildTarget, strippableReason } from './policies.js';
|
|
3
|
+
function manifest(directory, fs) {
|
|
4
|
+
const file = path.join(directory, 'package.json');
|
|
5
|
+
return fs.exists({ path: file }) ? JSON.parse(Buffer.from(fs.read({ path: file })).toString('utf8')) : {};
|
|
6
|
+
}
|
|
7
|
+
function safePackageName(name) {
|
|
8
|
+
if (!/^(?:@[a-zA-Z0-9._-]+\/)?[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name) || name === '..')
|
|
9
|
+
throw new Error(`Invalid package name: ${name}`);
|
|
10
|
+
}
|
|
11
|
+
export function isExcluded({ name, excluded }) {
|
|
12
|
+
return excluded.has(name) || excluded.has(name.replace(/\\/g, '/').split('/')[0]);
|
|
13
|
+
}
|
|
14
|
+
export function declaredDependencies({ packageDir, fs }) {
|
|
15
|
+
return Object.keys(manifest(packageDir, fs).dependencies ?? {});
|
|
16
|
+
}
|
|
17
|
+
export function stageDir(required, optional = {}) {
|
|
18
|
+
required.fs.copy({ from: required.source, to: required.destination }, optional);
|
|
19
|
+
}
|
|
20
|
+
/** Plan the production closure first. Fail unresolved/conflicting versions before copying anything. */
|
|
21
|
+
export function stageTransitiveDependencies(required) {
|
|
22
|
+
const { roots, outDir, excluded, fs, resolver } = required;
|
|
23
|
+
const visited = new Set(roots.map(root => fs.realpath({ path: root })));
|
|
24
|
+
const queue = [...visited];
|
|
25
|
+
const staged = new Map();
|
|
26
|
+
for (let index = 0; index < queue.length; index++) {
|
|
27
|
+
const from = queue[index];
|
|
28
|
+
for (const name of declaredDependencies({ packageDir: from, fs })) {
|
|
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
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let count = 0;
|
|
51
|
+
for (const [name, entry] of staged) {
|
|
52
|
+
const destination = path.join(outDir, 'node_modules', name);
|
|
53
|
+
if (fs.exists({ path: destination }))
|
|
54
|
+
continue;
|
|
55
|
+
stageDir({ source: entry.directory, destination, fs }, { dropNestedModules: true });
|
|
56
|
+
count++;
|
|
57
|
+
}
|
|
58
|
+
return count;
|
|
59
|
+
}
|
|
60
|
+
/** Enumerate real package roots, treating scoped directories as containers. */
|
|
61
|
+
export function stagedPackageDirs({ modulesDir, fs }) {
|
|
62
|
+
if (!fs.exists({ path: modulesDir }))
|
|
63
|
+
return [];
|
|
64
|
+
return fs.entries({ path: modulesDir }).filter(entry => !entry.startsWith('.')).flatMap(entry => {
|
|
65
|
+
const full = path.join(modulesDir, entry);
|
|
66
|
+
if (!entry.startsWith('@'))
|
|
67
|
+
return fs.exists({ path: path.join(full, 'package.json') }) ? [full] : [];
|
|
68
|
+
return fs.entries({ path: full }).map(scoped => path.join(full, scoped)).filter(dir => fs.exists({ path: path.join(dir, 'package.json') }));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Check nested/hoisted dependencies only inside shipped modules; ancestors cannot fill gaps. */
|
|
72
|
+
export function assertClosureComplete(required) {
|
|
73
|
+
const { outDir, excluded, fs } = required;
|
|
74
|
+
const modulesDir = path.join(outDir, 'node_modules');
|
|
75
|
+
const missing = [];
|
|
76
|
+
if (!fs.exists({ path: modulesDir }))
|
|
77
|
+
throw new Error('staged node_modules tree is missing');
|
|
78
|
+
for (const directory of stagedPackageDirs({ modulesDir, fs })) {
|
|
79
|
+
for (const name of declaredDependencies({ packageDir: directory, fs })) {
|
|
80
|
+
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') }))
|
|
84
|
+
missing.push(`${path.relative(modulesDir, directory)} -> ${name}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (missing.length)
|
|
88
|
+
throw new Error(`staged tree is missing ${missing.length} declared dependencies:\n ${missing.join('\n ')}`);
|
|
89
|
+
}
|
|
90
|
+
/** Share the existing workspace build/pack/rewritten-tarball implementation via a host binding. */
|
|
91
|
+
export function stagePackedWorkspace(required) {
|
|
92
|
+
const { packer, ...input } = required;
|
|
93
|
+
return packer.pack(input);
|
|
94
|
+
}
|
|
95
|
+
/** Run npm's dependency listing through an explicit process port, then parse with parseNpmLsPaths. */
|
|
96
|
+
export function productionDependencyOutput(required) {
|
|
97
|
+
const { runner, ...request } = required;
|
|
98
|
+
const result = runner.run(request);
|
|
99
|
+
if (result.exitCode !== 0)
|
|
100
|
+
throw new Error(`dependency listing failed with exit ${result.exitCode}`);
|
|
101
|
+
return result.stdout;
|
|
102
|
+
}
|
|
103
|
+
/** Source freshness scan ignores non-bundle inputs, hidden entries and dependency trees. */
|
|
104
|
+
export function newestMtime({ absolutePath, fs }) {
|
|
105
|
+
if (!fs.exists({ path: absolutePath }))
|
|
106
|
+
return 0;
|
|
107
|
+
const info = fs.stat({ path: absolutePath });
|
|
108
|
+
if (info.kind !== 'directory')
|
|
109
|
+
return info.kind === 'file' && isBundleInput({ relPath: absolutePath }) ? info.mtimeMs : 0;
|
|
110
|
+
let newest = 0;
|
|
111
|
+
for (const entry of fs.entries({ path: absolutePath })) {
|
|
112
|
+
if (entry.startsWith('.') || entry === 'node_modules' || !isBundleInput({ relPath: entry + '/' }))
|
|
113
|
+
continue;
|
|
114
|
+
newest = Math.max(newest, newestMtime({ absolutePath: path.join(absolutePath, entry), fs }));
|
|
115
|
+
}
|
|
116
|
+
return newest;
|
|
117
|
+
}
|
|
118
|
+
export function diskBytes({ absolutePath, fs }) {
|
|
119
|
+
const info = fs.stat({ path: absolutePath });
|
|
120
|
+
return info.kind === 'directory' ? fs.entries({ path: absolutePath }).reduce((sum, name) => sum + diskBytes({ absolutePath: path.join(absolutePath, name), fs }), 0) : info.diskBytes;
|
|
121
|
+
}
|
|
122
|
+
/** Only staged roots are accepted; the caller must keep them separate from its source dependency tree. */
|
|
123
|
+
export function stripNonRuntimeFiles(required) {
|
|
124
|
+
const { outDir, keepScopes, fs } = required;
|
|
125
|
+
const modulesDir = path.join(outDir, 'node_modules');
|
|
126
|
+
const tally = { declaration: 0, sourceMap: 0, coverage: 0, bytes: 0 };
|
|
127
|
+
if (!fs.exists({ path: modulesDir }))
|
|
128
|
+
return tally;
|
|
129
|
+
for (const directory of stagedPackageDirs({ modulesDir, fs })) {
|
|
130
|
+
const coverage = path.join(directory, 'coverage');
|
|
131
|
+
if (!fs.exists({ path: coverage }) || fs.stat({ path: coverage }).kind !== 'directory')
|
|
132
|
+
continue;
|
|
133
|
+
tally.bytes += diskBytes({ absolutePath: coverage, fs });
|
|
134
|
+
tally.coverage++;
|
|
135
|
+
fs.remove({ path: coverage });
|
|
136
|
+
}
|
|
137
|
+
function walk(directory) {
|
|
138
|
+
for (const name of fs.entries({ path: directory })) {
|
|
139
|
+
const full = path.join(directory, name);
|
|
140
|
+
const info = fs.stat({ path: full });
|
|
141
|
+
if (info.kind === 'directory') {
|
|
142
|
+
walk(full);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const reason = strippableReason({ relPath: path.relative(modulesDir, full).split(path.sep).join('/'), keepScopes });
|
|
146
|
+
if (!reason)
|
|
147
|
+
continue;
|
|
148
|
+
tally.bytes += info.diskBytes;
|
|
149
|
+
tally[reason]++;
|
|
150
|
+
fs.remove({ path: full });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
walk(modulesDir);
|
|
154
|
+
return tally;
|
|
155
|
+
}
|
|
156
|
+
/** Verify every target before removing foreign prebuilds or source build inputs. */
|
|
157
|
+
export function pruneNativePrebuilds(required) {
|
|
158
|
+
const { outDir, targets, fs } = required;
|
|
159
|
+
if (!targets.length)
|
|
160
|
+
throw new Error('at least one native target is required');
|
|
161
|
+
const modulesDir = path.join(outDir, 'node_modules');
|
|
162
|
+
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
|
+
}
|
|
179
|
+
for (const { full, reason } of removals) {
|
|
180
|
+
tally.bytes += diskBytes({ absolutePath: full, fs });
|
|
181
|
+
tally[reason]++;
|
|
182
|
+
fs.remove({ path: full });
|
|
183
|
+
}
|
|
184
|
+
return tally;
|
|
185
|
+
}
|
|
186
|
+
/** Runtime copy inventory is required, so no product shells or payload paths live in this package. */
|
|
187
|
+
export function stagePayloadFiles(required) {
|
|
188
|
+
const entries = required.relativePaths.map(relative => {
|
|
189
|
+
if (!relative || path.isAbsolute(relative) || relative.replace(/\\/g, '/').split('/').some(x => x === '..' || x === '.'))
|
|
190
|
+
throw new Error(`Unsafe payload path: ${relative}`);
|
|
191
|
+
const from = path.join(required.repoRoot, relative);
|
|
192
|
+
if (!required.fs.exists({ path: from }))
|
|
193
|
+
throw new Error(`Missing payload input: ${relative}`);
|
|
194
|
+
return { from, to: path.join(required.outDir, relative) };
|
|
195
|
+
});
|
|
196
|
+
for (const entry of entries)
|
|
197
|
+
required.fs.copy(entry);
|
|
198
|
+
}
|
|
199
|
+
/** Detect Mach-O/ELF/PE magic from bytes; short files are valid inputs. */
|
|
200
|
+
export function hasNativeBinaryMagic({ bytes }) {
|
|
201
|
+
const hex = Buffer.from(bytes.subarray(0, 4)).toString('hex');
|
|
202
|
+
return ['feedface', 'feedfacf', 'cafebabe', 'cefaedfe', 'cffaedfe', '7f454c46', '4d5a'].some(prefix => hex.startsWith(prefix));
|
|
203
|
+
}
|
|
204
|
+
/** Stage npm with an explicit drop policy, refusing unsigned native binaries before any copy. */
|
|
205
|
+
export function stageBundledNpm(required) {
|
|
206
|
+
const { npmSource, outDir, marker, droppedDirectoryNames, droppedFileSuffixes, fs } = required;
|
|
207
|
+
if (!marker || path.isAbsolute(marker) || marker.replace(/\\/g, '/').split('/').some(x => x === '.' || x === '..'))
|
|
208
|
+
throw new Error('Invalid npm marker');
|
|
209
|
+
if (!fs.exists({ path: path.join(npmSource, marker) }))
|
|
210
|
+
throw new Error(`stageBundledNpm: no ${marker} under ${npmSource}`);
|
|
211
|
+
const source = fs.realpath({ path: npmSource });
|
|
212
|
+
const target = path.resolve(outDir);
|
|
213
|
+
if (target === source || target.startsWith(source + path.sep) || source.startsWith(target + path.sep))
|
|
214
|
+
throw new Error('npm source and staging destination must be disjoint');
|
|
215
|
+
if (!fs.readPrefix)
|
|
216
|
+
throw new Error('stageBundledNpm: bounded prefix-read port is required');
|
|
217
|
+
const readPrefix = fs.readPrefix.bind(fs);
|
|
218
|
+
const excluded = ({ path: full, directory }) => directory ? droppedDirectoryNames.has(path.basename(full)) : droppedFileSuffixes.some(suffix => full.endsWith(suffix));
|
|
219
|
+
function inspect(directory) {
|
|
220
|
+
for (const entry of fs.entries({ path: directory })) {
|
|
221
|
+
const full = path.join(directory, entry);
|
|
222
|
+
const info = fs.stat({ path: full });
|
|
223
|
+
if (info.kind === 'other')
|
|
224
|
+
throw new Error(`stageBundledNpm: nonregular input ${full}`);
|
|
225
|
+
if (excluded({ path: full, directory: info.kind === 'directory' }))
|
|
226
|
+
continue;
|
|
227
|
+
if (info.kind === 'directory')
|
|
228
|
+
inspect(full);
|
|
229
|
+
else if (hasNativeBinaryMagic({ bytes: readPrefix({ path: full, maxBytes: 4 }) }))
|
|
230
|
+
throw new Error(`stageBundledNpm: ${path.relative(source, full)} starts with native-binary magic bytes`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
inspect(source);
|
|
234
|
+
fs.remove({ path: outDir });
|
|
235
|
+
fs.copy({ from: source, to: outDir }, { exclude: excluded });
|
|
236
|
+
let fileCount = 0;
|
|
237
|
+
function count(directory) {
|
|
238
|
+
for (const name of fs.entries({ path: directory })) {
|
|
239
|
+
const full = path.join(directory, name);
|
|
240
|
+
if (fs.stat({ path: full }).kind === 'directory')
|
|
241
|
+
count(full);
|
|
242
|
+
else
|
|
243
|
+
fileCount++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
count(outDir);
|
|
247
|
+
return { fileCount, bytes: diskBytes({ absolutePath: outDir, fs }) };
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=staging.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
import type { ImportReaderPort } from './ports.js';
|
|
3
|
+
/** Bind the maintained TypeScript parser supplied by the host; no parser dependency at runtime. */
|
|
4
|
+
export declare function createTypeScriptImportReader({ compiler }: {
|
|
5
|
+
compiler: typeof ts;
|
|
6
|
+
}): ImportReaderPort;
|
|
7
|
+
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Bind the maintained TypeScript parser supplied by the host; no parser dependency at runtime. */
|
|
2
|
+
export function createTypeScriptImportReader({ compiler }) {
|
|
3
|
+
return { imports({ file, source }) {
|
|
4
|
+
const tree = compiler.createSourceFile(file, source, compiler.ScriptTarget.Latest, false, compiler.ScriptKind.JS);
|
|
5
|
+
const found = [];
|
|
6
|
+
function visit(node) {
|
|
7
|
+
const literal = compiler.isImportDeclaration(node) || compiler.isExportDeclaration(node)
|
|
8
|
+
? node.moduleSpecifier
|
|
9
|
+
: compiler.isCallExpression(node) && node.expression.kind === compiler.SyntaxKind.ImportKeyword ? node.arguments[0] : undefined;
|
|
10
|
+
if (literal !== undefined && compiler.isStringLiteral(literal))
|
|
11
|
+
found.push(literal.text);
|
|
12
|
+
compiler.forEachChild(node, visit);
|
|
13
|
+
}
|
|
14
|
+
visit(tree);
|
|
15
|
+
return found;
|
|
16
|
+
} };
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CommitExportArgs, CommitFile, CommitOptions, CommitOrchestrationArgs, PreviewCommitExportResult, SourceControlCommitOutcome } from './contracts.js';
|
|
2
|
+
/** Normalize platform separators without changing the retained byte payload. */
|
|
3
|
+
export declare function toCommitFile(required: {
|
|
4
|
+
outputFile: string;
|
|
5
|
+
data: string | Buffer;
|
|
6
|
+
}): CommitFile;
|
|
7
|
+
/** Run a real fresh export, without credentials or repository I/O. */
|
|
8
|
+
export declare function previewCommitExport(required: CommitExportArgs, optional?: CommitOptions): Promise<PreviewCommitExportResult>;
|
|
9
|
+
/** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
|
|
10
|
+
export declare function commitSiteToSourceControl(required: CommitOrchestrationArgs, optional?: CommitOptions): Promise<SourceControlCommitOutcome>;
|
|
11
|
+
//# sourceMappingURL=commit.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { firstExportFailure } from '../static-export/failure-summary.js';
|
|
2
|
+
import { validateCommitTarget } from './repository-target.js';
|
|
3
|
+
/** Normalize platform separators without changing the retained byte payload. */
|
|
4
|
+
export function toCommitFile(required) {
|
|
5
|
+
return { path: required.outputFile.replace(/\\/g, '/'), data: required.data };
|
|
6
|
+
}
|
|
7
|
+
async function exportForCommit(input) {
|
|
8
|
+
let outputDir;
|
|
9
|
+
try {
|
|
10
|
+
outputDir = input.layout.outputDirectory({ workspaceId: input.workspaceId, providerId: input.providerId, runId: input.ids.next({}) });
|
|
11
|
+
const report = await input.files.export({ outputDir }, { clean: true });
|
|
12
|
+
const failure = firstExportFailure({ report });
|
|
13
|
+
if (failure)
|
|
14
|
+
return { ok: false, code: 'EXPORT_FAILED', message: `refused to commit: ${failure.count} ${failure.kind}(s) failed to export (first: '${failure.identifier}' — ${failure.reason})` };
|
|
15
|
+
return { ok: true, files: [...report.routes.succeeded.map(toCommitFile), ...report.assets.succeeded.map(toCommitFile)] };
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return { ok: false, code: 'EXPORT_FAILED', message: `export failed before committing could start: ${input.describeError({ error })}` };
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
if (outputDir !== undefined) {
|
|
22
|
+
// Byte payloads are retained by the report; cleanup cannot invalidate the commit.
|
|
23
|
+
try {
|
|
24
|
+
await input.layout.cleanup({ outputDir });
|
|
25
|
+
}
|
|
26
|
+
catch { /* Best effort, matching the original service. */ }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Run a real fresh export, without credentials or repository I/O. */
|
|
31
|
+
export async function previewCommitExport(required, optional = {}) {
|
|
32
|
+
const error = validateCommitTarget(required, optional);
|
|
33
|
+
if (error)
|
|
34
|
+
return { ok: false, code: 'INVALID_CONFIG', message: error };
|
|
35
|
+
const exported = await exportForCommit(required);
|
|
36
|
+
if (!exported.ok)
|
|
37
|
+
return exported;
|
|
38
|
+
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
|
+
}
|
|
40
|
+
/** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
|
|
41
|
+
export async function commitSiteToSourceControl(required, optional = {}) {
|
|
42
|
+
const configError = validateCommitTarget(required, optional);
|
|
43
|
+
if (configError)
|
|
44
|
+
return { ok: false, code: 'INVALID_CONFIG', message: configError };
|
|
45
|
+
let credential;
|
|
46
|
+
try {
|
|
47
|
+
credential = await required.credentials.resolve({ workspaceId: required.workspaceId, providerId: required.providerId });
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `credential could not be resolved: ${required.describeError({ error })}` };
|
|
51
|
+
}
|
|
52
|
+
if (!credential)
|
|
53
|
+
return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `No source control credential is configured for '${required.providerId}'.` };
|
|
54
|
+
if (credential.providerId !== required.providerId)
|
|
55
|
+
return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `The resolved default credential is not a '${required.providerId}' connection.` };
|
|
56
|
+
const exported = await exportForCommit(required);
|
|
57
|
+
if (!exported.ok)
|
|
58
|
+
return exported;
|
|
59
|
+
try {
|
|
60
|
+
const result = await required.adapter.commitSite({ token: credential.token, owner: required.owner, repo: required.repo, commitMessage: required.commitMessage, files: exported.files }, { ...(optional.branch !== undefined ? { branch: optional.branch } : {}) });
|
|
61
|
+
if (!result.ok) {
|
|
62
|
+
const codes = { 'repository-not-found': 'REPOSITORY_NOT_FOUND', 'no-changes': 'NO_CHANGES', diverged: 'DIVERGED_BRANCH', 'network-unreachable': 'NETWORK_UNREACHABLE', 'provider-error': 'PROVIDER_ERROR' };
|
|
63
|
+
return { ok: false, code: codes[result.code], message: result.message };
|
|
64
|
+
}
|
|
65
|
+
return { ...result, owner: required.owner, repo: required.repo, divergedPaths: result.divergedPaths ?? [] };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return { ok: false, code: 'PROVIDER_ERROR', message: required.describeError({ error }) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=commit.js.map
|