@playcraft/build 0.2.19-test-a → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-builder.js +2 -42
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/engines/playable-scripts-adapter.js +5 -2
- package/dist/index.d.ts +4 -21
- package/dist/index.js +2 -12
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.d.ts +0 -4
- package/dist/platforms/base.js +6 -25
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +2 -12
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.js +0 -5
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -201
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -64
- package/dist/validation/zip-reader.d.ts +0 -7
- package/dist/validation/zip-reader.js +26 -159
- package/dist/vite/config-builder-generic.d.ts +1 -3
- package/dist/vite/config-builder-generic.js +7 -9
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +30 -16
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -30
- package/templates/patches/one-page-mraid-resize-canvas.js +2 -0
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -21
- package/dist/delivery/command-isolation.js +0 -327
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -146
- package/dist/delivery/files.d.ts +0 -9
- package/dist/delivery/files.js +0 -144
- package/dist/delivery/git-source-fingerprint.d.ts +0 -2
- package/dist/delivery/git-source-fingerprint.js +0 -58
- package/dist/delivery/isolated-source.d.ts +0 -5
- package/dist/delivery/isolated-source.js +0 -148
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -81
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/redirect-policy.d.ts +0 -23
- package/dist/redirect-policy.js +0 -25
- package/dist/validation/artifact-qa.d.ts +0 -36
- package/dist/validation/artifact-qa.js +0 -263
- package/dist/validation/artifact-rules.d.ts +0 -39
- package/dist/validation/artifact-rules.js +0 -451
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/playwright-driver.d.ts +0 -37
- package/dist/validation/playwright-driver.js +0 -302
- package/dist/validation/runtime-cover.d.ts +0 -32
- package/dist/validation/runtime-cover.js +0 -120
- package/dist/validation/runtime-load.d.ts +0 -141
- package/dist/validation/runtime-load.js +0 -812
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
- package/templates/patches/playcraft-redirect-policy.js +0 -115
|
@@ -1,217 +1,84 @@
|
|
|
1
|
-
import { inflateRawSync } from '
|
|
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. */
|
|
1
|
+
import { inflateRawSync } from 'zlib';
|
|
42
2
|
export class SimpleZipReader {
|
|
43
3
|
constructor(buffer) {
|
|
44
4
|
this.buffer = buffer;
|
|
45
|
-
if (buffer.byteLength > MAX_ARCHIVE_BYTES)
|
|
46
|
-
invalid('archive exceeds the size limit');
|
|
47
5
|
}
|
|
48
6
|
listEntries() {
|
|
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
|
-
}));
|
|
7
|
+
return this.readCentralDirectory().map(({ localHeaderOffset: _offset, ...entry }) => entry);
|
|
60
8
|
}
|
|
61
9
|
readEntryText(entryPath) {
|
|
62
|
-
return this.readEntry(entryPath)?.toString('utf-8') ?? null;
|
|
63
|
-
}
|
|
64
|
-
readEntry(entryPath) {
|
|
65
10
|
const entry = this.readCentralDirectory().find((item) => item.path === entryPath);
|
|
66
11
|
if (!entry || entry.isDirectory)
|
|
67
12
|
return null;
|
|
68
|
-
|
|
13
|
+
const data = this.readEntryData(entry);
|
|
14
|
+
return data.toString('utf-8');
|
|
69
15
|
}
|
|
70
16
|
readCentralDirectory() {
|
|
71
17
|
if (this.entriesCache)
|
|
72
18
|
return this.entriesCache;
|
|
73
19
|
const eocdOffset = this.findEndOfCentralDirectory();
|
|
74
|
-
if (eocdOffset < 0)
|
|
75
|
-
|
|
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');
|
|
20
|
+
if (eocdOffset < 0) {
|
|
21
|
+
throw new Error('Invalid ZIP: end of central directory not found');
|
|
80
22
|
}
|
|
81
23
|
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);
|
|
86
24
|
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);
|
|
93
25
|
const entries = [];
|
|
94
|
-
const exactPaths = new Set();
|
|
95
|
-
const foldedPaths = new Set();
|
|
96
26
|
let offset = centralDirectoryOffset;
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
invalid(`bad central directory signature at ${offset}`);
|
|
27
|
+
for (let i = 0; i < totalEntries; i++) {
|
|
28
|
+
const signature = this.buffer.readUInt32LE(offset);
|
|
29
|
+
if (signature !== 0x02014b50) {
|
|
30
|
+
throw new Error(`Invalid ZIP: bad central directory signature at ${offset}`);
|
|
102
31
|
}
|
|
103
|
-
const creatorOs = this.buffer.readUInt8(offset + 5);
|
|
104
|
-
const flags = this.buffer.readUInt16LE(offset + 8);
|
|
105
32
|
const compressionMethod = this.buffer.readUInt16LE(offset + 10);
|
|
106
|
-
const crc = this.buffer.readUInt32LE(offset + 16);
|
|
107
33
|
const compressedSize = this.buffer.readUInt32LE(offset + 20);
|
|
108
34
|
const uncompressedSize = this.buffer.readUInt32LE(offset + 24);
|
|
109
35
|
const fileNameLength = this.buffer.readUInt16LE(offset + 28);
|
|
110
36
|
const extraLength = this.buffer.readUInt16LE(offset + 30);
|
|
111
37
|
const commentLength = this.buffer.readUInt16LE(offset + 32);
|
|
112
|
-
const externalAttributes = this.buffer.readUInt32LE(offset + 38);
|
|
113
38
|
const localHeaderOffset = this.buffer.readUInt32LE(offset + 42);
|
|
114
|
-
const
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
}
|
|
39
|
+
const fileNameStart = offset + 46;
|
|
40
|
+
const entryPath = this.buffer
|
|
41
|
+
.subarray(fileNameStart, fileNameStart + fileNameLength)
|
|
42
|
+
.toString('utf-8')
|
|
43
|
+
.replace(/\\/g, '/');
|
|
145
44
|
entries.push({
|
|
146
45
|
path: entryPath,
|
|
147
46
|
compressedSize,
|
|
148
47
|
uncompressedSize,
|
|
149
48
|
compressionMethod,
|
|
150
|
-
isDirectory,
|
|
151
|
-
externalAttributes,
|
|
152
|
-
creatorOs,
|
|
153
|
-
encrypted: (flags & 1) !== 0,
|
|
154
|
-
crc32: crc,
|
|
155
49
|
localHeaderOffset,
|
|
50
|
+
isDirectory: entryPath.endsWith('/'),
|
|
156
51
|
});
|
|
157
|
-
offset
|
|
52
|
+
offset = fileNameStart + fileNameLength + extraLength + commentLength;
|
|
158
53
|
}
|
|
159
|
-
if (offset !== eocdOffset)
|
|
160
|
-
invalid('central directory size mismatch');
|
|
161
54
|
this.entriesCache = entries;
|
|
162
55
|
return entries;
|
|
163
56
|
}
|
|
164
57
|
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
|
-
}
|
|
170
58
|
const offset = entry.localHeaderOffset;
|
|
171
|
-
this.
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
if (this.buffer.readUInt16LE(offset + 8) !== entry.compressionMethod) {
|
|
176
|
-
invalid(`local compression method differs: ${entry.path}`);
|
|
59
|
+
const signature = this.buffer.readUInt32LE(offset);
|
|
60
|
+
if (signature !== 0x04034b50) {
|
|
61
|
+
throw new Error(`Invalid ZIP: bad local header signature at ${offset}`);
|
|
177
62
|
}
|
|
178
63
|
const fileNameLength = this.buffer.readUInt16LE(offset + 26);
|
|
179
64
|
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}`);
|
|
184
65
|
const dataStart = offset + 30 + fileNameLength + extraLength;
|
|
185
|
-
this.requireRange(dataStart, entry.compressedSize);
|
|
186
66
|
const compressed = this.buffer.subarray(dataStart, dataStart + entry.compressedSize);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
data = entry.compressionMethod === 0
|
|
190
|
-
? Buffer.from(compressed)
|
|
191
|
-
: inflateRawSync(compressed, { maxOutputLength: entry.uncompressedSize + 1 });
|
|
67
|
+
if (entry.compressionMethod === 0) {
|
|
68
|
+
return Buffer.from(compressed);
|
|
192
69
|
}
|
|
193
|
-
|
|
194
|
-
|
|
70
|
+
if (entry.compressionMethod === 8) {
|
|
71
|
+
return inflateRawSync(compressed);
|
|
195
72
|
}
|
|
196
|
-
|
|
197
|
-
invalid(`entry size differs: ${entry.path}`);
|
|
198
|
-
if (crc32(data) !== entry.crc32)
|
|
199
|
-
invalid(`entry CRC differs: ${entry.path}`);
|
|
200
|
-
return data;
|
|
73
|
+
throw new Error(`Unsupported ZIP compression method: ${entry.compressionMethod}`);
|
|
201
74
|
}
|
|
202
75
|
findEndOfCentralDirectory() {
|
|
203
76
|
const minOffset = Math.max(0, this.buffer.length - 0xffff - 22);
|
|
204
77
|
for (let offset = this.buffer.length - 22; offset >= minOffset; offset--) {
|
|
205
|
-
if (this.buffer.readUInt32LE(offset) === 0x06054b50
|
|
206
|
-
offset + 22 + this.buffer.readUInt16LE(offset + 20) === this.buffer.length) {
|
|
78
|
+
if (this.buffer.readUInt32LE(offset) === 0x06054b50) {
|
|
207
79
|
return offset;
|
|
208
80
|
}
|
|
209
81
|
}
|
|
210
82
|
return -1;
|
|
211
83
|
}
|
|
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
|
-
}
|
|
217
84
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type UserConfig } from 'vite';
|
|
2
2
|
import type { Platform, BuildOptions, BaseBuildMetadata } from '../types.js';
|
|
3
|
-
import { type ViteWorkspace } from './workspace.js';
|
|
4
3
|
/**
|
|
5
4
|
* 通用 Vite 配置构建器(外部引擎专用)
|
|
6
5
|
*
|
|
@@ -17,10 +16,9 @@ export declare class GenericViteConfigBuilder {
|
|
|
17
16
|
private platform;
|
|
18
17
|
private options;
|
|
19
18
|
private baseBuildMetadata;
|
|
20
|
-
private workspace?;
|
|
21
19
|
private finalOutputDir;
|
|
22
20
|
private viteOutputDir;
|
|
23
|
-
constructor(baseBuildDir: string, platform: Platform, options: BuildOptions, baseBuildMetadata: BaseBuildMetadata
|
|
21
|
+
constructor(baseBuildDir: string, platform: Platform, options: BuildOptions, baseBuildMetadata: BaseBuildMetadata);
|
|
24
22
|
/**
|
|
25
23
|
* 创建 Vite 配置
|
|
26
24
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger, defineConfig
|
|
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,7 +9,6 @@ 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';
|
|
13
12
|
/**
|
|
14
13
|
* 通用 Vite 配置构建器(外部引擎专用)
|
|
15
14
|
*
|
|
@@ -22,12 +21,11 @@ import { resolveViteWorkspace } from './workspace.js';
|
|
|
22
21
|
* - viteImagemin:图片压缩
|
|
23
22
|
*/
|
|
24
23
|
export class GenericViteConfigBuilder {
|
|
25
|
-
constructor(baseBuildDir, platform, options, baseBuildMetadata
|
|
24
|
+
constructor(baseBuildDir, platform, options, baseBuildMetadata) {
|
|
26
25
|
this.baseBuildDir = baseBuildDir;
|
|
27
26
|
this.platform = platform;
|
|
28
27
|
this.options = options;
|
|
29
28
|
this.baseBuildMetadata = baseBuildMetadata;
|
|
30
|
-
this.workspace = workspace;
|
|
31
29
|
this.finalOutputDir = '';
|
|
32
30
|
this.viteOutputDir = '';
|
|
33
31
|
// 统一规范化 baseBuildDir(与 ViteConfigBuilder 一致)
|
|
@@ -45,18 +43,18 @@ export class GenericViteConfigBuilder {
|
|
|
45
43
|
const outputDir = this.options.outputDir || './dist';
|
|
46
44
|
const playableOptions = this.getPlayableOptions(platformConfig);
|
|
47
45
|
const rootDir = this.baseBuildDir;
|
|
48
|
-
const
|
|
49
|
-
const viteOutputDirAbsolute =
|
|
50
|
-
const finalOutputDir =
|
|
46
|
+
const viteOutputDir = '__dist__';
|
|
47
|
+
const viteOutputDirAbsolute = path.join(rootDir, viteOutputDir);
|
|
48
|
+
const finalOutputDir = path.isAbsolute(outputDir)
|
|
51
49
|
? outputDir
|
|
52
|
-
: path.resolve(process.cwd(), outputDir)
|
|
50
|
+
: path.resolve(process.cwd(), outputDir);
|
|
53
51
|
this.finalOutputDir = finalOutputDir;
|
|
54
52
|
this.viteOutputDir = viteOutputDirAbsolute;
|
|
55
53
|
console.log(`[GenericViteConfigBuilder] 路径配置:`);
|
|
56
54
|
console.log(` - root: ${rootDir}`);
|
|
57
55
|
console.log(` - viteOutputDir: ${viteOutputDirAbsolute}`);
|
|
58
56
|
console.log(` - finalOutputDir: ${finalOutputDir}`);
|
|
59
|
-
return this.createConfig(platformConfig,
|
|
57
|
+
return this.createConfig(platformConfig, viteOutputDir, playableOptions, rootDir);
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
62
60
|
* 获取 Vite 的临时输出目录
|
|
@@ -92,7 +92,7 @@ async function createZipOutput(outDir) {
|
|
|
92
92
|
name: relativePath.split(path.sep).join('/'),
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
archive.finalize();
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
async function keepSingleHtml(outDir, htmlFileName) {
|
|
@@ -156,6 +156,7 @@ 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);
|
|
159
160
|
}
|
|
160
161
|
async function rewriteIndexHtml(outDir, assetPrefix, configFilename) {
|
|
161
162
|
const indexPath = path.join(outDir, 'index.html');
|
|
@@ -247,6 +248,16 @@ async function rewriteSettings(folderPath, assetPrefix, configFilename) {
|
|
|
247
248
|
// 忽略缺失
|
|
248
249
|
}
|
|
249
250
|
}
|
|
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
|
+
}
|
|
250
261
|
/**
|
|
251
262
|
* 处理 ZIP 输出中 __settings__.js 的 PRELOAD_MODULES
|
|
252
263
|
*
|
|
@@ -355,25 +366,27 @@ async function stripAmmoAssetsFromConfig(outDir) {
|
|
|
355
366
|
try {
|
|
356
367
|
const raw = await fs.readFile(configPath, 'utf-8');
|
|
357
368
|
const configJson = JSON.parse(raw);
|
|
358
|
-
|
|
359
|
-
if (!assets)
|
|
369
|
+
if (!configJson.assets)
|
|
360
370
|
return;
|
|
371
|
+
const assets = configJson.assets;
|
|
361
372
|
const ammoAssetIds = new Set();
|
|
362
373
|
const ammoRelatedIds = new Set();
|
|
363
374
|
// 找出所有 ammo 相关的 wasm assets 及其关联的 glue/fallback script
|
|
364
375
|
for (const [id, asset] of Object.entries(assets)) {
|
|
365
|
-
|
|
376
|
+
const a = asset;
|
|
377
|
+
if (a.type === 'wasm' && a.data?.moduleName?.toLowerCase().includes('ammo')) {
|
|
366
378
|
ammoAssetIds.add(id);
|
|
367
|
-
if (
|
|
368
|
-
ammoRelatedIds.add(String(
|
|
369
|
-
if (
|
|
370
|
-
ammoRelatedIds.add(String(
|
|
379
|
+
if (a.data.glueScriptId != null)
|
|
380
|
+
ammoRelatedIds.add(String(a.data.glueScriptId));
|
|
381
|
+
if (a.data.fallbackScriptId != null)
|
|
382
|
+
ammoRelatedIds.add(String(a.data.fallbackScriptId));
|
|
371
383
|
}
|
|
372
384
|
}
|
|
373
385
|
// 也检查 file.url 中包含 ammo 的 assets
|
|
374
386
|
for (const [id, asset] of Object.entries(assets)) {
|
|
375
|
-
const
|
|
376
|
-
const
|
|
387
|
+
const a = asset;
|
|
388
|
+
const url = a.file?.url?.toLowerCase() || '';
|
|
389
|
+
const name = (a.name || '').toLowerCase();
|
|
377
390
|
if (url.includes('ammo') || name.includes('ammo')) {
|
|
378
391
|
ammoRelatedIds.add(id);
|
|
379
392
|
}
|
|
@@ -403,7 +416,8 @@ function isAmmoModule(module) {
|
|
|
403
416
|
fallbackUrl.includes('ammo'));
|
|
404
417
|
}
|
|
405
418
|
async function applyMraidSupport(outDir) {
|
|
406
|
-
//
|
|
419
|
+
// Note: We no longer patch fillMode to 'NONE' because it causes canvas scaling issues
|
|
420
|
+
// The MRAID resize patch handles the sizing correctly with any fillMode
|
|
407
421
|
await patchStylesForMraid(outDir);
|
|
408
422
|
}
|
|
409
423
|
async function patchStylesForMraid(outDir) {
|
|
@@ -564,7 +578,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
564
578
|
console.warn(`[Platform] inlineUnsupportedAssets: 无法读取 config.json: ${error}`);
|
|
565
579
|
return;
|
|
566
580
|
}
|
|
567
|
-
if (!configJson
|
|
581
|
+
if (!configJson?.assets) {
|
|
568
582
|
return;
|
|
569
583
|
}
|
|
570
584
|
const configDir = path.dirname(configPath);
|
|
@@ -578,7 +592,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
578
592
|
const url = file.url;
|
|
579
593
|
if (url.startsWith('data:') || url.startsWith('http://') || url.startsWith('https://'))
|
|
580
594
|
continue;
|
|
581
|
-
const cleanUrl = url.split('?')[0]
|
|
595
|
+
const cleanUrl = url.split('?')[0];
|
|
582
596
|
// 检查此文件是否为 Google 不支持的类型
|
|
583
597
|
if (isGoogleSupportedFile(cleanUrl))
|
|
584
598
|
continue;
|
|
@@ -662,7 +676,7 @@ async function findConfigJson(outDir) {
|
|
|
662
676
|
return directPath;
|
|
663
677
|
}
|
|
664
678
|
catch {
|
|
665
|
-
//
|
|
679
|
+
// 根目录没有配置时继续查找外置资源目录。
|
|
666
680
|
}
|
|
667
681
|
// 在子目录中查找(externFiles 场景)
|
|
668
682
|
const entries = await fs.readdir(outDir, { withFileTypes: true });
|
|
@@ -674,7 +688,7 @@ async function findConfigJson(outDir) {
|
|
|
674
688
|
return subPath;
|
|
675
689
|
}
|
|
676
690
|
catch {
|
|
677
|
-
//
|
|
691
|
+
// 当前子目录没有配置时继续检查其余目录。
|
|
678
692
|
}
|
|
679
693
|
}
|
|
680
694
|
}
|
|
@@ -692,7 +706,7 @@ async function cleanEmptyDirs(dir) {
|
|
|
692
706
|
await fs.rmdir(fullPath);
|
|
693
707
|
}
|
|
694
708
|
catch {
|
|
695
|
-
//
|
|
709
|
+
// 目录已消失或被其他操作写入时保留现有内容。
|
|
696
710
|
}
|
|
697
711
|
}
|
|
698
712
|
else {
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type { SourceBuilderPluginOptions } from './source-builder-types.js';
|
|
2
|
-
export type { SourceBuilderPluginOptions, UserScript } from './source-builder-types.js';
|
|
3
1
|
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
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
* Vite 插件:从源代码构建 PlayCanvas 项目
|
|
6
18
|
*/
|