@cocos/ccbuild 2.1.0 → 2.2.1
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/modules/build-engine/lib/engine-js/index.js +302 -331
- package/modules/build-engine/lib/engine-js/index.js.map +1 -1
- package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.js +89 -130
- package/modules/build-engine/lib/engine-js/rollup-plugins/external-wasm-loader.js.map +1 -1
- package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.js +2 -31
- package/modules/build-engine/lib/engine-js/rollup-plugins/module-query-plugin.js.map +1 -1
- package/modules/build-engine/lib/engine-ts/engine-builder.js +416 -461
- package/modules/build-engine/lib/engine-ts/engine-builder.js.map +1 -1
- package/modules/build-engine/lib/engine-ts/index.js +19 -48
- package/modules/build-engine/lib/engine-ts/index.js.map +1 -1
- package/modules/build-engine/lib/engine-ts/plugins/external-wasm-loader.js +31 -64
- package/modules/build-engine/lib/engine-ts/plugins/external-wasm-loader.js.map +1 -1
- package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.js +5 -34
- package/modules/build-engine/lib/engine-ts/plugins/module-query-plugin.js.map +1 -1
- package/modules/build-engine/lib/engine-ts/plugins/node-module-loader.js +28 -59
- package/modules/build-engine/lib/engine-ts/plugins/node-module-loader.js.map +1 -1
- package/modules/build-engine/lib/index.d.ts.map +1 -1
- package/modules/build-engine/lib/index.js +61 -81
- package/modules/build-engine/lib/index.js.map +1 -1
- package/modules/dts-bundler/lib/index.js +236 -265
- package/modules/dts-bundler/lib/index.js.map +1 -1
- package/modules/modularize/lib/module-query.js +153 -198
- package/modules/modularize/lib/module-query.js.map +1 -1
- package/modules/stats-query/lib/index.d.ts +5 -1
- package/modules/stats-query/lib/index.d.ts.map +1 -1
- package/modules/stats-query/lib/index.js +48 -81
- package/modules/stats-query/lib/index.js.map +1 -1
- package/modules/utils/lib/path.js +8 -37
- package/modules/utils/lib/path.js.map +1 -1
- 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,329 @@ 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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
+
cullMeshopt: buildTimeConstants.CULL_MESHOPT,
|
|
202
|
+
format: 'relative-from-chunk',
|
|
203
|
+
wasmSubpackage: buildTimeConstants.WASM_SUBPACKAGE
|
|
204
|
+
}), {
|
|
205
|
+
name: '@cocos/ccbuild|module-overrides',
|
|
206
|
+
resolveId(source, importer) {
|
|
207
|
+
if (moduleOverrides[source]) {
|
|
208
|
+
return source;
|
|
209
|
+
} else {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
load(id) {
|
|
214
|
+
const key = makePathEqualityKey(id);
|
|
215
|
+
if (!(key in moduleOverrides)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const replacement = moduleOverrides[key];
|
|
219
|
+
console.debug(`Redirect module ${id} to ${replacement}`);
|
|
220
|
+
return `export * from '${(0, utils_1.filePathToModuleRequest)(replacement)}';`;
|
|
225
221
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
}, rpVirtual(rpVirtualOptions), (0, module_query_plugin_1.default)(moduleQuery), (0, ts_paths_1.default)({
|
|
223
|
+
configFileName: path_1.default.resolve(options.engine, 'tsconfig.json')
|
|
224
|
+
}), resolve({
|
|
225
|
+
extensions: ['.js', '.ts', '.json'],
|
|
226
|
+
jail: await realPath(engineRoot),
|
|
227
|
+
rootDir: engineRoot
|
|
228
|
+
}), json({
|
|
229
|
+
preferConst: true
|
|
230
|
+
}), commonjs({
|
|
231
|
+
include: [/node_modules[/\\]/, /asm\.js/],
|
|
232
|
+
sourceMap: false
|
|
233
|
+
}), rpBabel(Object.assign({
|
|
234
|
+
skipPreflightCheck: true
|
|
235
|
+
}, babelOptions)));
|
|
236
|
+
// if (options.progress) {
|
|
237
|
+
// rollupPlugins.unshift(rpProgress());
|
|
238
|
+
// }
|
|
239
|
+
if (doUglify) {
|
|
240
|
+
// TODO: tree-shaking not clear!
|
|
241
|
+
rollupPlugins.push(rpTerser({
|
|
242
|
+
// see https://github.com/terser/terser#compress-options
|
|
243
|
+
compress: {
|
|
244
|
+
reduce_funcs: false,
|
|
245
|
+
keep_fargs: false,
|
|
246
|
+
unsafe_Function: true,
|
|
247
|
+
unsafe_math: true,
|
|
248
|
+
unsafe_methods: true,
|
|
249
|
+
passes: 2 // first: remove deadcodes and const objects, second: drop variables
|
|
240
250
|
},
|
|
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
251
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
252
|
+
mangle: doUglify,
|
|
253
|
+
keep_fnames: !doUglify,
|
|
254
|
+
output: {
|
|
255
|
+
beautify: !doUglify
|
|
256
|
+
},
|
|
257
|
+
// https://github.com/rollup/rollup/issues/3315
|
|
258
|
+
// We only do this for CommonJS.
|
|
259
|
+
// Especially, we cannot do this for IIFE.
|
|
260
|
+
toplevel: rollupFormat === 'cjs'
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
// const visualizeOptions = typeof options.visualize === 'object'
|
|
264
|
+
// ? options.visualize
|
|
265
|
+
// : (options.visualize ? {} : undefined);
|
|
266
|
+
// if (visualizeOptions) {
|
|
267
|
+
// let rpVisualizer;
|
|
268
|
+
// try {
|
|
269
|
+
// // @ts-expect-error: No typing
|
|
270
|
+
// rpVisualizer = await import('rollup-plugin-visualizer');
|
|
271
|
+
// } catch {
|
|
272
|
+
// console.warn('Visualizing needs \'rollup-plugin-visualizer\' to be installed. It\'s installed as dev-dependency.');
|
|
273
|
+
// }
|
|
274
|
+
// if (rpVisualizer) {
|
|
275
|
+
// const visualizeFile = visualizeOptions.file ?? ps.join(options.out, 'visualize.html');
|
|
276
|
+
// rollupPlugins.push(rpVisualizer({
|
|
277
|
+
// filename: visualizeFile,
|
|
278
|
+
// title: 'Cocos Creator build visualizer',
|
|
279
|
+
// template: 'treemap',
|
|
280
|
+
// }));
|
|
281
|
+
// }
|
|
282
|
+
// }
|
|
283
|
+
let hasCriticalWarns = false;
|
|
284
|
+
const rollupWarningHandler = (warning, defaultHandler) => {
|
|
285
|
+
var _a;
|
|
286
|
+
if (typeof warning !== 'string') {
|
|
287
|
+
if (warning.code === 'CIRCULAR_DEPENDENCY') {
|
|
288
|
+
hasCriticalWarns = true;
|
|
289
|
+
} else if (warning.code === 'THIS_IS_UNDEFINED') {
|
|
290
|
+
// TODO: It's really inappropriate to do this...
|
|
291
|
+
// Let's fix these files instead of suppressing rollup.
|
|
292
|
+
if ((_a = warning.id) === null || _a === void 0 ? void 0 : _a.match(/(?:spine-core\.js$)|(?:dragonBones\.js$)/)) {
|
|
293
|
+
console.debug(`Rollup warning 'THIS_IS_UNDEFINED' is omitted for ${warning.id}`);
|
|
294
|
+
return;
|
|
324
295
|
}
|
|
325
296
|
}
|
|
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
297
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
298
|
+
defaultHandler(warning);
|
|
299
|
+
};
|
|
300
|
+
const rollupOptions = {
|
|
301
|
+
input: rollupEntries,
|
|
302
|
+
plugins: rollupPlugins,
|
|
303
|
+
cache: false,
|
|
304
|
+
onwarn: rollupWarningHandler
|
|
305
|
+
};
|
|
306
|
+
const perf = true;
|
|
307
|
+
if (perf) {
|
|
308
|
+
rollupOptions.perf = true;
|
|
309
|
+
}
|
|
310
|
+
const rollupBuild = await rollup.rollup(rollupOptions);
|
|
311
|
+
const timing = (_e = rollupBuild.getTimings) === null || _e === void 0 ? void 0 : _e.call(rollupBuild);
|
|
312
|
+
if (timing) {
|
|
313
|
+
console.debug(`==== Performance ====`);
|
|
314
|
+
console.debug(JSON.stringify(timing));
|
|
315
|
+
console.debug(`==== ====`);
|
|
316
|
+
}
|
|
317
|
+
const {
|
|
318
|
+
incremental: incrementalFile
|
|
319
|
+
} = options;
|
|
320
|
+
if (incrementalFile) {
|
|
321
|
+
const watchFiles = {};
|
|
322
|
+
const files = rollupBuild.watchFiles;
|
|
323
|
+
await Promise.all(files.map(async watchFile => {
|
|
324
|
+
try {
|
|
325
|
+
const stat = await fs_extra_1.default.stat(watchFile);
|
|
326
|
+
watchFiles[watchFile] = stat.mtimeMs;
|
|
327
|
+
} catch (_a) {
|
|
328
|
+
// the `watchFiles` may contain non-fs modules.
|
|
329
|
+
}
|
|
330
|
+
}));
|
|
331
|
+
await fs_extra_1.default.ensureDir(path_1.default.dirname(incrementalFile));
|
|
332
|
+
await fs_extra_1.default.writeFile(incrementalFile, JSON.stringify(watchFiles, undefined, 2));
|
|
333
|
+
}
|
|
334
|
+
const result = {
|
|
335
|
+
chunkAliases: {},
|
|
336
|
+
exports: {},
|
|
337
|
+
chunkDepGraph: {},
|
|
338
|
+
assetDepGraph: {},
|
|
339
|
+
hasCriticalWarns: false
|
|
340
|
+
};
|
|
341
|
+
const rollupOutputOptions = {
|
|
342
|
+
format: rollupFormat,
|
|
343
|
+
sourcemap: options.sourceMap,
|
|
344
|
+
sourcemapFile: options.sourceMapFile,
|
|
345
|
+
name: rollupFormat === 'iife' ? 'ccm' : undefined,
|
|
346
|
+
dir: options.out,
|
|
347
|
+
// NOTE: parallel dynamic import has some issue on SystemJS, especially on OH platform
|
|
348
|
+
// see: https://github.com/systemjs/systemjs/issues/2297
|
|
349
|
+
inlineDynamicImports: options.platform === 'OPEN_HARMONY'
|
|
350
|
+
// minifyInternalExports: false,
|
|
351
|
+
// preserveEntrySignatures: "allow-extension",
|
|
352
|
+
};
|
|
381
353
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
354
|
+
const rollupOutput = await rollupBuild.write(rollupOutputOptions);
|
|
355
|
+
const validEntryChunks = {};
|
|
356
|
+
for (const output of rollupOutput.output) {
|
|
357
|
+
if (output.type === 'chunk') {
|
|
358
|
+
if (output.isEntry) {
|
|
359
|
+
const chunkName = output.name;
|
|
360
|
+
if (chunkName in rollupEntries || chunkName === 'cc') {
|
|
361
|
+
validEntryChunks[chunkName] = output.fileName;
|
|
391
362
|
}
|
|
392
363
|
}
|
|
393
364
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
365
|
+
}
|
|
366
|
+
Object.assign(result.exports, validEntryChunks);
|
|
367
|
+
result.dependencyGraph = {};
|
|
368
|
+
for (const output of rollupOutput.output) {
|
|
369
|
+
if (output.type === 'chunk') {
|
|
370
|
+
const depList = output.imports.concat(output.dynamicImports);
|
|
371
|
+
result.dependencyGraph[output.fileName] = depList;
|
|
372
|
+
result.chunkDepGraph[output.fileName] = depList;
|
|
373
|
+
result.assetDepGraph[output.fileName] = output.referencedFiles.slice();
|
|
403
374
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
375
|
+
}
|
|
376
|
+
result.hasCriticalWarns = hasCriticalWarns;
|
|
377
|
+
return result;
|
|
407
378
|
}
|
|
408
379
|
exports.buildJsEngine = buildJsEngine;
|