@cocos/ccbuild 2.2.0 → 2.2.2

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