@cocos/ccbuild 1.1.6 → 1.1.8
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 +13 -0
- package/README.md +14 -14
- 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 +412 -412
- package/lib/build-engine/engine-js/index.js.map +1 -1
- package/lib/build-engine/engine-js/rollup-plugins/external-wasm-loader.d.ts +43 -40
- 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 +151 -92
- 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 +34 -34
- 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 +130 -130
- package/lib/build-engine/index.js +138 -138
- 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 +163 -163
- 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 +3 -3
- package/lib/utils.js +19 -19
- package/package.json +2 -2
- 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,413 +1,413 @@
|
|
|
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.buildJsEngine = void 0;
|
|
39
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const plugin_babel_1 = __importDefault(require("@rollup/plugin-babel"));
|
|
42
|
-
const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
|
|
43
|
-
const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
|
|
44
|
-
const plugin_commonjs_1 = __importDefault(require("@rollup/plugin-commonjs"));
|
|
45
|
-
const rollup_plugin_terser_1 = require("rollup-plugin-terser");
|
|
46
|
-
const preset_env_1 = __importDefault(require("@babel/preset-env"));
|
|
47
|
-
const creator_programming_babel_preset_cc_1 = require("@cocos/creator-programming-babel-preset-cc");
|
|
48
|
-
// @ts-expect-error: No typing
|
|
49
|
-
const plugin_transform_for_of_1 = __importDefault(require("@babel/plugin-transform-for-of"));
|
|
50
|
-
const rollup = __importStar(require("rollup"));
|
|
51
|
-
// import rpProgress from 'rollup-plugin-progress';
|
|
52
|
-
const plugin_virtual_1 = __importDefault(require("@rollup/plugin-virtual"));
|
|
53
|
-
const resolve_1 = __importDefault(require("resolve"));
|
|
54
|
-
const babel_plugin_dynamic_import_vars_1 = __importDefault(require("@cocos/babel-plugin-dynamic-import-vars"));
|
|
55
|
-
const fs_1 = __importDefault(require("fs"));
|
|
56
|
-
const ts_paths_1 = __importDefault(require("./rollup-plugins/ts-paths"));
|
|
57
|
-
const remove_deprecated_features_1 = __importDefault(require("./rollup-plugins/remove-deprecated-features"));
|
|
58
|
-
const stats_query_1 = require("../../stats-query");
|
|
59
|
-
const utils_1 = require("../../utils");
|
|
60
|
-
const external_wasm_loader_1 = require("./rollup-plugins/external-wasm-loader");
|
|
61
|
-
// import * as decoratorRecorder from './babel-plugins/decorator-parser';
|
|
62
|
-
const realPath = (function () {
|
|
63
|
-
const realpath = typeof fs_1.default.realpath.native === 'function' ? fs_1.default.realpath.native : fs_1.default.realpath;
|
|
64
|
-
return (file) => new Promise((resolve, reject) => {
|
|
65
|
-
realpath(file, (err, path) => {
|
|
66
|
-
if (err && err.code !== 'ENOENT') {
|
|
67
|
-
reject(err);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
resolve(err ? file : path);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
})();
|
|
75
|
-
function makePathEqualityKey(path) {
|
|
76
|
-
return process.platform === 'win32' ? path.toLocaleLowerCase() : path;
|
|
77
|
-
}
|
|
78
|
-
function buildJsEngine(options) {
|
|
79
|
-
var _a, _b, _c, _d, _e;
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const doUglify = !!options.compress;
|
|
82
|
-
const engineRoot = path_1.default.resolve(options.engine);
|
|
83
|
-
const rollupFormat = (_a = options.moduleFormat) !== null && _a !== void 0 ? _a : 'iife';
|
|
84
|
-
const statsQuery = yield stats_query_1.StatsQuery.create(engineRoot);
|
|
85
|
-
if (options.features) {
|
|
86
|
-
for (const feature of options.features) {
|
|
87
|
-
if (!statsQuery.hasFeature(feature)) {
|
|
88
|
-
console.warn(`'${feature}' is not a valid feature.`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
let features;
|
|
93
|
-
let split = (_b = options.split) !== null && _b !== void 0 ? _b : false;
|
|
94
|
-
if (options.features && options.features.length !== 0) {
|
|
95
|
-
features = options.features;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
features = statsQuery.getFeatures();
|
|
99
|
-
if (split !== true) {
|
|
100
|
-
split = true;
|
|
101
|
-
console.warn(`You did not specify features which implies 'split: true'. `
|
|
102
|
-
+ `Explicitly set 'split: true' to suppress this warning.`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
let { ammoJsWasm } = options;
|
|
106
|
-
ammoJsWasm !== null && ammoJsWasm !== void 0 ? ammoJsWasm : (ammoJsWasm = true); // default is true
|
|
107
|
-
const forceBanningBulletWasm = !ammoJsWasm;
|
|
108
|
-
const flags = (_c = options.flags) !== null && _c !== void 0 ? _c : {};
|
|
109
|
-
flags.FORCE_BANNING_BULLET_WASM = forceBanningBulletWasm;
|
|
110
|
-
const intrinsicFlags = statsQuery.getIntrinsicFlagsOfFeatures(features);
|
|
111
|
-
let buildTimeConstants = statsQuery.constantManager.genBuildTimeConstants({
|
|
112
|
-
mode: options.mode,
|
|
113
|
-
platform: options.platform,
|
|
114
|
-
flags,
|
|
115
|
-
});
|
|
116
|
-
buildTimeConstants = Object.assign(Object.assign({}, intrinsicFlags), buildTimeConstants);
|
|
117
|
-
// if (typeof options.forceJitValue !== undefined) {
|
|
118
|
-
// buildTimeConstants['SUPPORT_JIT'] = options.forceJitValue as boolean;
|
|
119
|
-
// }
|
|
120
|
-
const moduleOverrides = Object.entries(statsQuery.evaluateModuleOverrides({
|
|
121
|
-
mode: options.mode,
|
|
122
|
-
platform: options.platform,
|
|
123
|
-
buildTimeConstants,
|
|
124
|
-
})).reduce((result, [k, v]) => {
|
|
125
|
-
result[makePathEqualityKey(k)] = v;
|
|
126
|
-
return result;
|
|
127
|
-
}, {});
|
|
128
|
-
const featureUnits = statsQuery.getUnitsOfFeatures(features);
|
|
129
|
-
const rpVirtualOptions = {};
|
|
130
|
-
const vmInternalConstants = statsQuery.constantManager.exportStaticConstants({
|
|
131
|
-
platform: options.platform,
|
|
132
|
-
mode: options.mode,
|
|
133
|
-
flags,
|
|
134
|
-
});
|
|
135
|
-
console.debug(`Module source "internal-constants":\n${vmInternalConstants}`);
|
|
136
|
-
rpVirtualOptions['internal:constants'] = vmInternalConstants;
|
|
137
|
-
rpVirtualOptions[creator_programming_babel_preset_cc_1.helpers.CC_HELPER_MODULE] = creator_programming_babel_preset_cc_1.helpers.generateHelperModuleSource();
|
|
138
|
-
// for some modules that we need to instantiate before cc module
|
|
139
|
-
// const forceStandaloneModules = ['wait-for-ammo-instantiation'];
|
|
140
|
-
const forceStandaloneModules = [];
|
|
141
|
-
let rollupEntries;
|
|
142
|
-
if (split) {
|
|
143
|
-
rollupEntries = featureUnits.reduce((result, featureUnit) => {
|
|
144
|
-
result[featureUnit] = statsQuery.getFeatureUnitFile(featureUnit);
|
|
145
|
-
return result;
|
|
146
|
-
}, {});
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
rollupEntries = {
|
|
150
|
-
cc: 'cc',
|
|
151
|
-
};
|
|
152
|
-
const selectedFeatureUnits = [];
|
|
153
|
-
for (const featureUnit of featureUnits) {
|
|
154
|
-
if (forceStandaloneModules.includes(featureUnit)) {
|
|
155
|
-
rollupEntries[featureUnit] = statsQuery.getFeatureUnitFile(featureUnit);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
selectedFeatureUnits.push(featureUnit);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
rpVirtualOptions.cc = statsQuery.evaluateIndexModuleSource(selectedFeatureUnits, (featureUnit) => (0, utils_1.filePathToModuleRequest)(statsQuery.getFeatureUnitFile(featureUnit)));
|
|
162
|
-
rollupEntries.cc = 'cc';
|
|
163
|
-
console.debug(`Module source "cc":\n${rpVirtualOptions.cc}`);
|
|
164
|
-
}
|
|
165
|
-
const presetEnvOptions = {
|
|
166
|
-
loose: (_d = options.loose) !== null && _d !== void 0 ? _d : true,
|
|
167
|
-
// We need explicitly specified targets.
|
|
168
|
-
// Ignore it to avoid the engine's parent dirs contain unexpected config.
|
|
169
|
-
ignoreBrowserslistConfig: true,
|
|
170
|
-
};
|
|
171
|
-
if (options.targets !== undefined) {
|
|
172
|
-
presetEnvOptions.targets = options.targets;
|
|
173
|
-
}
|
|
174
|
-
const babelPlugins = [];
|
|
175
|
-
if (options.targets === undefined) {
|
|
176
|
-
babelPlugins.push([plugin_transform_for_of_1.default, {
|
|
177
|
-
loose: true,
|
|
178
|
-
}]);
|
|
179
|
-
}
|
|
180
|
-
babelPlugins.push([babel_plugin_dynamic_import_vars_1.default, {
|
|
181
|
-
resolve: {
|
|
182
|
-
forwardExt: 'resolved',
|
|
183
|
-
},
|
|
184
|
-
}]);
|
|
185
|
-
const { fieldDecorators, editorDecorators } = statsQuery.getOptimizeDecorators();
|
|
186
|
-
const babelOptions = {
|
|
187
|
-
babelHelpers: 'bundled',
|
|
188
|
-
extensions: ['.js', '.ts'],
|
|
189
|
-
exclude: [
|
|
190
|
-
/node_modules[/\\]@cocos[/\\]ammo/,
|
|
191
|
-
/node_modules[/\\]@cocos[/\\]cannon/,
|
|
192
|
-
/node_modules[/\\]@cocos[/\\]physx/,
|
|
193
|
-
/\.asm\.js/,
|
|
194
|
-
],
|
|
195
|
-
comments: false,
|
|
196
|
-
overrides: [{
|
|
197
|
-
// Eliminates the babel compact warning:
|
|
198
|
-
// 'The code generator has deoptimised the styling of ...'
|
|
199
|
-
// that came from node_modules/@cocos
|
|
200
|
-
test: /node_modules[/\\]@cocos[/\\]/,
|
|
201
|
-
compact: true,
|
|
202
|
-
}],
|
|
203
|
-
plugins: babelPlugins,
|
|
204
|
-
presets: [
|
|
205
|
-
[preset_env_1.default, presetEnvOptions],
|
|
206
|
-
[creator_programming_babel_preset_cc_1.babelPresetCC, {
|
|
207
|
-
allowDeclareFields: true,
|
|
208
|
-
ccDecoratorHelpers: 'external',
|
|
209
|
-
fieldDecorators,
|
|
210
|
-
editorDecorators,
|
|
211
|
-
}],
|
|
212
|
-
],
|
|
213
|
-
};
|
|
214
|
-
// if (options.generateDecoratorsForJSB) {
|
|
215
|
-
// if (!process.env.ENGINE_PATH) {
|
|
216
|
-
// throw new Error('ENGINE_PATH environment variable not set');
|
|
217
|
-
// }
|
|
218
|
-
// babelOptions.presets?.push([() => ({ plugins: [[decoratorRecorder]] })]);
|
|
219
|
-
// }
|
|
220
|
-
const rollupPlugins = [];
|
|
221
|
-
if (options.noDeprecatedFeatures) {
|
|
222
|
-
rollupPlugins.push((0, remove_deprecated_features_1.default)(typeof options.noDeprecatedFeatures === 'string' ? options.noDeprecatedFeatures : undefined));
|
|
223
|
-
}
|
|
224
|
-
rollupPlugins.push((0, external_wasm_loader_1.externalWasmLoader)({
|
|
225
|
-
externalRoot: path_1.default.join(engineRoot, 'native/external'),
|
|
226
|
-
|
|
227
|
-
forceBanningBulletWasm,
|
|
228
|
-
format: 'relative-from-chunk',
|
|
229
|
-
}), {
|
|
230
|
-
name: '@cocos/ccbuild|module-overrides',
|
|
231
|
-
resolveId(source, importer) {
|
|
232
|
-
if (moduleOverrides[source]) {
|
|
233
|
-
return source;
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
load(id) {
|
|
240
|
-
const key = makePathEqualityKey(id);
|
|
241
|
-
if (!(key in moduleOverrides)) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
const replacement = moduleOverrides[key];
|
|
245
|
-
console.debug(`Redirect module ${id} to ${replacement}`);
|
|
246
|
-
return `export * from '${(0, utils_1.filePathToModuleRequest)(replacement)}';`;
|
|
247
|
-
},
|
|
248
|
-
}, (0, plugin_virtual_1.default)(rpVirtualOptions), (0, ts_paths_1.default)({
|
|
249
|
-
configFileName: path_1.default.resolve(options.engine, 'tsconfig.json'),
|
|
250
|
-
}), (0, plugin_node_resolve_1.default)({
|
|
251
|
-
extensions: ['.js', '.ts', '.json'],
|
|
252
|
-
jail: yield realPath(engineRoot),
|
|
253
|
-
rootDir: engineRoot,
|
|
254
|
-
}), (0, plugin_json_1.default)({
|
|
255
|
-
preferConst: true,
|
|
256
|
-
}), (0, plugin_commonjs_1.default)({
|
|
257
|
-
include: [
|
|
258
|
-
/node_modules[/\\]/,
|
|
259
|
-
/asm\.js/,
|
|
260
|
-
],
|
|
261
|
-
sourceMap: false,
|
|
262
|
-
}), (0, plugin_babel_1.default)(Object.assign({ skipPreflightCheck: true }, babelOptions)));
|
|
263
|
-
// if (options.progress) {
|
|
264
|
-
// rollupPlugins.unshift(rpProgress());
|
|
265
|
-
// }
|
|
266
|
-
if (doUglify) { // TODO: tree-shaking not clear!
|
|
267
|
-
rollupPlugins.push((0, rollup_plugin_terser_1.terser)({
|
|
268
|
-
// see https://github.com/terser/terser#compress-options
|
|
269
|
-
compress: {
|
|
270
|
-
reduce_funcs: false,
|
|
271
|
-
keep_fargs: false,
|
|
272
|
-
unsafe_Function: true,
|
|
273
|
-
unsafe_math: true,
|
|
274
|
-
unsafe_methods: true,
|
|
275
|
-
passes: 2, // first: remove deadcodes and const objects, second: drop variables
|
|
276
|
-
},
|
|
277
|
-
mangle: doUglify,
|
|
278
|
-
keep_fnames: !doUglify,
|
|
279
|
-
output: {
|
|
280
|
-
beautify: !doUglify,
|
|
281
|
-
},
|
|
282
|
-
// https://github.com/rollup/rollup/issues/3315
|
|
283
|
-
// We only do this for CommonJS.
|
|
284
|
-
// Especially, we cannot do this for IIFE.
|
|
285
|
-
toplevel: rollupFormat === 'cjs',
|
|
286
|
-
}));
|
|
287
|
-
}
|
|
288
|
-
// const visualizeOptions = typeof options.visualize === 'object'
|
|
289
|
-
// ? options.visualize
|
|
290
|
-
// : (options.visualize ? {} : undefined);
|
|
291
|
-
// if (visualizeOptions) {
|
|
292
|
-
// let rpVisualizer;
|
|
293
|
-
// try {
|
|
294
|
-
// // @ts-expect-error: No typing
|
|
295
|
-
// rpVisualizer = await import('rollup-plugin-visualizer');
|
|
296
|
-
// } catch {
|
|
297
|
-
// console.warn('Visualizing needs \'rollup-plugin-visualizer\' to be installed. It\'s installed as dev-dependency.');
|
|
298
|
-
// }
|
|
299
|
-
// if (rpVisualizer) {
|
|
300
|
-
// const visualizeFile = visualizeOptions.file ?? ps.join(options.out, 'visualize.html');
|
|
301
|
-
// rollupPlugins.push(rpVisualizer({
|
|
302
|
-
// filename: visualizeFile,
|
|
303
|
-
// title: 'Cocos Creator build visualizer',
|
|
304
|
-
// template: 'treemap',
|
|
305
|
-
// }));
|
|
306
|
-
// }
|
|
307
|
-
// }
|
|
308
|
-
let hasCriticalWarns = false;
|
|
309
|
-
const rollupWarningHandler = (warning, defaultHandler) => {
|
|
310
|
-
var _a;
|
|
311
|
-
if (typeof warning !== 'string') {
|
|
312
|
-
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
|
313
|
-
hasCriticalWarns = true;
|
|
314
|
-
}
|
|
315
|
-
else if (warning.code === 'THIS_IS_UNDEFINED') {
|
|
316
|
-
// TODO: It's really inappropriate to do this...
|
|
317
|
-
// Let's fix these files instead of suppressing rollup.
|
|
318
|
-
if ((_a = warning.id) === null || _a === void 0 ? void 0 : _a.match(/(?:spine-core\.js$)|(?:dragonBones\.js$)/)) {
|
|
319
|
-
console.debug(`Rollup warning 'THIS_IS_UNDEFINED' is omitted for ${warning.id}`);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
defaultHandler(warning);
|
|
325
|
-
};
|
|
326
|
-
const rollupOptions = {
|
|
327
|
-
input: rollupEntries,
|
|
328
|
-
plugins: rollupPlugins,
|
|
329
|
-
cache: false,
|
|
330
|
-
onwarn: rollupWarningHandler,
|
|
331
|
-
};
|
|
332
|
-
const perf = true;
|
|
333
|
-
if (perf) {
|
|
334
|
-
rollupOptions.perf = true;
|
|
335
|
-
}
|
|
336
|
-
const rollupBuild = yield rollup.rollup(rollupOptions);
|
|
337
|
-
const timing = (_e = rollupBuild.getTimings) === null || _e === void 0 ? void 0 : _e.call(rollupBuild);
|
|
338
|
-
if (timing) {
|
|
339
|
-
console.debug(`==== Performance ====`);
|
|
340
|
-
console.debug(JSON.stringify(timing));
|
|
341
|
-
console.debug(`==== ====`);
|
|
342
|
-
}
|
|
343
|
-
const { incremental: incrementalFile } = options;
|
|
344
|
-
if (incrementalFile) {
|
|
345
|
-
const watchFiles = {};
|
|
346
|
-
const files = rollupBuild.watchFiles;
|
|
347
|
-
yield Promise.all(files.map((watchFile) => __awaiter(this, void 0, void 0, function* () {
|
|
348
|
-
try {
|
|
349
|
-
const stat = yield fs_extra_1.default.stat(watchFile);
|
|
350
|
-
watchFiles[watchFile] = stat.mtimeMs;
|
|
351
|
-
}
|
|
352
|
-
catch (_f) {
|
|
353
|
-
// the `watchFiles` may contain non-fs modules.
|
|
354
|
-
}
|
|
355
|
-
})));
|
|
356
|
-
yield fs_extra_1.default.ensureDir(path_1.default.dirname(incrementalFile));
|
|
357
|
-
yield fs_extra_1.default.writeFile(incrementalFile, JSON.stringify(watchFiles, undefined, 2));
|
|
358
|
-
}
|
|
359
|
-
const result = {
|
|
360
|
-
chunkAliases: {},
|
|
361
|
-
exports: {},
|
|
362
|
-
hasCriticalWarns: false,
|
|
363
|
-
};
|
|
364
|
-
const rollupOutputOptions = {
|
|
365
|
-
format: rollupFormat,
|
|
366
|
-
sourcemap: options.sourceMap,
|
|
367
|
-
sourcemapFile: options.sourceMapFile,
|
|
368
|
-
name: (rollupFormat === 'iife' ? 'ccm' : undefined),
|
|
369
|
-
dir: options.out,
|
|
370
|
-
// minifyInternalExports: false,
|
|
371
|
-
// preserveEntrySignatures: "allow-extension",
|
|
372
|
-
};
|
|
373
|
-
const rollupOutput = yield rollupBuild.write(rollupOutputOptions);
|
|
374
|
-
const validEntryChunks = {};
|
|
375
|
-
for (const output of rollupOutput.output) {
|
|
376
|
-
if (output.type === 'chunk') {
|
|
377
|
-
if (output.isEntry) {
|
|
378
|
-
const chunkName = output.name;
|
|
379
|
-
if (chunkName in rollupEntries || chunkName === 'cc') {
|
|
380
|
-
validEntryChunks[chunkName] = output.fileName;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
Object.assign(result.exports, validEntryChunks);
|
|
386
|
-
result.dependencyGraph = {};
|
|
387
|
-
for (const output of rollupOutput.output) {
|
|
388
|
-
if (output.type === 'chunk') {
|
|
389
|
-
result.dependencyGraph[output.fileName] = output.imports.concat(output.dynamicImports);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
result.hasCriticalWarns = hasCriticalWarns;
|
|
393
|
-
return result;
|
|
394
|
-
function nodeResolveAsync(specifier) {
|
|
395
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
return new Promise((r, reject) => {
|
|
397
|
-
(0, resolve_1.default)(specifier, {
|
|
398
|
-
basedir: engineRoot,
|
|
399
|
-
}, (err, resolved, pkg) => {
|
|
400
|
-
if (err) {
|
|
401
|
-
reject(err);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
r(resolved);
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
exports.buildJsEngine = buildJsEngine;
|
|
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.buildJsEngine = void 0;
|
|
39
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const plugin_babel_1 = __importDefault(require("@rollup/plugin-babel"));
|
|
42
|
+
const plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
|
|
43
|
+
const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
|
|
44
|
+
const plugin_commonjs_1 = __importDefault(require("@rollup/plugin-commonjs"));
|
|
45
|
+
const rollup_plugin_terser_1 = require("rollup-plugin-terser");
|
|
46
|
+
const preset_env_1 = __importDefault(require("@babel/preset-env"));
|
|
47
|
+
const creator_programming_babel_preset_cc_1 = require("@cocos/creator-programming-babel-preset-cc");
|
|
48
|
+
// @ts-expect-error: No typing
|
|
49
|
+
const plugin_transform_for_of_1 = __importDefault(require("@babel/plugin-transform-for-of"));
|
|
50
|
+
const rollup = __importStar(require("rollup"));
|
|
51
|
+
// import rpProgress from 'rollup-plugin-progress';
|
|
52
|
+
const plugin_virtual_1 = __importDefault(require("@rollup/plugin-virtual"));
|
|
53
|
+
const resolve_1 = __importDefault(require("resolve"));
|
|
54
|
+
const babel_plugin_dynamic_import_vars_1 = __importDefault(require("@cocos/babel-plugin-dynamic-import-vars"));
|
|
55
|
+
const fs_1 = __importDefault(require("fs"));
|
|
56
|
+
const ts_paths_1 = __importDefault(require("./rollup-plugins/ts-paths"));
|
|
57
|
+
const remove_deprecated_features_1 = __importDefault(require("./rollup-plugins/remove-deprecated-features"));
|
|
58
|
+
const stats_query_1 = require("../../stats-query");
|
|
59
|
+
const utils_1 = require("../../utils");
|
|
60
|
+
const external_wasm_loader_1 = require("./rollup-plugins/external-wasm-loader");
|
|
61
|
+
// import * as decoratorRecorder from './babel-plugins/decorator-parser';
|
|
62
|
+
const realPath = (function () {
|
|
63
|
+
const realpath = typeof fs_1.default.realpath.native === 'function' ? fs_1.default.realpath.native : fs_1.default.realpath;
|
|
64
|
+
return (file) => new Promise((resolve, reject) => {
|
|
65
|
+
realpath(file, (err, path) => {
|
|
66
|
+
if (err && err.code !== 'ENOENT') {
|
|
67
|
+
reject(err);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolve(err ? file : path);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
})();
|
|
75
|
+
function makePathEqualityKey(path) {
|
|
76
|
+
return process.platform === 'win32' ? path.toLocaleLowerCase() : path;
|
|
77
|
+
}
|
|
78
|
+
function buildJsEngine(options) {
|
|
79
|
+
var _a, _b, _c, _d, _e;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const doUglify = !!options.compress;
|
|
82
|
+
const engineRoot = path_1.default.resolve(options.engine);
|
|
83
|
+
const rollupFormat = (_a = options.moduleFormat) !== null && _a !== void 0 ? _a : 'iife';
|
|
84
|
+
const statsQuery = yield stats_query_1.StatsQuery.create(engineRoot);
|
|
85
|
+
if (options.features) {
|
|
86
|
+
for (const feature of options.features) {
|
|
87
|
+
if (!statsQuery.hasFeature(feature)) {
|
|
88
|
+
console.warn(`'${feature}' is not a valid feature.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let features;
|
|
93
|
+
let split = (_b = options.split) !== null && _b !== void 0 ? _b : false;
|
|
94
|
+
if (options.features && options.features.length !== 0) {
|
|
95
|
+
features = options.features;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
features = statsQuery.getFeatures();
|
|
99
|
+
if (split !== true) {
|
|
100
|
+
split = true;
|
|
101
|
+
console.warn(`You did not specify features which implies 'split: true'. `
|
|
102
|
+
+ `Explicitly set 'split: true' to suppress this warning.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
let { ammoJsWasm } = options;
|
|
106
|
+
ammoJsWasm !== null && ammoJsWasm !== void 0 ? ammoJsWasm : (ammoJsWasm = true); // default is true
|
|
107
|
+
const forceBanningBulletWasm = !ammoJsWasm;
|
|
108
|
+
const flags = (_c = options.flags) !== null && _c !== void 0 ? _c : {};
|
|
109
|
+
flags.FORCE_BANNING_BULLET_WASM = forceBanningBulletWasm;
|
|
110
|
+
const intrinsicFlags = statsQuery.getIntrinsicFlagsOfFeatures(features);
|
|
111
|
+
let buildTimeConstants = statsQuery.constantManager.genBuildTimeConstants({
|
|
112
|
+
mode: options.mode,
|
|
113
|
+
platform: options.platform,
|
|
114
|
+
flags,
|
|
115
|
+
});
|
|
116
|
+
buildTimeConstants = Object.assign(Object.assign({}, intrinsicFlags), buildTimeConstants);
|
|
117
|
+
// if (typeof options.forceJitValue !== undefined) {
|
|
118
|
+
// buildTimeConstants['SUPPORT_JIT'] = options.forceJitValue as boolean;
|
|
119
|
+
// }
|
|
120
|
+
const moduleOverrides = Object.entries(statsQuery.evaluateModuleOverrides({
|
|
121
|
+
mode: options.mode,
|
|
122
|
+
platform: options.platform,
|
|
123
|
+
buildTimeConstants,
|
|
124
|
+
})).reduce((result, [k, v]) => {
|
|
125
|
+
result[makePathEqualityKey(k)] = v;
|
|
126
|
+
return result;
|
|
127
|
+
}, {});
|
|
128
|
+
const featureUnits = statsQuery.getUnitsOfFeatures(features);
|
|
129
|
+
const rpVirtualOptions = {};
|
|
130
|
+
const vmInternalConstants = statsQuery.constantManager.exportStaticConstants({
|
|
131
|
+
platform: options.platform,
|
|
132
|
+
mode: options.mode,
|
|
133
|
+
flags,
|
|
134
|
+
});
|
|
135
|
+
console.debug(`Module source "internal-constants":\n${vmInternalConstants}`);
|
|
136
|
+
rpVirtualOptions['internal:constants'] = vmInternalConstants;
|
|
137
|
+
rpVirtualOptions[creator_programming_babel_preset_cc_1.helpers.CC_HELPER_MODULE] = creator_programming_babel_preset_cc_1.helpers.generateHelperModuleSource();
|
|
138
|
+
// for some modules that we need to instantiate before cc module
|
|
139
|
+
// const forceStandaloneModules = ['wait-for-ammo-instantiation'];
|
|
140
|
+
const forceStandaloneModules = [];
|
|
141
|
+
let rollupEntries;
|
|
142
|
+
if (split) {
|
|
143
|
+
rollupEntries = featureUnits.reduce((result, featureUnit) => {
|
|
144
|
+
result[featureUnit] = statsQuery.getFeatureUnitFile(featureUnit);
|
|
145
|
+
return result;
|
|
146
|
+
}, {});
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
rollupEntries = {
|
|
150
|
+
cc: 'cc',
|
|
151
|
+
};
|
|
152
|
+
const selectedFeatureUnits = [];
|
|
153
|
+
for (const featureUnit of featureUnits) {
|
|
154
|
+
if (forceStandaloneModules.includes(featureUnit)) {
|
|
155
|
+
rollupEntries[featureUnit] = statsQuery.getFeatureUnitFile(featureUnit);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
selectedFeatureUnits.push(featureUnit);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
rpVirtualOptions.cc = statsQuery.evaluateIndexModuleSource(selectedFeatureUnits, (featureUnit) => (0, utils_1.filePathToModuleRequest)(statsQuery.getFeatureUnitFile(featureUnit)));
|
|
162
|
+
rollupEntries.cc = 'cc';
|
|
163
|
+
console.debug(`Module source "cc":\n${rpVirtualOptions.cc}`);
|
|
164
|
+
}
|
|
165
|
+
const presetEnvOptions = {
|
|
166
|
+
loose: (_d = options.loose) !== null && _d !== void 0 ? _d : true,
|
|
167
|
+
// We need explicitly specified targets.
|
|
168
|
+
// Ignore it to avoid the engine's parent dirs contain unexpected config.
|
|
169
|
+
ignoreBrowserslistConfig: true,
|
|
170
|
+
};
|
|
171
|
+
if (options.targets !== undefined) {
|
|
172
|
+
presetEnvOptions.targets = options.targets;
|
|
173
|
+
}
|
|
174
|
+
const babelPlugins = [];
|
|
175
|
+
if (options.targets === undefined) {
|
|
176
|
+
babelPlugins.push([plugin_transform_for_of_1.default, {
|
|
177
|
+
loose: true,
|
|
178
|
+
}]);
|
|
179
|
+
}
|
|
180
|
+
babelPlugins.push([babel_plugin_dynamic_import_vars_1.default, {
|
|
181
|
+
resolve: {
|
|
182
|
+
forwardExt: 'resolved',
|
|
183
|
+
},
|
|
184
|
+
}]);
|
|
185
|
+
const { fieldDecorators, editorDecorators } = statsQuery.getOptimizeDecorators();
|
|
186
|
+
const babelOptions = {
|
|
187
|
+
babelHelpers: 'bundled',
|
|
188
|
+
extensions: ['.js', '.ts'],
|
|
189
|
+
exclude: [
|
|
190
|
+
/node_modules[/\\]@cocos[/\\]ammo/,
|
|
191
|
+
/node_modules[/\\]@cocos[/\\]cannon/,
|
|
192
|
+
/node_modules[/\\]@cocos[/\\]physx/,
|
|
193
|
+
/\.asm\.js/,
|
|
194
|
+
],
|
|
195
|
+
comments: false,
|
|
196
|
+
overrides: [{
|
|
197
|
+
// Eliminates the babel compact warning:
|
|
198
|
+
// 'The code generator has deoptimised the styling of ...'
|
|
199
|
+
// that came from node_modules/@cocos
|
|
200
|
+
test: /node_modules[/\\]@cocos[/\\]/,
|
|
201
|
+
compact: true,
|
|
202
|
+
}],
|
|
203
|
+
plugins: babelPlugins,
|
|
204
|
+
presets: [
|
|
205
|
+
[preset_env_1.default, presetEnvOptions],
|
|
206
|
+
[creator_programming_babel_preset_cc_1.babelPresetCC, {
|
|
207
|
+
allowDeclareFields: true,
|
|
208
|
+
ccDecoratorHelpers: 'external',
|
|
209
|
+
fieldDecorators,
|
|
210
|
+
editorDecorators,
|
|
211
|
+
}],
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
// if (options.generateDecoratorsForJSB) {
|
|
215
|
+
// if (!process.env.ENGINE_PATH) {
|
|
216
|
+
// throw new Error('ENGINE_PATH environment variable not set');
|
|
217
|
+
// }
|
|
218
|
+
// babelOptions.presets?.push([() => ({ plugins: [[decoratorRecorder]] })]);
|
|
219
|
+
// }
|
|
220
|
+
const rollupPlugins = [];
|
|
221
|
+
if (options.noDeprecatedFeatures) {
|
|
222
|
+
rollupPlugins.push((0, remove_deprecated_features_1.default)(typeof options.noDeprecatedFeatures === 'string' ? options.noDeprecatedFeatures : undefined));
|
|
223
|
+
}
|
|
224
|
+
rollupPlugins.push((0, external_wasm_loader_1.externalWasmLoader)({
|
|
225
|
+
externalRoot: path_1.default.join(engineRoot, 'native/external'),
|
|
226
|
+
wasmSupportMode: buildTimeConstants.WASM_SUPPORT_MODE,
|
|
227
|
+
forceBanningBulletWasm,
|
|
228
|
+
format: 'relative-from-chunk',
|
|
229
|
+
}), {
|
|
230
|
+
name: '@cocos/ccbuild|module-overrides',
|
|
231
|
+
resolveId(source, importer) {
|
|
232
|
+
if (moduleOverrides[source]) {
|
|
233
|
+
return source;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
load(id) {
|
|
240
|
+
const key = makePathEqualityKey(id);
|
|
241
|
+
if (!(key in moduleOverrides)) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const replacement = moduleOverrides[key];
|
|
245
|
+
console.debug(`Redirect module ${id} to ${replacement}`);
|
|
246
|
+
return `export * from '${(0, utils_1.filePathToModuleRequest)(replacement)}';`;
|
|
247
|
+
},
|
|
248
|
+
}, (0, plugin_virtual_1.default)(rpVirtualOptions), (0, ts_paths_1.default)({
|
|
249
|
+
configFileName: path_1.default.resolve(options.engine, 'tsconfig.json'),
|
|
250
|
+
}), (0, plugin_node_resolve_1.default)({
|
|
251
|
+
extensions: ['.js', '.ts', '.json'],
|
|
252
|
+
jail: yield realPath(engineRoot),
|
|
253
|
+
rootDir: engineRoot,
|
|
254
|
+
}), (0, plugin_json_1.default)({
|
|
255
|
+
preferConst: true,
|
|
256
|
+
}), (0, plugin_commonjs_1.default)({
|
|
257
|
+
include: [
|
|
258
|
+
/node_modules[/\\]/,
|
|
259
|
+
/asm\.js/,
|
|
260
|
+
],
|
|
261
|
+
sourceMap: false,
|
|
262
|
+
}), (0, plugin_babel_1.default)(Object.assign({ skipPreflightCheck: true }, babelOptions)));
|
|
263
|
+
// if (options.progress) {
|
|
264
|
+
// rollupPlugins.unshift(rpProgress());
|
|
265
|
+
// }
|
|
266
|
+
if (doUglify) { // TODO: tree-shaking not clear!
|
|
267
|
+
rollupPlugins.push((0, rollup_plugin_terser_1.terser)({
|
|
268
|
+
// see https://github.com/terser/terser#compress-options
|
|
269
|
+
compress: {
|
|
270
|
+
reduce_funcs: false,
|
|
271
|
+
keep_fargs: false,
|
|
272
|
+
unsafe_Function: true,
|
|
273
|
+
unsafe_math: true,
|
|
274
|
+
unsafe_methods: true,
|
|
275
|
+
passes: 2, // first: remove deadcodes and const objects, second: drop variables
|
|
276
|
+
},
|
|
277
|
+
mangle: doUglify,
|
|
278
|
+
keep_fnames: !doUglify,
|
|
279
|
+
output: {
|
|
280
|
+
beautify: !doUglify,
|
|
281
|
+
},
|
|
282
|
+
// https://github.com/rollup/rollup/issues/3315
|
|
283
|
+
// We only do this for CommonJS.
|
|
284
|
+
// Especially, we cannot do this for IIFE.
|
|
285
|
+
toplevel: rollupFormat === 'cjs',
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
// const visualizeOptions = typeof options.visualize === 'object'
|
|
289
|
+
// ? options.visualize
|
|
290
|
+
// : (options.visualize ? {} : undefined);
|
|
291
|
+
// if (visualizeOptions) {
|
|
292
|
+
// let rpVisualizer;
|
|
293
|
+
// try {
|
|
294
|
+
// // @ts-expect-error: No typing
|
|
295
|
+
// rpVisualizer = await import('rollup-plugin-visualizer');
|
|
296
|
+
// } catch {
|
|
297
|
+
// console.warn('Visualizing needs \'rollup-plugin-visualizer\' to be installed. It\'s installed as dev-dependency.');
|
|
298
|
+
// }
|
|
299
|
+
// if (rpVisualizer) {
|
|
300
|
+
// const visualizeFile = visualizeOptions.file ?? ps.join(options.out, 'visualize.html');
|
|
301
|
+
// rollupPlugins.push(rpVisualizer({
|
|
302
|
+
// filename: visualizeFile,
|
|
303
|
+
// title: 'Cocos Creator build visualizer',
|
|
304
|
+
// template: 'treemap',
|
|
305
|
+
// }));
|
|
306
|
+
// }
|
|
307
|
+
// }
|
|
308
|
+
let hasCriticalWarns = false;
|
|
309
|
+
const rollupWarningHandler = (warning, defaultHandler) => {
|
|
310
|
+
var _a;
|
|
311
|
+
if (typeof warning !== 'string') {
|
|
312
|
+
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
|
313
|
+
hasCriticalWarns = true;
|
|
314
|
+
}
|
|
315
|
+
else if (warning.code === 'THIS_IS_UNDEFINED') {
|
|
316
|
+
// TODO: It's really inappropriate to do this...
|
|
317
|
+
// Let's fix these files instead of suppressing rollup.
|
|
318
|
+
if ((_a = warning.id) === null || _a === void 0 ? void 0 : _a.match(/(?:spine-core\.js$)|(?:dragonBones\.js$)/)) {
|
|
319
|
+
console.debug(`Rollup warning 'THIS_IS_UNDEFINED' is omitted for ${warning.id}`);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
defaultHandler(warning);
|
|
325
|
+
};
|
|
326
|
+
const rollupOptions = {
|
|
327
|
+
input: rollupEntries,
|
|
328
|
+
plugins: rollupPlugins,
|
|
329
|
+
cache: false,
|
|
330
|
+
onwarn: rollupWarningHandler,
|
|
331
|
+
};
|
|
332
|
+
const perf = true;
|
|
333
|
+
if (perf) {
|
|
334
|
+
rollupOptions.perf = true;
|
|
335
|
+
}
|
|
336
|
+
const rollupBuild = yield rollup.rollup(rollupOptions);
|
|
337
|
+
const timing = (_e = rollupBuild.getTimings) === null || _e === void 0 ? void 0 : _e.call(rollupBuild);
|
|
338
|
+
if (timing) {
|
|
339
|
+
console.debug(`==== Performance ====`);
|
|
340
|
+
console.debug(JSON.stringify(timing));
|
|
341
|
+
console.debug(`==== ====`);
|
|
342
|
+
}
|
|
343
|
+
const { incremental: incrementalFile } = options;
|
|
344
|
+
if (incrementalFile) {
|
|
345
|
+
const watchFiles = {};
|
|
346
|
+
const files = rollupBuild.watchFiles;
|
|
347
|
+
yield Promise.all(files.map((watchFile) => __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
try {
|
|
349
|
+
const stat = yield fs_extra_1.default.stat(watchFile);
|
|
350
|
+
watchFiles[watchFile] = stat.mtimeMs;
|
|
351
|
+
}
|
|
352
|
+
catch (_f) {
|
|
353
|
+
// the `watchFiles` may contain non-fs modules.
|
|
354
|
+
}
|
|
355
|
+
})));
|
|
356
|
+
yield fs_extra_1.default.ensureDir(path_1.default.dirname(incrementalFile));
|
|
357
|
+
yield fs_extra_1.default.writeFile(incrementalFile, JSON.stringify(watchFiles, undefined, 2));
|
|
358
|
+
}
|
|
359
|
+
const result = {
|
|
360
|
+
chunkAliases: {},
|
|
361
|
+
exports: {},
|
|
362
|
+
hasCriticalWarns: false,
|
|
363
|
+
};
|
|
364
|
+
const rollupOutputOptions = {
|
|
365
|
+
format: rollupFormat,
|
|
366
|
+
sourcemap: options.sourceMap,
|
|
367
|
+
sourcemapFile: options.sourceMapFile,
|
|
368
|
+
name: (rollupFormat === 'iife' ? 'ccm' : undefined),
|
|
369
|
+
dir: options.out,
|
|
370
|
+
// minifyInternalExports: false,
|
|
371
|
+
// preserveEntrySignatures: "allow-extension",
|
|
372
|
+
};
|
|
373
|
+
const rollupOutput = yield rollupBuild.write(rollupOutputOptions);
|
|
374
|
+
const validEntryChunks = {};
|
|
375
|
+
for (const output of rollupOutput.output) {
|
|
376
|
+
if (output.type === 'chunk') {
|
|
377
|
+
if (output.isEntry) {
|
|
378
|
+
const chunkName = output.name;
|
|
379
|
+
if (chunkName in rollupEntries || chunkName === 'cc') {
|
|
380
|
+
validEntryChunks[chunkName] = output.fileName;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
Object.assign(result.exports, validEntryChunks);
|
|
386
|
+
result.dependencyGraph = {};
|
|
387
|
+
for (const output of rollupOutput.output) {
|
|
388
|
+
if (output.type === 'chunk') {
|
|
389
|
+
result.dependencyGraph[output.fileName] = output.imports.concat(output.dynamicImports);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
result.hasCriticalWarns = hasCriticalWarns;
|
|
393
|
+
return result;
|
|
394
|
+
function nodeResolveAsync(specifier) {
|
|
395
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
+
return new Promise((r, reject) => {
|
|
397
|
+
(0, resolve_1.default)(specifier, {
|
|
398
|
+
basedir: engineRoot,
|
|
399
|
+
}, (err, resolved, pkg) => {
|
|
400
|
+
if (err) {
|
|
401
|
+
reject(err);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
r(resolved);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
exports.buildJsEngine = buildJsEngine;
|
|
413
413
|
//# sourceMappingURL=index.js.map
|