@playcraft/build 0.1.91 → 0.1.92-test
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/dist/base-builder.js +2 -41
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/index.d.ts +4 -19
- package/dist/index.js +2 -11
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.js +2 -2
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -4
- package/dist/validation/index.js +0 -4
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -155
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -68
- package/dist/validation/zip-reader.d.ts +0 -7
- package/dist/validation/zip-reader.js +26 -159
- package/dist/vite/config-builder-generic.d.ts +1 -3
- package/dist/vite/config-builder-generic.js +7 -9
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +54 -30
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -16
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -7
- package/dist/delivery/command-isolation.js +0 -252
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -137
- package/dist/delivery/files.d.ts +0 -9
- package/dist/delivery/files.js +0 -144
- package/dist/delivery/git-source-fingerprint.d.ts +0 -2
- package/dist/delivery/git-source-fingerprint.js +0 -58
- package/dist/delivery/isolated-source.d.ts +0 -5
- package/dist/delivery/isolated-source.js +0 -126
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -76
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/validation/artifact-qa.d.ts +0 -44
- package/dist/validation/artifact-qa.js +0 -170
- package/dist/validation/artifact-rules.d.ts +0 -28
- package/dist/validation/artifact-rules.js +0 -440
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/runtime-load.d.ts +0 -89
- package/dist/validation/runtime-load.js +0 -654
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { OutputFormat, Platform } from '../types.js';
|
|
2
|
-
import { type ArtifactDescriptor, type ArtifactIdentity } from './artifact-descriptor.js';
|
|
3
|
-
export declare const ARTIFACT_LIMITS: {
|
|
4
|
-
readonly maxFiles: 4096;
|
|
5
|
-
readonly maxFileBytes: number;
|
|
6
|
-
readonly maxTotalBytes: number;
|
|
7
|
-
readonly maxCompressionRatio: 200;
|
|
8
|
-
};
|
|
9
|
-
export type ArtifactInputFile = {
|
|
10
|
-
path: string;
|
|
11
|
-
bytes: Uint8Array;
|
|
12
|
-
};
|
|
13
|
-
export type PackageChannelArtifactOptions = ArtifactIdentity & {
|
|
14
|
-
channel: Platform;
|
|
15
|
-
format: OutputFormat;
|
|
16
|
-
files: ArtifactInputFile[];
|
|
17
|
-
projectRoot?: string;
|
|
18
|
-
};
|
|
19
|
-
export declare function normalizeArtifactPath(value: string): string;
|
|
20
|
-
export declare function validateArtifactFiles(values: readonly ArtifactInputFile[], channel: Platform): ArtifactInputFile[];
|
|
21
|
-
export declare function readArtifactDirectory(root: string, channel: Platform): Promise<ArtifactInputFile[]>;
|
|
22
|
-
/** Uses the streaming API so even numeric-looking filenames retain UTF-8 path ordering. */
|
|
23
|
-
export declare function createNormalizedZip(values: readonly ArtifactInputFile[], channel: Platform): Promise<Buffer>;
|
|
24
|
-
export declare function readZipArtifact(bytes: Uint8Array, channel: Platform): Promise<ArtifactInputFile[]>;
|
|
25
|
-
export declare function packageChannelArtifact(options: PackageChannelArtifactOptions): Promise<{
|
|
26
|
-
bytes: Buffer;
|
|
27
|
-
descriptor: ArtifactDescriptor;
|
|
28
|
-
}>;
|
|
29
|
-
export type DescribeChannelArtifactOptions = ArtifactIdentity & {
|
|
30
|
-
channel: Platform;
|
|
31
|
-
format: OutputFormat;
|
|
32
|
-
bytes: Uint8Array;
|
|
33
|
-
artifactName?: string;
|
|
34
|
-
projectRoot?: string;
|
|
35
|
-
};
|
|
36
|
-
/** Rebuilds the descriptor from actual bytes; used by Business instead of trusting Runner metadata. */
|
|
37
|
-
export declare function describeChannelArtifact(options: DescribeChannelArtifactOptions): Promise<ArtifactDescriptor>;
|
|
38
|
-
/** Checks digest, per-file hashes and a fresh channel report against the supplied manifest. */
|
|
39
|
-
export declare function verifyChannelArtifactDescriptor(value: unknown, options: {
|
|
40
|
-
bytes: Uint8Array;
|
|
41
|
-
artifactName?: string;
|
|
42
|
-
projectRoot?: string;
|
|
43
|
-
}): Promise<ArtifactDescriptor>;
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { constants } from 'node:fs';
|
|
2
|
-
import { lstat, open, readdir, realpath } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { Zip, ZipDeflate } from 'fflate';
|
|
5
|
-
import { getChannelCapability } from '../validation/profiles.js';
|
|
6
|
-
import { runChannelArtifactValidation } from '../validation/validation-runner.js';
|
|
7
|
-
import { SimpleZipReader } from '../validation/zip-reader.js';
|
|
8
|
-
import { ProjectDeliveryError } from './recipe.js';
|
|
9
|
-
import { artifactBytesDigest, artifactFileDescriptor, assertArtifactDescriptorDigest, } from './artifact-descriptor.js';
|
|
10
|
-
export const ARTIFACT_LIMITS = {
|
|
11
|
-
maxFiles: 4096,
|
|
12
|
-
maxFileBytes: 64 * 1024 * 1024,
|
|
13
|
-
maxTotalBytes: 128 * 1024 * 1024,
|
|
14
|
-
maxCompressionRatio: 200,
|
|
15
|
-
};
|
|
16
|
-
function failure(code, message, file) {
|
|
17
|
-
throw new ProjectDeliveryError(code, message, file);
|
|
18
|
-
}
|
|
19
|
-
export function normalizeArtifactPath(value) {
|
|
20
|
-
if (!value ||
|
|
21
|
-
value.length > 1024 ||
|
|
22
|
-
value.includes('\0') ||
|
|
23
|
-
value.includes('\\') ||
|
|
24
|
-
path.posix.isAbsolute(value) ||
|
|
25
|
-
/^[A-Za-z]:/.test(value) ||
|
|
26
|
-
value.split('/').some((segment) => !segment || segment === '.' || segment === '..') ||
|
|
27
|
-
path.posix.normalize(value) !== value) {
|
|
28
|
-
failure('artifact_path_unsafe', 'Artifact paths must be normalized POSIX relative paths', value);
|
|
29
|
-
}
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
function comparePaths(left, right) {
|
|
33
|
-
return Buffer.compare(Buffer.from(left, 'utf8'), Buffer.from(right, 'utf8'));
|
|
34
|
-
}
|
|
35
|
-
export function validateArtifactFiles(values, channel) {
|
|
36
|
-
const capability = getChannelCapability(channel);
|
|
37
|
-
const maximumFiles = Math.min(capability.maxFiles ?? ARTIFACT_LIMITS.maxFiles, ARTIFACT_LIMITS.maxFiles);
|
|
38
|
-
if (values.length === 0 || values.length > maximumFiles) {
|
|
39
|
-
failure('artifact_file_count_invalid', `Artifact must contain between 1 and ${maximumFiles} files`);
|
|
40
|
-
}
|
|
41
|
-
const paths = new Set();
|
|
42
|
-
const caseInsensitivePaths = new Set();
|
|
43
|
-
let totalBytes = 0;
|
|
44
|
-
const files = values.map((value) => {
|
|
45
|
-
const member = normalizeArtifactPath(value.path);
|
|
46
|
-
const folded = member.normalize('NFC').toLowerCase();
|
|
47
|
-
if (paths.has(member))
|
|
48
|
-
failure('artifact_duplicate_path', 'Duplicate artifact path', member);
|
|
49
|
-
if (caseInsensitivePaths.has(folded)) {
|
|
50
|
-
failure('artifact_case_conflict', 'Artifact paths differ only by case', member);
|
|
51
|
-
}
|
|
52
|
-
paths.add(member);
|
|
53
|
-
caseInsensitivePaths.add(folded);
|
|
54
|
-
if (!Number.isSafeInteger(value.bytes.byteLength) || value.bytes.byteLength > ARTIFACT_LIMITS.maxFileBytes) {
|
|
55
|
-
failure('artifact_file_too_large', 'Artifact file exceeds the size limit', member);
|
|
56
|
-
}
|
|
57
|
-
totalBytes += value.bytes.byteLength;
|
|
58
|
-
if (totalBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
59
|
-
failure('artifact_total_size_exceeded', 'Artifact uncompressed size exceeds the limit');
|
|
60
|
-
}
|
|
61
|
-
return { path: member, bytes: Buffer.from(value.bytes) };
|
|
62
|
-
});
|
|
63
|
-
if (capability.rootEntryRequired && !paths.has('index.html')) {
|
|
64
|
-
failure('artifact_root_entry_required', 'This channel requires a root index.html');
|
|
65
|
-
}
|
|
66
|
-
return files.sort((left, right) => comparePaths(left.path, right.path));
|
|
67
|
-
}
|
|
68
|
-
export async function readArtifactDirectory(root, channel) {
|
|
69
|
-
const requestedInfo = await lstat(root);
|
|
70
|
-
if (!requestedInfo.isDirectory() || requestedInfo.isSymbolicLink()) {
|
|
71
|
-
failure('artifact_source_invalid', 'Artifact source must be a real non-aliased directory');
|
|
72
|
-
}
|
|
73
|
-
const resolved = await realpath(root);
|
|
74
|
-
const rootInfo = await lstat(resolved);
|
|
75
|
-
if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) {
|
|
76
|
-
failure('artifact_source_invalid', 'Artifact source must be a real directory');
|
|
77
|
-
}
|
|
78
|
-
const files = [];
|
|
79
|
-
let visited = 0;
|
|
80
|
-
let totalBytes = 0;
|
|
81
|
-
async function visit(directory, prefix) {
|
|
82
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
83
|
-
for (const entry of entries) {
|
|
84
|
-
if (++visited > ARTIFACT_LIMITS.maxFiles * 2) {
|
|
85
|
-
failure('artifact_file_count_invalid', 'Artifact source contains too many entries');
|
|
86
|
-
}
|
|
87
|
-
const member = normalizeArtifactPath(prefix ? `${prefix}/${entry.name}` : entry.name);
|
|
88
|
-
const filename = path.join(directory, entry.name);
|
|
89
|
-
const info = await lstat(filename);
|
|
90
|
-
if (info.isSymbolicLink() || (!info.isDirectory() && !info.isFile())) {
|
|
91
|
-
failure('artifact_non_regular_file', 'Artifact source contains a non-regular file', member);
|
|
92
|
-
}
|
|
93
|
-
if (info.isDirectory()) {
|
|
94
|
-
await visit(filename, member);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (info.nlink !== 1 || info.size > ARTIFACT_LIMITS.maxFileBytes) {
|
|
98
|
-
failure('artifact_file_too_large', 'Artifact file is linked or exceeds the size limit', member);
|
|
99
|
-
}
|
|
100
|
-
totalBytes += info.size;
|
|
101
|
-
if (totalBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
102
|
-
failure('artifact_total_size_exceeded', 'Artifact uncompressed size exceeds the limit');
|
|
103
|
-
}
|
|
104
|
-
const handle = await open(filename, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
105
|
-
try {
|
|
106
|
-
const before = await handle.stat();
|
|
107
|
-
const bytes = await handle.readFile();
|
|
108
|
-
const after = await handle.stat();
|
|
109
|
-
if (!before.isFile() ||
|
|
110
|
-
!after.isFile() ||
|
|
111
|
-
before.dev !== after.dev ||
|
|
112
|
-
before.ino !== after.ino ||
|
|
113
|
-
before.size !== bytes.byteLength ||
|
|
114
|
-
after.size !== bytes.byteLength ||
|
|
115
|
-
before.mtimeMs !== after.mtimeMs ||
|
|
116
|
-
before.ctimeMs !== after.ctimeMs) {
|
|
117
|
-
failure('artifact_source_changed', 'Artifact source changed while being read', member);
|
|
118
|
-
}
|
|
119
|
-
files.push({ path: member, bytes });
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
await handle.close();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
await visit(resolved, '');
|
|
127
|
-
return validateArtifactFiles(files, channel);
|
|
128
|
-
}
|
|
129
|
-
/** Uses the streaming API so even numeric-looking filenames retain UTF-8 path ordering. */
|
|
130
|
-
export async function createNormalizedZip(values, channel) {
|
|
131
|
-
const files = validateArtifactFiles(values, channel);
|
|
132
|
-
return new Promise((resolve, reject) => {
|
|
133
|
-
const chunks = [];
|
|
134
|
-
const archive = new Zip((error, data, final) => {
|
|
135
|
-
if (error) {
|
|
136
|
-
reject(error);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
chunks.push(Buffer.from(data));
|
|
140
|
-
if (final)
|
|
141
|
-
resolve(Buffer.concat(chunks));
|
|
142
|
-
});
|
|
143
|
-
for (const file of files) {
|
|
144
|
-
const entry = new ZipDeflate(file.path, { level: 6 });
|
|
145
|
-
entry.mtime = new Date(1980, 0, 1, 0, 0, 0);
|
|
146
|
-
entry.os = 3;
|
|
147
|
-
entry.attrs = 0o100644 << 16;
|
|
148
|
-
archive.add(entry);
|
|
149
|
-
entry.push(file.bytes, true);
|
|
150
|
-
}
|
|
151
|
-
archive.end();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
export async function readZipArtifact(bytes, channel) {
|
|
155
|
-
const reader = new SimpleZipReader(Buffer.from(bytes));
|
|
156
|
-
const entries = reader.listEntries();
|
|
157
|
-
const files = [];
|
|
158
|
-
let compressedBytes = 0;
|
|
159
|
-
let uncompressedBytes = 0;
|
|
160
|
-
for (const entry of entries) {
|
|
161
|
-
if (entry.isDirectory) {
|
|
162
|
-
failure('artifact_non_regular_file', 'Directory entries are not allowed in a normalized artifact', entry.path);
|
|
163
|
-
}
|
|
164
|
-
normalizeArtifactPath(entry.path);
|
|
165
|
-
if (entry.encrypted || entry.uncompressedSize > ARTIFACT_LIMITS.maxFileBytes) {
|
|
166
|
-
failure('artifact_file_too_large', 'ZIP entry is encrypted or exceeds the size limit', entry.path);
|
|
167
|
-
}
|
|
168
|
-
if (entry.compressionMethod !== 0 && entry.compressionMethod !== 8) {
|
|
169
|
-
failure('artifact_compression_unsupported', 'ZIP entry uses an unsupported compression method', entry.path);
|
|
170
|
-
}
|
|
171
|
-
const fileType = (entry.externalAttributes ?? 0) >>> 16;
|
|
172
|
-
if (fileType !== 0 && (fileType & 0o170000) !== 0o100000) {
|
|
173
|
-
failure('artifact_non_regular_file', 'ZIP entry is not a regular file', entry.path);
|
|
174
|
-
}
|
|
175
|
-
compressedBytes += entry.compressedSize;
|
|
176
|
-
uncompressedBytes += entry.uncompressedSize;
|
|
177
|
-
if (uncompressedBytes > ARTIFACT_LIMITS.maxTotalBytes) {
|
|
178
|
-
failure('artifact_total_size_exceeded', 'ZIP uncompressed size exceeds the limit');
|
|
179
|
-
}
|
|
180
|
-
if (entry.uncompressedSize > 64 * 1024 &&
|
|
181
|
-
entry.uncompressedSize / Math.max(1, entry.compressedSize) > ARTIFACT_LIMITS.maxCompressionRatio) {
|
|
182
|
-
failure('artifact_compression_ratio_exceeded', 'ZIP entry compression ratio exceeds the limit', entry.path);
|
|
183
|
-
}
|
|
184
|
-
const content = reader.readEntry(entry.path);
|
|
185
|
-
if (!content || content.byteLength !== entry.uncompressedSize) {
|
|
186
|
-
failure('artifact_entry_size_mismatch', 'ZIP entry size differs from its central directory', entry.path);
|
|
187
|
-
}
|
|
188
|
-
files.push({ path: entry.path, bytes: content });
|
|
189
|
-
}
|
|
190
|
-
if (compressedBytes > bytes.byteLength) {
|
|
191
|
-
failure('artifact_zip_invalid', 'ZIP compressed sizes exceed the artifact size');
|
|
192
|
-
}
|
|
193
|
-
return validateArtifactFiles(files, channel);
|
|
194
|
-
}
|
|
195
|
-
function descriptor(options, bytes, files, validation) {
|
|
196
|
-
return {
|
|
197
|
-
version: 1,
|
|
198
|
-
channel: options.channel,
|
|
199
|
-
format: options.format,
|
|
200
|
-
...artifactBytesDigest(bytes),
|
|
201
|
-
contentType: options.format === 'html' ? 'text/html; charset=utf-8' : 'application/zip',
|
|
202
|
-
files,
|
|
203
|
-
sourceFingerprint: options.sourceFingerprint,
|
|
204
|
-
recipeDigest: options.recipeDigest,
|
|
205
|
-
environmentDigest: options.environmentDigest,
|
|
206
|
-
channelRulesVersion: options.channelRulesVersion,
|
|
207
|
-
validation,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
export async function packageChannelArtifact(options) {
|
|
211
|
-
if (!getChannelCapability(options.channel).supportedFormats.includes(options.format)) {
|
|
212
|
-
failure('delivery_context_invalid', `${options.channel} does not support ${options.format} delivery`);
|
|
213
|
-
}
|
|
214
|
-
const files = validateArtifactFiles(options.files, options.channel);
|
|
215
|
-
if (options.format === 'html' && files.length !== 1) {
|
|
216
|
-
failure('artifact_single_html_required', 'HTML delivery must contain exactly one file');
|
|
217
|
-
}
|
|
218
|
-
const bytes = options.format === 'html'
|
|
219
|
-
? Buffer.from(files[0].bytes)
|
|
220
|
-
: await createNormalizedZip(files, options.channel);
|
|
221
|
-
const entryName = options.format === 'html' ? files[0].path : 'index.html';
|
|
222
|
-
const entry = options.format === 'html'
|
|
223
|
-
? files[0].bytes
|
|
224
|
-
: (await readZipArtifact(bytes, options.channel)).find((file) => file.path === entryName)?.bytes;
|
|
225
|
-
if (!entry)
|
|
226
|
-
failure('artifact_root_entry_required', 'The final artifact has no HTML entry', entryName);
|
|
227
|
-
const validation = await runChannelArtifactValidation({
|
|
228
|
-
channel: options.channel,
|
|
229
|
-
format: options.format,
|
|
230
|
-
bytes,
|
|
231
|
-
htmlBytes: entry,
|
|
232
|
-
artifactName: entryName,
|
|
233
|
-
projectRoot: options.projectRoot,
|
|
234
|
-
});
|
|
235
|
-
return {
|
|
236
|
-
bytes,
|
|
237
|
-
descriptor: descriptor(options, bytes, files.map((file) => artifactFileDescriptor(file.path, file.bytes)), validation),
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/** Rebuilds the descriptor from actual bytes; used by Business instead of trusting Runner metadata. */
|
|
241
|
-
export async function describeChannelArtifact(options) {
|
|
242
|
-
const capability = getChannelCapability(options.channel);
|
|
243
|
-
if (!capability.supportedFormats.includes(options.format)) {
|
|
244
|
-
failure('delivery_context_invalid', `${options.channel} does not support ${options.format} delivery`);
|
|
245
|
-
}
|
|
246
|
-
const artifactName = options.artifactName ?? 'index.html';
|
|
247
|
-
const files = options.format === 'html'
|
|
248
|
-
? validateArtifactFiles([{ path: artifactName, bytes: options.bytes }], options.channel)
|
|
249
|
-
: await readZipArtifact(options.bytes, options.channel);
|
|
250
|
-
const entry = options.format === 'html'
|
|
251
|
-
? options.bytes
|
|
252
|
-
: files.find((file) => file.path === 'index.html')?.bytes;
|
|
253
|
-
if (!entry)
|
|
254
|
-
failure('artifact_root_entry_required', 'The final artifact has no root index.html');
|
|
255
|
-
const validation = await runChannelArtifactValidation({
|
|
256
|
-
channel: options.channel,
|
|
257
|
-
format: options.format,
|
|
258
|
-
bytes: options.bytes,
|
|
259
|
-
htmlBytes: entry,
|
|
260
|
-
artifactName: options.format === 'html' ? files[0].path : 'index.html',
|
|
261
|
-
projectRoot: options.projectRoot,
|
|
262
|
-
});
|
|
263
|
-
return descriptor({ ...options, files }, options.bytes, files.map((file) => artifactFileDescriptor(file.path, file.bytes)), validation);
|
|
264
|
-
}
|
|
265
|
-
/** Checks digest, per-file hashes and a fresh channel report against the supplied manifest. */
|
|
266
|
-
export async function verifyChannelArtifactDescriptor(value, options) {
|
|
267
|
-
const expected = assertArtifactDescriptorDigest(value, options.bytes);
|
|
268
|
-
const actual = await describeChannelArtifact({
|
|
269
|
-
channel: expected.channel,
|
|
270
|
-
format: expected.format,
|
|
271
|
-
bytes: options.bytes,
|
|
272
|
-
artifactName: options.artifactName ?? (expected.format === 'html' ? expected.files[0].path : 'index.html'),
|
|
273
|
-
projectRoot: options.projectRoot,
|
|
274
|
-
sourceFingerprint: expected.sourceFingerprint,
|
|
275
|
-
recipeDigest: expected.recipeDigest,
|
|
276
|
-
environmentDigest: expected.environmentDigest,
|
|
277
|
-
channelRulesVersion: expected.channelRulesVersion,
|
|
278
|
-
});
|
|
279
|
-
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
280
|
-
throw new ProjectDeliveryError('artifact_descriptor_mismatch', 'Artifact files or validation differ from the descriptor');
|
|
281
|
-
}
|
|
282
|
-
return actual;
|
|
283
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { BuildPlan } from './build-plan.types.js';
|
|
2
|
-
/** Strictly parses the portable plan; absolute Runtime workspace paths are deliberately absent. */
|
|
3
|
-
export declare function parseBuildPlan(value: unknown): BuildPlan;
|
|
4
|
-
export declare function buildPlanDigest(value: BuildPlan): string;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { agentBuildSourceRulesVersionSchema } from '@playcraft/common/cloud-workspace/runtime';
|
|
3
|
-
import { CHANNEL_RULE_PROFILES } from '../validation/profiles.js';
|
|
4
|
-
import { ProjectDeliveryError, relativePath } from './recipe.js';
|
|
5
|
-
const HASH = /^[a-f0-9]{64}$/;
|
|
6
|
-
const COMMIT = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
7
|
-
const FORMATS = ['html', 'zip'];
|
|
8
|
-
const PACKAGE_MANAGERS = ['pnpm', 'npm', 'yarn', 'bun'];
|
|
9
|
-
const COMPILE_STRATEGIES = ['project-command', 'platform-vite', 'project-owned'];
|
|
10
|
-
const PACKAGE_STRATEGIES = ['single-html', 'normalized-zip', 'project-owned'];
|
|
11
|
-
function invalid(message, file) {
|
|
12
|
-
throw new ProjectDeliveryError('delivery_build_plan_invalid', message, file);
|
|
13
|
-
}
|
|
14
|
-
function record(value, field) {
|
|
15
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
16
|
-
invalid(`${field} must be an object`);
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
function keys(value, allowed, field) {
|
|
21
|
-
const actual = Object.keys(value).sort();
|
|
22
|
-
const expected = [...allowed].sort();
|
|
23
|
-
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
24
|
-
invalid(`${field} has missing or unsupported fields`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function allowedKeys(value, allowed, field) {
|
|
28
|
-
if (Object.keys(value).some((key) => !allowed.includes(key))) {
|
|
29
|
-
invalid(`${field} has unsupported fields`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function text(value, field, maximum = 4096) {
|
|
33
|
-
if (typeof value !== 'string' || !value.trim() || value.length > maximum || value.includes('\0')) {
|
|
34
|
-
invalid(`Invalid ${field}`);
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
function hash(value, field) {
|
|
39
|
-
const result = text(value, field, 64);
|
|
40
|
-
if (!HASH.test(result))
|
|
41
|
-
invalid(`${field} must be a lowercase SHA-256 digest`);
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
function choice(value, values, field) {
|
|
45
|
-
if (typeof value !== 'string' || !values.includes(value))
|
|
46
|
-
invalid(`Invalid ${field}`);
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
function command(value, field) {
|
|
50
|
-
const input = record(value, field);
|
|
51
|
-
allowedKeys(input, ['argv', 'cwd', 'timeoutMs'], field);
|
|
52
|
-
if (!Array.isArray(input.argv) || input.argv.length === 0 || input.argv.length > 128) {
|
|
53
|
-
invalid(`${field}.argv must be a nonempty bounded array`);
|
|
54
|
-
}
|
|
55
|
-
const result = {
|
|
56
|
-
argv: input.argv.map((argument, index) => text(argument, `${field}.argv[${index}]`)),
|
|
57
|
-
};
|
|
58
|
-
if (input.cwd !== undefined) {
|
|
59
|
-
result.cwd = relativePath(text(input.cwd, `${field}.cwd`), `${field}.cwd`, true);
|
|
60
|
-
}
|
|
61
|
-
if (input.timeoutMs !== undefined) {
|
|
62
|
-
if (!Number.isInteger(input.timeoutMs) || Number(input.timeoutMs) < 1000 || Number(input.timeoutMs) > 1800000) {
|
|
63
|
-
invalid(`${field}.timeoutMs must be between 1000 and 1800000`);
|
|
64
|
-
}
|
|
65
|
-
result.timeoutMs = Number(input.timeoutMs);
|
|
66
|
-
}
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
function optionalCommands(value, field) {
|
|
70
|
-
if (!Array.isArray(value) || value.length > 16)
|
|
71
|
-
invalid(`Invalid ${field}`);
|
|
72
|
-
return value.map((item, index) => command(item, `${field}[${index}]`));
|
|
73
|
-
}
|
|
74
|
-
function relativePaths(value, field) {
|
|
75
|
-
if (!Array.isArray(value) || value.length > 32)
|
|
76
|
-
invalid(`Invalid ${field}`);
|
|
77
|
-
const paths = value.map((item, index) => relativePath(text(item, `${field}[${index}]`), `${field}[${index}]`));
|
|
78
|
-
if (new Set(paths).size !== paths.length)
|
|
79
|
-
invalid(`${field} contains duplicates`);
|
|
80
|
-
return paths;
|
|
81
|
-
}
|
|
82
|
-
/** Strictly parses the portable plan; absolute Runtime workspace paths are deliberately absent. */
|
|
83
|
-
export function parseBuildPlan(value) {
|
|
84
|
-
const input = record(value, 'buildPlan');
|
|
85
|
-
keys(input, ['planVersion', 'source', 'target', 'environment', 'setup', 'compile', 'delivery'], 'buildPlan');
|
|
86
|
-
if (input.planVersion !== 1)
|
|
87
|
-
invalid('buildPlan.planVersion must be 1');
|
|
88
|
-
const source = record(input.source, 'source');
|
|
89
|
-
keys(source, ['commitHash', 'sourceFingerprint', 'sourceRulesVersion', 'recipeDigest'], 'source');
|
|
90
|
-
const commitHash = text(source.commitHash, 'source.commitHash', 64);
|
|
91
|
-
if (!COMMIT.test(commitHash))
|
|
92
|
-
invalid('source.commitHash must be a lowercase Git object id');
|
|
93
|
-
const sourceRules = agentBuildSourceRulesVersionSchema.safeParse(source.sourceRulesVersion);
|
|
94
|
-
if (!sourceRules.success)
|
|
95
|
-
invalid('Unsupported source.sourceRulesVersion');
|
|
96
|
-
const target = record(input.target, 'target');
|
|
97
|
-
keys(target, ['channel', 'format'], 'target');
|
|
98
|
-
const channel = text(target.channel, 'target.channel', 64);
|
|
99
|
-
if (!Object.prototype.hasOwnProperty.call(CHANNEL_RULE_PROFILES, channel))
|
|
100
|
-
invalid('Unsupported target.channel');
|
|
101
|
-
const format = choice(target.format, FORMATS, 'target.format');
|
|
102
|
-
const environment = record(input.environment, 'environment');
|
|
103
|
-
keys(environment, ['packageManager', 'executables', 'isolation', 'maxDurationMs'], 'environment');
|
|
104
|
-
if (environment.isolation !== 'managed-delivery-v1')
|
|
105
|
-
invalid('Unsupported environment.isolation');
|
|
106
|
-
if (!Number.isInteger(environment.maxDurationMs) || Number(environment.maxDurationMs) < 1000 || Number(environment.maxDurationMs) > 1800000) {
|
|
107
|
-
invalid('environment.maxDurationMs must be between 1000 and 1800000');
|
|
108
|
-
}
|
|
109
|
-
if (!Array.isArray(environment.executables) || environment.executables.length > 32) {
|
|
110
|
-
invalid('Invalid environment.executables');
|
|
111
|
-
}
|
|
112
|
-
const setup = record(input.setup, 'setup');
|
|
113
|
-
keys(setup, ['install', 'prepareCommands', 'generatedDirectories'], 'setup');
|
|
114
|
-
if (setup.install !== 'frozen-lockfile')
|
|
115
|
-
invalid('setup.install must be frozen-lockfile');
|
|
116
|
-
const compile = record(input.compile, 'compile');
|
|
117
|
-
const output = record(compile.output, 'compile.output');
|
|
118
|
-
keys(output, ['kind', 'directory', 'entry'], 'compile.output');
|
|
119
|
-
const kind = choice(output.kind, ['web-bundle', 'channel-package'], 'compile.output.kind');
|
|
120
|
-
const strategy = choice(compile.strategy, COMPILE_STRATEGIES, 'compile.strategy');
|
|
121
|
-
const scope = choice(compile.scope, ['shared', 'per-channel'], 'compile.scope');
|
|
122
|
-
const hasCommand = compile.command !== undefined;
|
|
123
|
-
keys(compile, hasCommand ? ['strategy', 'command', 'scope', 'output'] : ['strategy', 'scope', 'output'], 'compile');
|
|
124
|
-
if (strategy !== 'project-owned' && !hasCommand) {
|
|
125
|
-
invalid('Project-command and platform-vite strategies require a compile command');
|
|
126
|
-
}
|
|
127
|
-
if (scope === 'shared' && (kind !== 'web-bundle' || strategy === 'project-owned')) {
|
|
128
|
-
invalid('Only a project-compiled web-bundle can be shared across channels');
|
|
129
|
-
}
|
|
130
|
-
const delivery = record(input.delivery, 'delivery');
|
|
131
|
-
keys(delivery, ['channelRulesVersion', 'packageStrategy'], 'delivery');
|
|
132
|
-
const packageStrategy = choice(delivery.packageStrategy, PACKAGE_STRATEGIES, 'delivery.packageStrategy');
|
|
133
|
-
if (kind === 'channel-package' && (strategy === 'platform-vite' || packageStrategy !== 'project-owned')) {
|
|
134
|
-
invalid('A channel-package must stay project-owned and must not enter platform Vite packaging');
|
|
135
|
-
}
|
|
136
|
-
if (kind === 'web-bundle' && packageStrategy === 'project-owned') {
|
|
137
|
-
invalid('A web-bundle requires platform-owned final packaging');
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
planVersion: 1,
|
|
141
|
-
source: {
|
|
142
|
-
commitHash,
|
|
143
|
-
sourceFingerprint: hash(source.sourceFingerprint, 'source.sourceFingerprint'),
|
|
144
|
-
sourceRulesVersion: sourceRules.data,
|
|
145
|
-
recipeDigest: hash(source.recipeDigest, 'source.recipeDigest'),
|
|
146
|
-
},
|
|
147
|
-
target: { channel: channel, format },
|
|
148
|
-
environment: {
|
|
149
|
-
packageManager: choice(environment.packageManager, PACKAGE_MANAGERS, 'environment.packageManager'),
|
|
150
|
-
executables: environment.executables.map((item, index) => text(item, `environment.executables[${index}]`)),
|
|
151
|
-
isolation: 'managed-delivery-v1',
|
|
152
|
-
maxDurationMs: Number(environment.maxDurationMs),
|
|
153
|
-
},
|
|
154
|
-
setup: {
|
|
155
|
-
install: 'frozen-lockfile',
|
|
156
|
-
prepareCommands: optionalCommands(setup.prepareCommands, 'setup.prepareCommands'),
|
|
157
|
-
generatedDirectories: relativePaths(setup.generatedDirectories, 'setup.generatedDirectories'),
|
|
158
|
-
},
|
|
159
|
-
compile: {
|
|
160
|
-
strategy,
|
|
161
|
-
...(hasCommand ? { command: command(compile.command, 'compile.command') } : {}),
|
|
162
|
-
scope,
|
|
163
|
-
output: {
|
|
164
|
-
kind,
|
|
165
|
-
directory: relativePath(text(output.directory, 'compile.output.directory'), 'compile.output.directory'),
|
|
166
|
-
entry: relativePath(text(output.entry, 'compile.output.entry'), 'compile.output.entry'),
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
delivery: {
|
|
170
|
-
channelRulesVersion: text(delivery.channelRulesVersion, 'delivery.channelRulesVersion', 64),
|
|
171
|
-
packageStrategy,
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function canonical(value) {
|
|
176
|
-
if (Array.isArray(value))
|
|
177
|
-
return `[${value.map(canonical).join(',')}]`;
|
|
178
|
-
if (value && typeof value === 'object') {
|
|
179
|
-
const entries = Object.entries(value)
|
|
180
|
-
.filter(([, item]) => item !== undefined)
|
|
181
|
-
.sort(([left], [right]) => left.localeCompare(right));
|
|
182
|
-
return `{${entries.map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`).join(',')}}`;
|
|
183
|
-
}
|
|
184
|
-
return JSON.stringify(value) ?? 'null';
|
|
185
|
-
}
|
|
186
|
-
export function buildPlanDigest(value) {
|
|
187
|
-
const plan = parseBuildPlan(value);
|
|
188
|
-
return createHash('sha256').update(`playcraft-build-plan-v1\0${canonical(plan)}`).digest('hex');
|
|
189
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { AgentBuildSourceRulesVersion } from '@playcraft/common/cloud-workspace/runtime';
|
|
2
|
-
import type { OutputFormat, Platform } from '../types.js';
|
|
3
|
-
import type { DeliveryCommand } from './types.js';
|
|
4
|
-
export type BuildPackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
5
|
-
export type BuildPlan = {
|
|
6
|
-
planVersion: 1;
|
|
7
|
-
source: {
|
|
8
|
-
commitHash: string;
|
|
9
|
-
sourceFingerprint: string;
|
|
10
|
-
sourceRulesVersion: AgentBuildSourceRulesVersion;
|
|
11
|
-
recipeDigest: string;
|
|
12
|
-
};
|
|
13
|
-
target: {
|
|
14
|
-
channel: Platform;
|
|
15
|
-
format: OutputFormat;
|
|
16
|
-
};
|
|
17
|
-
environment: {
|
|
18
|
-
packageManager: BuildPackageManager;
|
|
19
|
-
executables: string[];
|
|
20
|
-
isolation: 'managed-delivery-v1';
|
|
21
|
-
maxDurationMs: number;
|
|
22
|
-
};
|
|
23
|
-
setup: {
|
|
24
|
-
install: 'frozen-lockfile';
|
|
25
|
-
prepareCommands: DeliveryCommand[];
|
|
26
|
-
generatedDirectories: string[];
|
|
27
|
-
};
|
|
28
|
-
compile: {
|
|
29
|
-
strategy: 'project-command' | 'platform-vite' | 'project-owned';
|
|
30
|
-
command?: DeliveryCommand;
|
|
31
|
-
scope: 'shared' | 'per-channel';
|
|
32
|
-
output: {
|
|
33
|
-
kind: 'web-bundle' | 'channel-package';
|
|
34
|
-
directory: string;
|
|
35
|
-
entry: string;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
delivery: {
|
|
39
|
-
channelRulesVersion: string;
|
|
40
|
-
packageStrategy: 'single-html' | 'normalized-zip' | 'project-owned';
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export type RecipeBuildPlanOptions = {
|
|
44
|
-
commitHash: string;
|
|
45
|
-
sourceFingerprint: string;
|
|
46
|
-
sourceRulesVersion: AgentBuildSourceRulesVersion;
|
|
47
|
-
channel: Platform;
|
|
48
|
-
format: OutputFormat;
|
|
49
|
-
packageManager: BuildPackageManager;
|
|
50
|
-
maxDurationMs?: number;
|
|
51
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type DeliveryCommandIsolation = {
|
|
2
|
-
projectRoot: string;
|
|
3
|
-
isolatedRoot: string;
|
|
4
|
-
dependencyRoots?: readonly string[];
|
|
5
|
-
};
|
|
6
|
-
/** Construct argv for the existing managed launcher; never execute or fall back here. */
|
|
7
|
-
export declare function wrapDeliveryCommand(argv: readonly string[], options: DeliveryCommandIsolation): Promise<string[]>;
|