@jini-ai/devops 0.3.3 → 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 +65 -5
- 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/index.d.ts +0 -4
- package/dist/deploy/index.js +0 -4
- package/dist/deploy/naming.d.ts +9 -6
- package/dist/deploy/naming.js +5 -7
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +47 -18
- package/dist/deploy/reachability.js +77 -71
- package/dist/deploy/redirect-guard.d.ts +15 -11
- package/dist/deploy/redirect-guard.js +11 -12
- package/dist/deploy/tokens.d.ts +17 -14
- package/dist/deploy/tokens.js +16 -16
- package/dist/deploy/tool.d.ts +12 -8
- package/dist/deploy/tool.js +9 -10
- package/dist/deploy/types.d.ts +27 -15
- package/dist/deploy/types.js +3 -3
- 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
- package/dist/deploy/cloudflare-pages.d.ts +0 -105
- package/dist/deploy/cloudflare-pages.js +0 -943
- package/dist/deploy/github-pages.d.ts +0 -62
- package/dist/deploy/github-pages.js +0 -373
- package/dist/deploy/netlify.d.ts +0 -40
- package/dist/deploy/netlify.js +0 -299
- package/dist/deploy/vercel.d.ts +0 -56
- package/dist/deploy/vercel.js +0 -258
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync, readFileSync, lstatSync, readdirSync, realpathSync, mkdirSync, cpSync, rmSync, statSync, openSync, readSync, closeSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Explicit Node filesystem adapter. No effects occur until a port method is called. */
|
|
4
|
+
export function createNodePackagingFilesystem(_required) {
|
|
5
|
+
return {
|
|
6
|
+
exists: ({ path }) => existsSync(path), read: ({ path }) => readFileSync(path),
|
|
7
|
+
// Allocation and I/O depend only on the prefix bound, even for very large payload files.
|
|
8
|
+
readPrefix: ({ path, maxBytes }) => {
|
|
9
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0)
|
|
10
|
+
throw new Error('maxBytes must be a nonnegative safe integer');
|
|
11
|
+
const bytes = Buffer.alloc(maxBytes);
|
|
12
|
+
const fd = openSync(path, 'r');
|
|
13
|
+
try {
|
|
14
|
+
const bytesRead = readSync(fd, bytes, 0, maxBytes, 0);
|
|
15
|
+
return bytes.subarray(0, bytesRead);
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
closeSync(fd);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
stat: ({ path }) => { const info = lstatSync(path); return { kind: info.isFile() ? 'file' : info.isDirectory() ? 'directory' : 'other', mtimeMs: info.mtimeMs, diskBytes: info.blocks * 512 }; },
|
|
22
|
+
entries: ({ path }) => readdirSync(path), realpath: ({ path }) => realpathSync(path),
|
|
23
|
+
copy: ({ from, to }, optional = {}) => {
|
|
24
|
+
const source = realpathSync(from);
|
|
25
|
+
const destination = path.resolve(to);
|
|
26
|
+
if (destination === source || destination.startsWith(source + path.sep) || source.startsWith(destination + path.sep))
|
|
27
|
+
throw new Error('staging source and destination must be disjoint');
|
|
28
|
+
mkdirSync(path.dirname(destination), { recursive: true });
|
|
29
|
+
cpSync(source, destination, { recursive: true, dereference: true, filter: full => full === source || (!(optional.dropNestedModules && path.basename(full) === 'node_modules') && !optional.exclude?.({ path: full, directory: statSync(full).isDirectory() })) });
|
|
30
|
+
},
|
|
31
|
+
remove: ({ path }) => rmSync(path, { recursive: true, force: true }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Node's upward node_modules walk resolves pnpm links to real package roots. */
|
|
35
|
+
export function createNodePackageResolver({ fs }) {
|
|
36
|
+
return { resolve({ fromDirectory, packageName }) {
|
|
37
|
+
if (!/^(?:@[a-zA-Z0-9._-]+\/)?[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(packageName))
|
|
38
|
+
throw new Error('Invalid package name');
|
|
39
|
+
let directory = path.resolve(fromDirectory);
|
|
40
|
+
for (;;) {
|
|
41
|
+
const candidate = path.join(directory, 'node_modules', packageName);
|
|
42
|
+
if (fs.exists({ path: path.join(candidate, 'package.json') }))
|
|
43
|
+
return fs.realpath({ path: candidate });
|
|
44
|
+
const parent = path.dirname(directory);
|
|
45
|
+
if (parent === directory)
|
|
46
|
+
return undefined;
|
|
47
|
+
directory = parent;
|
|
48
|
+
}
|
|
49
|
+
} };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface Target {
|
|
2
|
+
platform: string;
|
|
3
|
+
arch: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PrebuildBuilt {
|
|
6
|
+
platform: string;
|
|
7
|
+
architectures: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface StalenessShell {
|
|
10
|
+
relative: string;
|
|
11
|
+
marker: string;
|
|
12
|
+
buildWith: string;
|
|
13
|
+
}
|
|
14
|
+
/** Independent live signals; a quiet sample still requires post-package byte verification. */
|
|
15
|
+
export declare function treeQuietProblems(required: {
|
|
16
|
+
surface: string;
|
|
17
|
+
watcherRunning: boolean;
|
|
18
|
+
gitDirtyPaths?: readonly string[];
|
|
19
|
+
movingPaths?: readonly string[];
|
|
20
|
+
}): string[];
|
|
21
|
+
/** Conservative bundle-input policy, shared by source timestamp scanning. */
|
|
22
|
+
export declare function isBundleInput({ relPath }: {
|
|
23
|
+
relPath: string;
|
|
24
|
+
}): boolean;
|
|
25
|
+
/** Missing timestamps defer to the host's existence checks; there is no stale-build tolerance. */
|
|
26
|
+
export declare function shellStalenessFailure({ builtAt, sourceAt, shell }: {
|
|
27
|
+
builtAt: number;
|
|
28
|
+
sourceAt: number;
|
|
29
|
+
shell: StalenessShell;
|
|
30
|
+
}): string | null;
|
|
31
|
+
/** npm's parseable output may contain duplicates and Windows CRLF endings. */
|
|
32
|
+
export declare function parseNpmLsPaths({ stdout, modulesDir, separator }: {
|
|
33
|
+
stdout: string;
|
|
34
|
+
modulesDir: string;
|
|
35
|
+
separator: string;
|
|
36
|
+
}): string[];
|
|
37
|
+
/** Unknown formats are retained rather than guessed to be incompatible. */
|
|
38
|
+
export declare function prebuildTarget({ entryName }: {
|
|
39
|
+
entryName: string;
|
|
40
|
+
}): PrebuildBuilt | undefined;
|
|
41
|
+
/** Targets come from arguments, never application environment names. */
|
|
42
|
+
export declare function resolveTargets({ host }: {
|
|
43
|
+
host: Target;
|
|
44
|
+
}, optional?: {
|
|
45
|
+
platform?: string;
|
|
46
|
+
arch?: string;
|
|
47
|
+
}): Target[];
|
|
48
|
+
/** Prefer npm-cli.js under Node; direct npm needs a shell only for Windows cmd wrappers. */
|
|
49
|
+
export declare function resolveNpmLsCommand(required: {
|
|
50
|
+
platform: string;
|
|
51
|
+
execPath: string;
|
|
52
|
+
}, optional?: {
|
|
53
|
+
npmExecPath?: string;
|
|
54
|
+
}): {
|
|
55
|
+
command: string;
|
|
56
|
+
args: string[];
|
|
57
|
+
shell: boolean;
|
|
58
|
+
};
|
|
59
|
+
/** Keep source maps only for scopes explicitly supplied by the consumer. */
|
|
60
|
+
export declare function strippableReason({ relPath, keepScopes }: {
|
|
61
|
+
relPath: string;
|
|
62
|
+
keepScopes: ReadonlySet<string>;
|
|
63
|
+
}): 'declaration' | 'sourceMap' | undefined;
|
|
64
|
+
//# sourceMappingURL=policies.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/** Independent live signals; a quiet sample still requires post-package byte verification. */
|
|
3
|
+
export function treeQuietProblems(required) {
|
|
4
|
+
const problems = [];
|
|
5
|
+
if (required.watcherRunning)
|
|
6
|
+
problems.push(`a build watch process is rewriting ${required.surface}; stop it before packaging.`);
|
|
7
|
+
if (required.gitDirtyPaths?.length)
|
|
8
|
+
problems.push(`${required.surface} has uncommitted changes: ${required.gitDirtyPaths.join(', ')}.`);
|
|
9
|
+
if (required.movingPaths?.length)
|
|
10
|
+
problems.push(`${required.surface} is still being written to: ${required.movingPaths.join(', ')} changed during this check.`);
|
|
11
|
+
return problems;
|
|
12
|
+
}
|
|
13
|
+
/** Conservative bundle-input policy, shared by source timestamp scanning. */
|
|
14
|
+
export function isBundleInput({ relPath }) {
|
|
15
|
+
const normalized = relPath.replace(/\\/g, '/');
|
|
16
|
+
if (normalized.split('/').some(segment => segment === '__tests__' || segment === '__measurements__'))
|
|
17
|
+
return false;
|
|
18
|
+
return !/\.(test|spec)\.[cm]?[jt]sx?$/.test(normalized);
|
|
19
|
+
}
|
|
20
|
+
/** Missing timestamps defer to the host's existence checks; there is no stale-build tolerance. */
|
|
21
|
+
export function shellStalenessFailure({ builtAt, sourceAt, shell }) {
|
|
22
|
+
if (builtAt === 0 || sourceAt === 0 || builtAt >= sourceAt)
|
|
23
|
+
return null;
|
|
24
|
+
return `the built shell at ${shell.relative} is STALE — its ${shell.marker} is ${((sourceAt - builtAt) / 86_400_000).toFixed(1)} day(s) older than its own source. Rebuild it with: ${shell.buildWith}`;
|
|
25
|
+
}
|
|
26
|
+
/** npm's parseable output may contain duplicates and Windows CRLF endings. */
|
|
27
|
+
export function parseNpmLsPaths({ stdout, modulesDir, separator }) {
|
|
28
|
+
const prefix = modulesDir + separator;
|
|
29
|
+
return [...new Set(stdout.split(/\r?\n/).filter(line => line.startsWith(prefix)).map(line => line.slice(prefix.length)))].sort();
|
|
30
|
+
}
|
|
31
|
+
/** Unknown formats are retained rather than guessed to be incompatible. */
|
|
32
|
+
export function prebuildTarget({ entryName }) {
|
|
33
|
+
const tag = entryName.endsWith('.node') ? entryName.slice(0, -5) : entryName;
|
|
34
|
+
const split = tag.indexOf('-');
|
|
35
|
+
if (split <= 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
const platform = tag.slice(0, split);
|
|
38
|
+
const architectures = tag.slice(split + 1).split('+');
|
|
39
|
+
if (!['aix', 'android', 'darwin', 'freebsd', 'linux', 'linuxmusl', 'openbsd', 'sunos', 'win32'].includes(platform) || !architectures.every(Boolean))
|
|
40
|
+
return undefined;
|
|
41
|
+
return { platform, architectures };
|
|
42
|
+
}
|
|
43
|
+
/** Targets come from arguments, never application environment names. */
|
|
44
|
+
export function resolveTargets({ host }, optional = {}) {
|
|
45
|
+
const platform = optional.platform || host.platform;
|
|
46
|
+
const arch = optional.arch || host.arch;
|
|
47
|
+
return (arch === 'universal' ? ['x64', 'arm64'] : [arch]).map(arch => ({ platform, arch }));
|
|
48
|
+
}
|
|
49
|
+
/** Prefer npm-cli.js under Node; direct npm needs a shell only for Windows cmd wrappers. */
|
|
50
|
+
export function resolveNpmLsCommand(required, optional = {}) {
|
|
51
|
+
const args = ['ls', '--omit=dev', '--parseable', '--all'];
|
|
52
|
+
return optional.npmExecPath ? { command: required.execPath, args: [optional.npmExecPath, ...args], shell: false } : { command: 'npm', args, shell: required.platform === 'win32' };
|
|
53
|
+
}
|
|
54
|
+
/** Keep source maps only for scopes explicitly supplied by the consumer. */
|
|
55
|
+
export function strippableReason({ relPath, keepScopes }) {
|
|
56
|
+
const name = path.posix.basename(relPath);
|
|
57
|
+
if (/\.d\.[cm]?ts(\.map)?$/.test(name))
|
|
58
|
+
return 'declaration';
|
|
59
|
+
if (!name.endsWith('.map') || keepScopes.has(relPath.split('/')[0]))
|
|
60
|
+
return undefined;
|
|
61
|
+
return 'sourceMap';
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=policies.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export interface FileInfo {
|
|
2
|
+
kind: 'file' | 'directory' | 'other';
|
|
3
|
+
mtimeMs: number;
|
|
4
|
+
diskBytes: number;
|
|
5
|
+
}
|
|
6
|
+
/** lstat semantics for stat; copy may dereference package symlinks as explicitly requested. */
|
|
7
|
+
export interface PackagingFilesystemPort {
|
|
8
|
+
exists(required: {
|
|
9
|
+
path: string;
|
|
10
|
+
}): boolean;
|
|
11
|
+
read(required: {
|
|
12
|
+
path: string;
|
|
13
|
+
}): Uint8Array;
|
|
14
|
+
/** Required for npm staging: read at most maxBytes from offset zero, never the whole file.
|
|
15
|
+
* Optional so adapters used only for other packaging operations keep their existing shape. */
|
|
16
|
+
readPrefix?(required: {
|
|
17
|
+
path: string;
|
|
18
|
+
maxBytes: number;
|
|
19
|
+
}): Uint8Array;
|
|
20
|
+
stat(required: {
|
|
21
|
+
path: string;
|
|
22
|
+
}): FileInfo;
|
|
23
|
+
entries(required: {
|
|
24
|
+
path: string;
|
|
25
|
+
}): readonly string[];
|
|
26
|
+
realpath(required: {
|
|
27
|
+
path: string;
|
|
28
|
+
}): string;
|
|
29
|
+
copy(required: {
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
}, optional?: {
|
|
33
|
+
dropNestedModules?: boolean;
|
|
34
|
+
exclude?: (required: {
|
|
35
|
+
path: string;
|
|
36
|
+
directory: boolean;
|
|
37
|
+
}) => boolean;
|
|
38
|
+
}): void;
|
|
39
|
+
remove(required: {
|
|
40
|
+
path: string;
|
|
41
|
+
}): void;
|
|
42
|
+
}
|
|
43
|
+
export interface PackageResolverPort {
|
|
44
|
+
resolve(required: {
|
|
45
|
+
fromDirectory: string;
|
|
46
|
+
packageName: string;
|
|
47
|
+
}): string | undefined;
|
|
48
|
+
}
|
|
49
|
+
export interface ProcessRunnerPort {
|
|
50
|
+
run(required: {
|
|
51
|
+
command: string;
|
|
52
|
+
args: readonly string[];
|
|
53
|
+
cwd: string;
|
|
54
|
+
shell: boolean;
|
|
55
|
+
}): {
|
|
56
|
+
stdout: string;
|
|
57
|
+
exitCode: number;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface AsarHeaderNode {
|
|
61
|
+
files?: Record<string, AsarHeaderNode>;
|
|
62
|
+
link?: string;
|
|
63
|
+
size?: number;
|
|
64
|
+
offset?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface ArchiveReaderPort {
|
|
67
|
+
header(required: {
|
|
68
|
+
archivePath: string;
|
|
69
|
+
}): {
|
|
70
|
+
files?: Record<string, AsarHeaderNode>;
|
|
71
|
+
};
|
|
72
|
+
read(required: {
|
|
73
|
+
archivePath: string;
|
|
74
|
+
entryPath: string;
|
|
75
|
+
}): Uint8Array;
|
|
76
|
+
}
|
|
77
|
+
/** Must parse static imports, re-exports and literal dynamic imports using an AST, ignoring comments. */
|
|
78
|
+
export interface ImportReaderPort {
|
|
79
|
+
imports(required: {
|
|
80
|
+
file: string;
|
|
81
|
+
source: string;
|
|
82
|
+
}): readonly string[];
|
|
83
|
+
}
|
|
84
|
+
export interface ImportAliasPort {
|
|
85
|
+
resolve(required: {
|
|
86
|
+
specifier: string;
|
|
87
|
+
fromFile: string;
|
|
88
|
+
distDir: string;
|
|
89
|
+
}): string | undefined;
|
|
90
|
+
}
|
|
91
|
+
/** Bind to scripts/lib/pack-jini-packages.ts buildAndPackClosure in the host, not inside a package. */
|
|
92
|
+
export interface WorkspacePackagePackerPort {
|
|
93
|
+
pack(required: {
|
|
94
|
+
repoRoot: string;
|
|
95
|
+
packagesDir: string;
|
|
96
|
+
rootNames: readonly string[];
|
|
97
|
+
destDir: string;
|
|
98
|
+
}): {
|
|
99
|
+
readonly closure: readonly string[];
|
|
100
|
+
readonly tarballPathByName: ReadonlyMap<string, string>;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export interface SnapshotPort {
|
|
104
|
+
snapshot(required: {
|
|
105
|
+
roots: readonly string[];
|
|
106
|
+
}): ReadonlyMap<string, string>;
|
|
107
|
+
}
|
|
108
|
+
export interface SleepPort {
|
|
109
|
+
sleep(required: {
|
|
110
|
+
milliseconds: number;
|
|
111
|
+
}): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SnapshotPort, SleepPort } from './ports.js';
|
|
2
|
+
/** Compare live observations, not absolute file ages: a fresh checkout is quiet if unchanged. */
|
|
3
|
+
export declare function observeMovingPaths(required: {
|
|
4
|
+
roots: readonly string[];
|
|
5
|
+
intervalMs: number;
|
|
6
|
+
snapshots: SnapshotPort;
|
|
7
|
+
clock: SleepPort;
|
|
8
|
+
}): Promise<string[]>;
|
|
9
|
+
//# sourceMappingURL=stability.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Compare live observations, not absolute file ages: a fresh checkout is quiet if unchanged. */
|
|
2
|
+
export async function observeMovingPaths(required) {
|
|
3
|
+
if (!Number.isFinite(required.intervalMs) || required.intervalMs <= 0)
|
|
4
|
+
throw new Error('intervalMs must be positive');
|
|
5
|
+
if (!required.roots.length)
|
|
6
|
+
throw new Error('packaged surface roots are required');
|
|
7
|
+
const before = new Map(required.snapshots.snapshot({ roots: required.roots }));
|
|
8
|
+
await required.clock.sleep({ milliseconds: required.intervalMs });
|
|
9
|
+
const after = required.snapshots.snapshot({ roots: required.roots });
|
|
10
|
+
return [...new Set([...before.keys(), ...after.keys()])].filter(file => before.get(file) !== after.get(file)).sort();
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=stability.js.map
|
|
@@ -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
|