@playcraft/build 0.2.15-test-a → 0.2.16-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.
Files changed (122) hide show
  1. package/dist/base-builder.js +2 -41
  2. package/dist/engines/engine-detector.js +0 -4
  3. package/dist/engines/generic-adapter.js +19 -14
  4. package/dist/engines/playable-scripts-adapter.js +5 -2
  5. package/dist/index.d.ts +4 -21
  6. package/dist/index.js +2 -12
  7. package/dist/platforms/adikteev.js +0 -1
  8. package/dist/platforms/applovin.js +0 -1
  9. package/dist/platforms/base.d.ts +0 -4
  10. package/dist/platforms/base.js +6 -25
  11. package/dist/platforms/bigo.js +0 -1
  12. package/dist/platforms/facebook.js +0 -1
  13. package/dist/platforms/google.js +0 -1
  14. package/dist/platforms/inmobi.js +0 -1
  15. package/dist/platforms/ironsource.js +0 -1
  16. package/dist/platforms/liftoff.js +0 -1
  17. package/dist/platforms/mintegral.js +0 -1
  18. package/dist/platforms/moloco.js +0 -1
  19. package/dist/platforms/playcraft.js +0 -1
  20. package/dist/platforms/remerge.js +0 -1
  21. package/dist/platforms/snapchat.js +0 -1
  22. package/dist/platforms/tiktok.js +0 -1
  23. package/dist/platforms/unity.js +0 -1
  24. package/dist/types.d.ts +2 -10
  25. package/dist/validation/html-validator.d.ts +0 -5
  26. package/dist/validation/html-validator.js +17 -19
  27. package/dist/validation/index.d.ts +0 -5
  28. package/dist/validation/index.js +0 -5
  29. package/dist/validation/package-validator.d.ts +0 -2
  30. package/dist/validation/package-validator.js +64 -25
  31. package/dist/validation/profiles.d.ts +1 -13
  32. package/dist/validation/profiles.js +0 -27
  33. package/dist/validation/source-scanner.d.ts +0 -11
  34. package/dist/validation/source-scanner.js +2 -32
  35. package/dist/validation/types.d.ts +2 -201
  36. package/dist/validation/types.js +1 -1
  37. package/dist/validation/validation-runner.d.ts +2 -22
  38. package/dist/validation/validation-runner.js +3 -64
  39. package/dist/validation/zip-reader.d.ts +0 -7
  40. package/dist/validation/zip-reader.js +26 -159
  41. package/dist/vite/config-builder-generic.d.ts +1 -3
  42. package/dist/vite/config-builder-generic.js +7 -9
  43. package/dist/vite/config-builder.js +1 -1
  44. package/dist/vite/plugin-platform.js +30 -16
  45. package/dist/vite/plugin-source-builder.d.ts +14 -2
  46. package/dist/vite/plugin-source-builder.js +997 -61
  47. package/dist/vite-builder.d.ts +5 -4
  48. package/dist/vite-builder.js +34 -33
  49. package/package.json +4 -30
  50. package/dist/audio-source-files.d.ts +0 -5
  51. package/dist/audio-source-files.js +0 -135
  52. package/dist/delivery/agent-build-runner.d.ts +0 -44
  53. package/dist/delivery/agent-build-runner.js +0 -365
  54. package/dist/delivery/agent-build-source.d.ts +0 -8
  55. package/dist/delivery/agent-build-source.js +0 -25
  56. package/dist/delivery/artifact-descriptor.d.ts +0 -31
  57. package/dist/delivery/artifact-descriptor.js +0 -237
  58. package/dist/delivery/artifact-package.d.ts +0 -43
  59. package/dist/delivery/artifact-package.js +0 -283
  60. package/dist/delivery/build-plan.d.ts +0 -4
  61. package/dist/delivery/build-plan.js +0 -189
  62. package/dist/delivery/build-plan.types.d.ts +0 -51
  63. package/dist/delivery/build-plan.types.js +0 -1
  64. package/dist/delivery/command-isolation.d.ts +0 -21
  65. package/dist/delivery/command-isolation.js +0 -327
  66. package/dist/delivery/commands.d.ts +0 -5
  67. package/dist/delivery/commands.js +0 -146
  68. package/dist/delivery/files.d.ts +0 -9
  69. package/dist/delivery/files.js +0 -144
  70. package/dist/delivery/git-source-fingerprint.d.ts +0 -2
  71. package/dist/delivery/git-source-fingerprint.js +0 -58
  72. package/dist/delivery/isolated-source.d.ts +0 -5
  73. package/dist/delivery/isolated-source.js +0 -131
  74. package/dist/delivery/output-publication.d.ts +0 -21
  75. package/dist/delivery/output-publication.js +0 -444
  76. package/dist/delivery/project-delivery.d.ts +0 -6
  77. package/dist/delivery/project-delivery.js +0 -287
  78. package/dist/delivery/recipe-build-plan.d.ts +0 -4
  79. package/dist/delivery/recipe-build-plan.js +0 -53
  80. package/dist/delivery/recipe.d.ts +0 -20
  81. package/dist/delivery/recipe.js +0 -211
  82. package/dist/delivery/safe-path.d.ts +0 -2
  83. package/dist/delivery/safe-path.js +0 -18
  84. package/dist/delivery/types.d.ts +0 -76
  85. package/dist/delivery/types.js +0 -1
  86. package/dist/production-animation-presence.d.ts +0 -2
  87. package/dist/production-animation-presence.js +0 -146
  88. package/dist/production-inputs.d.ts +0 -30
  89. package/dist/production-inputs.js +0 -262
  90. package/dist/production-source-paths.d.ts +0 -5
  91. package/dist/production-source-paths.js +0 -27
  92. package/dist/redirect-policy.d.ts +0 -23
  93. package/dist/redirect-policy.js +0 -25
  94. package/dist/validation/artifact-qa.d.ts +0 -36
  95. package/dist/validation/artifact-qa.js +0 -263
  96. package/dist/validation/artifact-rules.d.ts +0 -39
  97. package/dist/validation/artifact-rules.js +0 -451
  98. package/dist/validation/artifact.d.ts +0 -14
  99. package/dist/validation/artifact.js +0 -188
  100. package/dist/validation/playwright-driver.d.ts +0 -37
  101. package/dist/validation/playwright-driver.js +0 -302
  102. package/dist/validation/runtime-cover.d.ts +0 -32
  103. package/dist/validation/runtime-cover.js +0 -120
  104. package/dist/validation/runtime-load.d.ts +0 -141
  105. package/dist/validation/runtime-load.js +0 -812
  106. package/dist/vite/source-builder-asset-paths.d.ts +0 -25
  107. package/dist/vite/source-builder-asset-paths.js +0 -154
  108. package/dist/vite/source-builder-esm.d.ts +0 -7
  109. package/dist/vite/source-builder-esm.js +0 -877
  110. package/dist/vite/source-builder-types.d.ts +0 -14
  111. package/dist/vite/source-builder-types.js +0 -1
  112. package/dist/vite/workspace.d.ts +0 -6
  113. package/dist/vite/workspace.js +0 -41
  114. package/dist/workspace-css-imports.d.ts +0 -2
  115. package/dist/workspace-css-imports.js +0 -139
  116. package/dist/workspace-model-source.d.ts +0 -14
  117. package/dist/workspace-model-source.js +0 -184
  118. package/dist/workspace-public-imports.d.ts +0 -11
  119. package/dist/workspace-public-imports.js +0 -232
  120. package/dist/workspace-public-source.d.ts +0 -15
  121. package/dist/workspace-public-source.js +0 -564
  122. package/templates/patches/playcraft-redirect-policy.js +0 -115
