xhs-mp-compiler-cli 2.0.4-beta.4 → 2.0.5
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/dist/compilerManager.d.ts +95 -0
- package/dist/compilerManager.js +590 -0
- package/dist/index.d.ts +1 -95
- package/dist/index.js +15 -582
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
12
14
|
};
|
|
13
15
|
(function (factory) {
|
|
14
16
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
@@ -16,579 +18,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
18
|
if (v !== undefined) module.exports = v;
|
|
17
19
|
}
|
|
18
20
|
else if (typeof define === "function" && define.amd) {
|
|
19
|
-
define(["require", "exports", "./
|
|
21
|
+
define(["require", "exports", "./compilerManager"], factory);
|
|
20
22
|
}
|
|
21
23
|
})(function (require, exports) {
|
|
22
24
|
"use strict";
|
|
23
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
|
|
25
|
-
const constant_config_1 = require("./config/constant.config");
|
|
26
|
-
Object.defineProperty(exports, "COMPILE_ENTRY", { enumerable: true, get: function () { return constant_config_1.COMPILE_ENTRY; } });
|
|
27
|
-
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
28
|
-
const events_1 = __importDefault(require("events"));
|
|
29
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const utils_1 = require("./utils/utils");
|
|
32
|
-
const project_1 = require("./utils/project");
|
|
33
|
-
const dir_config_1 = require("./config/dir.config");
|
|
34
|
-
const compiler_1 = require("./compiler");
|
|
35
|
-
Object.defineProperty(exports, "prepareDevPool", { enumerable: true, get: function () { return compiler_1.prepareDevPool; } });
|
|
36
|
-
const sharedFs_1 = __importDefault(require("./sharedFs"));
|
|
37
|
-
class ProjectCompilerManager extends events_1.default {
|
|
38
|
-
constructor(props) {
|
|
39
|
-
super();
|
|
40
|
-
this.compilerImplMap = {};
|
|
41
|
-
this.getCompiler = (entryType = constant_config_1.COMPILE_ENTRY.simulator) => {
|
|
42
|
-
if (!this.compilerImplMap[entryType]) {
|
|
43
|
-
this.compilerImplMap[entryType] = this.createCompiler(entryType);
|
|
44
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
45
|
-
this.initSimulatorCompiler(this.compilerImplMap[entryType]);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
this.initBuildCompiler(this.compilerImplMap[entryType]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return this.compilerImplMap[entryType];
|
|
52
|
-
};
|
|
53
|
-
this.initSimulatorCompiler = compiler => {
|
|
54
|
-
compiler.on('buildStart', data => {
|
|
55
|
-
this.emit('simulator-compile-start', data);
|
|
56
|
-
});
|
|
57
|
-
compiler.on('compileInfo', data => {
|
|
58
|
-
this.emit('simulator-compile-info', data);
|
|
59
|
-
});
|
|
60
|
-
compiler.on('buildSuccess', data => {
|
|
61
|
-
this.emit('simulator-compile-success', data);
|
|
62
|
-
});
|
|
63
|
-
compiler.on('buildError', data => {
|
|
64
|
-
this.emit('simulator-compile-error', data);
|
|
65
|
-
});
|
|
66
|
-
compiler.on('compileFinishWhenFileChange', data => {
|
|
67
|
-
this.emit('simulator-file-change-compile-finish', data);
|
|
68
|
-
});
|
|
69
|
-
compiler.on('compilePercent', data => {
|
|
70
|
-
this.emit('simulator-compile-percent', data);
|
|
71
|
-
});
|
|
72
|
-
compiler.on('emitCompileStats', data => {
|
|
73
|
-
this.emit('simulator-compile-stats', data);
|
|
74
|
-
});
|
|
75
|
-
compiler.on('unexpectedExit', data => {
|
|
76
|
-
this.emit('simulator-compile-unexpectedExit', data);
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
this.initBuildCompiler = compiler => {
|
|
80
|
-
compiler.on('compilePercent', data => {
|
|
81
|
-
this.emit('full-compile-percent', data);
|
|
82
|
-
});
|
|
83
|
-
compiler.on('compileInfo', data => {
|
|
84
|
-
this.emit('full-compiler-info', data);
|
|
85
|
-
});
|
|
86
|
-
compiler.on('emitCompileStats', data => {
|
|
87
|
-
this.emit('full-compile-stats', data);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const { logger, report, projectPath, project } = props;
|
|
91
|
-
this.logger = logger || console;
|
|
92
|
-
this.report = report;
|
|
93
|
-
this.compilerProps = props;
|
|
94
|
-
if (!project && !projectPath)
|
|
95
|
-
return;
|
|
96
|
-
this.project = (project ||
|
|
97
|
-
new xhs_mp_project_1.Project({
|
|
98
|
-
projectPath: projectPath
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
bindProject(props) {
|
|
102
|
-
const { projectPath, project } = props;
|
|
103
|
-
if (!project && !projectPath) {
|
|
104
|
-
throw new Error('project 和 projectPath 均为undefined');
|
|
105
|
-
}
|
|
106
|
-
this.project = (project ||
|
|
107
|
-
new xhs_mp_project_1.Project({
|
|
108
|
-
projectPath: projectPath
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
// 根据使用的场景或者配置,采用不同的compiler类型
|
|
112
|
-
getCompilerType(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
113
|
-
const isGame = this.project.appMode === constant_config_1.MiniMode.minigame;
|
|
114
|
-
const settings = this.project.settings || {};
|
|
115
|
-
// 使用旧编译
|
|
116
|
-
if (isGame || !settings.useNewCompiler) {
|
|
117
|
-
return entryType === constant_config_1.COMPILE_ENTRY.simulator
|
|
118
|
-
? constant_config_1.COMPILER_TYPE.legacy_dev
|
|
119
|
-
: constant_config_1.COMPILER_TYPE.legacy_build;
|
|
120
|
-
}
|
|
121
|
-
// 使用新编译
|
|
122
|
-
return entryType === constant_config_1.COMPILE_ENTRY.simulator
|
|
123
|
-
? constant_config_1.COMPILER_TYPE.dev
|
|
124
|
-
: entryType === constant_config_1.COMPILE_ENTRY.upload
|
|
125
|
-
? constant_config_1.COMPILER_TYPE.legacy_build
|
|
126
|
-
: constant_config_1.COMPILER_TYPE.build;
|
|
127
|
-
}
|
|
128
|
-
getDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
129
|
-
const { compileDistDir = dir_config_1.mpCompileDirPath } = this.compilerProps;
|
|
130
|
-
const compilerType = this.getCompilerType(entryType);
|
|
131
|
-
const projectPath = this.project.projectPath;
|
|
132
|
-
const basename = path_1.default.basename(projectPath);
|
|
133
|
-
const hash = (0, utils_1.getMd5)(projectPath).slice(0, 8);
|
|
134
|
-
const distDir = path_1.default.join(path_1.default.resolve(compileDistDir, `${basename}_${hash}`), compilerType);
|
|
135
|
-
fs_extra_1.default.ensureDirSync(distDir);
|
|
136
|
-
return distDir;
|
|
137
|
-
}
|
|
138
|
-
removeDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
139
|
-
try {
|
|
140
|
-
const distDir = this.getDistDir(entryType);
|
|
141
|
-
if (fs_extra_1.default.existsSync(distDir)) {
|
|
142
|
-
fs_extra_1.default.removeSync(distDir);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (error) { }
|
|
146
|
-
}
|
|
147
|
-
getCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
148
|
-
const { compileCacheDir = dir_config_1.mpCompileCachePath } = this.compilerProps;
|
|
149
|
-
const projectPath = this.project.projectPath;
|
|
150
|
-
const compilerType = this.getCompilerType(entryType);
|
|
151
|
-
const basename = path_1.default.basename(projectPath);
|
|
152
|
-
const hash = (0, utils_1.getMd5)(projectPath).slice(0, 8);
|
|
153
|
-
const distDir = path_1.default.join(path_1.default.resolve(compileCacheDir, `${basename}_${hash}`), compilerType);
|
|
154
|
-
fs_extra_1.default.ensureDirSync(distDir);
|
|
155
|
-
return distDir;
|
|
156
|
-
}
|
|
157
|
-
removeCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
158
|
-
const cacheDir = this.getCacheDir(entryType);
|
|
159
|
-
if (fs_extra_1.default.existsSync(cacheDir)) {
|
|
160
|
-
fs_extra_1.default.removeSync(cacheDir);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
removeAllCacheDir() {
|
|
164
|
-
// 移除编译缓存
|
|
165
|
-
const cacheDir = this.getCacheDir();
|
|
166
|
-
const parenCacheDir = path_1.default.dirname(cacheDir);
|
|
167
|
-
if (fs_extra_1.default.existsSync(parenCacheDir)) {
|
|
168
|
-
fs_extra_1.default.removeSync(parenCacheDir);
|
|
169
|
-
}
|
|
170
|
-
// 移除编译产物
|
|
171
|
-
const distDir = this.getDistDir();
|
|
172
|
-
const parentDistDir = path_1.default.dirname(distDir);
|
|
173
|
-
if (fs_extra_1.default.existsSync(parentDistDir)) {
|
|
174
|
-
fs_extra_1.default.removeSync(parentDistDir);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
createCompiler(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
178
|
-
const { nodeJsPath } = this.compilerProps;
|
|
179
|
-
const distDir = this.getDistDir(entryType);
|
|
180
|
-
const cacheDir = this.getCacheDir(entryType);
|
|
181
|
-
const compilerType = this.getCompilerType(entryType);
|
|
182
|
-
const packMode = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
|
|
183
|
-
? 'webpack'
|
|
184
|
-
: 'mp-pack';
|
|
185
|
-
const options = {
|
|
186
|
-
packMode,
|
|
187
|
-
projectPath: this.project.projectPath,
|
|
188
|
-
appMode: this.project.appMode,
|
|
189
|
-
extJsonPath: this.project.extJsonDir,
|
|
190
|
-
platform: 'xhs',
|
|
191
|
-
distDir,
|
|
192
|
-
enablePersistCache: entryType !== constant_config_1.COMPILE_ENTRY.upload,
|
|
193
|
-
cacheDirectory: cacheDir
|
|
194
|
-
};
|
|
195
|
-
this.removeDistDir(entryType);
|
|
196
|
-
// this.removeCacheDir(entryType)
|
|
197
|
-
const CompilerClass = (0, compiler_1.getProjectCompilerClass)(compilerType);
|
|
198
|
-
const compiler = new CompilerClass(options, {
|
|
199
|
-
workerType: entryType === constant_config_1.COMPILE_ENTRY.simulator ? 'web' : 'process',
|
|
200
|
-
nodeJsPath
|
|
201
|
-
});
|
|
202
|
-
return compiler;
|
|
203
|
-
}
|
|
204
|
-
// 使用的编译目标包类型
|
|
205
|
-
getUsingPackageType() {
|
|
206
|
-
return __awaiter(this, arguments, void 0, function* (entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
207
|
-
let enableV1 = false;
|
|
208
|
-
let enableV2 = true;
|
|
209
|
-
let enableVDom = false;
|
|
210
|
-
const settings = this.project.settings || {};
|
|
211
|
-
const isUpload = entryType === constant_config_1.COMPILE_ENTRY.upload;
|
|
212
|
-
if (this.project.appMode === constant_config_1.MiniMode.minigame) {
|
|
213
|
-
enableV1 = true;
|
|
214
|
-
enableV2 = false;
|
|
215
|
-
enableVDom = false;
|
|
216
|
-
}
|
|
217
|
-
else if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
218
|
-
if (this.compilerProps.getLibFeatures) {
|
|
219
|
-
const libFeatures = yield this.compilerProps.getLibFeatures();
|
|
220
|
-
enableV2 = libFeatures.supportV2 && settings.enableV2;
|
|
221
|
-
enableVDom = !enableV2 && libFeatures.supportVDom && settings.enableVDom;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
enableV2 = settings.enableV2;
|
|
225
|
-
enableVDom = !enableV2 && settings.enableVDom;
|
|
226
|
-
}
|
|
227
|
-
// enableVDom = !enableV2 && settings.enableVDom
|
|
228
|
-
enableV1 = !enableV2;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
// 上传模式下按照勾选开启
|
|
232
|
-
enableVDom = settings.enableVDom;
|
|
233
|
-
enableV2 = settings.enableV2;
|
|
234
|
-
enableV1 = true;
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
enableV1,
|
|
238
|
-
enableV2,
|
|
239
|
-
enableVDom
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
makePkgsReady(opts) {
|
|
244
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
var _a, _b;
|
|
246
|
-
const { compilePkgs } = opts;
|
|
247
|
-
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
248
|
-
const defaultOptions = yield this.getUsingPackageType(entryType);
|
|
249
|
-
const compiler = this.getCompiler(entryType);
|
|
250
|
-
const startTime = Date.now();
|
|
251
|
-
// 如果要编主包,看看入口页是否普通分包,也加进去
|
|
252
|
-
if (compilePkgs === null || compilePkgs === void 0 ? void 0 : compilePkgs.includes(constant_config_1.MAIN_PKG_ROOT)) {
|
|
253
|
-
const customEntry = this.project.customEntry;
|
|
254
|
-
const subPackages = this.project.getSubPackages();
|
|
255
|
-
const subPkg = subPackages.find((item) => customEntry.startsWith(`${item.root}/`));
|
|
256
|
-
if (subPkg && !subPkg.independent) {
|
|
257
|
-
compilePkgs.push(subPkg.root);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const config = Object.assign(Object.assign({ compilePkgs, compressCss: false, compressJs: true, enableSourcemap: true, appendSourcemapComment: true, runInServiceSandbox: true, devWriteToDisk: true }, defaultOptions), opts);
|
|
261
|
-
console.log('[compiler]makePkgsReady', config);
|
|
262
|
-
try {
|
|
263
|
-
this.emit('makePkgsReady-start', { config });
|
|
264
|
-
yield compiler.makePkgsReady(config);
|
|
265
|
-
this.emit('makePkgsReady-end', { config });
|
|
266
|
-
(_a = this.report) === null || _a === void 0 ? void 0 : _a.call(this, 'compile', {
|
|
267
|
-
result: 'success',
|
|
268
|
-
entryType,
|
|
269
|
-
config: JSON.stringify(config),
|
|
270
|
-
duration: Date.now() - startTime
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
this.emit('makePkgsReady-error', { config, error });
|
|
275
|
-
(_b = this.report) === null || _b === void 0 ? void 0 : _b.call(this, 'compile', {
|
|
276
|
-
result: 'fail',
|
|
277
|
-
entryType,
|
|
278
|
-
config: JSON.stringify(config),
|
|
279
|
-
reason: error.message
|
|
280
|
-
});
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
reCompilePkgs(opts) {
|
|
286
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
-
var _a, _b, _c;
|
|
288
|
-
const { compilePkgs } = opts;
|
|
289
|
-
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
290
|
-
const compiler = this.getCompiler(entryType);
|
|
291
|
-
const defaultOptions = yield this.getUsingPackageType(entryType);
|
|
292
|
-
const startTime = Date.now();
|
|
293
|
-
const config = Object.assign(Object.assign({ compilePkgs, compressCss: false, compressJs: true, enableSourcemap: true, appendSourcemapComment: true, runInServiceSandbox: true, devWriteToDisk: true }, defaultOptions), opts);
|
|
294
|
-
console.log('[compiler]reCompilePkgs', config);
|
|
295
|
-
try {
|
|
296
|
-
this.emit('recompile-pkgs-start', { config });
|
|
297
|
-
(_a = (0, sharedFs_1.default)(true)) === null || _a === void 0 ? void 0 : _a.clear();
|
|
298
|
-
yield compiler.reCompilePkgs(config);
|
|
299
|
-
this.emit('recompile-pkgs-end', { config });
|
|
300
|
-
(_b = this.report) === null || _b === void 0 ? void 0 : _b.call(this, 'compile', {
|
|
301
|
-
result: 'success',
|
|
302
|
-
entryType,
|
|
303
|
-
config: JSON.stringify(config),
|
|
304
|
-
duration: Date.now() - startTime
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
this.emit('recompile-pkgs-error', { config, error });
|
|
309
|
-
(_c = this.report) === null || _c === void 0 ? void 0 : _c.call(this, 'compile', {
|
|
310
|
-
result: 'fail',
|
|
311
|
-
entryType,
|
|
312
|
-
config: JSON.stringify(config),
|
|
313
|
-
reason: error.message
|
|
314
|
-
});
|
|
315
|
-
throw error;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
compileProject(config) {
|
|
320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
var _a, _b, _c, _d, _e;
|
|
322
|
-
const { entryType } = config;
|
|
323
|
-
try {
|
|
324
|
-
this.emit('compile-project-start');
|
|
325
|
-
const startTime = Date.now();
|
|
326
|
-
const compiler = this.getCompiler(entryType);
|
|
327
|
-
this.removeDistDir(entryType);
|
|
328
|
-
(_a = (0, sharedFs_1.default)(true)) === null || _a === void 0 ? void 0 : _a.clear();
|
|
329
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project...');
|
|
330
|
-
yield compiler.build(config);
|
|
331
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project done...');
|
|
332
|
-
this.emit('compile-project-end');
|
|
333
|
-
(_d = this.report) === null || _d === void 0 ? void 0 : _d.call(this, 'compile', {
|
|
334
|
-
result: 'success',
|
|
335
|
-
entryType,
|
|
336
|
-
config: JSON.stringify(config),
|
|
337
|
-
duration: Date.now() - startTime
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
catch (stats) {
|
|
341
|
-
let errors = [];
|
|
342
|
-
if (stats.errors) {
|
|
343
|
-
errors = stats.errors;
|
|
344
|
-
}
|
|
345
|
-
else if (stats instanceof Error) {
|
|
346
|
-
errors = [stats.message];
|
|
347
|
-
}
|
|
348
|
-
this.emit('compile-project-error', { config, errors });
|
|
349
|
-
const error = new Error(errors.join('\n\n'));
|
|
350
|
-
(_e = this.report) === null || _e === void 0 ? void 0 : _e.call(this, 'compile', {
|
|
351
|
-
result: 'fail',
|
|
352
|
-
entryType,
|
|
353
|
-
config: JSON.stringify(config),
|
|
354
|
-
reason: error.message
|
|
355
|
-
});
|
|
356
|
-
throw error;
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
compileAndZip(opts) {
|
|
361
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
362
|
-
var _a;
|
|
363
|
-
const { can_upload_ext_json, entryType } = opts;
|
|
364
|
-
try {
|
|
365
|
-
const appJsonContent = this.project.appJsonContent;
|
|
366
|
-
const settings = this.project.settings || {};
|
|
367
|
-
let subPackages = appJsonContent.subPackages || appJsonContent.subpackages || [];
|
|
368
|
-
const formatGameAppJSON = this.project.formatGameAppJSON;
|
|
369
|
-
subPackages =
|
|
370
|
-
this.project.appMode === constant_config_1.MiniMode.miniprogram
|
|
371
|
-
? subPackages
|
|
372
|
-
: formatGameAppJSON(subPackages);
|
|
373
|
-
const { enableV1, enableV2, enableVDom } = yield this.getUsingPackageType(entryType);
|
|
374
|
-
let compressJs = false;
|
|
375
|
-
let compressCss = false;
|
|
376
|
-
let enableSourcemap = true;
|
|
377
|
-
let appendSourcemapComment = true;
|
|
378
|
-
let runInServiceSandbox = false;
|
|
379
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
380
|
-
compressCss = true;
|
|
381
|
-
compressJs = true;
|
|
382
|
-
enableSourcemap = false;
|
|
383
|
-
appendSourcemapComment = false;
|
|
384
|
-
}
|
|
385
|
-
else if (entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
386
|
-
compressCss = true;
|
|
387
|
-
compressJs = true;
|
|
388
|
-
appendSourcemapComment = false;
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
compressCss = false;
|
|
392
|
-
compressJs = (_a = settings.minified) !== null && _a !== void 0 ? _a : false;
|
|
393
|
-
runInServiceSandbox = true;
|
|
394
|
-
}
|
|
395
|
-
const buildConfig = Object.assign({ entryType,
|
|
396
|
-
compressCss,
|
|
397
|
-
compressJs,
|
|
398
|
-
enableSourcemap,
|
|
399
|
-
appendSourcemapComment,
|
|
400
|
-
runInServiceSandbox,
|
|
401
|
-
enableV1,
|
|
402
|
-
enableV2,
|
|
403
|
-
enableVDom, mpUploadOptions: this.project.appMode === constant_config_1.MiniMode.miniprogram && opts }, opts);
|
|
404
|
-
// 编译
|
|
405
|
-
this.emit('compile-and-zip-status', { status: 'build-start' });
|
|
406
|
-
yield this.compileProject(buildConfig);
|
|
407
|
-
this.emit('compile-and-zip-status', { status: 'build-done' });
|
|
408
|
-
// 生成zip
|
|
409
|
-
this.emit('compile-and-zip-status', { status: 'zip-start' });
|
|
410
|
-
let entryZips = [];
|
|
411
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
412
|
-
entryZips = [
|
|
413
|
-
this.zipWithFullPackage(opts, subPackages, 'v0'),
|
|
414
|
-
this.zipWithSubPackage(opts, subPackages, 'v1'),
|
|
415
|
-
// 小程序模式有v2包
|
|
416
|
-
buildConfig.enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2')
|
|
417
|
-
];
|
|
418
|
-
}
|
|
419
|
-
else if (entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
420
|
-
entryZips = [
|
|
421
|
-
this.zipWithFullPackage(opts, subPackages, 'v0', true),
|
|
422
|
-
this.zipWithSubPackage(opts, subPackages, 'v1', true),
|
|
423
|
-
// 小程序模式有v2包
|
|
424
|
-
enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2', true)
|
|
425
|
-
];
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
// 真机调试
|
|
429
|
-
entryZips = [this.zipWithSubPackage(opts, subPackages, enableV2 ? 'v2' : 'v1')];
|
|
430
|
-
}
|
|
431
|
-
const zipTask = yield Promise.all(entryZips.filter(Boolean));
|
|
432
|
-
const zipResult = zipTask.flat(2);
|
|
433
|
-
this.emit('compile-and-zip-status', { status: 'zip-done' });
|
|
434
|
-
// change ext
|
|
435
|
-
if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
436
|
-
this.project.changeExtJsonPermission(!!can_upload_ext_json);
|
|
437
|
-
}
|
|
438
|
-
resolve(zipResult);
|
|
439
|
-
}
|
|
440
|
-
catch (error) {
|
|
441
|
-
reject(error);
|
|
442
|
-
}
|
|
443
|
-
}));
|
|
444
|
-
}
|
|
445
|
-
closeCompiler(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
446
|
-
const compiler = this.compilerImplMap[entryType];
|
|
447
|
-
if (compiler) {
|
|
448
|
-
compiler.close();
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
killCompiler(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
452
|
-
const compiler = this.compilerImplMap[entryType];
|
|
453
|
-
if (!compiler) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
compiler.kill();
|
|
457
|
-
delete this.compilerImplMap[entryType];
|
|
458
|
-
}
|
|
459
|
-
killAll() {
|
|
460
|
-
Object.values(this.compilerImplMap).forEach((compiler) => {
|
|
461
|
-
compiler.kill();
|
|
462
|
-
});
|
|
463
|
-
this.compilerImplMap = {};
|
|
464
|
-
}
|
|
465
|
-
/* 使用v0的入口,zip整包 */
|
|
466
|
-
zipWithFullPackage(opts_1) {
|
|
467
|
-
return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type, excludeSourcemap) {
|
|
468
|
-
const { upload_app_id, can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
469
|
-
const buildDir = this.getDistDir(entryType);
|
|
470
|
-
const appendFile = [];
|
|
471
|
-
const appendBuffer = [];
|
|
472
|
-
appendFile.push(this.project.projectJsonPath); // zip添加project.config.json
|
|
473
|
-
/* 是否需要上传ext.json */
|
|
474
|
-
if (can_upload_ext_json && fs_extra_1.default.existsSync(this.project.extJsonPath)) {
|
|
475
|
-
appendFile.push(this.project.extJsonPath);
|
|
476
|
-
}
|
|
477
|
-
if (pkgInfo) {
|
|
478
|
-
/* 是否需要额外添加pkgInfo.json信息 */
|
|
479
|
-
const content = { version: pkgInfo.version };
|
|
480
|
-
const contentStr = JSON.stringify(content);
|
|
481
|
-
appendBuffer.push({
|
|
482
|
-
name: 'pkgInfo.json',
|
|
483
|
-
buffer: Buffer.from(contentStr, 'utf-8')
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
let ignore = [];
|
|
487
|
-
if (excludeSourcemap) {
|
|
488
|
-
ignore = ['**/*.map'];
|
|
489
|
-
}
|
|
490
|
-
const tasks = [];
|
|
491
|
-
const baseZipConfig = {
|
|
492
|
-
inputDir: path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0' // 如果没有开启分包,则把v1包当作v0包
|
|
493
|
-
), // 输入的路径
|
|
494
|
-
type,
|
|
495
|
-
prefix: upload_app_id,
|
|
496
|
-
meta: {
|
|
497
|
-
root: ''
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
tasks.push((0, project_1.zipFactory)(Object.assign(Object.assign({}, baseZipConfig), { pattern: '**/*', ignore,
|
|
501
|
-
appendFile,
|
|
502
|
-
appendBuffer, outputDir: path_1.default.resolve(buildDir, `${type}-full-pack.zip`) // 输出的路径
|
|
503
|
-
})));
|
|
504
|
-
if (excludeSourcemap) {
|
|
505
|
-
tasks.push((0, project_1.zipFactory)(Object.assign(Object.assign({}, baseZipConfig), { pattern: '**/*.map', ignore: [], appendFile: [], appendBuffer: [], outputDir: path_1.default.resolve(buildDir, `${type}-full-pack-sourcemap.zip`) // 输出的路径
|
|
506
|
-
})));
|
|
507
|
-
}
|
|
508
|
-
return Promise.all(tasks);
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
/* 使用v1的入口。zip主包和分包 */
|
|
512
|
-
zipWithSubPackage(opts, subPackages, type, excludeSourcemap) {
|
|
513
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
514
|
-
const projectConfig = this.project;
|
|
515
|
-
const { can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
516
|
-
const isRemoteDebug = entryType === constant_config_1.COMPILE_ENTRY.remotedebug;
|
|
517
|
-
const appendFile = []; // 额外的文件
|
|
518
|
-
const appendBuffer = [];
|
|
519
|
-
appendFile.push(projectConfig.projectJsonPath); // zip添加project.config.json
|
|
520
|
-
const buildDir = this.getDistDir(entryType);
|
|
521
|
-
const mainEntry = path_1.default.resolve(buildDir, type);
|
|
522
|
-
// 主包里需要忽略分包的路径
|
|
523
|
-
const mainIgnore = (subPackages || []).map((item) => item.root.endsWith('/') ? `${item.root}**` : `${item.root}/**`);
|
|
524
|
-
const subIgnore = [];
|
|
525
|
-
if (excludeSourcemap) {
|
|
526
|
-
mainIgnore.push('**/*.map');
|
|
527
|
-
subIgnore.push('**/*.map');
|
|
528
|
-
}
|
|
529
|
-
/* 是否需要上传ext.json */
|
|
530
|
-
if (can_upload_ext_json && fs_extra_1.default.existsSync(projectConfig.extJsonPath)) {
|
|
531
|
-
appendFile.push(projectConfig.extJsonPath);
|
|
532
|
-
}
|
|
533
|
-
if (pkgInfo) {
|
|
534
|
-
/* 是否需要额外添加pkgInfo.json信息 */
|
|
535
|
-
const content = { version: pkgInfo.version };
|
|
536
|
-
const contentStr = JSON.stringify(content);
|
|
537
|
-
appendBuffer.push({
|
|
538
|
-
name: 'pkgInfo.json',
|
|
539
|
-
buffer: Buffer.from(contentStr, 'utf-8')
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
const tasks = [];
|
|
543
|
-
// // 主包
|
|
544
|
-
tasks.push((0, project_1.zipFactory)({
|
|
545
|
-
inputDir: mainEntry, // 输入的路径
|
|
546
|
-
type,
|
|
547
|
-
prefix: '',
|
|
548
|
-
meta: {
|
|
549
|
-
root: '/'
|
|
550
|
-
},
|
|
551
|
-
pattern: '**/*',
|
|
552
|
-
ignore: mainIgnore,
|
|
553
|
-
appendFile,
|
|
554
|
-
appendBuffer,
|
|
555
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-main-pack.zip`) // 输出的路径
|
|
556
|
-
}));
|
|
557
|
-
(subPackages || []).forEach((item, index) => {
|
|
558
|
-
const pkgRoot = item.root.replace(/\//g, constant_config_1.PKG_ROOT_SEP);
|
|
559
|
-
tasks.push((0, project_1.zipFactory)({
|
|
560
|
-
inputDir: path_1.default.resolve(buildDir, type, item.root),
|
|
561
|
-
prefix: `${item.root}`,
|
|
562
|
-
appendFile: [],
|
|
563
|
-
appendBuffer: [],
|
|
564
|
-
pattern: '**/*',
|
|
565
|
-
ignore: subIgnore,
|
|
566
|
-
type,
|
|
567
|
-
meta: {
|
|
568
|
-
root: item.root
|
|
569
|
-
},
|
|
570
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-sub-pack-${isRemoteDebug ? pkgRoot : index}.zip`)
|
|
571
|
-
}));
|
|
572
|
-
});
|
|
573
|
-
// sourcemap
|
|
574
|
-
if (excludeSourcemap) {
|
|
575
|
-
tasks.push((0, project_1.zipFactory)({
|
|
576
|
-
inputDir: mainEntry, // 输入的路径
|
|
577
|
-
pattern: '**/*.map',
|
|
578
|
-
ignore: [],
|
|
579
|
-
appendFile: [],
|
|
580
|
-
appendBuffer: [],
|
|
581
|
-
type,
|
|
582
|
-
prefix: '',
|
|
583
|
-
meta: {
|
|
584
|
-
root: '/'
|
|
585
|
-
},
|
|
586
|
-
outputDir: path_1.default.resolve(buildDir, `${type}-pack-sourcemap.zip`) // 输出的路径
|
|
587
|
-
}));
|
|
588
|
-
}
|
|
589
|
-
return Promise.all(tasks);
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
exports.ProjectCompilerManager = ProjectCompilerManager;
|
|
26
|
+
__exportStar(require("./compilerManager"), exports);
|
|
594
27
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "xhs mp command tool.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -88,18 +88,18 @@
|
|
|
88
88
|
"webpack-chain": "^6.5.1",
|
|
89
89
|
"webpack-sources": "^3.2.2",
|
|
90
90
|
"xhs-mp-workerpool": "^9.1.3",
|
|
91
|
-
"xhs-mp-ml-loader": "2.0.
|
|
92
|
-
"xhs-mp-compiler-utils": "2.0.
|
|
93
|
-
"xhs-mp-pack": "2.0.
|
|
94
|
-
"xhs-mp-project": "2.0.
|
|
95
|
-
"xhs-mp-shared": "2.0.
|
|
96
|
-
"xhs-mp-shared-fs": "2.0.
|
|
97
|
-
"xhs-mp-sjs-loader": "2.0.
|
|
98
|
-
"xhs-mp-sketch-loader": "2.0.
|
|
91
|
+
"xhs-mp-ml-loader": "2.0.5",
|
|
92
|
+
"xhs-mp-compiler-utils": "2.0.5",
|
|
93
|
+
"xhs-mp-pack": "2.0.5",
|
|
94
|
+
"xhs-mp-project": "2.0.5",
|
|
95
|
+
"xhs-mp-shared": "2.0.5",
|
|
96
|
+
"xhs-mp-shared-fs": "2.0.5",
|
|
97
|
+
"xhs-mp-sjs-loader": "2.0.5",
|
|
98
|
+
"xhs-mp-sketch-loader": "2.0.5",
|
|
99
99
|
"yauzl": "^2.10.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
-
"xhs-mp-ml-parser": "2.0.
|
|
102
|
+
"xhs-mp-ml-parser": "2.0.5"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@types/babel__generator": "7.6.3",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"typescript": "5.1.6",
|
|
124
124
|
"vue3-jest": "27.0.0-alpha.2",
|
|
125
125
|
"webpack-dev-server": "4.0.0-beta.3",
|
|
126
|
-
"xhs-mp-ml-parser": "2.0.
|
|
126
|
+
"xhs-mp-ml-parser": "2.0.5"
|
|
127
127
|
},
|
|
128
128
|
"scripts": {
|
|
129
129
|
"version": "formula changelog && git add .",
|