@playcraft/build 0.1.96-test-a → 0.1.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-builder.js +2 -41
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/index.d.ts +4 -19
- package/dist/index.js +2 -11
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.js +2 -2
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -4
- package/dist/validation/index.js +0 -4
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -178
- 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 +54 -30
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -16
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -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 -131
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -76
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/validation/artifact-qa.d.ts +0 -36
- package/dist/validation/artifact-qa.js +0 -261
- 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/runtime-load.d.ts +0 -94
- package/dist/validation/runtime-load.js +0 -653
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
|
@@ -1,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 的临时输出目录
|
|
@@ -62,7 +62,7 @@ export function vitePlatformPlugin(options) {
|
|
|
62
62
|
}
|
|
63
63
|
if (options.outputFormat === 'zip') {
|
|
64
64
|
// 等待 ZIP 创建完成
|
|
65
|
-
await createZipOutput(options.outputDir);
|
|
65
|
+
await createZipOutput(options.outputDir, platformConfig.outputFileName);
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
};
|
|
@@ -70,8 +70,8 @@ export function vitePlatformPlugin(options) {
|
|
|
70
70
|
/**
|
|
71
71
|
* 创建 ZIP 输出
|
|
72
72
|
*/
|
|
73
|
-
function createZipOutput(outDir) {
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
73
|
+
function createZipOutput(outDir, htmlFileName) {
|
|
74
|
+
return new Promise(async (resolve, reject) => {
|
|
75
75
|
const zipPath = path.join(outDir, 'playable.zip');
|
|
76
76
|
const output = createWriteStream(zipPath);
|
|
77
77
|
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
@@ -88,7 +88,7 @@ function createZipOutput(outDir) {
|
|
|
88
88
|
cwd: outDir,
|
|
89
89
|
ignore: ['playable.zip'],
|
|
90
90
|
});
|
|
91
|
-
|
|
91
|
+
archive.finalize();
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
async function keepSingleHtml(outDir, htmlFileName) {
|
|
@@ -96,7 +96,7 @@ async function keepSingleHtml(outDir, htmlFileName) {
|
|
|
96
96
|
try {
|
|
97
97
|
entries = await fs.readdir(outDir, { withFileTypes: true });
|
|
98
98
|
}
|
|
99
|
-
catch {
|
|
99
|
+
catch (error) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
// 如果目标文件名不是 index.html,先重命名
|
|
@@ -107,7 +107,7 @@ async function keepSingleHtml(outDir, htmlFileName) {
|
|
|
107
107
|
await fs.rename(indexPath, targetPath);
|
|
108
108
|
console.log(`[Platform] 已重命名 index.html -> ${htmlFileName}`);
|
|
109
109
|
}
|
|
110
|
-
catch {
|
|
110
|
+
catch (error) {
|
|
111
111
|
// index.html 可能不存在,忽略错误
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -147,6 +147,7 @@ async function applyExternFiles(outDir, externFiles) {
|
|
|
147
147
|
const configFilename = `${folderName}/config.json`;
|
|
148
148
|
await rewriteIndexHtml(outDir, assetPrefix, configFilename);
|
|
149
149
|
await rewriteSettings(folderPath, assetPrefix, configFilename);
|
|
150
|
+
await rewriteConfig(path.join(folderPath), folderPath, folderName);
|
|
150
151
|
}
|
|
151
152
|
async function rewriteIndexHtml(outDir, assetPrefix, configFilename) {
|
|
152
153
|
const indexPath = path.join(outDir, 'index.html');
|
|
@@ -234,7 +235,17 @@ async function rewriteSettings(folderPath, assetPrefix, configFilename) {
|
|
|
234
235
|
}
|
|
235
236
|
await fs.writeFile(settingsPath, code);
|
|
236
237
|
}
|
|
237
|
-
catch {
|
|
238
|
+
catch (error) {
|
|
239
|
+
// 忽略缺失
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
async function rewriteConfig(configDir, _folderPath, _folderName) {
|
|
243
|
+
// config.json 已移入资产文件夹,在此处可对其进行后处理
|
|
244
|
+
const configPath = path.join(configDir, 'config.json');
|
|
245
|
+
try {
|
|
246
|
+
await fs.access(configPath);
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
238
249
|
// 忽略缺失
|
|
239
250
|
}
|
|
240
251
|
}
|
|
@@ -346,25 +357,27 @@ async function stripAmmoAssetsFromConfig(outDir) {
|
|
|
346
357
|
try {
|
|
347
358
|
const raw = await fs.readFile(configPath, 'utf-8');
|
|
348
359
|
const configJson = JSON.parse(raw);
|
|
349
|
-
|
|
350
|
-
if (!assets)
|
|
360
|
+
if (!configJson.assets)
|
|
351
361
|
return;
|
|
362
|
+
const assets = configJson.assets;
|
|
352
363
|
const ammoAssetIds = new Set();
|
|
353
364
|
const ammoRelatedIds = new Set();
|
|
354
365
|
// 找出所有 ammo 相关的 wasm assets 及其关联的 glue/fallback script
|
|
355
366
|
for (const [id, asset] of Object.entries(assets)) {
|
|
356
|
-
|
|
367
|
+
const a = asset;
|
|
368
|
+
if (a.type === 'wasm' && a.data?.moduleName?.toLowerCase().includes('ammo')) {
|
|
357
369
|
ammoAssetIds.add(id);
|
|
358
|
-
if (
|
|
359
|
-
ammoRelatedIds.add(String(
|
|
360
|
-
if (
|
|
361
|
-
ammoRelatedIds.add(String(
|
|
370
|
+
if (a.data.glueScriptId != null)
|
|
371
|
+
ammoRelatedIds.add(String(a.data.glueScriptId));
|
|
372
|
+
if (a.data.fallbackScriptId != null)
|
|
373
|
+
ammoRelatedIds.add(String(a.data.fallbackScriptId));
|
|
362
374
|
}
|
|
363
375
|
}
|
|
364
376
|
// 也检查 file.url 中包含 ammo 的 assets
|
|
365
377
|
for (const [id, asset] of Object.entries(assets)) {
|
|
366
|
-
const
|
|
367
|
-
const
|
|
378
|
+
const a = asset;
|
|
379
|
+
const url = a.file?.url?.toLowerCase() || '';
|
|
380
|
+
const name = (a.name || '').toLowerCase();
|
|
368
381
|
if (url.includes('ammo') || name.includes('ammo')) {
|
|
369
382
|
ammoRelatedIds.add(id);
|
|
370
383
|
}
|
|
@@ -394,9 +407,26 @@ function isAmmoModule(module) {
|
|
|
394
407
|
fallbackUrl.includes('ammo'));
|
|
395
408
|
}
|
|
396
409
|
async function applyMraidSupport(outDir) {
|
|
397
|
-
//
|
|
410
|
+
// Note: We no longer patch fillMode to 'NONE' because it causes canvas scaling issues
|
|
411
|
+
// The MRAID resize patch handles the sizing correctly with any fillMode
|
|
412
|
+
// await patchConfigFillMode(outDir); // Removed: causes canvas scaling issues
|
|
398
413
|
await patchStylesForMraid(outDir);
|
|
399
414
|
}
|
|
415
|
+
async function patchConfigFillMode(outDir) {
|
|
416
|
+
const configPath = path.join(outDir, 'config.json');
|
|
417
|
+
try {
|
|
418
|
+
const raw = await fs.readFile(configPath, 'utf-8');
|
|
419
|
+
const json = JSON.parse(raw);
|
|
420
|
+
json.application_properties = {
|
|
421
|
+
...(json.application_properties || {}),
|
|
422
|
+
fillMode: 'NONE',
|
|
423
|
+
};
|
|
424
|
+
await fs.writeFile(configPath, JSON.stringify(json));
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
// 忽略缺失
|
|
428
|
+
}
|
|
429
|
+
}
|
|
400
430
|
async function patchStylesForMraid(outDir) {
|
|
401
431
|
const cssPath = path.join(outDir, 'styles.css');
|
|
402
432
|
try {
|
|
@@ -406,7 +436,7 @@ async function patchStylesForMraid(outDir) {
|
|
|
406
436
|
await fs.writeFile(cssPath, css);
|
|
407
437
|
}
|
|
408
438
|
}
|
|
409
|
-
catch {
|
|
439
|
+
catch (error) {
|
|
410
440
|
// 忽略缺失
|
|
411
441
|
}
|
|
412
442
|
}
|
|
@@ -493,7 +523,7 @@ async function minifyJSFilesInDir(dir) {
|
|
|
493
523
|
const ratio = originalSize > 0 ? ((saved / originalSize) * 100).toFixed(1) : '0';
|
|
494
524
|
console.log(` ✓ ${relativePath}: ${(originalSize / 1024).toFixed(1)}KB → ${(minifiedSize / 1024).toFixed(1)}KB (-${ratio}%)`);
|
|
495
525
|
}
|
|
496
|
-
catch {
|
|
526
|
+
catch (error) {
|
|
497
527
|
console.warn(` ⚠ ${path.relative(dir, filePath)}: 压缩失败,保留原文件`);
|
|
498
528
|
}
|
|
499
529
|
}
|
|
@@ -579,7 +609,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
579
609
|
console.warn(`[Platform] inlineUnsupportedAssets: 无法读取 config.json: ${error}`);
|
|
580
610
|
return;
|
|
581
611
|
}
|
|
582
|
-
if (!configJson
|
|
612
|
+
if (!configJson?.assets) {
|
|
583
613
|
return;
|
|
584
614
|
}
|
|
585
615
|
const configDir = path.dirname(configPath);
|
|
@@ -593,7 +623,7 @@ async function inlineUnsupportedAssetsIntoConfig(outDir) {
|
|
|
593
623
|
const url = file.url;
|
|
594
624
|
if (url.startsWith('data:') || url.startsWith('http://') || url.startsWith('https://'))
|
|
595
625
|
continue;
|
|
596
|
-
const cleanUrl = url.split('?')[0]
|
|
626
|
+
const cleanUrl = url.split('?')[0];
|
|
597
627
|
// 检查此文件是否为 Google 不支持的类型
|
|
598
628
|
if (isGoogleSupportedFile(cleanUrl))
|
|
599
629
|
continue;
|
|
@@ -676,9 +706,7 @@ async function findConfigJson(outDir) {
|
|
|
676
706
|
await fs.access(directPath);
|
|
677
707
|
return directPath;
|
|
678
708
|
}
|
|
679
|
-
catch {
|
|
680
|
-
// 根目录没有 config.json,继续搜索子目录
|
|
681
|
-
}
|
|
709
|
+
catch { }
|
|
682
710
|
// 在子目录中查找(externFiles 场景)
|
|
683
711
|
const entries = await fs.readdir(outDir, { withFileTypes: true });
|
|
684
712
|
for (const entry of entries) {
|
|
@@ -688,9 +716,7 @@ async function findConfigJson(outDir) {
|
|
|
688
716
|
await fs.access(subPath);
|
|
689
717
|
return subPath;
|
|
690
718
|
}
|
|
691
|
-
catch {
|
|
692
|
-
// 继续尝试其他子目录
|
|
693
|
-
}
|
|
719
|
+
catch { }
|
|
694
720
|
}
|
|
695
721
|
}
|
|
696
722
|
return null;
|
|
@@ -706,9 +732,7 @@ async function cleanEmptyDirs(dir) {
|
|
|
706
732
|
try {
|
|
707
733
|
await fs.rmdir(fullPath);
|
|
708
734
|
}
|
|
709
|
-
catch {
|
|
710
|
-
// 忽略删除失败
|
|
711
|
-
}
|
|
735
|
+
catch { }
|
|
712
736
|
}
|
|
713
737
|
else {
|
|
714
738
|
isEmpty = false;
|
|
@@ -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
|
*/
|