@playcraft/build 0.2.18 → 0.2.19-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.
- package/dist/audio-source-files.d.ts +5 -0
- package/dist/audio-source-files.js +135 -0
- package/dist/base-builder.js +42 -2
- package/dist/delivery/agent-build-runner.d.ts +44 -0
- package/dist/delivery/agent-build-runner.js +365 -0
- package/dist/delivery/agent-build-source.d.ts +8 -0
- package/dist/delivery/agent-build-source.js +25 -0
- package/dist/delivery/artifact-descriptor.d.ts +31 -0
- package/dist/delivery/artifact-descriptor.js +237 -0
- package/dist/delivery/artifact-package.d.ts +43 -0
- package/dist/delivery/artifact-package.js +283 -0
- package/dist/delivery/build-plan.d.ts +4 -0
- package/dist/delivery/build-plan.js +189 -0
- package/dist/delivery/build-plan.types.d.ts +51 -0
- package/dist/delivery/build-plan.types.js +1 -0
- package/dist/delivery/command-isolation.d.ts +21 -0
- package/dist/delivery/command-isolation.js +327 -0
- package/dist/delivery/commands.d.ts +5 -0
- package/dist/delivery/commands.js +146 -0
- package/dist/delivery/files.d.ts +9 -0
- package/dist/delivery/files.js +144 -0
- package/dist/delivery/git-source-fingerprint.d.ts +2 -0
- package/dist/delivery/git-source-fingerprint.js +58 -0
- package/dist/delivery/isolated-source.d.ts +5 -0
- package/dist/delivery/isolated-source.js +148 -0
- package/dist/delivery/output-publication.d.ts +21 -0
- package/dist/delivery/output-publication.js +444 -0
- package/dist/delivery/project-delivery.d.ts +6 -0
- package/dist/delivery/project-delivery.js +287 -0
- package/dist/delivery/recipe-build-plan.d.ts +4 -0
- package/dist/delivery/recipe-build-plan.js +53 -0
- package/dist/delivery/recipe.d.ts +20 -0
- package/dist/delivery/recipe.js +211 -0
- package/dist/delivery/safe-path.d.ts +2 -0
- package/dist/delivery/safe-path.js +18 -0
- package/dist/delivery/types.d.ts +81 -0
- package/dist/delivery/types.js +1 -0
- package/dist/engines/engine-detector.js +4 -0
- package/dist/engines/generic-adapter.js +14 -19
- package/dist/engines/playable-scripts-adapter.js +2 -5
- package/dist/index.d.ts +21 -4
- package/dist/index.js +12 -2
- package/dist/platforms/adikteev.js +1 -0
- package/dist/platforms/applovin.js +1 -0
- package/dist/platforms/base.d.ts +4 -0
- package/dist/platforms/base.js +25 -6
- package/dist/platforms/bigo.js +1 -0
- package/dist/platforms/facebook.js +1 -0
- package/dist/platforms/google.js +1 -0
- package/dist/platforms/inmobi.js +1 -0
- package/dist/platforms/ironsource.js +1 -0
- package/dist/platforms/liftoff.js +1 -0
- package/dist/platforms/mintegral.js +1 -0
- package/dist/platforms/moloco.js +1 -0
- package/dist/platforms/playcraft.js +1 -0
- package/dist/platforms/remerge.js +1 -0
- package/dist/platforms/snapchat.js +1 -0
- package/dist/platforms/tiktok.js +1 -0
- package/dist/platforms/unity.js +1 -0
- package/dist/production-animation-presence.d.ts +2 -0
- package/dist/production-animation-presence.js +146 -0
- package/dist/production-inputs.d.ts +30 -0
- package/dist/production-inputs.js +262 -0
- package/dist/production-source-paths.d.ts +5 -0
- package/dist/production-source-paths.js +27 -0
- package/dist/redirect-policy.d.ts +23 -0
- package/dist/redirect-policy.js +25 -0
- package/dist/types.d.ts +12 -2
- package/dist/validation/artifact-qa.d.ts +36 -0
- package/dist/validation/artifact-qa.js +263 -0
- package/dist/validation/artifact-rules.d.ts +39 -0
- package/dist/validation/artifact-rules.js +451 -0
- package/dist/validation/artifact.d.ts +14 -0
- package/dist/validation/artifact.js +188 -0
- package/dist/validation/html-validator.d.ts +5 -0
- package/dist/validation/html-validator.js +19 -17
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/package-validator.d.ts +2 -0
- package/dist/validation/package-validator.js +25 -64
- package/dist/validation/playwright-driver.d.ts +37 -0
- package/dist/validation/playwright-driver.js +302 -0
- package/dist/validation/profiles.d.ts +13 -1
- package/dist/validation/profiles.js +27 -0
- package/dist/validation/runtime-cover.d.ts +32 -0
- package/dist/validation/runtime-cover.js +120 -0
- package/dist/validation/runtime-load.d.ts +141 -0
- package/dist/validation/runtime-load.js +812 -0
- package/dist/validation/source-scanner.d.ts +11 -0
- package/dist/validation/source-scanner.js +32 -2
- package/dist/validation/types.d.ts +201 -2
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +22 -2
- package/dist/validation/validation-runner.js +64 -3
- package/dist/validation/zip-reader.d.ts +7 -0
- package/dist/validation/zip-reader.js +159 -26
- package/dist/vite/config-builder-generic.d.ts +3 -1
- package/dist/vite/config-builder-generic.js +9 -7
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +16 -30
- package/dist/vite/plugin-source-builder.d.ts +2 -14
- package/dist/vite/plugin-source-builder.js +61 -997
- package/dist/vite/source-builder-asset-paths.d.ts +25 -0
- package/dist/vite/source-builder-asset-paths.js +154 -0
- package/dist/vite/source-builder-esm.d.ts +7 -0
- package/dist/vite/source-builder-esm.js +877 -0
- package/dist/vite/source-builder-types.d.ts +14 -0
- package/dist/vite/source-builder-types.js +1 -0
- package/dist/vite/workspace.d.ts +6 -0
- package/dist/vite/workspace.js +41 -0
- package/dist/vite-builder.d.ts +4 -5
- package/dist/vite-builder.js +33 -34
- package/dist/workspace-css-imports.d.ts +2 -0
- package/dist/workspace-css-imports.js +139 -0
- package/dist/workspace-model-source.d.ts +14 -0
- package/dist/workspace-model-source.js +184 -0
- package/dist/workspace-public-imports.d.ts +11 -0
- package/dist/workspace-public-imports.js +232 -0
- package/dist/workspace-public-source.d.ts +15 -0
- package/dist/workspace-public-source.js +564 -0
- package/package.json +30 -4
- package/templates/patches/one-page-mraid-resize-canvas.js +0 -2
- package/templates/patches/playcraft-redirect-policy.js +115 -0
|
@@ -1,84 +1,217 @@
|
|
|
1
|
-
import { inflateRawSync } from 'zlib';
|
|
1
|
+
import { inflateRawSync } from 'node:zlib';
|
|
2
|
+
const MAX_ARCHIVE_BYTES = 64 * 1024 * 1024;
|
|
3
|
+
const MAX_ENTRY_BYTES = 64 * 1024 * 1024;
|
|
4
|
+
const MAX_TOTAL_BYTES = 128 * 1024 * 1024;
|
|
5
|
+
const MAX_ENTRIES = 4096;
|
|
6
|
+
const MAX_COMPRESSION_RATIO = 200;
|
|
7
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
8
|
+
function invalid(message) {
|
|
9
|
+
throw new Error(`Invalid ZIP: ${message}`);
|
|
10
|
+
}
|
|
11
|
+
function decode(bytes) {
|
|
12
|
+
try {
|
|
13
|
+
return decoder.decode(bytes);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
invalid('entry filename is not valid UTF-8');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function validateEntryPath(value, directory) {
|
|
20
|
+
const member = directory ? value.slice(0, -1) : value;
|
|
21
|
+
if (!member ||
|
|
22
|
+
member.length > 1024 ||
|
|
23
|
+
member.includes('\0') ||
|
|
24
|
+
member.includes('\\') ||
|
|
25
|
+
member.startsWith('/') ||
|
|
26
|
+
/^[A-Za-z]:/.test(member) ||
|
|
27
|
+
member.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
28
|
+
invalid(`unsafe entry path: ${JSON.stringify(value)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function crc32(bytes) {
|
|
32
|
+
let crc = 0xffffffff;
|
|
33
|
+
for (const byte of bytes) {
|
|
34
|
+
crc ^= byte;
|
|
35
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
36
|
+
crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
40
|
+
}
|
|
41
|
+
/** Bounded ZIP reader used for both local reports and untrusted uploaded bytes. */
|
|
2
42
|
export class SimpleZipReader {
|
|
3
43
|
constructor(buffer) {
|
|
4
44
|
this.buffer = buffer;
|
|
45
|
+
if (buffer.byteLength > MAX_ARCHIVE_BYTES)
|
|
46
|
+
invalid('archive exceeds the size limit');
|
|
5
47
|
}
|
|
6
48
|
listEntries() {
|
|
7
|
-
return this.readCentralDirectory().map((
|
|
49
|
+
return this.readCentralDirectory().map((entry) => ({
|
|
50
|
+
path: entry.path,
|
|
51
|
+
compressedSize: entry.compressedSize,
|
|
52
|
+
uncompressedSize: entry.uncompressedSize,
|
|
53
|
+
compressionMethod: entry.compressionMethod,
|
|
54
|
+
isDirectory: entry.isDirectory,
|
|
55
|
+
externalAttributes: entry.externalAttributes,
|
|
56
|
+
creatorOs: entry.creatorOs,
|
|
57
|
+
encrypted: entry.encrypted,
|
|
58
|
+
crc32: entry.crc32,
|
|
59
|
+
}));
|
|
8
60
|
}
|
|
9
61
|
readEntryText(entryPath) {
|
|
62
|
+
return this.readEntry(entryPath)?.toString('utf-8') ?? null;
|
|
63
|
+
}
|
|
64
|
+
readEntry(entryPath) {
|
|
10
65
|
const entry = this.readCentralDirectory().find((item) => item.path === entryPath);
|
|
11
66
|
if (!entry || entry.isDirectory)
|
|
12
67
|
return null;
|
|
13
|
-
|
|
14
|
-
return data.toString('utf-8');
|
|
68
|
+
return this.readEntryData(entry);
|
|
15
69
|
}
|
|
16
70
|
readCentralDirectory() {
|
|
17
71
|
if (this.entriesCache)
|
|
18
72
|
return this.entriesCache;
|
|
19
73
|
const eocdOffset = this.findEndOfCentralDirectory();
|
|
20
|
-
if (eocdOffset < 0)
|
|
21
|
-
|
|
74
|
+
if (eocdOffset < 0)
|
|
75
|
+
invalid('end of central directory not found');
|
|
76
|
+
this.requireRange(eocdOffset, 22);
|
|
77
|
+
if (this.buffer.readUInt16LE(eocdOffset + 4) !== 0 ||
|
|
78
|
+
this.buffer.readUInt16LE(eocdOffset + 6) !== 0) {
|
|
79
|
+
invalid('multi-disk archives are not supported');
|
|
22
80
|
}
|
|
23
81
|
const totalEntries = this.buffer.readUInt16LE(eocdOffset + 10);
|
|
82
|
+
if (totalEntries !== this.buffer.readUInt16LE(eocdOffset + 8) || totalEntries > MAX_ENTRIES) {
|
|
83
|
+
invalid('entry count is inconsistent or exceeds the limit');
|
|
84
|
+
}
|
|
85
|
+
const centralDirectorySize = this.buffer.readUInt32LE(eocdOffset + 12);
|
|
24
86
|
const centralDirectoryOffset = this.buffer.readUInt32LE(eocdOffset + 16);
|
|
87
|
+
if (centralDirectoryOffset === 0xffffffff ||
|
|
88
|
+
centralDirectorySize === 0xffffffff ||
|
|
89
|
+
centralDirectoryOffset + centralDirectorySize !== eocdOffset) {
|
|
90
|
+
invalid('ZIP64 or inconsistent central directory');
|
|
91
|
+
}
|
|
92
|
+
this.requireRange(centralDirectoryOffset, centralDirectorySize);
|
|
25
93
|
const entries = [];
|
|
94
|
+
const exactPaths = new Set();
|
|
95
|
+
const foldedPaths = new Set();
|
|
26
96
|
let offset = centralDirectoryOffset;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
97
|
+
let totalUncompressed = 0;
|
|
98
|
+
for (let index = 0; index < totalEntries; index++) {
|
|
99
|
+
this.requireRange(offset, 46);
|
|
100
|
+
if (this.buffer.readUInt32LE(offset) !== 0x02014b50) {
|
|
101
|
+
invalid(`bad central directory signature at ${offset}`);
|
|
31
102
|
}
|
|
103
|
+
const creatorOs = this.buffer.readUInt8(offset + 5);
|
|
104
|
+
const flags = this.buffer.readUInt16LE(offset + 8);
|
|
32
105
|
const compressionMethod = this.buffer.readUInt16LE(offset + 10);
|
|
106
|
+
const crc = this.buffer.readUInt32LE(offset + 16);
|
|
33
107
|
const compressedSize = this.buffer.readUInt32LE(offset + 20);
|
|
34
108
|
const uncompressedSize = this.buffer.readUInt32LE(offset + 24);
|
|
35
109
|
const fileNameLength = this.buffer.readUInt16LE(offset + 28);
|
|
36
110
|
const extraLength = this.buffer.readUInt16LE(offset + 30);
|
|
37
111
|
const commentLength = this.buffer.readUInt16LE(offset + 32);
|
|
112
|
+
const externalAttributes = this.buffer.readUInt32LE(offset + 38);
|
|
38
113
|
const localHeaderOffset = this.buffer.readUInt32LE(offset + 42);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
114
|
+
const entryLength = 46 + fileNameLength + extraLength + commentLength;
|
|
115
|
+
this.requireRange(offset, entryLength);
|
|
116
|
+
if (compressedSize === 0xffffffff ||
|
|
117
|
+
uncompressedSize === 0xffffffff ||
|
|
118
|
+
localHeaderOffset === 0xffffffff) {
|
|
119
|
+
invalid('ZIP64 entries are not supported');
|
|
120
|
+
}
|
|
121
|
+
const entryPath = decode(this.buffer.subarray(offset + 46, offset + 46 + fileNameLength));
|
|
122
|
+
const isDirectory = entryPath.endsWith('/');
|
|
123
|
+
validateEntryPath(entryPath, isDirectory);
|
|
124
|
+
const comparablePath = isDirectory ? entryPath.slice(0, -1) : entryPath;
|
|
125
|
+
const folded = comparablePath.normalize('NFC').toLowerCase();
|
|
126
|
+
if (exactPaths.has(comparablePath))
|
|
127
|
+
invalid(`duplicate entry path: ${comparablePath}`);
|
|
128
|
+
if (foldedPaths.has(folded))
|
|
129
|
+
invalid(`case-conflicting entry path: ${comparablePath}`);
|
|
130
|
+
exactPaths.add(comparablePath);
|
|
131
|
+
foldedPaths.add(folded);
|
|
132
|
+
const fileType = externalAttributes >>> 16;
|
|
133
|
+
if (!isDirectory && fileType !== 0 && (fileType & 0o170000) !== 0o100000) {
|
|
134
|
+
invalid(`entry is not a regular file: ${entryPath}`);
|
|
135
|
+
}
|
|
136
|
+
if (uncompressedSize > MAX_ENTRY_BYTES)
|
|
137
|
+
invalid(`entry exceeds the size limit: ${entryPath}`);
|
|
138
|
+
totalUncompressed += uncompressedSize;
|
|
139
|
+
if (totalUncompressed > MAX_TOTAL_BYTES)
|
|
140
|
+
invalid('total uncompressed size exceeds the limit');
|
|
141
|
+
if (uncompressedSize > 64 * 1024 &&
|
|
142
|
+
uncompressedSize / Math.max(1, compressedSize) > MAX_COMPRESSION_RATIO) {
|
|
143
|
+
invalid(`compression ratio exceeds the limit: ${entryPath}`);
|
|
144
|
+
}
|
|
44
145
|
entries.push({
|
|
45
146
|
path: entryPath,
|
|
46
147
|
compressedSize,
|
|
47
148
|
uncompressedSize,
|
|
48
149
|
compressionMethod,
|
|
150
|
+
isDirectory,
|
|
151
|
+
externalAttributes,
|
|
152
|
+
creatorOs,
|
|
153
|
+
encrypted: (flags & 1) !== 0,
|
|
154
|
+
crc32: crc,
|
|
49
155
|
localHeaderOffset,
|
|
50
|
-
isDirectory: entryPath.endsWith('/'),
|
|
51
156
|
});
|
|
52
|
-
offset
|
|
157
|
+
offset += entryLength;
|
|
53
158
|
}
|
|
159
|
+
if (offset !== eocdOffset)
|
|
160
|
+
invalid('central directory size mismatch');
|
|
54
161
|
this.entriesCache = entries;
|
|
55
162
|
return entries;
|
|
56
163
|
}
|
|
57
164
|
readEntryData(entry) {
|
|
165
|
+
if (entry.encrypted)
|
|
166
|
+
invalid(`encrypted entry is not supported: ${entry.path}`);
|
|
167
|
+
if (entry.compressionMethod !== 0 && entry.compressionMethod !== 8) {
|
|
168
|
+
invalid(`unsupported compression method ${entry.compressionMethod}: ${entry.path}`);
|
|
169
|
+
}
|
|
58
170
|
const offset = entry.localHeaderOffset;
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
171
|
+
this.requireRange(offset, 30);
|
|
172
|
+
if (this.buffer.readUInt32LE(offset) !== 0x04034b50) {
|
|
173
|
+
invalid(`bad local header signature at ${offset}`);
|
|
174
|
+
}
|
|
175
|
+
if (this.buffer.readUInt16LE(offset + 8) !== entry.compressionMethod) {
|
|
176
|
+
invalid(`local compression method differs: ${entry.path}`);
|
|
62
177
|
}
|
|
63
178
|
const fileNameLength = this.buffer.readUInt16LE(offset + 26);
|
|
64
179
|
const extraLength = this.buffer.readUInt16LE(offset + 28);
|
|
180
|
+
this.requireRange(offset, 30 + fileNameLength + extraLength);
|
|
181
|
+
const localPath = decode(this.buffer.subarray(offset + 30, offset + 30 + fileNameLength));
|
|
182
|
+
if (localPath !== entry.path)
|
|
183
|
+
invalid(`local filename differs: ${entry.path}`);
|
|
65
184
|
const dataStart = offset + 30 + fileNameLength + extraLength;
|
|
185
|
+
this.requireRange(dataStart, entry.compressedSize);
|
|
66
186
|
const compressed = this.buffer.subarray(dataStart, dataStart + entry.compressedSize);
|
|
67
|
-
|
|
68
|
-
|
|
187
|
+
let data;
|
|
188
|
+
try {
|
|
189
|
+
data = entry.compressionMethod === 0
|
|
190
|
+
? Buffer.from(compressed)
|
|
191
|
+
: inflateRawSync(compressed, { maxOutputLength: entry.uncompressedSize + 1 });
|
|
69
192
|
}
|
|
70
|
-
|
|
71
|
-
|
|
193
|
+
catch {
|
|
194
|
+
invalid(`entry cannot be inflated safely: ${entry.path}`);
|
|
72
195
|
}
|
|
73
|
-
|
|
196
|
+
if (data.byteLength !== entry.uncompressedSize)
|
|
197
|
+
invalid(`entry size differs: ${entry.path}`);
|
|
198
|
+
if (crc32(data) !== entry.crc32)
|
|
199
|
+
invalid(`entry CRC differs: ${entry.path}`);
|
|
200
|
+
return data;
|
|
74
201
|
}
|
|
75
202
|
findEndOfCentralDirectory() {
|
|
76
203
|
const minOffset = Math.max(0, this.buffer.length - 0xffff - 22);
|
|
77
204
|
for (let offset = this.buffer.length - 22; offset >= minOffset; offset--) {
|
|
78
|
-
if (this.buffer.readUInt32LE(offset) === 0x06054b50
|
|
205
|
+
if (this.buffer.readUInt32LE(offset) === 0x06054b50 &&
|
|
206
|
+
offset + 22 + this.buffer.readUInt16LE(offset + 20) === this.buffer.length) {
|
|
79
207
|
return offset;
|
|
80
208
|
}
|
|
81
209
|
}
|
|
82
210
|
return -1;
|
|
83
211
|
}
|
|
212
|
+
requireRange(offset, length) {
|
|
213
|
+
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset < 0 || length < 0 || offset + length > this.buffer.length) {
|
|
214
|
+
invalid('truncated archive');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
84
217
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type UserConfig } from 'vite';
|
|
2
2
|
import type { Platform, BuildOptions, BaseBuildMetadata } from '../types.js';
|
|
3
|
+
import { type ViteWorkspace } from './workspace.js';
|
|
3
4
|
/**
|
|
4
5
|
* 通用 Vite 配置构建器(外部引擎专用)
|
|
5
6
|
*
|
|
@@ -16,9 +17,10 @@ export declare class GenericViteConfigBuilder {
|
|
|
16
17
|
private platform;
|
|
17
18
|
private options;
|
|
18
19
|
private baseBuildMetadata;
|
|
20
|
+
private workspace?;
|
|
19
21
|
private finalOutputDir;
|
|
20
22
|
private viteOutputDir;
|
|
21
|
-
constructor(baseBuildDir: string, platform: Platform, options: BuildOptions, baseBuildMetadata: BaseBuildMetadata);
|
|
23
|
+
constructor(baseBuildDir: string, platform: Platform, options: BuildOptions, baseBuildMetadata: BaseBuildMetadata, workspace?: ViteWorkspace | undefined);
|
|
22
24
|
/**
|
|
23
25
|
* 创建 Vite 配置
|
|
24
26
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger, defineConfig } from 'vite';
|
|
1
|
+
import { createLogger, defineConfig, } from 'vite';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { viteSingleFile } from 'vite-plugin-singlefile';
|
|
@@ -9,6 +9,7 @@ import imageminWebp from 'imagemin-webp';
|
|
|
9
9
|
import { PLATFORM_CONFIGS } from './platform-configs.js';
|
|
10
10
|
import { vitePlatformPlugin } from './plugin-platform.js';
|
|
11
11
|
import { createPlatformAdapter } from '../platforms/index.js';
|
|
12
|
+
import { resolveViteWorkspace } from './workspace.js';
|
|
12
13
|
/**
|
|
13
14
|
* 通用 Vite 配置构建器(外部引擎专用)
|
|
14
15
|
*
|
|
@@ -21,11 +22,12 @@ import { createPlatformAdapter } from '../platforms/index.js';
|
|
|
21
22
|
* - viteImagemin:图片压缩
|
|
22
23
|
*/
|
|
23
24
|
export class GenericViteConfigBuilder {
|
|
24
|
-
constructor(baseBuildDir, platform, options, baseBuildMetadata) {
|
|
25
|
+
constructor(baseBuildDir, platform, options, baseBuildMetadata, workspace) {
|
|
25
26
|
this.baseBuildDir = baseBuildDir;
|
|
26
27
|
this.platform = platform;
|
|
27
28
|
this.options = options;
|
|
28
29
|
this.baseBuildMetadata = baseBuildMetadata;
|
|
30
|
+
this.workspace = workspace;
|
|
29
31
|
this.finalOutputDir = '';
|
|
30
32
|
this.viteOutputDir = '';
|
|
31
33
|
// 统一规范化 baseBuildDir(与 ViteConfigBuilder 一致)
|
|
@@ -43,18 +45,18 @@ export class GenericViteConfigBuilder {
|
|
|
43
45
|
const outputDir = this.options.outputDir || './dist';
|
|
44
46
|
const playableOptions = this.getPlayableOptions(platformConfig);
|
|
45
47
|
const rootDir = this.baseBuildDir;
|
|
46
|
-
const
|
|
47
|
-
const viteOutputDirAbsolute = path.join(rootDir,
|
|
48
|
-
const finalOutputDir = path.isAbsolute(outputDir)
|
|
48
|
+
const workspace = this.workspace ? resolveViteWorkspace(rootDir, this.workspace) : undefined;
|
|
49
|
+
const viteOutputDirAbsolute = workspace?.intermediateDir ?? path.join(rootDir, '__dist__');
|
|
50
|
+
const finalOutputDir = workspace?.finalOutputDir ?? (path.isAbsolute(outputDir)
|
|
49
51
|
? outputDir
|
|
50
|
-
: path.resolve(process.cwd(), outputDir);
|
|
52
|
+
: path.resolve(process.cwd(), outputDir));
|
|
51
53
|
this.finalOutputDir = finalOutputDir;
|
|
52
54
|
this.viteOutputDir = viteOutputDirAbsolute;
|
|
53
55
|
console.log(`[GenericViteConfigBuilder] 路径配置:`);
|
|
54
56
|
console.log(` - root: ${rootDir}`);
|
|
55
57
|
console.log(` - viteOutputDir: ${viteOutputDirAbsolute}`);
|
|
56
58
|
console.log(` - finalOutputDir: ${finalOutputDir}`);
|
|
57
|
-
return this.createConfig(platformConfig,
|
|
59
|
+
return this.createConfig(platformConfig, workspace ? viteOutputDirAbsolute : '__dist__', playableOptions, rootDir);
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* 获取 Vite 的临时输出目录
|
|
@@ -92,7 +92,7 @@ async function createZipOutput(outDir) {
|
|
|
92
92
|
name: relativePath.split(path.sep).join('/'),
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
archive.finalize();
|
|
95
|
+
void archive.finalize().catch(reject);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
async function keepSingleHtml(outDir, htmlFileName) {
|
|
@@ -156,7 +156,6 @@ async function applyExternFiles(outDir, externFiles) {
|
|
|
156
156
|
const configFilename = `${folderName}/config.json`;
|
|
157
157
|
await rewriteIndexHtml(outDir, assetPrefix, configFilename);
|
|
158
158
|
await rewriteSettings(folderPath, assetPrefix, configFilename);
|
|
159
|
-
await rewriteConfig(folderPath);
|
|
160
159
|
}
|
|
161
160
|
async function rewriteIndexHtml(outDir, assetPrefix, configFilename) {
|
|
162
161
|
const indexPath = path.join(outDir, 'index.html');
|
|
@@ -248,16 +247,6 @@ async function rewriteSettings(folderPath, assetPrefix, configFilename) {
|
|
|
248
247
|
// 忽略缺失
|
|
249
248
|
}
|
|
250
249
|
}
|
|
251
|
-
async function rewriteConfig(configDir) {
|
|
252
|
-
// config.json 已移入资产文件夹,在此处可对其进行后处理
|
|
253
|
-
const configPath = path.join(configDir, 'config.json');
|
|
254
|
-
try {
|
|
255
|
-
await fs.access(configPath);
|
|
256
|
-
}
|
|
257
|
-
catch {
|
|
258
|
-
// 忽略缺失
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
250
|
/**
|
|
262
251
|
* 处理 ZIP 输出中 __settings__.js 的 PRELOAD_MODULES
|
|
263
252
|
*
|
|
@@ -366,27 +355,25 @@ async function stripAmmoAssetsFromConfig(outDir) {
|
|
|
366
355
|
try {
|
|
367
356
|
const raw = await fs.readFile(configPath, 'utf-8');
|
|
368
357
|
const configJson = JSON.parse(raw);
|
|
369
|
-
if (!configJson.assets)
|
|
370
|
-
return;
|
|
371
358
|
const assets = configJson.assets;
|
|
359
|
+
if (!assets)
|
|
360
|
+
return;
|
|
372
361
|
const ammoAssetIds = new Set();
|
|
373
362
|
const ammoRelatedIds = new Set();
|
|
374
363
|
// 找出所有 ammo 相关的 wasm assets 及其关联的 glue/fallback script
|
|
375
364
|
for (const [id, asset] of Object.entries(assets)) {
|
|
376
|
-
|
|
377
|
-
if (a.type === 'wasm' && a.data?.moduleName?.toLowerCase().includes('ammo')) {
|
|
365
|
+
if (asset.type === 'wasm' && asset.data?.moduleName?.toLowerCase().includes('ammo')) {
|
|
378
366
|
ammoAssetIds.add(id);
|
|
379
|
-
if (
|
|
380
|
-
ammoRelatedIds.add(String(
|
|
381
|
-
if (
|
|
382
|
-
ammoRelatedIds.add(String(
|
|
367
|
+
if (asset.data.glueScriptId != null)
|
|
368
|
+
ammoRelatedIds.add(String(asset.data.glueScriptId));
|
|
369
|
+
if (asset.data.fallbackScriptId != null)
|
|
370
|
+
ammoRelatedIds.add(String(asset.data.fallbackScriptId));
|
|
383
371
|
}
|
|
384
372
|
}
|
|
385
373
|
// 也检查 file.url 中包含 ammo 的 assets
|
|
386
374
|
for (const [id, asset] of Object.entries(assets)) {
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
const name = (a.name || '').toLowerCase();
|
|
375
|
+
const url = asset.file?.url?.toLowerCase() || '';
|
|
376
|
+
const name = (asset.name || '').toLowerCase();
|
|
390
377
|
if (url.includes('ammo') || name.includes('ammo')) {
|
|
391
378
|
ammoRelatedIds.add(id);
|
|
392
379
|
}
|
|
@@ -416,8 +403,7 @@ function isAmmoModule(module) {
|
|
|
416
403
|
fallbackUrl.includes('ammo'));
|
|
417
404
|
}
|
|
418
405
|
async function applyMraidSupport(outDir) {
|
|
419
|
-
//
|
|
420
|
-
// The MRAID resize patch handles the sizing correctly with any fillMode
|
|
406
|
+
// MRAID resize patch 会处理画布尺寸,不再修改 fillMode,避免缩放问题
|
|
421
407
|
await patchStylesForMraid(outDir);
|
|
422
408
|
}
|
|
423
409
|
async function patchStylesForMraid(outDir) {
|
|
@@ -578,7 +564,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
578
564
|
console.warn(`[Platform] inlineUnsupportedAssets: 无法读取 config.json: ${error}`);
|
|
579
565
|
return;
|
|
580
566
|
}
|
|
581
|
-
if (!configJson
|
|
567
|
+
if (!configJson.assets) {
|
|
582
568
|
return;
|
|
583
569
|
}
|
|
584
570
|
const configDir = path.dirname(configPath);
|
|
@@ -592,7 +578,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
592
578
|
const url = file.url;
|
|
593
579
|
if (url.startsWith('data:') || url.startsWith('http://') || url.startsWith('https://'))
|
|
594
580
|
continue;
|
|
595
|
-
const cleanUrl = url.split('?')[0];
|
|
581
|
+
const cleanUrl = url.split('?')[0] ?? url;
|
|
596
582
|
// 检查此文件是否为 Google 不支持的类型
|
|
597
583
|
if (isGoogleSupportedFile(cleanUrl))
|
|
598
584
|
continue;
|
|
@@ -676,7 +662,7 @@ async function findConfigJson(outDir) {
|
|
|
676
662
|
return directPath;
|
|
677
663
|
}
|
|
678
664
|
catch {
|
|
679
|
-
//
|
|
665
|
+
// 根目录没有 config.json,继续搜索子目录
|
|
680
666
|
}
|
|
681
667
|
// 在子目录中查找(externFiles 场景)
|
|
682
668
|
const entries = await fs.readdir(outDir, { withFileTypes: true });
|
|
@@ -688,7 +674,7 @@ async function findConfigJson(outDir) {
|
|
|
688
674
|
return subPath;
|
|
689
675
|
}
|
|
690
676
|
catch {
|
|
691
|
-
//
|
|
677
|
+
// 继续尝试其他子目录
|
|
692
678
|
}
|
|
693
679
|
}
|
|
694
680
|
}
|
|
@@ -706,7 +692,7 @@ async function cleanEmptyDirs(dir) {
|
|
|
706
692
|
await fs.rmdir(fullPath);
|
|
707
693
|
}
|
|
708
694
|
catch {
|
|
709
|
-
//
|
|
695
|
+
// 忽略删除失败
|
|
710
696
|
}
|
|
711
697
|
}
|
|
712
698
|
else {
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
+
import type { SourceBuilderPluginOptions } from './source-builder-types.js';
|
|
2
|
+
export type { SourceBuilderPluginOptions, UserScript } from './source-builder-types.js';
|
|
1
3
|
import type { Plugin } from 'vite';
|
|
2
|
-
import { type ImportMapAsset } from '../loaders/playcanvas-loader.js';
|
|
3
|
-
export interface SourceBuilderPluginOptions {
|
|
4
|
-
projectDir: string;
|
|
5
|
-
outputDir: string;
|
|
6
|
-
selectedScenes?: string[];
|
|
7
|
-
buildMode?: 'classic' | 'esm';
|
|
8
|
-
importMap?: ImportMapAsset;
|
|
9
|
-
}
|
|
10
|
-
export interface UserScript {
|
|
11
|
-
id: string;
|
|
12
|
-
path: string;
|
|
13
|
-
code: string;
|
|
14
|
-
name: string;
|
|
15
|
-
}
|
|
16
4
|
/**
|
|
17
5
|
* Vite 插件:从源代码构建 PlayCanvas 项目
|
|
18
6
|
*/
|