@playcraft/build 0.1.92-test → 0.1.94-test-a

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 (113) hide show
  1. package/dist/audio-source-files.d.ts +5 -0
  2. package/dist/audio-source-files.js +135 -0
  3. package/dist/base-builder.js +41 -2
  4. package/dist/delivery/agent-build-runner.d.ts +44 -0
  5. package/dist/delivery/agent-build-runner.js +365 -0
  6. package/dist/delivery/agent-build-source.d.ts +8 -0
  7. package/dist/delivery/agent-build-source.js +25 -0
  8. package/dist/delivery/artifact-descriptor.d.ts +31 -0
  9. package/dist/delivery/artifact-descriptor.js +237 -0
  10. package/dist/delivery/artifact-package.d.ts +43 -0
  11. package/dist/delivery/artifact-package.js +283 -0
  12. package/dist/delivery/build-plan.d.ts +4 -0
  13. package/dist/delivery/build-plan.js +189 -0
  14. package/dist/delivery/build-plan.types.d.ts +51 -0
  15. package/dist/delivery/build-plan.types.js +1 -0
  16. package/dist/delivery/command-isolation.d.ts +20 -0
  17. package/dist/delivery/command-isolation.js +324 -0
  18. package/dist/delivery/commands.d.ts +5 -0
  19. package/dist/delivery/commands.js +146 -0
  20. package/dist/delivery/files.d.ts +9 -0
  21. package/dist/delivery/files.js +144 -0
  22. package/dist/delivery/git-source-fingerprint.d.ts +2 -0
  23. package/dist/delivery/git-source-fingerprint.js +58 -0
  24. package/dist/delivery/isolated-source.d.ts +5 -0
  25. package/dist/delivery/isolated-source.js +126 -0
  26. package/dist/delivery/output-publication.d.ts +21 -0
  27. package/dist/delivery/output-publication.js +444 -0
  28. package/dist/delivery/project-delivery.d.ts +6 -0
  29. package/dist/delivery/project-delivery.js +287 -0
  30. package/dist/delivery/recipe-build-plan.d.ts +4 -0
  31. package/dist/delivery/recipe-build-plan.js +53 -0
  32. package/dist/delivery/recipe.d.ts +20 -0
  33. package/dist/delivery/recipe.js +211 -0
  34. package/dist/delivery/safe-path.d.ts +2 -0
  35. package/dist/delivery/safe-path.js +18 -0
  36. package/dist/delivery/types.d.ts +76 -0
  37. package/dist/delivery/types.js +1 -0
  38. package/dist/engines/engine-detector.js +4 -0
  39. package/dist/engines/generic-adapter.js +14 -19
  40. package/dist/index.d.ts +19 -4
  41. package/dist/index.js +11 -2
  42. package/dist/platforms/adikteev.js +1 -0
  43. package/dist/platforms/applovin.js +1 -0
  44. package/dist/platforms/base.js +2 -2
  45. package/dist/platforms/bigo.js +1 -0
  46. package/dist/platforms/facebook.js +1 -0
  47. package/dist/platforms/google.js +1 -0
  48. package/dist/platforms/inmobi.js +1 -0
  49. package/dist/platforms/ironsource.js +1 -0
  50. package/dist/platforms/liftoff.js +1 -0
  51. package/dist/platforms/mintegral.js +1 -0
  52. package/dist/platforms/moloco.js +1 -0
  53. package/dist/platforms/playcraft.js +1 -0
  54. package/dist/platforms/remerge.js +1 -0
  55. package/dist/platforms/snapchat.js +1 -0
  56. package/dist/platforms/tiktok.js +1 -0
  57. package/dist/platforms/unity.js +1 -0
  58. package/dist/production-animation-presence.d.ts +2 -0
  59. package/dist/production-animation-presence.js +146 -0
  60. package/dist/production-inputs.d.ts +30 -0
  61. package/dist/production-inputs.js +262 -0
  62. package/dist/production-source-paths.d.ts +5 -0
  63. package/dist/production-source-paths.js +27 -0
  64. package/dist/types.d.ts +5 -0
  65. package/dist/validation/artifact-qa.d.ts +44 -0
  66. package/dist/validation/artifact-qa.js +170 -0
  67. package/dist/validation/artifact-rules.d.ts +28 -0
  68. package/dist/validation/artifact-rules.js +440 -0
  69. package/dist/validation/artifact.d.ts +14 -0
  70. package/dist/validation/artifact.js +188 -0
  71. package/dist/validation/html-validator.d.ts +5 -0
  72. package/dist/validation/html-validator.js +19 -17
  73. package/dist/validation/index.d.ts +4 -0
  74. package/dist/validation/index.js +4 -0
  75. package/dist/validation/package-validator.d.ts +2 -0
  76. package/dist/validation/package-validator.js +25 -64
  77. package/dist/validation/profiles.d.ts +13 -1
  78. package/dist/validation/profiles.js +27 -0
  79. package/dist/validation/runtime-load.d.ts +89 -0
  80. package/dist/validation/runtime-load.js +654 -0
  81. package/dist/validation/source-scanner.d.ts +11 -0
  82. package/dist/validation/source-scanner.js +32 -2
  83. package/dist/validation/types.d.ts +155 -2
  84. package/dist/validation/types.js +1 -1
  85. package/dist/validation/validation-runner.d.ts +22 -2
  86. package/dist/validation/validation-runner.js +68 -3
  87. package/dist/validation/zip-reader.d.ts +7 -0
  88. package/dist/validation/zip-reader.js +159 -26
  89. package/dist/vite/config-builder-generic.d.ts +3 -1
  90. package/dist/vite/config-builder-generic.js +9 -7
  91. package/dist/vite/config-builder.js +1 -1
  92. package/dist/vite/plugin-platform.js +30 -54
  93. package/dist/vite/plugin-source-builder.d.ts +2 -14
  94. package/dist/vite/plugin-source-builder.js +61 -997
  95. package/dist/vite/source-builder-asset-paths.d.ts +25 -0
  96. package/dist/vite/source-builder-asset-paths.js +154 -0
  97. package/dist/vite/source-builder-esm.d.ts +7 -0
  98. package/dist/vite/source-builder-esm.js +877 -0
  99. package/dist/vite/source-builder-types.d.ts +14 -0
  100. package/dist/vite/source-builder-types.js +1 -0
  101. package/dist/vite/workspace.d.ts +6 -0
  102. package/dist/vite/workspace.js +41 -0
  103. package/dist/vite-builder.d.ts +4 -5
  104. package/dist/vite-builder.js +33 -34
  105. package/dist/workspace-css-imports.d.ts +2 -0
  106. package/dist/workspace-css-imports.js +139 -0
  107. package/dist/workspace-model-source.d.ts +14 -0
  108. package/dist/workspace-model-source.js +184 -0
  109. package/dist/workspace-public-imports.d.ts +11 -0
  110. package/dist/workspace-public-imports.js +232 -0
  111. package/dist/workspace-public-source.d.ts +15 -0
  112. package/dist/workspace-public-source.js +564 -0
  113. package/package.json +16 -4
