@cocos/ccbuild 1.0.0-alpha.0 → 1.0.0-alpha.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.
- package/lib/api-builder.d.ts +0 -0
- package/lib/api-builder.js +2 -0
- package/lib/api-builder.js.map +1 -0
- package/lib/babel-plugins/transform-virtual-specifier.js +71 -0
- package/lib/babel-plugins/transform-virtual-specifier.js.map +1 -0
- package/lib/config-interface.js +3 -0
- package/lib/config-interface.js.map +1 -0
- package/lib/config-paerser/config-interface.js +3 -0
- package/lib/config-paerser/config-interface.js.map +1 -0
- package/lib/config-paerser/config-parser.js +34 -0
- package/lib/config-paerser/config-parser.js.map +1 -0
- package/lib/config-parser/config-interface.js +4 -0
- package/lib/config-parser/config-interface.js.map +1 -0
- package/lib/config-parser/config-parser.js +37 -0
- package/lib/config-parser/config-parser.js.map +1 -0
- package/lib/config-parser/constant-interface.js +3 -0
- package/lib/config-parser/constant-interface.js.map +1 -0
- package/lib/config-parser/constant-manager.js +263 -0
- package/lib/config-parser/constant-manager.js.map +1 -0
- package/lib/config-parser/index.js +286 -0
- package/lib/config-parser/index.js.map +1 -0
- package/lib/config-parser/stats-query.js +248 -0
- package/lib/config-parser/stats-query.js.map +1 -0
- package/lib/config-parser.js +34 -0
- package/lib/config-parser.js.map +1 -0
- package/lib/engine-builder.d.ts +41 -0
- package/lib/engine-builder.js +437 -0
- package/lib/engine-builder.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/module-resolver.d.ts +7 -0
- package/lib/module-resolver.js +29 -0
- package/lib/module-resolver.js.map +1 -0
- package/lib/stats-query/config-interface.d.ts +129 -0
- package/lib/stats-query/config-interface.js +4 -0
- package/lib/stats-query/config-interface.js.map +1 -0
- package/lib/stats-query/constant-interface.js +3 -0
- package/lib/stats-query/constant-interface.js.map +1 -0
- package/lib/stats-query/constant-manager.d.ts +67 -0
- package/lib/stats-query/constant-manager.js +271 -0
- package/lib/stats-query/constant-manager.js.map +1 -0
- package/lib/stats-query/index.d.ts +91 -0
- package/lib/stats-query/index.js +264 -0
- package/lib/stats-query/index.js.map +1 -0
- package/lib/stats-query/path-utils.d.ts +2 -0
- package/lib/stats-query/path-utils.js +36 -0
- package/lib/stats-query/path-utils.js.map +1 -0
- package/lib/stats-query/stats-query.js +248 -0
- package/lib/stats-query/stats-query.js.map +1 -0
- package/lib/transformer.d.ts +2 -0
- package/lib/transformer.js +7 -0
- package/lib/transformer.js.map +1 -0
- package/package.json +2 -4
|
@@ -0,0 +1,437 @@
|
|
|
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.EngineBuilder = void 0;
|
|
39
|
+
const fs = __importStar(require("fs-extra"));
|
|
40
|
+
const ps = __importStar(require("path"));
|
|
41
|
+
const babel = __importStar(require("@babel/core"));
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
const plugin_syntax_typescript_1 = __importDefault(require("@babel/plugin-syntax-typescript"));
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
const plugin_syntax_decorators_1 = __importDefault(require("@babel/plugin-syntax-decorators"));
|
|
46
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
47
|
+
const stats_query_1 = require("./stats-query");
|
|
48
|
+
const path_utils_1 = require("./stats-query/path-utils");
|
|
49
|
+
const json5 = __importStar(require("json5"));
|
|
50
|
+
const eslint_1 = require("eslint");
|
|
51
|
+
var t = babel.types;
|
|
52
|
+
class EngineBuilder {
|
|
53
|
+
constructor() {
|
|
54
|
+
this._entries = [];
|
|
55
|
+
this._entriesForPass2 = new Set;
|
|
56
|
+
this._virtual2code = {};
|
|
57
|
+
this._virtualOverrides = {};
|
|
58
|
+
this._buildResult = {};
|
|
59
|
+
this._resolveExtension = ['.ts', '.js', '.json']; // not an option
|
|
60
|
+
// TODO: for now OH global interface conflict with Rect and Path, struct
|
|
61
|
+
// so we need to rename them.
|
|
62
|
+
this._renameMap = {
|
|
63
|
+
Rect: 'RectAlias',
|
|
64
|
+
Path: 'PathAlias',
|
|
65
|
+
struct: 'structAlias',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
build(options) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const { root } = options;
|
|
71
|
+
this._buildResult = {};
|
|
72
|
+
const handleIdList = (idList) => {
|
|
73
|
+
for (let id of idList) {
|
|
74
|
+
const handleResult = this._handleId(id);
|
|
75
|
+
this._buildResult[handleResult.file] = handleResult;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
// pass1: build ts for native engine
|
|
79
|
+
yield this._initOptions(options);
|
|
80
|
+
handleIdList(this._entries);
|
|
81
|
+
// pass2: build web version for jsb type declarations
|
|
82
|
+
const entries2 = Array.from(this._entriesForPass2);
|
|
83
|
+
this._moduleOverrides = Object.entries(this._moduleOverrides).reduce((result, [k, v]) => {
|
|
84
|
+
if (!fs.existsSync(k) || !entries2.includes(k)) {
|
|
85
|
+
result[k] = v;
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}, {});
|
|
89
|
+
handleIdList(entries2);
|
|
90
|
+
if (options.outDir) {
|
|
91
|
+
for (let file in this._buildResult) {
|
|
92
|
+
const res = this._buildResult[file];
|
|
93
|
+
const output = ps.join(options.outDir, ps.relative(root, file));
|
|
94
|
+
fs.outputFileSync(output, res.code, 'utf8');
|
|
95
|
+
}
|
|
96
|
+
// pass3: post handle to lint import
|
|
97
|
+
yield this._lintImport([
|
|
98
|
+
(0, path_utils_1.normalizePath)(ps.join(options.outDir, '**/*.ts'))
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
return this._buildResult;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
_initOptions(options) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
this._options = options;
|
|
107
|
+
const { root, flagConfig, platform, mode } = options;
|
|
108
|
+
const statsQuery = yield stats_query_1.StatsQuery.create(root);
|
|
109
|
+
const constantManager = statsQuery.constantManager;
|
|
110
|
+
if (options.features) {
|
|
111
|
+
const featureUnits = statsQuery.getUnitsOfFeatures(options.features);
|
|
112
|
+
this._entries = featureUnits.map(fu => (0, path_utils_1.normalizePath)(statsQuery.getFeatureUnitFile(fu)));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const featureUnits = statsQuery.getFeatureUnits();
|
|
116
|
+
this._entries = featureUnits.map(fu => (0, path_utils_1.normalizePath)(statsQuery.getFeatureUnitFile(fu)));
|
|
117
|
+
}
|
|
118
|
+
this._buildTimeConstants = constantManager.genBuildTimeConstants({
|
|
119
|
+
platform,
|
|
120
|
+
mode,
|
|
121
|
+
flags: flagConfig,
|
|
122
|
+
});
|
|
123
|
+
this._moduleOverrides = statsQuery.evaluateModuleOverrides({
|
|
124
|
+
mode: options.mode,
|
|
125
|
+
platform: options.platform,
|
|
126
|
+
buildTimeConstants: this._buildTimeConstants,
|
|
127
|
+
});
|
|
128
|
+
this._moduleOverrides = Object.entries(this._moduleOverrides).reduce((result, [k, v]) => {
|
|
129
|
+
result[(0, path_utils_1.normalizePath)(k)] = (0, path_utils_1.normalizePath)(v);
|
|
130
|
+
return result;
|
|
131
|
+
}, {});
|
|
132
|
+
// paths in tsconfig.json
|
|
133
|
+
const tsconfigFile = ps.join(root, './tsconfig.json');
|
|
134
|
+
if (fs.existsSync(tsconfigFile)) {
|
|
135
|
+
const tsconfigContent = fs.readFileSync(tsconfigFile, 'utf8');
|
|
136
|
+
const tsconfig = json5.parse(tsconfigContent);
|
|
137
|
+
const compilerOptions = tsconfig.compilerOptions;
|
|
138
|
+
if (compilerOptions && compilerOptions.baseUrl && compilerOptions.paths) {
|
|
139
|
+
for (let [key, paths] of Object.entries(compilerOptions.paths)) {
|
|
140
|
+
this._moduleOverrides[key] = (0, path_utils_1.normalizePath)(ps.join(ps.dirname(tsconfigFile), compilerOptions.baseUrl, paths[0]));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this._virtual2code['internal:constants'] = constantManager.exportStaticConstants({
|
|
145
|
+
platform,
|
|
146
|
+
mode,
|
|
147
|
+
flags: flagConfig,
|
|
148
|
+
});
|
|
149
|
+
// TODO: resolve node modules
|
|
150
|
+
this._virtual2code['@cocos/dragonbones-js'] = 'export {}';
|
|
151
|
+
this._virtual2code['@cocos/box2d'] = 'export {}';
|
|
152
|
+
this._virtual2code['@cocos/bullet'] = 'export {}';
|
|
153
|
+
this._virtual2code['@cocos/cannon'] = 'export {}';
|
|
154
|
+
for (let virtualName in this._virtual2code) {
|
|
155
|
+
this._virtualOverrides[virtualName] = (0, path_utils_1.normalizePath)(ps.join(root, '__virtual__', virtualName.replace(/:/g, '_'))) + '.ts';
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
_handleId(id, importer) {
|
|
160
|
+
const resolvedId = this._resolve(id, importer);
|
|
161
|
+
if (typeof resolvedId === 'undefined') {
|
|
162
|
+
throw new Error(`Cannot resolve module id: ${id} ${importer ? `in file ${importer}` : ''}`);
|
|
163
|
+
}
|
|
164
|
+
const code = this._load(resolvedId);
|
|
165
|
+
if (typeof code === 'undefined') {
|
|
166
|
+
throw new Error(`Cannot load module: ${resolvedId} ${importer ? `in file ${importer}` : ''}`);
|
|
167
|
+
}
|
|
168
|
+
let overrideId = this._getOverrideId(id, importer);
|
|
169
|
+
// handle output file
|
|
170
|
+
let file = overrideId || resolvedId;
|
|
171
|
+
if (file.endsWith('.json')) {
|
|
172
|
+
file = file.slice(0, -5) + '.ts';
|
|
173
|
+
}
|
|
174
|
+
if (this._buildResult[file]) {
|
|
175
|
+
// skip cached file
|
|
176
|
+
return this._buildResult[file];
|
|
177
|
+
}
|
|
178
|
+
const transformResult = this._transform(resolvedId, code);
|
|
179
|
+
const handleResult = this._buildResult[file] = {
|
|
180
|
+
code: transformResult.code,
|
|
181
|
+
file,
|
|
182
|
+
originalId: id,
|
|
183
|
+
resolvedId,
|
|
184
|
+
map: transformResult.map,
|
|
185
|
+
};
|
|
186
|
+
transformResult.depIdList.forEach(id => {
|
|
187
|
+
const handleResult = this._handleId(id, file);
|
|
188
|
+
this._buildResult[handleResult.file] = handleResult;
|
|
189
|
+
});
|
|
190
|
+
return handleResult;
|
|
191
|
+
}
|
|
192
|
+
_getOverrideId(id, importer) {
|
|
193
|
+
let overrideId;
|
|
194
|
+
if (id in this._virtualOverrides) {
|
|
195
|
+
overrideId = this._virtualOverrides[id];
|
|
196
|
+
}
|
|
197
|
+
else if (id in this._moduleOverrides) {
|
|
198
|
+
overrideId = this._moduleOverrides[id];
|
|
199
|
+
}
|
|
200
|
+
else if (!ps.isAbsolute(id) && importer) {
|
|
201
|
+
const absolutePath = this._resolveRelative(id, importer);
|
|
202
|
+
if (absolutePath && this._moduleOverrides[absolutePath] === importer) {
|
|
203
|
+
this._entriesForPass2.add(absolutePath); // for next pass
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (absolutePath && absolutePath in this._moduleOverrides) {
|
|
207
|
+
overrideId = this._moduleOverrides[absolutePath];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return overrideId;
|
|
211
|
+
}
|
|
212
|
+
_resolve(id, importer) {
|
|
213
|
+
var _a;
|
|
214
|
+
if (!importer) {
|
|
215
|
+
return id; // entry
|
|
216
|
+
}
|
|
217
|
+
else if (id in this._virtualOverrides) {
|
|
218
|
+
return id; // virtual module does not have real fs path
|
|
219
|
+
}
|
|
220
|
+
else if (id in this._moduleOverrides) {
|
|
221
|
+
return this._moduleOverrides[id];
|
|
222
|
+
}
|
|
223
|
+
else if (ps.isAbsolute(id)) {
|
|
224
|
+
return id;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
const resolved = this._resolveRelative(id, importer);
|
|
228
|
+
if (resolved) {
|
|
229
|
+
return (_a = this._moduleOverrides[resolved]) !== null && _a !== void 0 ? _a : resolved;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
_resolveRelative(id, importer) {
|
|
234
|
+
const file = (0, path_utils_1.normalizePath)(ps.join(ps.dirname(importer), id));
|
|
235
|
+
if (ps.extname(file) && fs.existsSync(file)) {
|
|
236
|
+
return file;
|
|
237
|
+
}
|
|
238
|
+
// resolve extension less
|
|
239
|
+
for (const ext of this._resolveExtension) {
|
|
240
|
+
const fileExt = file + ext;
|
|
241
|
+
const indexExt = (0, path_utils_1.normalizePath)(ps.join(file, 'index')) + ext;
|
|
242
|
+
if (fs.existsSync(fileExt)) {
|
|
243
|
+
return fileExt;
|
|
244
|
+
}
|
|
245
|
+
else if (fs.existsSync(indexExt)) {
|
|
246
|
+
return indexExt;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
_load(id) {
|
|
251
|
+
if (fs.existsSync(id)) {
|
|
252
|
+
let code = fs.readFileSync(id, 'utf8');
|
|
253
|
+
if (id.endsWith('.json')) {
|
|
254
|
+
code = `export default ${code};`;
|
|
255
|
+
}
|
|
256
|
+
return code;
|
|
257
|
+
}
|
|
258
|
+
else if (this._virtualOverrides[id]) {
|
|
259
|
+
return this._virtual2code[id];
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
_transform(file, code) {
|
|
263
|
+
const depIdList = [];
|
|
264
|
+
if (ps.extname(file) === '.js') {
|
|
265
|
+
const dtsFile = (0, path_utils_1.toExtensionLess)(file) + '.d.ts';
|
|
266
|
+
if (fs.existsSync(dtsFile)) {
|
|
267
|
+
depIdList.push(dtsFile);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const importExportVisitor = (path) => {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
const source = path.node.source;
|
|
273
|
+
if (source) {
|
|
274
|
+
const specifier = source.value;
|
|
275
|
+
// add dependency
|
|
276
|
+
depIdList.push(specifier);
|
|
277
|
+
// transform import/export declaration if needed
|
|
278
|
+
const overrideId = this._getOverrideId(specifier, file);
|
|
279
|
+
if (overrideId) {
|
|
280
|
+
let relativePath = (0, path_utils_1.normalizePath)(ps.relative(ps.dirname(file), overrideId));
|
|
281
|
+
if (!relativePath.startsWith('.')) {
|
|
282
|
+
relativePath = './' + relativePath;
|
|
283
|
+
}
|
|
284
|
+
relativePath = relativePath.slice(0, -3); // remove '.ts'
|
|
285
|
+
// traverse to transform specifier
|
|
286
|
+
(0, traverse_1.default)(path.node, {
|
|
287
|
+
StringLiteral(path) {
|
|
288
|
+
path.replaceWith(babel.types.stringLiteral(relativePath));
|
|
289
|
+
path.skip();
|
|
290
|
+
},
|
|
291
|
+
}, path.scope);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const importExportSpecifier = (path) => {
|
|
295
|
+
const name = path.node.local.name;
|
|
296
|
+
const alias = this._renameMap[name];
|
|
297
|
+
if (alias) {
|
|
298
|
+
path.replaceWith(babel.types.exportSpecifier(babel.types.identifier(alias), babel.types.identifier(alias)));
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
path.traverse({
|
|
302
|
+
ExportSpecifier: importExportSpecifier,
|
|
303
|
+
ImportSpecifier: importExportSpecifier,
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
const transformResult = babel.transformSync(code, {
|
|
307
|
+
plugins: [
|
|
308
|
+
[plugin_syntax_typescript_1.default],
|
|
309
|
+
[plugin_syntax_decorators_1.default, {
|
|
310
|
+
version: '2018-09',
|
|
311
|
+
decoratorsBeforeExport: true,
|
|
312
|
+
}],
|
|
313
|
+
[
|
|
314
|
+
() => {
|
|
315
|
+
return {
|
|
316
|
+
name: 'custom-transform',
|
|
317
|
+
visitor: {
|
|
318
|
+
ImportDeclaration: importExportVisitor,
|
|
319
|
+
ExportDeclaration: importExportVisitor,
|
|
320
|
+
// TODO: here we rename class Rect and Path
|
|
321
|
+
CallExpression: (path) => {
|
|
322
|
+
if (path.node.callee.type === 'MemberExpression') {
|
|
323
|
+
const memberExpressionPath = path.get('callee');
|
|
324
|
+
const objectPath = memberExpressionPath.get('object');
|
|
325
|
+
const name = objectPath.node.name;
|
|
326
|
+
const alias = this._renameMap[name];
|
|
327
|
+
if (typeof alias === 'string' && path.node.callee.object.type === 'Identifier') {
|
|
328
|
+
objectPath.replaceWith(t.identifier(alias));
|
|
329
|
+
}
|
|
330
|
+
// TODO: for now, OH doesn't support standard console interface,
|
|
331
|
+
// so we need to ignore the type checking for console call expressions.
|
|
332
|
+
else if (name === 'console') {
|
|
333
|
+
path.node.leadingComments = [{
|
|
334
|
+
type: 'CommentLine',
|
|
335
|
+
value: ' @ts-ignore',
|
|
336
|
+
}];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
ClassDeclaration: (path) => {
|
|
341
|
+
const idPath = path.get('id');
|
|
342
|
+
const name = idPath.node.name;
|
|
343
|
+
const alias = this._renameMap[name];
|
|
344
|
+
if (typeof alias === 'string') {
|
|
345
|
+
idPath.replaceWith(t.identifier(alias));
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
NewExpression: (path) => {
|
|
349
|
+
const calleePath = path.get('callee');
|
|
350
|
+
// @ts-ignore
|
|
351
|
+
const name = calleePath.node.name;
|
|
352
|
+
if (name) {
|
|
353
|
+
const alias = this._renameMap[name];
|
|
354
|
+
if (typeof alias === 'string') {
|
|
355
|
+
calleePath.replaceWith(t.identifier(alias));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
TSTypeAnnotation: (path) => {
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
const typeName = path.node.typeAnnotation.typeName;
|
|
362
|
+
const childPath = path.get('typeAnnotation');
|
|
363
|
+
if (typeName) {
|
|
364
|
+
const name = typeName.name;
|
|
365
|
+
const alias = this._renameMap[name];
|
|
366
|
+
if (typeof alias === 'string') {
|
|
367
|
+
path.replaceWith(t.tsTypeAnnotation({
|
|
368
|
+
type: 'TSExpressionWithTypeArguments',
|
|
369
|
+
expression: t.identifier(alias),
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else if (childPath.type === 'TSLiteralType') {
|
|
374
|
+
const literalPath = childPath.get('literal');
|
|
375
|
+
if (literalPath.type === 'TemplateLiteral') {
|
|
376
|
+
path.replaceWith(t.tsTypeAnnotation(t.tsStringKeyword()));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
Identifier: (path) => {
|
|
381
|
+
const name = path.node.name;
|
|
382
|
+
const alias = this._renameMap[name];
|
|
383
|
+
if (typeof alias === 'string') {
|
|
384
|
+
if (path.parent.type === 'ObjectProperty' || path.parent.type === 'TSPropertySignature') {
|
|
385
|
+
if (path.parent.key !== path.node) {
|
|
386
|
+
path.replaceWith(t.identifier(alias));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else if (path.parent.type === 'MemberExpression' || path.parent.type === 'OptionalMemberExpression') {
|
|
390
|
+
if (path.parent.property !== path.node) {
|
|
391
|
+
path.replaceWith(t.identifier(alias));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else if (!(path.parent.type === 'ClassMethod' && (path.parent.kind === 'get' || path.parent.kind === 'set' || path.parent.key === path.node))
|
|
395
|
+
&& path.parent.type !== 'ClassProperty') {
|
|
396
|
+
const newIdentifier = t.identifier(alias);
|
|
397
|
+
if (path.node.typeAnnotation) {
|
|
398
|
+
newIdentifier.typeAnnotation = path.node.typeAnnotation;
|
|
399
|
+
}
|
|
400
|
+
path.replaceWith(newIdentifier);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
]
|
|
408
|
+
],
|
|
409
|
+
});
|
|
410
|
+
return {
|
|
411
|
+
code: transformResult === null || transformResult === void 0 ? void 0 : transformResult.code,
|
|
412
|
+
depIdList,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
_lintImport(lintFiles, verbose = false) {
|
|
416
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
417
|
+
const eslint = new eslint_1.ESLint({ fix: true,
|
|
418
|
+
baseConfig: {
|
|
419
|
+
parser: "@typescript-eslint/parser",
|
|
420
|
+
plugins: ["@typescript-eslint", "unused-imports"],
|
|
421
|
+
rules: {
|
|
422
|
+
"@typescript-eslint/consistent-type-imports": "error",
|
|
423
|
+
"unused-imports/no-unused-imports": "error",
|
|
424
|
+
},
|
|
425
|
+
} });
|
|
426
|
+
const results = yield eslint.lintFiles(lintFiles);
|
|
427
|
+
yield eslint_1.ESLint.outputFixes(results);
|
|
428
|
+
if (verbose) {
|
|
429
|
+
const formatter = yield eslint.loadFormatter();
|
|
430
|
+
const resultText = formatter.format(results);
|
|
431
|
+
console.log(resultText);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
exports.EngineBuilder = EngineBuilder;
|
|
437
|
+
//# sourceMappingURL=engine-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-builder.js","sourceRoot":"","sources":["../src/engine-builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,yCAA2B;AAC3B,mDAAqC;AACrC,aAAa;AACb,+FAA6D;AAC7D,aAAa;AACb,+FAA+D;AAC/D,+DAAuC;AACvC,+CAA8G;AAC9G,yDAA0E;AAC1E,6CAA+B;AAC/B,mCAAgC;AAEhC,IAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;AA6BvB,MAAa,aAAa;IAA1B;QAEY,aAAQ,GAAa,EAAE,CAAC;QACxB,qBAAgB,GAAgB,IAAI,GAAW,CAAC;QAChD,kBAAa,GAA2B,EAAE,CAAC;QAC3C,sBAAiB,GAA2B,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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EngineBuilder = void 0;
|
|
4
|
+
var engine_builder_1 = require("./engine-builder");
|
|
5
|
+
Object.defineProperty(exports, "EngineBuilder", { enumerable: true, get: function () { return engine_builder_1.EngineBuilder; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,+GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ModuleResolver = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const importRegExp = /[(import)(export)].*?['"](.*?)['"]/g;
|
|
10
|
+
class ModuleResolver {
|
|
11
|
+
resolve(filepath) {
|
|
12
|
+
const code = fs_extra_1.default.readFileSync(filepath, 'utf8');
|
|
13
|
+
const all = code.matchAll(importRegExp);
|
|
14
|
+
const deps = [];
|
|
15
|
+
for (let item of all) {
|
|
16
|
+
let dep = item[1];
|
|
17
|
+
if (!path_1.default.isAbsolute(dep)) {
|
|
18
|
+
dep = path_1.default.join(path_1.default.dirname(filepath), dep);
|
|
19
|
+
}
|
|
20
|
+
deps.push(dep + '.ts');
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
id: filepath,
|
|
24
|
+
deps,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ModuleResolver = ModuleResolver;
|
|
29
|
+
//# sourceMappingURL=module-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-resolver.js","sourceRoot":"","sources":["../src/module-resolver.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAsB;AAOtB,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D,MAAa,cAAc;IAEvB,OAAO,CAAE,QAAgB;QACrB,MAAM,IAAI,GAAG,kBAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,IAAI,IAAI,GAAG,EAAG;YACnB,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,cAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACrB,GAAG,GAAG,cAAE,CAAC,IAAI,CAAC,cAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;aAC5C;YACD,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;SAC1B;QACD,OAAO;YACH,EAAE,EAAE,QAAQ;YACZ,IAAI;SACP,CAAC;IACN,CAAC;CACJ;AAlBD,wCAkBC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
/**
|
|
3
|
+
* Engine features. Keys are feature IDs.
|
|
4
|
+
*/
|
|
5
|
+
features: Record<string, Feature>;
|
|
6
|
+
/**
|
|
7
|
+
* Describe how to generate the index module `'cc'`.
|
|
8
|
+
* Currently not used.
|
|
9
|
+
*/
|
|
10
|
+
index?: IndexConfig;
|
|
11
|
+
moduleOverrides?: Array<{
|
|
12
|
+
test: Test;
|
|
13
|
+
overrides: Record<string, string>;
|
|
14
|
+
isVirtualModule: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Included files for quick-compiler.
|
|
18
|
+
*/
|
|
19
|
+
includes: Array<string>;
|
|
20
|
+
/**
|
|
21
|
+
* The constants config for engine and user.
|
|
22
|
+
*/
|
|
23
|
+
constants: IConstantConfig;
|
|
24
|
+
/**
|
|
25
|
+
* The decorators to be optimize when build engine.
|
|
26
|
+
*/
|
|
27
|
+
optimizeDecorators: IOptimizeDecorators;
|
|
28
|
+
}
|
|
29
|
+
export interface IndexConfig {
|
|
30
|
+
modules?: Record<string, {
|
|
31
|
+
/**
|
|
32
|
+
* If specified, export contents of the module into a namespace specified by `ns`
|
|
33
|
+
* and then export that namespace into `'cc'`.
|
|
34
|
+
* If not specified, contents of the module will be directly exported into `'cc'`.
|
|
35
|
+
*/
|
|
36
|
+
ns?: string;
|
|
37
|
+
/**
|
|
38
|
+
* If `true`, accesses the exports of this module from `'cc'` will be marked as deprecated.
|
|
39
|
+
*/
|
|
40
|
+
deprecated?: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
export declare type Test = string;
|
|
44
|
+
/**
|
|
45
|
+
* An engine feature.
|
|
46
|
+
*/
|
|
47
|
+
export interface Feature {
|
|
48
|
+
/**
|
|
49
|
+
* Modules to be included in this feature in their IDs.
|
|
50
|
+
* The ID of a module is its relative path(no extension) under /exports/.
|
|
51
|
+
*/
|
|
52
|
+
modules: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Flags to set when this feature is enabled.
|
|
55
|
+
*/
|
|
56
|
+
intrinsicFlags?: Record<string, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* List of uuid that the feature depend on.
|
|
59
|
+
*/
|
|
60
|
+
dependentAssets?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* List of module that the feature depend on.
|
|
63
|
+
*/
|
|
64
|
+
dependentModules?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Whether it is a native only feature, default is false.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
isNativeOnly?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface Context {
|
|
72
|
+
mode?: string;
|
|
73
|
+
platform?: string;
|
|
74
|
+
buildTimeConstants?: Object;
|
|
75
|
+
}
|
|
76
|
+
export declare type ConstantTypeName = 'boolean' | 'number';
|
|
77
|
+
export interface IConstantInfo {
|
|
78
|
+
/**
|
|
79
|
+
* The comment of the constant.
|
|
80
|
+
* Which is used to generate the consts.d.ts file.
|
|
81
|
+
*/
|
|
82
|
+
readonly comment: string;
|
|
83
|
+
/**
|
|
84
|
+
* The type of the constant for generating consts.d.ts file.
|
|
85
|
+
*/
|
|
86
|
+
readonly type: ConstantTypeName;
|
|
87
|
+
/**
|
|
88
|
+
* The default value of the constant.
|
|
89
|
+
* It can be a boolean, number or string.
|
|
90
|
+
* When it's a string type, the value is the result of eval().
|
|
91
|
+
*/
|
|
92
|
+
value: boolean | string | number;
|
|
93
|
+
/**
|
|
94
|
+
* Whether exported to global as a `CC_XXXX` constant.
|
|
95
|
+
* eg. WECHAT is exported to global.CC_WECHAT
|
|
96
|
+
* NOTE: this is a feature of compatibility with Cocos 2.x engine.
|
|
97
|
+
* Default is false.
|
|
98
|
+
*
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
ccGlobal?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Whether exported to developer.
|
|
104
|
+
* If true, it's only exported to engine.
|
|
105
|
+
*/
|
|
106
|
+
readonly internal: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Some constant can't specify the value in the Editor, Preview or Test environment,
|
|
109
|
+
* so we need to dynamically judge them in runtime.
|
|
110
|
+
* These values are specified in a helper called `helper-dynamic-constants.ts`.
|
|
111
|
+
* Default is false.
|
|
112
|
+
*
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
115
|
+
dynamic?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface IConstantConfig {
|
|
118
|
+
[ConstantName: string]: IConstantInfo;
|
|
119
|
+
}
|
|
120
|
+
export interface IOptimizeDecorators {
|
|
121
|
+
/**
|
|
122
|
+
* The decorators which should be optimized when they only decorate class fields.
|
|
123
|
+
*/
|
|
124
|
+
fieldDecorators: string[];
|
|
125
|
+
/**
|
|
126
|
+
* The decorators which should be removed directly when they only work in Cocos Creator editor.
|
|
127
|
+
*/
|
|
128
|
+
editorDecorators: string[];
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-interface.js","sourceRoot":"","sources":["../../src/stats-query/config-interface.ts"],"names":[],"mappings":";AAAA,2DAA2D"}
|