@@ -1,287 +0,0 @@
1
- import { cp, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
2
- import { randomUUID } from 'node:crypto';
3
- import path from 'node:path';
4
- import { deliveryContext, ProjectDeliveryError, readProjectDeliveryRecipe, recipeDigest, validateGeneratedDirectories, } from './recipe.js';
5
- import { deliverySourceFingerprint, deliveryProductionSourceSnapshot, checkOutputDirectory, entryRevision, inside, outputFingerprint, safeExistingPath, } from './files.js';
6
- import { requireExecutable, runDeliveryCommand } from './commands.js';
7
- import { buildIsolatedDelivery } from './isolated-source.js';
8
- import { hasPendingDeliveryOutputPublication } from './output-publication.js';
9
- function issue(error) {
10
- const code = error instanceof ProjectDeliveryError ? error.code : 'delivery_preparation_failed';
11
- const message = error instanceof Error ? error.message : String(error);
12
- return {
13
- code: code.slice(0, 128),
14
- message: (message || 'Delivery preparation failed').slice(0, 2000),
15
- ...(error instanceof ProjectDeliveryError && error.file
16
- ? { path: error.file.slice(0, 512) }
17
- : {}),
18
- };
19
- }
20
- function receiptFile(root, key, options) {
21
- return (options.receiptPath ??
22
- path.join(options.receiptDirectory ?? path.join(root, '.playcraft', 'delivery'), `${key}.json`));
23
- }
24
- async function contextFor(root, options) {
25
- const recipe = await readProjectDeliveryRecipe(root);
26
- if (!recipe)
27
- return undefined;
28
- const context = deliveryContext(recipe, options);
29
- const receiptPath = receiptFile(root, context.key, options);
30
- const production = await deliveryProductionSourceSnapshot(root, recipe.output.directory, receiptPath, recipe.generatedDirectories);
31
- const sourceFingerprint = production?.fingerprint ?? await deliverySourceFingerprint(root, recipe.output.directory, receiptPath, recipe.generatedDirectories);
32
- return { recipe, context, receiptPath, sourceFingerprint, recipeDigest: recipeDigest(recipe), production };
33
- }
34
- function inspection(value, status, errors = []) {
35
- return {
36
- status,
37
- checkedAt: new Date().toISOString(),
38
- errors,
39
- ...(value
40
- ? {
41
- recipe: value.recipe,
42
- sourceFingerprint: value.sourceFingerprint,
43
- ...(value.production ? { sourceRulesVersion: value.production.sourceRulesVersion } : {}),
44
- recipeDigest: value.recipeDigest,
45
- ...(value.context.scoped
46
- ? { channel: value.context.channel, format: value.context.format }
47
- : {}),
48
- }
49
- : {}),
50
- };
51
- }
52
- export async function inspectProjectDelivery(root, options = {}) {
53
- // The shared panel can show the latest verified scope; exports still request an exact scope.
54
- if (!options.channel && !options.format) {
55
- let recipe;
56
- try {
57
- recipe = await readProjectDeliveryRecipe(root);
58
- }
59
- catch (error) {
60
- return inspection(undefined, 'invalid', [issue(error)]);
61
- }
62
- if (recipe &&
63
- (recipe.output.kind === 'channel-package' ||
64
- /\{(?:channel|format)\}/.test(JSON.stringify(recipe)))) {
65
- const directory = options.receiptDirectory ?? path.join(root, '.playcraft', 'delivery');
66
- const files = options.receiptPath
67
- ? [options.receiptPath]
68
- : (await readdir(directory).catch(() => []))
69
- .filter((file) => /^[a-z][a-z0-9-]{0,63}-(?:html|zip)\.json$/.test(file))
70
- .slice(0, 128)
71
- .map((file) => path.join(directory, file));
72
- const receipts = await Promise.all(files.map(async (file) => {
73
- try {
74
- return JSON.parse(await readFile(file, 'utf8'));
75
- }
76
- catch {
77
- return undefined;
78
- }
79
- }));
80
- for (const receipt of receipts
81
- .filter((item) => Boolean(item?.channel && item?.format))
82
- .sort((a, b) => String(b.verifiedAt).localeCompare(String(a.verifiedAt)))) {
83
- const result = await inspectProjectDelivery(root, {
84
- ...options,
85
- channel: receipt.channel,
86
- format: receipt.format,
87
- });
88
- if (result.status === 'ready')
89
- return result;
90
- }
91
- return {
92
- ...inspection(undefined, 'stale', [
93
- {
94
- code: 'delivery_preparation_missing',
95
- message: 'Prepare a concrete delivery channel and format',
96
- },
97
- ]),
98
- recipe,
99
- recipeDigest: recipeDigest(recipe),
100
- };
101
- }
102
- }
103
- let value;
104
- try {
105
- value = await contextFor(root, options);
106
- }
107
- catch (error) {
108
- return inspection(undefined, 'invalid', [issue(error)]);
109
- }
110
- if (!value)
111
- return inspection(undefined, 'missing', [
112
- {
113
- code: 'delivery_recipe_missing',
114
- message: 'Initialize playcraft.config.json build.delivery for this project',
115
- },
116
- ]);
117
- try {
118
- if (value.production && await hasPendingDeliveryOutputPublication({
119
- root, outputDirectory: value.context.outputDirectory, entry: value.context.entry,
120
- sourceFingerprint: value.sourceFingerprint, recipeDigest: value.recipeDigest,
121
- receiptDirectory: path.dirname(value.receiptPath), key: value.context.key,
122
- }))
123
- return inspection(value, 'stale', [{ code: 'delivery_publication_pending', message: 'The previous output publication must be reconciled by an authorized preparation' }]);
124
- }
125
- catch (error) {
126
- return inspection(value, 'stale', [issue(error)]);
127
- }
128
- let receipt;
129
- try {
130
- receipt = JSON.parse(await readFile(value.receiptPath, 'utf8'));
131
- }
132
- catch {
133
- return inspection(value, 'stale', [
134
- {
135
- code: 'delivery_preparation_missing',
136
- message: 'Run delivery preparation for the current project',
137
- },
138
- ]);
139
- }
140
- if (receipt.version !== 1 ||
141
- receipt.sourceRulesVersion !== value.production?.sourceRulesVersion ||
142
- receipt.recipeDigest !== value.recipeDigest ||
143
- receipt.sourceFingerprint !== value.sourceFingerprint ||
144
- receipt.scope !== value.context.key ||
145
- typeof receipt.verifiedAt !== 'string' ||
146
- !Number.isFinite(Date.parse(receipt.verifiedAt))) {
147
- return inspection(value, 'stale', [
148
- {
149
- code: 'delivery_preparation_stale',
150
- message: 'The delivery recipe or project source changed; prepare it again',
151
- },
152
- ]);
153
- }
154
- try {
155
- const output = await outputFingerprint(root, value.context.outputDirectory, value.context.entry);
156
- if (output !== receipt.outputFingerprint)
157
- throw new ProjectDeliveryError('delivery_output_changed', 'The verified delivery output changed; prepare it again');
158
- }
159
- catch (error) {
160
- return inspection(value, 'stale', [issue(error)]);
161
- }
162
- return inspection(value, 'ready');
163
- }
164
- async function buildProjectOutput(root, value, options) {
165
- if (value.production) {
166
- const output = await buildIsolatedDelivery(root, value.production, value.recipe, options, (isolated, isolation) => buildDirectProjectOutput(isolated, value, options, isolation));
167
- const current = await contextFor(root, options);
168
- if (!current?.production || current.sourceFingerprint !== value.sourceFingerprint || current.recipeDigest !== value.recipeDigest)
169
- throw new ProjectDeliveryError('delivery_source_changed', 'Production source or recipe changed while preparing delivery');
170
- return output;
171
- }
172
- return buildDirectProjectOutput(root, value, options);
173
- }
174
- async function buildDirectProjectOutput(root, value, options, isolation) {
175
- await checkOutputDirectory(root, value.context.outputDirectory);
176
- for (const executable of value.recipe.toolchain?.executables ?? []) {
177
- await requireExecutable(root, value.context.replace(executable), root, options, isolation);
178
- }
179
- const previous = await entryRevision(root, value.context.outputDirectory, value.context.entry);
180
- for (const command of [...(value.recipe.prepareCommands ?? []), value.recipe.command]) {
181
- await runDeliveryCommand(root, command, value.context.replace, options, isolation);
182
- }
183
- await validateGeneratedDirectories(root, value.recipe);
184
- const after = await deliverySourceFingerprint(root, value.recipe.output.directory, value.receiptPath, value.recipe.generatedDirectories);
185
- if (after !== value.sourceFingerprint)
186
- throw new ProjectDeliveryError('delivery_source_changed', 'Project source changed while preparing delivery; prepare the new source again');
187
- const output = await outputFingerprint(root, value.context.outputDirectory, value.context.entry);
188
- const current = await entryRevision(root, value.context.outputDirectory, value.context.entry);
189
- if (previous !== undefined && previous === current)
190
- throw new ProjectDeliveryError('delivery_output_not_refreshed', 'The delivery command did not refresh its declared entry', value.context.entry);
191
- return output;
192
- }
193
- export async function prepareProjectDelivery(root, options = {}) {
194
- let value;
195
- try {
196
- value = await contextFor(root, options);
197
- }
198
- catch (error) {
199
- return inspection(undefined, 'invalid', [issue(error)]);
200
- }
201
- if (!value)
202
- return inspection(undefined, 'missing', [
203
- {
204
- code: 'delivery_recipe_missing',
205
- message: 'Initialize playcraft.config.json build.delivery for this project',
206
- },
207
- ]);
208
- // Invalidate the previous receipt before running: a failed recheck cannot leave a stale ready result.
209
- try {
210
- await rm(value.receiptPath, { force: true });
211
- const output = await buildProjectOutput(root, value, options);
212
- const receipt = {
213
- version: 1,
214
- ...(value.production ? { sourceRulesVersion: value.production.sourceRulesVersion } : {}),
215
- recipeDigest: value.recipeDigest,
216
- sourceFingerprint: value.sourceFingerprint,
217
- outputFingerprint: output,
218
- scope: value.context.key,
219
- verifiedAt: new Date().toISOString(),
220
- ...(value.context.scoped
221
- ? { channel: value.context.channel, format: value.context.format }
222
- : {}),
223
- };
224
- await mkdir(path.dirname(value.receiptPath), { recursive: true, mode: 0o700 });
225
- const temporary = `${value.receiptPath}.${randomUUID()}.tmp`;
226
- try {
227
- await writeFile(temporary, `${JSON.stringify(receipt, null, 2)}\n`, {
228
- mode: 0o600,
229
- flag: 'wx',
230
- });
231
- await rename(temporary, value.receiptPath);
232
- }
233
- finally {
234
- await rm(temporary, { force: true });
235
- }
236
- return inspection(value, 'ready');
237
- }
238
- catch (error) {
239
- return inspection(value, 'stale', [issue(error)]);
240
- }
241
- }
242
- /** Executes the same project recipe in CLI and queue workers; platform packing remains platform-owned. */
243
- export async function executeProjectDelivery(root, options) {
244
- const value = await contextFor(root, options);
245
- if (!value) {
246
- if (options.expectedPreparation)
247
- throw new ProjectDeliveryError('delivery_recipe_missing', 'The prepared delivery recipe is missing from this source snapshot');
248
- return undefined;
249
- }
250
- if (process.env.PLAYCRAFT_DELIVERY_EXECUTING === '1')
251
- throw new ProjectDeliveryError('delivery_recipe_recursive', 'The delivery command called the delivery builder recursively; use the project compiler or bundler command directly');
252
- if (options.expectedPreparation &&
253
- (options.expectedPreparation.recipeDigest !== value.recipeDigest ||
254
- options.expectedPreparation.sourceRulesVersion !== value.production?.sourceRulesVersion ||
255
- options.expectedPreparation.sourceFingerprint !== value.sourceFingerprint)) {
256
- throw new ProjectDeliveryError('delivery_preparation_stale', 'This source snapshot does not match the prepared delivery recipe');
257
- }
258
- if (options.expectedPreparation &&
259
- value.context.scoped &&
260
- (options.expectedPreparation.channel !== value.context.channel ||
261
- options.expectedPreparation.format !== value.context.format)) {
262
- throw new ProjectDeliveryError('delivery_preparation_scope_mismatch', 'This preparation was verified for a different delivery channel or format');
263
- }
264
- await buildProjectOutput(root, value, options);
265
- const source = await safeExistingPath(root, value.context.outputDirectory);
266
- const destination = path.resolve(options.outputDir);
267
- if (source !== destination) {
268
- if (inside(source, destination) || inside(destination, source))
269
- throw new ProjectDeliveryError('delivery_output_overlap', 'The collected output directory must not contain the project output');
270
- await mkdir(destination, { recursive: true });
271
- await cp(source, destination, { recursive: true, force: true, dereference: false });
272
- }
273
- // Keep an HTML alias beside the declared entry: moving it to the output root would break URLs.
274
- const entry = path.join(destination, value.context.entry);
275
- const collectedDirectory = value.recipe.output.kind === 'web-bundle' ? path.dirname(entry) : destination;
276
- if (value.recipe.output.kind === 'web-bundle' && path.basename(entry) !== 'index.html') {
277
- await cp(entry, path.join(collectedDirectory, 'index.html'));
278
- }
279
- return {
280
- kind: value.recipe.output.kind,
281
- directory: collectedDirectory,
282
- entry,
283
- recipeDigest: value.recipeDigest,
284
- sourceFingerprint: value.sourceFingerprint,
285
- ...(value.production ? { sourceRulesVersion: value.production.sourceRulesVersion } : {}),
286
- };
287
- }
@@ -1,4 +0,0 @@
1
- import type { BuildPlan, RecipeBuildPlanOptions } from './build-plan.types.js';
2
- import type { ProjectDeliveryRecipe } from './types.js';
3
- /** Maps a committed v1 recipe without changing its command, paths, ordering or legacy digest. */
4
- export declare function createRecipeBuildPlan(value: ProjectDeliveryRecipe, options: RecipeBuildPlanOptions): BuildPlan;
@@ -1,53 +0,0 @@
1
- import { CHANNEL_RULES_VERSION, getChannelCapability } from '../validation/profiles.js';
2
- import { parseBuildPlan } from './build-plan.js';
3
- import { deliveryContext, parseProjectDeliveryRecipe, ProjectDeliveryError, recipeDigest } from './recipe.js';
4
- /** Maps a committed v1 recipe without changing its command, paths, ordering or legacy digest. */
5
- export function createRecipeBuildPlan(value, options) {
6
- const recipe = parseProjectDeliveryRecipe(value);
7
- const capability = getChannelCapability(options.channel);
8
- if (!capability.supportedFormats.includes(options.format)) {
9
- throw new ProjectDeliveryError('delivery_context_invalid', `${options.channel} does not support ${options.format} delivery`);
10
- }
11
- // Validates the concrete channel/format entry while leaving the recipe argv and cwd untouched.
12
- deliveryContext(recipe, options);
13
- const projectOwned = recipe.output.kind === 'channel-package';
14
- return parseBuildPlan({
15
- planVersion: 1,
16
- source: {
17
- commitHash: options.commitHash,
18
- sourceFingerprint: options.sourceFingerprint,
19
- sourceRulesVersion: options.sourceRulesVersion,
20
- recipeDigest: recipeDigest(recipe),
21
- },
22
- target: { channel: options.channel, format: options.format },
23
- environment: {
24
- packageManager: options.packageManager,
25
- executables: [...(recipe.toolchain?.executables ?? [])],
26
- isolation: 'managed-delivery-v1',
27
- maxDurationMs: options.maxDurationMs ?? 1800000,
28
- },
29
- setup: {
30
- install: 'frozen-lockfile',
31
- prepareCommands: (recipe.prepareCommands ?? []).map((command) => ({
32
- ...command,
33
- argv: [...command.argv],
34
- })),
35
- generatedDirectories: [...(recipe.generatedDirectories ?? [])],
36
- },
37
- compile: {
38
- strategy: projectOwned ? 'project-owned' : 'project-command',
39
- command: { ...recipe.command, argv: [...recipe.command.argv] },
40
- // A v1 recipe has no proof that its command ignores channel-specific inputs.
41
- scope: 'per-channel',
42
- output: { ...recipe.output },
43
- },
44
- delivery: {
45
- channelRulesVersion: CHANNEL_RULES_VERSION,
46
- packageStrategy: projectOwned
47
- ? 'project-owned'
48
- : options.format === 'zip'
49
- ? 'normalized-zip'
50
- : 'single-html',
51
- },
52
- });
53
- }
@@ -1,20 +0,0 @@
1
- import type { ProjectDeliveryOptions, ProjectDeliveryRecipe } from './types.js';
2
- export declare class ProjectDeliveryError extends Error {
3
- readonly code: string;
4
- readonly file?: string | undefined;
5
- constructor(code: string, message: string, file?: string | undefined);
6
- }
7
- export declare function relativePath(value: string, field: string, allowRoot?: boolean): string;
8
- export declare function parseProjectDeliveryRecipe(value: unknown): ProjectDeliveryRecipe;
9
- export declare function readProjectDeliveryRecipe(root: string): Promise<ProjectDeliveryRecipe | undefined>;
10
- export declare function validateGeneratedDirectories(root: string, recipe: ProjectDeliveryRecipe): Promise<void>;
11
- export declare function recipeDigest(recipe: ProjectDeliveryRecipe): string;
12
- export declare function deliveryContext(recipe: ProjectDeliveryRecipe, options: ProjectDeliveryOptions): {
13
- channel: string;
14
- format: "html" | "zip";
15
- replace: (value: string) => string;
16
- outputDirectory: string;
17
- entry: string;
18
- scoped: boolean;
19
- key: string;
20
- };
@@ -1,211 +0,0 @@
1
- import { lstat, readFile } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { createHash } from 'node:crypto';
4
- export class ProjectDeliveryError extends Error {
5
- constructor(code, message, file) {
6
- super(message);
7
- this.code = code;
8
- this.file = file;
9
- this.name = 'ProjectDeliveryError';
10
- }
11
- }
12
- function record(value) {
13
- return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
14
- }
15
- function keys(value, allowed, field) {
16
- if (Object.keys(value).some((key) => !allowed.includes(key))) {
17
- throw new ProjectDeliveryError('delivery_recipe_invalid', `Unsupported field in ${field}`);
18
- }
19
- }
20
- function text(value, field) {
21
- if (typeof value !== 'string' || !value.trim() || value.length > 4096 || value.includes('\0')) {
22
- throw new ProjectDeliveryError('delivery_recipe_invalid', `Invalid ${field}`);
23
- }
24
- return value;
25
- }
26
- export function relativePath(value, field, allowRoot = false) {
27
- if (value.includes('\\') ||
28
- path.posix.isAbsolute(value) ||
29
- /^[A-Za-z]:/.test(value) ||
30
- value.split('/').includes('..') ||
31
- (!allowRoot && path.posix.normalize(value) === '.')) {
32
- throw new ProjectDeliveryError('delivery_recipe_invalid', `${field} must stay inside the project`, value);
33
- }
34
- return value;
35
- }
36
- function command(value, field) {
37
- if (!record(value))
38
- throw new ProjectDeliveryError('delivery_recipe_invalid', `${field} must be an object`);
39
- keys(value, ['argv', 'cwd', 'timeoutMs'], field);
40
- if (!Array.isArray(value.argv) || !value.argv.length || value.argv.length > 128) {
41
- throw new ProjectDeliveryError('delivery_recipe_invalid', `${field}.argv must be a nonempty array`);
42
- }
43
- const argv = value.argv.map((arg, index) => text(arg, `${field}.argv[${index}]`));
44
- const cwd = value.cwd === undefined
45
- ? undefined
46
- : relativePath(text(value.cwd, `${field}.cwd`), `${field}.cwd`, true);
47
- if (value.timeoutMs !== undefined &&
48
- (!Number.isInteger(value.timeoutMs) ||
49
- Number(value.timeoutMs) < 1000 ||
50
- Number(value.timeoutMs) > 1800000)) {
51
- throw new ProjectDeliveryError('delivery_recipe_invalid', `${field}.timeoutMs must be between 1000 and 1800000`);
52
- }
53
- return {
54
- argv,
55
- ...(cwd !== undefined ? { cwd } : {}),
56
- ...(value.timeoutMs !== undefined ? { timeoutMs: Number(value.timeoutMs) } : {}),
57
- };
58
- }
59
- export function parseProjectDeliveryRecipe(value) {
60
- if (!record(value) || value.version !== 1)
61
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'build.delivery.version must be 1');
62
- keys(value, ['version', 'command', 'prepareCommands', 'generatedDirectories', 'output', 'toolchain'], 'build.delivery');
63
- if (!record(value.output) ||
64
- !['web-bundle', 'channel-package'].includes(String(value.output.kind))) {
65
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Invalid delivery output kind');
66
- }
67
- keys(value.output, ['kind', 'directory', 'entry'], 'output');
68
- const directory = relativePath(text(value.output.directory, 'output.directory'), 'output.directory');
69
- const entry = relativePath(text(value.output.entry, 'output.entry'), 'output.entry');
70
- let prepareCommands;
71
- if (value.prepareCommands !== undefined) {
72
- if (!Array.isArray(value.prepareCommands) || value.prepareCommands.length > 16)
73
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Invalid prepareCommands');
74
- prepareCommands = value.prepareCommands.map((item, index) => command(item, `prepareCommands[${index}]`));
75
- }
76
- let toolchain;
77
- if (value.toolchain !== undefined) {
78
- if (!record(value.toolchain) ||
79
- !Array.isArray(value.toolchain.executables) ||
80
- value.toolchain.executables.length > 32) {
81
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Invalid toolchain.executables');
82
- }
83
- keys(value.toolchain, ['executables'], 'toolchain');
84
- toolchain = {
85
- executables: value.toolchain.executables.map((item) => text(item, 'toolchain.executables')),
86
- };
87
- }
88
- const buildCommand = command(value.command, 'command');
89
- let generatedDirectories;
90
- if (value.generatedDirectories !== undefined) {
91
- if (!Array.isArray(value.generatedDirectories) || value.generatedDirectories.length > 32)
92
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Invalid generatedDirectories');
93
- const protectedInputs = [
94
- 'playcraft.config.json',
95
- 'package.json',
96
- 'pnpm-lock.yaml',
97
- 'package-lock.json',
98
- 'npm-shrinkwrap.json',
99
- 'yarn.lock',
100
- 'bun.lock',
101
- 'bun.lockb',
102
- 'scripts',
103
- ];
104
- for (const item of [buildCommand, ...(prepareCommands ?? [])]) {
105
- for (const filename of [
106
- 'playcraft.config.json',
107
- 'package.json',
108
- 'pnpm-lock.yaml',
109
- 'package-lock.json',
110
- 'yarn.lock',
111
- ])
112
- protectedInputs.push(path.posix.normalize(path.posix.join(item.cwd ?? '.', filename)));
113
- for (const argument of item.argv) {
114
- if (argument.startsWith('-') ||
115
- path.posix.isAbsolute(argument) ||
116
- /^[A-Za-z]:/.test(argument))
117
- continue;
118
- if (argument.includes('/') || /\.(?:[cm]?[jt]sx?|sh|bash|py|rb|pl)$/i.test(argument))
119
- protectedInputs.push(path.posix.normalize(path.posix.join(item.cwd ?? '.', argument)));
120
- }
121
- }
122
- generatedDirectories = value.generatedDirectories.map((item) => {
123
- const directory = path.posix.normalize(relativePath(text(item, 'generatedDirectories'), 'generatedDirectories'));
124
- if (/[{}]/.test(directory) ||
125
- protectedInputs.some((input) => input === directory || input.startsWith(`${directory}/`)))
126
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Generated directories must not contain project configuration, lockfiles or build scripts', directory);
127
- return directory;
128
- });
129
- if (new Set(generatedDirectories).size !== generatedDirectories.length)
130
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'Duplicate generatedDirectories');
131
- }
132
- return {
133
- version: 1,
134
- command: buildCommand,
135
- output: {
136
- kind: value.output.kind,
137
- directory,
138
- entry,
139
- },
140
- ...(prepareCommands ? { prepareCommands } : {}),
141
- ...(generatedDirectories ? { generatedDirectories } : {}),
142
- ...(toolchain ? { toolchain } : {}),
143
- };
144
- }
145
- export async function readProjectDeliveryRecipe(root) {
146
- let source;
147
- try {
148
- source = await readFile(path.join(root, 'playcraft.config.json'), 'utf8');
149
- }
150
- catch (error) {
151
- if (error.code === 'ENOENT')
152
- return undefined;
153
- throw error;
154
- }
155
- let config;
156
- try {
157
- config = JSON.parse(source);
158
- }
159
- catch {
160
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'playcraft.config.json is not valid JSON');
161
- }
162
- if (!record(config))
163
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'playcraft.config.json must be an object');
164
- if (!record(config.build) || config.build.delivery === undefined)
165
- return undefined;
166
- const recipe = parseProjectDeliveryRecipe(config.build.delivery);
167
- await validateGeneratedDirectories(root, recipe);
168
- return recipe;
169
- }
170
- export async function validateGeneratedDirectories(root, recipe) {
171
- for (const directory of recipe.generatedDirectories ?? []) {
172
- try {
173
- const info = await lstat(path.join(root, directory));
174
- if (!info.isDirectory() || info.isSymbolicLink())
175
- throw new ProjectDeliveryError('delivery_recipe_invalid', 'A generated directory must be an actual project directory', directory);
176
- }
177
- catch (error) {
178
- if (error.code !== 'ENOENT')
179
- throw error;
180
- }
181
- }
182
- }
183
- export function recipeDigest(recipe) {
184
- return createHash('sha256').update(JSON.stringify(recipe)).digest('hex');
185
- }
186
- export function deliveryContext(recipe, options) {
187
- const templated = /\{(?:channel|format)\}/.test(JSON.stringify(recipe));
188
- const scoped = recipe.output.kind === 'channel-package' || templated;
189
- if (scoped && (!options.channel || !options.format))
190
- throw new ProjectDeliveryError('delivery_context_required', 'This recipe requires a channel and format');
191
- const channel = options.channel ?? 'playcraft';
192
- const format = options.format ?? 'html';
193
- if (!/^[a-z][a-z0-9-]{0,63}$/.test(channel) || !['html', 'zip'].includes(format))
194
- throw new ProjectDeliveryError('delivery_context_invalid', 'Invalid delivery channel or format');
195
- const replace = (value) => value.replace(/\{channel\}/g, channel).replace(/\{format\}/g, format);
196
- const outputDirectory = relativePath(replace(recipe.output.directory), 'output.directory');
197
- const entry = relativePath(replace(recipe.output.entry), 'output.entry');
198
- const extension = path.extname(entry).toLowerCase();
199
- if (recipe.output.kind === 'web-bundle' ? extension !== '.html' : extension !== `.${format}`) {
200
- throw new ProjectDeliveryError('delivery_output_format_mismatch', 'The declared entry does not match the output kind or requested format', entry);
201
- }
202
- return {
203
- channel,
204
- format,
205
- replace,
206
- outputDirectory,
207
- entry,
208
- scoped,
209
- key: scoped ? `${channel}-${format}` : 'web-bundle',
210
- };
211
- }
@@ -1,2 +0,0 @@
1
- export declare function inside(root: string, target: string): boolean;
2
- export declare function safeExistingPath(root: string, relative: string): Promise<string>;
@@ -1,18 +0,0 @@
1
- import { realpath } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { ProjectDeliveryError } from './recipe.js';
4
- export function inside(root, target) {
5
- const relative = path.relative(root, target);
6
- return (relative === '' ||
7
- (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative)));
8
- }
9
- export async function safeExistingPath(root, relative) {
10
- const base = await realpath(root);
11
- const target = await realpath(path.resolve(root, relative)).catch(() => {
12
- throw new ProjectDeliveryError('delivery_path_missing', `Required delivery path is missing: ${relative}`, relative);
13
- });
14
- if (!inside(base, target)) {
15
- throw new ProjectDeliveryError('delivery_path_outside_project', 'Delivery paths must stay inside the project', relative);
16
- }
17
- return target;
18
- }