@@ -0,0 +1,564 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { constants } from 'node:fs';
3
+ import { builtinModules } from 'node:module';
4
+ import { lstat, open, readdir, realpath } from 'node:fs/promises';
5
+ import { join, posix } from 'node:path';
6
+ import JSON5 from 'json5';
7
+ import { compileLevelEditorDefinition, projectWorkspacePublicDeclaration, workspacePublicPreviewSdkManifestSchema, workspaceRelativePathSchema, WORKSPACE_PUBLIC_DECLARATION_PATH, WORKSPACE_PREVIEW_RUNTIME_DIRECTORY, } from '@playcraft/common/cloud-workspace/runtime';
8
+ import { readWorkspaceModelSourceClosure } from './workspace-model-source.js';
9
+ import { workspacePublicSourceDependencies, WorkspacePublicSourceError } from './workspace-public-imports.js';
10
+ import { productionSourcePathAllowed } from './production-source-paths.js';
11
+ export { WorkspacePublicSourceError } from './workspace-public-imports.js';
12
+ const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
13
+ const skipped = new Set(['node_modules', 'dist', 'dist-all', 'build', 'coverage', 'parameter-admission', 'work']);
14
+ const same = (a, b) => a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs && a.ctimeMs === b.ctimeMs;
15
+ const MAX_FILES = 4096, MAX_TOTAL = 256 * 1024 * 1024;
16
+ const plain = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
17
+ function registryVersion(version) {
18
+ if (version.startsWith('npm:')) {
19
+ const alias = /^npm:((?:@[a-z0-9._-]+\/)?[a-z0-9._-]+)@(.+)$/i.exec(version);
20
+ return Boolean(alias && !alias[2].startsWith('npm:') && registryVersion(alias[2]));
21
+ }
22
+ if (/^[a-z][a-z0-9._-]{0,127}$/i.test(version))
23
+ return true;
24
+ const part = '(?:\\d+|[xX*])(?:\\.(?:\\d+|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?';
25
+ const range = new RegExp(`^(?:(?:\\^|~|>=|<=|>|<|=)?\\s*${part})(?:\\s+(?:(?:>=|<=|>|<|=)?\\s*${part}))*$`);
26
+ const hyphen = new RegExp(`^${part}\\s+-\\s+${part}$`);
27
+ return version.split('||').every(value => range.test(value.trim()) || hyphen.test(value.trim()));
28
+ }
29
+ function failure(code, file) { throw new WorkspacePublicSourceError(code, file); }
30
+ function publicPath(path, hidden = false) {
31
+ const allowed = productionSourcePathAllowed(path) || hidden && path.startsWith('.playcraft/') && productionSourcePathAllowed(path.slice('.playcraft/'.length));
32
+ if (!workspaceRelativePathSchema.safeParse(path).success || !allowed ||
33
+ path.split('/').some(part => skipped.has(part.toLowerCase()) || /(?:secret|credential|private[-_.]?key)/i.test(part)))
34
+ return failure('workspace_public_source_path_forbidden', path);
35
+ return path;
36
+ }
37
+ class SourceReader {
38
+ constructor(root) {
39
+ this.root = root;
40
+ this.observedFiles = new Map();
41
+ this.total = 0;
42
+ }
43
+ async read(path, maximum = 64 * 1024 * 1024) {
44
+ publicPath(path, true);
45
+ const cached = this.observedFiles.get(path);
46
+ if (cached) {
47
+ if (cached.body.length > maximum)
48
+ failure('workspace_public_source_limit', path);
49
+ return cached;
50
+ }
51
+ const file = await this.physical(path, maximum);
52
+ if (this.observedFiles.size >= MAX_FILES || this.total + file.body.length > MAX_TOTAL)
53
+ failure('workspace_public_source_limit', path);
54
+ this.total += file.body.length;
55
+ this.observedFiles.set(path, file);
56
+ return file;
57
+ }
58
+ async physical(path, maximum) {
59
+ publicPath(path, true);
60
+ const parents = [];
61
+ let target = this.root;
62
+ for (const part of path.split('/').slice(0, -1)) {
63
+ target = join(target, part);
64
+ const stat = await lstat(target);
65
+ if (!stat.isDirectory() || stat.isSymbolicLink())
66
+ failure('workspace_public_source_path_unsafe', path);
67
+ parents.push({ path: target, stat });
68
+ }
69
+ target = join(this.root, path);
70
+ const handle = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
71
+ try {
72
+ const before = await handle.stat();
73
+ if (!before.isFile() || before.nlink !== 1 || before.size > maximum)
74
+ failure('workspace_public_source_path_unsafe', path);
75
+ const body = await handle.readFile(), after = await handle.stat(), named = await lstat(target);
76
+ if (body.length !== before.size || !same(before, after) || !same(after, named) || named.isSymbolicLink())
77
+ failure('workspace_public_source_changed', path);
78
+ for (const parent of parents) {
79
+ const now = await lstat(parent.path);
80
+ if (!now.isDirectory() || now.isSymbolicLink() || now.ino !== parent.stat.ino || now.dev !== parent.stat.dev)
81
+ failure('workspace_public_source_changed', path);
82
+ }
83
+ return { body, mode: before.mode & 0o111 ? '100755' : '100644' };
84
+ }
85
+ finally {
86
+ await handle.close();
87
+ }
88
+ }
89
+ async optional(path, maximum) {
90
+ try {
91
+ return await this.read(path, maximum);
92
+ }
93
+ catch (error) {
94
+ if (error.code === 'ENOENT')
95
+ return undefined;
96
+ throw error;
97
+ }
98
+ }
99
+ async verify() {
100
+ for (const [path, file] of this.observedFiles) {
101
+ const current = await this.physical(path, Math.max(file.body.length, 1));
102
+ if (current.mode !== file.mode || !current.body.equals(file.body))
103
+ failure('workspace_public_source_changed', path);
104
+ }
105
+ }
106
+ }
107
+ async function readerAt(root) {
108
+ const canonical = await realpath(root);
109
+ if (!(await lstat(canonical)).isDirectory())
110
+ failure('workspace_public_source_root_unsafe');
111
+ return new SourceReader(canonical);
112
+ }
113
+ function json(bytes, path) {
114
+ try {
115
+ const value = JSON5.parse(bytes.toString('utf8'));
116
+ if (plain(value))
117
+ return value;
118
+ }
119
+ catch { /* A malformed declaration never becomes a legacy project. */ }
120
+ return failure('workspace_public_declaration_invalid', path);
121
+ }
122
+ /** Old source rules can diagnose capabilities without changing their file set or fingerprint. */
123
+ export async function hasWorkspacePublicSourceDeclaration(root) {
124
+ const reader = await readerAt(root), file = await reader.optional(WORKSPACE_PUBLIC_DECLARATION_PATH, 4 * 1024 * 1024);
125
+ if (!file)
126
+ return false;
127
+ const value = json(file.body, WORKSPACE_PUBLIC_DECLARATION_PATH);
128
+ return ['parameters', 'levelEditor', 'previewRuntime', 'preview'].some(key => Object.prototype.hasOwnProperty.call(value, key));
129
+ }
130
+ /** A source snapshot only: no inference, build script, plugin, provider or admission is executed. */
131
+ export async function readWorkspacePublicSourceClosure(root) {
132
+ const reader = await readerAt(root);
133
+ const raw = await reader.read(WORKSPACE_PUBLIC_DECLARATION_PATH, 4 * 1024 * 1024);
134
+ let declaration;
135
+ try {
136
+ declaration = projectWorkspacePublicDeclaration(json(raw.body, WORKSPACE_PUBLIC_DECLARATION_PATH));
137
+ }
138
+ catch {
139
+ return failure('workspace_public_declaration_invalid', WORKSPACE_PUBLIC_DECLARATION_PATH);
140
+ }
141
+ const projection = Buffer.from(`${JSON.stringify(declaration, null, 2)}\n`);
142
+ const files = new Map([[WORKSPACE_PUBLIC_DECLARATION_PATH, { body: projection, mode: '100644' }]]);
143
+ const requiredPaths = new Set([WORKSPACE_PUBLIC_DECLARATION_PATH]);
144
+ const queued = new Map(), inspected = new Set();
145
+ const enqueue = (path, webRoot) => {
146
+ if (queued.has(path) && queued.get(path) !== webRoot)
147
+ failure('workspace_public_dependency_ambiguous', path);
148
+ queued.set(path, webRoot);
149
+ };
150
+ const add = async (path, hidden = false, optional = false, inspect = true, webRoot = '.') => {
151
+ publicPath(path, hidden);
152
+ const file = optional ? await reader.optional(path) : await reader.read(path);
153
+ if (!file)
154
+ return undefined;
155
+ if (path !== WORKSPACE_PUBLIC_DECLARATION_PATH)
156
+ files.set(path, file);
157
+ requiredPaths.add(path);
158
+ if (inspect && !path.startsWith(WORKSPACE_PREVIEW_RUNTIME_DIRECTORY + '/'))
159
+ enqueue(path, webRoot);
160
+ return file;
161
+ };
162
+ const packages = new Map();
163
+ const scripts = new Map();
164
+ const configurations = new Set();
165
+ const aliases = [];
166
+ const directoryPath = (cwd, path) => cwd === '.' ? path : posix.join(cwd, path);
167
+ async function packageAt(cwd, required = false) {
168
+ const path = directoryPath(cwd, 'package.json');
169
+ const file = await add(path, false, !required, false);
170
+ if (!file)
171
+ return;
172
+ const value = json(file.body, path);
173
+ for (const key of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
174
+ if (value[key] === undefined)
175
+ continue;
176
+ if (!plain(value[key]))
177
+ failure('workspace_public_package_invalid', path);
178
+ for (const [name, version] of Object.entries(value[key])) {
179
+ if (typeof version !== 'string')
180
+ failure('workspace_public_package_invalid', path);
181
+ packages.set(name, version);
182
+ }
183
+ }
184
+ scripts.set(cwd, plain(value.scripts) ? value.scripts : {});
185
+ for (const name of ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock', 'bun.lockb'])
186
+ await add(directoryPath(cwd, name), false, true, false);
187
+ }
188
+ async function configAt(path, required = false) {
189
+ if (configurations.has(path))
190
+ return;
191
+ configurations.add(path);
192
+ const file = await add(path, false, !required, false);
193
+ if (!file)
194
+ return;
195
+ const value = json(file.body, path), options = value.compilerOptions;
196
+ if (value.extends !== undefined) {
197
+ if (typeof value.extends !== 'string' || !value.extends.startsWith('.'))
198
+ failure('workspace_public_dependency_unsupported', path);
199
+ let extended = posix.normalize(posix.join(posix.dirname(path), value.extends));
200
+ if (!extended.endsWith('.json') && !(await reader.optional(extended, 4 * 1024 * 1024)))
201
+ extended += '.json';
202
+ await configAt(extended, true);
203
+ }
204
+ if (plain(options) && options.paths !== undefined) {
205
+ if (!plain(options.paths) || Object.keys(options.paths).length > 64 || options.baseUrl !== undefined && typeof options.baseUrl !== 'string')
206
+ failure('workspace_public_dependency_unsupported', path);
207
+ if (typeof options.baseUrl === 'string' && (posix.isAbsolute(options.baseUrl) || /[:\\]/.test(options.baseUrl)))
208
+ failure('workspace_public_dependency_unsupported', path);
209
+ const base = posix.normalize(posix.join(posix.dirname(path), typeof options.baseUrl === 'string' ? options.baseUrl : '.'));
210
+ for (const [pattern, targets] of Object.entries(options.paths)) {
211
+ if (!Array.isArray(targets) || !targets.length || targets.length > 8 || !targets.every(target => typeof target === 'string' && !posix.isAbsolute(target) && !/[:\\]/.test(target) && target.split('*').length <= 2) || pattern.split('*').length > 2)
212
+ failure('workspace_public_dependency_unsupported', path);
213
+ aliases.push({ pattern, paths: targets, base });
214
+ }
215
+ }
216
+ }
217
+ await packageAt('.');
218
+ await configAt('tsconfig.json');
219
+ {
220
+ let { schemaPath, dataPath, themeId } = declaration.parameters ?? {};
221
+ const explicitPaths = Boolean(schemaPath || dataPath);
222
+ // Preserve locateParameterFiles: either explicit path suppresses inference of the
223
+ // other one. Conventional discovery is only used when both paths are absent.
224
+ if (!explicitPaths) {
225
+ schemaPath = 'src/theme/theme.schema.json5';
226
+ const index = await add('src/theme/index.ts', false, true);
227
+ const text = index?.body.toString('utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
228
+ const selected = text?.match(/export\s+\{\s*default\s*\}\s+from\s+['"]\.\/([^'"]+)['"]/);
229
+ themeId ?? (themeId = selected?.[1]?.trim());
230
+ if (themeId)
231
+ dataPath = `src/theme/${themeId}/theme.data.json5`;
232
+ else {
233
+ const entries = await readdir(join(reader.root, 'src/theme'), { withFileTypes: true }).catch((error) => { if (error.code === 'ENOENT')
234
+ return []; throw error; });
235
+ const candidates = [];
236
+ for (const entry of entries)
237
+ if (entry.isDirectory() && !entry.name.startsWith('.')) {
238
+ const path = `src/theme/${entry.name}/theme.data.json5`;
239
+ if (await add(path, false, true, false))
240
+ candidates.push(path);
241
+ }
242
+ if (candidates.length === 1)
243
+ dataPath = candidates[0];
244
+ }
245
+ }
246
+ if (schemaPath)
247
+ await add(schemaPath, false, !explicitPaths);
248
+ if (dataPath === '.playcraft/model-adaptation.json') {
249
+ const model = await readWorkspaceModelSourceClosure({ dataPath, workspaceProjection: projection, readFile: reader.read.bind(reader) });
250
+ for (const [path, file] of model.files) {
251
+ files.set(path, file);
252
+ enqueue(path, '.');
253
+ }
254
+ for (const path of model.requiredPaths)
255
+ requiredPaths.add(path);
256
+ }
257
+ else if (dataPath)
258
+ await add(dataPath, false, !explicitPaths);
259
+ for (const path of [...(schemaPath ? [posix.join(posix.dirname(schemaPath), 'i18n.platform.json5'), posix.join(posix.dirname(schemaPath), 'i18n.runtime.json5')] : []), ...(dataPath ? [posix.join(posix.dirname(dataPath), 'theme.i18n.runtime.json5')] : [])]) {
260
+ if (path.startsWith('.playcraft/'))
261
+ continue;
262
+ await add(path, false, true, false);
263
+ }
264
+ }
265
+ if (declaration.levelEditor) {
266
+ const path = declaration.levelEditor.definition, file = await add(path);
267
+ const compiled = compileLevelEditorDefinition(json(file.body, path));
268
+ if (!compiled.ok)
269
+ failure('workspace_public_level_editor_invalid', path);
270
+ const definition = compiled.definition, schemas = {};
271
+ const isolatedModules = new Set();
272
+ for (const [id, document] of Object.entries(definition.documents)) {
273
+ await add(document.path);
274
+ schemas[id] = json((await add(document.schema)).body, document.schema);
275
+ if (document.provider)
276
+ isolatedModules.add(document.provider.module);
277
+ }
278
+ if (!compileLevelEditorDefinition(definition, schemas).ok)
279
+ failure('workspace_public_level_editor_invalid', path);
280
+ for (const item of definition.extensions?.validators ?? [])
281
+ isolatedModules.add(item.module);
282
+ for (const path of isolatedModules) {
283
+ const file = await add(path);
284
+ if (!path.endsWith('.mjs') || workspacePublicSourceDependencies(path, file.body).length)
285
+ failure('workspace_public_dependency_unsupported', path);
286
+ }
287
+ for (const item of Object.values(definition.extensions?.views ?? {}))
288
+ await add(item.entry);
289
+ for (const path of Object.values(definition.preview ?? {}))
290
+ await add(path);
291
+ }
292
+ if (declaration.previewRuntime) {
293
+ const config = declaration.previewRuntime;
294
+ await packageAt('.', true);
295
+ if (typeof scripts.get('.')?.[config.buildScript] !== 'string' || !config.entryPath)
296
+ failure('workspace_public_preview_runtime_unsupported', WORKSPACE_PUBLIC_DECLARATION_PATH);
297
+ for (const path of [...config.gameFilePaths, config.entryPath, ...(config.viteConfigPath ? [config.viteConfigPath] : [])]) {
298
+ if (!path.startsWith(WORKSPACE_PREVIEW_RUNTIME_DIRECTORY + '/'))
299
+ await add(path);
300
+ }
301
+ const sdkPath = WORKSPACE_PREVIEW_RUNTIME_DIRECTORY + '/manifest.json';
302
+ const sdkFile = await add(sdkPath, true, false, false);
303
+ const parsed = workspacePublicPreviewSdkManifestSchema.safeParse(json(sdkFile.body, sdkPath));
304
+ if (!parsed.success)
305
+ failure('workspace_public_sdk_unsupported', sdkPath);
306
+ for (const [name, expected] of Object.entries(parsed.data.files)) {
307
+ const path = `${WORKSPACE_PREVIEW_RUNTIME_DIRECTORY}/${name}`, file = await add(path, true, false, false);
308
+ if (hash(file.body) !== expected)
309
+ failure('workspace_public_sdk_changed', path);
310
+ }
311
+ }
312
+ async function walk(cwd, depth = 0, webRoot = cwd) {
313
+ if (depth > 24)
314
+ failure('workspace_public_source_limit', cwd);
315
+ const full = cwd === '.' ? reader.root : join(reader.root, publicPath(cwd));
316
+ const entries = await readdir(full, { withFileTypes: true });
317
+ if (entries.length > MAX_FILES)
318
+ failure('workspace_public_source_limit', cwd);
319
+ for (const entry of entries) {
320
+ const path = directoryPath(cwd, entry.name);
321
+ if (entry.name.startsWith('.') || skipped.has(entry.name.toLowerCase()))
322
+ continue;
323
+ try {
324
+ publicPath(path);
325
+ }
326
+ catch {
327
+ continue;
328
+ }
329
+ if (entry.isSymbolicLink())
330
+ failure('workspace_public_source_path_unsafe', path);
331
+ if (entry.isDirectory())
332
+ await walk(path, depth + 1, webRoot);
333
+ else if (entry.isFile())
334
+ await add(path, false, false, true, webRoot);
335
+ else
336
+ failure('workspace_public_source_path_unsafe', path);
337
+ }
338
+ }
339
+ const scriptSeen = new Set();
340
+ async function commandDirectory(cwd, value) {
341
+ if (!value || posix.isAbsolute(value) || value.includes('\\'))
342
+ failure('workspace_public_preview_command_unsupported');
343
+ const path = posix.normalize(directoryPath(cwd, value));
344
+ if (cwd !== '.' && path !== cwd && !path.startsWith(cwd + '/') || path === '..' || path.startsWith('../'))
345
+ failure('workspace_public_source_path_forbidden', path);
346
+ if (path !== '.')
347
+ publicPath(path);
348
+ let directory = reader.root;
349
+ for (const part of path === '.' ? [] : path.split('/')) {
350
+ directory = join(directory, part);
351
+ const stat = await lstat(directory);
352
+ if (!stat.isDirectory() || stat.isSymbolicLink())
353
+ failure('workspace_public_source_path_unsafe', path);
354
+ }
355
+ return path;
356
+ }
357
+ async function inspectCommand(command, cwd, forwarded = []) {
358
+ if (/[`$;&|<>\\*?\n\r]/.test(command))
359
+ failure('workspace_public_preview_command_unsupported');
360
+ const tokens = [];
361
+ let token = '', quote, started = false;
362
+ for (const char of command) {
363
+ if (quote) {
364
+ if (char === quote)
365
+ quote = undefined;
366
+ else
367
+ token += char;
368
+ }
369
+ else if (char === '"' || char === "'") {
370
+ quote = char;
371
+ started = true;
372
+ }
373
+ else if (/\s/.test(char)) {
374
+ if (started) {
375
+ tokens.push(token);
376
+ token = '';
377
+ started = false;
378
+ }
379
+ }
380
+ else {
381
+ token += char;
382
+ started = true;
383
+ }
384
+ }
385
+ if (quote)
386
+ failure('workspace_public_preview_command_unsupported');
387
+ if (started)
388
+ tokens.push(token);
389
+ tokens.push(...forwarded);
390
+ if (!tokens.length)
391
+ failure('workspace_public_preview_command_unsupported');
392
+ const [binary, ...args] = tokens;
393
+ if (['pnpm', 'npm', 'yarn'].includes(binary)) {
394
+ const action = args[0] === 'run' ? args[1] : args[0];
395
+ if (action === 'exec' && args[1] === 'vite')
396
+ return inspectCommand('vite', cwd, args.slice(2));
397
+ if (!action || scriptSeen.has(`${cwd}:${action}`))
398
+ failure('workspace_public_preview_command_unsupported');
399
+ const script = scripts.get(cwd)?.[action];
400
+ if (typeof script !== 'string')
401
+ failure('workspace_public_preview_command_unsupported');
402
+ scriptSeen.add(`${cwd}:${action}`);
403
+ const extra = args.slice(args[0] === 'run' ? 2 : 1);
404
+ return inspectCommand(script, cwd, extra[0] === '--' ? extra.slice(1) : extra);
405
+ }
406
+ else if (['vite', 'http-server', 'serve', 'python', 'python3'].includes(binary)) {
407
+ let webRoot = cwd, positional = false;
408
+ let offset = 0;
409
+ if (['python', 'python3'].includes(binary)) {
410
+ if (args[0] !== '-m' || args[1] !== 'http.server')
411
+ failure('workspace_public_preview_command_unsupported');
412
+ offset = 2;
413
+ }
414
+ const configs = [];
415
+ for (let index = offset; index < args.length; index++) {
416
+ const arg = args[index];
417
+ const [flag, equalValue] = arg.split('=', 2);
418
+ const take = () => {
419
+ const value = equalValue ?? args[++index];
420
+ if (!value || value.startsWith('-'))
421
+ return failure('workspace_public_preview_command_unsupported');
422
+ return value;
423
+ };
424
+ if (binary === 'vite' && ['--config', '-c'].includes(flag)) {
425
+ const configured = take();
426
+ if (posix.isAbsolute(configured))
427
+ failure('workspace_public_source_path_forbidden', configured);
428
+ const path = posix.normalize(directoryPath(cwd, configured));
429
+ publicPath(path);
430
+ configs.push(path);
431
+ }
432
+ else if (['--root', '--directory', '-d'].includes(flag))
433
+ webRoot = await commandDirectory(cwd, take());
434
+ else if (['--port', '-p'].includes(flag) || binary === 'serve' && ['--listen', '-l'].includes(flag)) {
435
+ if (!/^(?:\{port\}|\d{1,5})$/.test(take()))
436
+ failure('workspace_public_preview_command_unsupported');
437
+ }
438
+ else if (['--host', '--bind', '-a'].includes(flag)) {
439
+ if (flag === '--host' && equalValue === undefined && (!args[index + 1] || args[index + 1].startsWith('-')))
440
+ continue;
441
+ if (!/^[a-z0-9.:[\]_-]+$/i.test(take()))
442
+ failure('workspace_public_preview_command_unsupported');
443
+ }
444
+ else if (['--strictPort', '--cors', '--single', '-s'].includes(flag) && equalValue === undefined) {
445
+ // Known booleans do not change project input locations.
446
+ }
447
+ else if (arg.startsWith('-'))
448
+ failure('workspace_public_preview_command_unsupported');
449
+ else if (['python', 'python3'].includes(binary) && /^(?:\{port\}|\d{1,5})$/.test(arg) && !positional)
450
+ positional = true;
451
+ else {
452
+ if (positional)
453
+ failure('workspace_public_preview_command_unsupported');
454
+ webRoot = await commandDirectory(cwd, arg);
455
+ positional = true;
456
+ }
457
+ }
458
+ for (const path of configs)
459
+ await add(path, false, false, true, webRoot);
460
+ return webRoot;
461
+ }
462
+ else if (['node', 'tsx', 'ts-node'].includes(binary)) {
463
+ if (!args[0] || args[0].startsWith('-'))
464
+ failure('workspace_public_preview_command_unsupported');
465
+ if (args.length !== 1)
466
+ failure('workspace_public_preview_command_unsupported');
467
+ await add(posix.normalize(directoryPath(cwd, args[0])), false, false, true, cwd);
468
+ return cwd;
469
+ }
470
+ else
471
+ failure('workspace_public_preview_command_unsupported');
472
+ }
473
+ if (declaration.preview) {
474
+ const cwd = declaration.preview.cwd ?? '.';
475
+ if (cwd !== '.') {
476
+ publicPath(cwd);
477
+ let directory = reader.root;
478
+ for (const part of cwd.split('/')) {
479
+ directory = join(directory, part);
480
+ const stat = await lstat(directory);
481
+ if (!stat.isDirectory() || stat.isSymbolicLink())
482
+ failure('workspace_public_source_path_unsafe', cwd);
483
+ }
484
+ await packageAt(cwd);
485
+ await configAt(directoryPath(cwd, 'tsconfig.json'));
486
+ }
487
+ const webRoot = await inspectCommand(declaration.preview.command, cwd);
488
+ await packageAt(webRoot);
489
+ await configAt(directoryPath(webRoot, 'tsconfig.json'));
490
+ await walk(webRoot);
491
+ }
492
+ async function resolveLocal(importer, specifier, kind, webRoot, projectAbsolute = false) {
493
+ if (specifier.startsWith('data:') || specifier.startsWith('#'))
494
+ return;
495
+ if (/^[a-z][a-z\d+.-]*:/i.test(specifier) || specifier.startsWith('//'))
496
+ failure('workspace_public_dependency_external', importer);
497
+ let decoded;
498
+ try {
499
+ decoded = decodeURIComponent(specifier.split(/[?#]/)[0]);
500
+ }
501
+ catch {
502
+ return failure('workspace_public_dependency_unsupported', importer);
503
+ }
504
+ const path = posix.normalize(decoded.startsWith('/') ? posix.join(projectAbsolute ? '.' : webRoot, decoded.slice(1)) : posix.join(posix.dirname(importer), decoded));
505
+ const sdkMember = path.startsWith(WORKSPACE_PREVIEW_RUNTIME_DIRECTORY + '/') && Boolean(declaration.previewRuntime) && files.has(path);
506
+ publicPath(path, sdkMember);
507
+ const candidates = kind === 'resource' && !/\.[cm]?[jt]sx?$/i.test(path) ? [path] : posix.extname(path)
508
+ ? [path, ...(/\.js$/i.test(path) ? [path.slice(0, -3) + '.ts', path.slice(0, -3) + '.tsx'] : [])]
509
+ : [path, ...['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.json', '.d.ts', '.d.mts', '.d.cts', '/index.ts', '/index.tsx', '/index.js', '/index.mjs', '/index.d.ts'].map(extension => path + extension)];
510
+ const found = [];
511
+ for (const candidate of candidates) {
512
+ const stat = await lstat(join(reader.root, candidate)).catch((error) => { if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
513
+ return undefined; throw error; });
514
+ if (stat?.isSymbolicLink())
515
+ failure('workspace_public_source_path_unsafe', candidate);
516
+ if (stat?.isFile())
517
+ found.push(candidate);
518
+ if (candidate === path && stat?.isFile() && posix.extname(path))
519
+ break;
520
+ }
521
+ if (found.length !== 1)
522
+ failure(found.length ? 'workspace_public_dependency_ambiguous' : 'workspace_public_dependency_missing', path);
523
+ await add(found[0], sdkMember, false, true, webRoot);
524
+ }
525
+ while ([...queued.keys()].some(path => !inspected.has(path))) {
526
+ for (const [path, webRoot] of [...queued]) {
527
+ if (inspected.has(path))
528
+ continue;
529
+ inspected.add(path);
530
+ for (const dependency of workspacePublicSourceDependencies(path, files.get(path).body)) {
531
+ const value = dependency.specifier;
532
+ if (dependency.kind === 'resource' || /^(?:\.|\/)/.test(value)) {
533
+ await resolveLocal(path, value, dependency.kind === 'types' ? 'module' : dependency.kind, webRoot);
534
+ continue;
535
+ }
536
+ const matchedAliases = aliases.filter(item => {
537
+ const [prefix, suffix] = item.pattern.split('*');
538
+ return item.pattern.includes('*') ? value.startsWith(prefix) && value.endsWith(suffix) : value === item.pattern;
539
+ });
540
+ if (matchedAliases.length > 1)
541
+ failure('workspace_public_dependency_ambiguous', path);
542
+ const alias = matchedAliases[0];
543
+ if (alias) {
544
+ if (alias.paths.length !== 1)
545
+ failure('workspace_public_dependency_ambiguous', path);
546
+ const [prefix, suffix] = alias.pattern.split('*');
547
+ const match = alias.pattern.includes('*') ? value.slice(prefix.length, value.length - suffix.length) : '';
548
+ await resolveLocal(path, '/' + posix.join(alias.base, alias.paths[0].replace('*', match)), 'module', webRoot, true);
549
+ }
550
+ else {
551
+ if (dependency.kind !== 'types' && (value.startsWith('node:') && builtinModules.includes(value.slice(5)) || builtinModules.includes(value)))
552
+ continue;
553
+ const name = value.startsWith('@') ? value.split('/').slice(0, 2).join('/') : value.split('/')[0];
554
+ const typePackage = name.startsWith('@') ? '@types/' + name.slice(1).replace('/', '__') : '@types/' + name;
555
+ const version = packages.get(name) ?? (dependency.kind === 'types' ? packages.get(typePackage) : undefined);
556
+ if (!/^@?[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)?$/i.test(name) || !version || !registryVersion(version))
557
+ failure('workspace_public_dependency_unsupported', path);
558
+ }
559
+ }
560
+ }
561
+ }
562
+ await reader.verify();
563
+ return { files: new Map([...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)), requiredPaths: [...requiredPaths].sort(), observedFiles: reader.observedFiles };
564
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/build",
3
- "version": "0.1.92-test",
3
+ "version": "0.1.94-test-a",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,6 +21,11 @@
21
21
  "require": "./dist/analyzers/scene-asset-collector.js",
22
22
  "types": "./dist/analyzers/scene-asset-collector.d.ts"
23
23
  },
24
+ "./agent-runner": {
25
+ "import": "./dist/delivery/agent-build-runner.js",
26
+ "require": "./dist/delivery/agent-build-runner.js",
27
+ "types": "./dist/delivery/agent-build-runner.d.ts"
28
+ },
24
29
  "./dist/*": "./dist/*"
25
30
  },
26
31
  "files": [
@@ -30,34 +35,41 @@
30
35
  "README.md"
31
36
  ],
32
37
  "dependencies": {
33
- "@playcraft/ads-tracking": "^1.0.0",
34
38
  "@gltf-transform/core": "^4.3.0",
35
39
  "@gltf-transform/extensions": "^4.3.0",
36
40
  "@gltf-transform/functions": "^4.3.0",
41
+ "@playcraft/ads-tracking": "^1.0.0",
37
42
  "@vheemstra/vite-plugin-imagemin": "^2.2.1",
38
43
  "archiver": "^7.0.1",
44
+ "css-tree": "3.2.1",
39
45
  "draco3dgltf": "^1.5.7",
40
46
  "fflate": "^0.8.2",
41
47
  "imagemin-mozjpeg": "^10.0.0",
42
48
  "imagemin-pngquant": "^10.0.0",
43
49
  "imagemin-webp": "^8.0.0",
44
50
  "javascript-obfuscator": "^5.3.0",
51
+ "json5": "^2.2.3",
45
52
  "lightningcss": "^1.31.1",
46
53
  "mime-types": "^2.1.35",
54
+ "parse5": "^7.3.0",
47
55
  "rollup-plugin-visualizer": "^6.0.5",
48
56
  "sharp": "^0.34.5",
49
57
  "terser": "^5.46.0",
58
+ "typescript": "^5.9.3",
50
59
  "vite": "^8.0.3",
51
- "vite-plugin-singlefile": "^2.3.2"
60
+ "vite-plugin-singlefile": "^2.3.2",
61
+ "@playcraft/common": "0.1.94-test-a"
52
62
  },
53
63
  "devDependencies": {
54
64
  "@playcraft/ads-tracking": "^1.0.0",
55
65
  "@types/archiver": "^6.0.4",
66
+ "@types/css-tree": "3.2.0",
56
67
  "@types/mime-types": "^2.1.4",
57
68
  "@types/node": "^22.19.8",
58
- "typescript": "^5.9.3"
69
+ "vitest": "^3.2.4"
59
70
  },
60
71
  "scripts": {
72
+ "test": "vitest run",
61
73
  "lint": "pnpm -w run lint:eslint packages/build",
62
74
  "dev": "tsc -w",
63
75
  "build": "tsc",