@cocos/ccbuild 1.1.17 → 1.1.19
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/CHANGELOG.md +12 -0
- package/README.md +37 -37
- package/lib/api-builder.js +1 -1
- package/lib/build-engine/engine-js/index.d.ts +2 -2
- package/lib/build-engine/engine-js/index.js +406 -406
- package/lib/build-engine/engine-js/rollup-plugins/external-wasm-loader.d.ts +57 -57
- package/lib/build-engine/engine-js/rollup-plugins/external-wasm-loader.d.ts.map +1 -1
- package/lib/build-engine/engine-js/rollup-plugins/external-wasm-loader.js +326 -298
- package/lib/build-engine/engine-js/rollup-plugins/external-wasm-loader.js.map +1 -1
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.d.ts +2 -2
- package/lib/build-engine/engine-js/rollup-plugins/remove-deprecated-features.js +37 -37
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.d.ts +4 -4
- package/lib/build-engine/engine-js/rollup-plugins/ts-paths.js +42 -42
- package/lib/build-engine/engine-ts/engine-builder.d.ts +57 -57
- package/lib/build-engine/engine-ts/engine-builder.js +631 -631
- package/lib/build-engine/engine-ts/field-decorator-helper.d.ts +9 -9
- package/lib/build-engine/engine-ts/field-decorator-helper.js +54 -54
- package/lib/build-engine/engine-ts/index.d.ts +2 -2
- package/lib/build-engine/engine-ts/index.js +36 -36
- package/lib/build-engine/engine-ts/plugins/external-wasm-loader.d.ts +6 -6
- package/lib/build-engine/engine-ts/plugins/external-wasm-loader.js +65 -65
- package/lib/build-engine/engine-ts/plugins/interface.d.ts +20 -20
- package/lib/build-engine/engine-ts/plugins/interface.js +1 -1
- package/lib/build-engine/index.d.ts +145 -145
- package/lib/build-engine/index.d.ts.map +1 -1
- package/lib/build-engine/index.js +167 -167
- package/lib/build-engine/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +33 -33
- package/lib/module-resolver.d.ts +7 -7
- package/lib/module-resolver.js +28 -28
- package/lib/stats-query/config-interface.d.ts +129 -129
- package/lib/stats-query/config-interface.js +3 -3
- package/lib/stats-query/index.d.ts +183 -183
- package/lib/stats-query/index.js +531 -531
- package/lib/stats-query/path-utils.d.ts +2 -2
- package/lib/stats-query/path-utils.js +35 -35
- package/lib/transformer/babel.d.ts +5 -5
- package/lib/transformer/babel.js +34 -34
- package/lib/transformer/index.d.ts +2 -2
- package/lib/transformer/index.js +28 -28
- package/lib/utils.d.ts +4 -4
- package/lib/utils.js +23 -23
- package/package.json +1 -1
- package/static/helper-dynamic-constants.txt +13 -13
- package/static/helper-file-decorator.ts +20 -20
- package/static/helper-global-exporter.txt +8 -8
- package/static/lib.dom.d.ts +20227 -20227
|
@@ -1,299 +1,327 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.pathToAssetRefURL = exports.externalWasmLoader = void 0;
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.pathToAssetRefURL = exports.externalWasmLoader = void 0;
|
|
39
|
+
const rollup = __importStar(require("rollup"));
|
|
40
|
+
const plugin_commonjs_1 = __importDefault(require("@rollup/plugin-commonjs"));
|
|
41
|
+
const url_1 = require("url");
|
|
42
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const babel = __importStar(require("@babel/core"));
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
const plugin_transform_modules_systemjs_1 = __importDefault(require("@babel/plugin-transform-modules-systemjs"));
|
|
47
|
+
const externalOrigin = 'external:';
|
|
48
|
+
function normalizePath(path) {
|
|
49
|
+
return path.replace(/\\/g, '/');
|
|
50
|
+
}
|
|
51
|
+
const suffixReplaceConfig = {
|
|
52
|
+
'.mem': '.mem.bin',
|
|
53
|
+
'.wasm.fallback': '.wasm.fallback.bin',
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* emit asset and return the export statement
|
|
57
|
+
*/
|
|
58
|
+
function emitAsset(context, filePath) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
let basename = path_1.default.basename(filePath);
|
|
61
|
+
for (let suffixToReplace in suffixReplaceConfig) {
|
|
62
|
+
const replacement = suffixReplaceConfig[suffixToReplace];
|
|
63
|
+
if (basename.endsWith(suffixToReplace)) {
|
|
64
|
+
// some platforms doesn't support files with special suffix like '.mem', we replace it to '.bin'
|
|
65
|
+
basename = basename.slice(0, -suffixToReplace.length) + replacement;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const referenceId = context.emitFile({
|
|
69
|
+
type: 'asset',
|
|
70
|
+
name: basename,
|
|
71
|
+
// fileName: path,
|
|
72
|
+
source: yield fs_extra_1.default.readFile(filePath),
|
|
73
|
+
});
|
|
74
|
+
return `export default import.meta.ROLLUP_FILE_URL_${referenceId};`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function shouldCullBulletWasmModule(options, id) {
|
|
78
|
+
return options.forceBanningBulletWasm && id.includes('bullet');
|
|
79
|
+
}
|
|
80
|
+
function shouldCullAsmJsModule(options, id) {
|
|
81
|
+
return options.wasmSupportMode !== 0 && options.cullAsmJsModule;
|
|
82
|
+
}
|
|
83
|
+
const loadConfig = {
|
|
84
|
+
'.wasm': {
|
|
85
|
+
shouldCullModule(options, id) {
|
|
86
|
+
return options.wasmSupportMode === 0 || shouldCullBulletWasmModule(options, id);
|
|
87
|
+
},
|
|
88
|
+
shouldEmitAsset(options, id) {
|
|
89
|
+
return !this.shouldCullModule(options, id);
|
|
90
|
+
},
|
|
91
|
+
cullingContent: `export default '';`,
|
|
92
|
+
},
|
|
93
|
+
'.js.mem': {
|
|
94
|
+
shouldCullModule(options, id) {
|
|
95
|
+
return (options.wasmSupportMode === 1 && !shouldCullBulletWasmModule(options, id)) || shouldCullAsmJsModule(options, id);
|
|
96
|
+
},
|
|
97
|
+
shouldEmitAsset(options, id) {
|
|
98
|
+
return !this.shouldCullModule(options, id);
|
|
99
|
+
},
|
|
100
|
+
cullingContent: `export default '';`,
|
|
101
|
+
},
|
|
102
|
+
'.wasm.js': {
|
|
103
|
+
shouldCullModule(options, id) {
|
|
104
|
+
return options.wasmSupportMode === 0 || shouldCullBulletWasmModule(options, id);
|
|
105
|
+
},
|
|
106
|
+
shouldEmitAsset(options, id) {
|
|
107
|
+
return false;
|
|
108
|
+
},
|
|
109
|
+
cullingContent: `export default function () {}`,
|
|
110
|
+
},
|
|
111
|
+
'.asm.js': {
|
|
112
|
+
shouldCullModule(options, id) {
|
|
113
|
+
return (options.wasmSupportMode === 1 && !shouldCullBulletWasmModule(options, id)) || shouldCullAsmJsModule(options, id);
|
|
114
|
+
},
|
|
115
|
+
shouldEmitAsset(options, id) {
|
|
116
|
+
return false;
|
|
117
|
+
},
|
|
118
|
+
cullingContent: `export default function () {}`,
|
|
119
|
+
},
|
|
120
|
+
'.wasm.fallback': {
|
|
121
|
+
shouldCullModule(options, id) {
|
|
122
|
+
return loadConfig['.wasm'].shouldCullModule(options, id) || !options.wasmFallback;
|
|
123
|
+
},
|
|
124
|
+
shouldEmitAsset(options, id) {
|
|
125
|
+
return !this.shouldCullModule(options, id);
|
|
126
|
+
},
|
|
127
|
+
cullingContent: `export default '';`,
|
|
128
|
+
},
|
|
129
|
+
'.wasm.fallback.js': {
|
|
130
|
+
shouldCullModule(options, id) {
|
|
131
|
+
return loadConfig['.wasm.js'].shouldCullModule(options, id) || !options.wasmFallback;
|
|
132
|
+
},
|
|
133
|
+
shouldEmitAsset(options, id) {
|
|
134
|
+
return false;
|
|
135
|
+
},
|
|
136
|
+
cullingContent: `export default function () {}`,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* This is a module bundler for minigame subpacakge.
|
|
141
|
+
* We need an entry script called 'game.js' for each subpackage.
|
|
142
|
+
*/
|
|
143
|
+
class ExternalWasmModuleBundler {
|
|
144
|
+
constructor(options) {
|
|
145
|
+
this._loadedChunkMap = {}; // id to code
|
|
146
|
+
this._options = options;
|
|
147
|
+
}
|
|
148
|
+
_resolveId(source) {
|
|
149
|
+
let id = normalizePath(path_1.default.join(this._options.externalRoot, source.substring(externalOrigin.length)));
|
|
150
|
+
return id;
|
|
151
|
+
}
|
|
152
|
+
_load(id) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
for (const suffix in loadConfig) {
|
|
155
|
+
if (id.endsWith(suffix)) {
|
|
156
|
+
const config = loadConfig[suffix];
|
|
157
|
+
if (config.shouldCullModule(this._options, id)) {
|
|
158
|
+
return config.cullingContent;
|
|
159
|
+
}
|
|
160
|
+
else if (config.shouldEmitAsset(this._options, id)) {
|
|
161
|
+
return this._emitAsset(id);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return yield this._transformSystemJs(id);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// fallback
|
|
169
|
+
return yield this._transformSystemJs(id);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// NOTE: we use rollup to transform CommonJS / ES Module to SystemJs.
|
|
173
|
+
_transformSystemJs(id) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const systemJsModuleId = externalOrigin + path_1.default.relative(this._options.externalRoot, id).replace(/\\/g, '/');
|
|
176
|
+
const res = yield rollup.rollup({
|
|
177
|
+
input: id,
|
|
178
|
+
plugins: [(0, plugin_commonjs_1.default)()],
|
|
179
|
+
});
|
|
180
|
+
const output = yield res.generate({
|
|
181
|
+
format: 'system',
|
|
182
|
+
name: systemJsModuleId,
|
|
183
|
+
});
|
|
184
|
+
yield res.close();
|
|
185
|
+
return output.output[0].code;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
_emitAsset(id) {
|
|
189
|
+
let basename = path_1.default.basename(id);
|
|
190
|
+
for (let suffixToReplace in suffixReplaceConfig) {
|
|
191
|
+
const replacement = suffixReplaceConfig[suffixToReplace];
|
|
192
|
+
if (basename.endsWith(suffixToReplace)) {
|
|
193
|
+
// some platforms doesn't support files with special suffix like '.mem', we replace it to '.bin'
|
|
194
|
+
basename = basename.slice(0, -suffixToReplace.length) + replacement;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const buffer = fs_extra_1.default.readFileSync(id);
|
|
198
|
+
const assetsDir = path_1.default.join(this._options.outDir, 'assets');
|
|
199
|
+
fs_extra_1.default.outputFileSync(path_1.default.join(assetsDir, basename), buffer);
|
|
200
|
+
// output game.js
|
|
201
|
+
const gameJs = path_1.default.join(assetsDir, 'game.js');
|
|
202
|
+
if (!fs_extra_1.default.existsSync(gameJs)) {
|
|
203
|
+
fs_extra_1.default.outputFileSync(gameJs, `console.log('[CC Subpackage] wasm assets loaded');`, 'utf8');
|
|
204
|
+
}
|
|
205
|
+
return `export default 'assets/${basename}';`;
|
|
206
|
+
}
|
|
207
|
+
_transform(id, code) {
|
|
208
|
+
if (code.startsWith('System.register')) {
|
|
209
|
+
// NOTE: if it's already SystemJS module, we don't need to transform it again.
|
|
210
|
+
return code;
|
|
211
|
+
}
|
|
212
|
+
const systemJsModuleId = externalOrigin + path_1.default.relative(this._options.externalRoot, id).replace(/\\/g, '/');
|
|
213
|
+
const res = babel.transformSync(code, {
|
|
214
|
+
compact: true,
|
|
215
|
+
plugins: [
|
|
216
|
+
[plugin_transform_modules_systemjs_1.default, {
|
|
217
|
+
moduleId: systemJsModuleId,
|
|
218
|
+
}],
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
code = res.code;
|
|
222
|
+
return code;
|
|
223
|
+
}
|
|
224
|
+
bundle() {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
// transform all external wasm modules
|
|
227
|
+
for (const externalWasmModule of this._options.externalWasmModules) {
|
|
228
|
+
const id = this._resolveId(externalWasmModule);
|
|
229
|
+
const code = yield this._load(id);
|
|
230
|
+
this._loadedChunkMap[id] = this._transform(id, code);
|
|
231
|
+
}
|
|
232
|
+
// bundle
|
|
233
|
+
let result = [`console.log('[CC Subpackage] wasm chunks loaded');`];
|
|
234
|
+
for (let id in this._loadedChunkMap) {
|
|
235
|
+
const code = this._loadedChunkMap[id];
|
|
236
|
+
result.push(code);
|
|
237
|
+
}
|
|
238
|
+
return result.join('\n');
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* This plugin enable to load script or wasm with url based on 'external://' origin.
|
|
244
|
+
*/
|
|
245
|
+
function externalWasmLoader(options) {
|
|
246
|
+
const externalWasmModules = [];
|
|
247
|
+
return {
|
|
248
|
+
name: '@cocos/ccbuild|external-loader',
|
|
249
|
+
resolveId(source, importer) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
if (source.startsWith(externalOrigin)) {
|
|
252
|
+
if (options.wasmSubpackage) {
|
|
253
|
+
externalWasmModules.push(source);
|
|
254
|
+
return {
|
|
255
|
+
id: source,
|
|
256
|
+
external: true,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
return source;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
load(id) {
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
if (id.startsWith(externalOrigin)) {
|
|
267
|
+
let filePath = normalizePath(path_1.default.join(options.externalRoot, id.substring(externalOrigin.length)));
|
|
268
|
+
for (const suffix in loadConfig) {
|
|
269
|
+
if (filePath.endsWith(suffix)) {
|
|
270
|
+
const config = loadConfig[suffix];
|
|
271
|
+
if (config.shouldCullModule(options, id)) {
|
|
272
|
+
return config.cullingContent;
|
|
273
|
+
}
|
|
274
|
+
else if (config.shouldEmitAsset(options, id)) {
|
|
275
|
+
return emitAsset(this, filePath);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return yield fs_extra_1.default.readFile(filePath, 'utf8');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// some external module that doesn't obey the suffix specification, we return its content by default.
|
|
283
|
+
return yield fs_extra_1.default.readFile(filePath, 'utf8');
|
|
284
|
+
}
|
|
285
|
+
return null;
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
// Generates the `import.meta.ROLLUP_FILE_URL_referenceId`.
|
|
289
|
+
resolveFileUrl({
|
|
290
|
+
// > The path and file name of the emitted asset, relative to `output.dir` without a leading `./`.
|
|
291
|
+
fileName,
|
|
292
|
+
// > The path and file name of the emitted file,
|
|
293
|
+
// > relative to the chunk the file is referenced from.
|
|
294
|
+
// > This will path will contain no leading `./` but may contain a leading `../`.
|
|
295
|
+
relativePath, }) {
|
|
296
|
+
switch (options.format) {
|
|
297
|
+
case 'relative-from-chunk':
|
|
298
|
+
return `'${relativePath}'`;
|
|
299
|
+
case 'relative-from-out':
|
|
300
|
+
return `'${fileName}'`;
|
|
301
|
+
case 'runtime-resolved':
|
|
302
|
+
default:
|
|
303
|
+
return undefined; // return `new URL('${fileName}', import.meta.url).href`;
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
generateBundle(opts, bundles) {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
if (externalWasmModules.length !== 0) {
|
|
309
|
+
const bundler = new ExternalWasmModuleBundler(Object.assign(Object.assign({}, options), { externalWasmModules, outDir: opts.dir }));
|
|
310
|
+
const code = yield bundler.bundle();
|
|
311
|
+
fs_extra_1.default.outputFileSync(path_1.default.join(opts.dir, 'chunks/game.js'), code, 'utf8');
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
exports.externalWasmLoader = externalWasmLoader;
|
|
318
|
+
/**
|
|
319
|
+
* Convert the file path to asset ref URL.
|
|
320
|
+
* @param file File path in absolute.
|
|
321
|
+
*/
|
|
322
|
+
function pathToAssetRefURL(file) {
|
|
323
|
+
return `${assetPrefix}${(0, url_1.pathToFileURL)(file).pathname}`;
|
|
324
|
+
}
|
|
325
|
+
exports.pathToAssetRefURL = pathToAssetRefURL;
|
|
326
|
+
const assetPrefix = 'asset:';
|
|
299
327
|
//# sourceMappingURL=external-wasm-loader.js.map
|