xhs-mp-compiler-cli 1.6.0-beta.2 → 2.0.0-beta.3
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/compiler.d.ts +13 -15
- package/dist/compiler.js +40 -96
- package/dist/{compilerImpl.js → compilerCP.js} +42 -29
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -5
- package/dist/packs/mp-pack/index.js +1 -0
- package/dist/packs/webpack/dev-server/index.js +0 -1
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +4 -3
- package/dist/packs/webpack/webpack.d.ts +1 -1
- package/dist/packs/webpack/webpack.js +2 -6
- package/dist/presets/configs/miniprogram/render/index.d.ts +3 -2
- package/dist/presets/configs/miniprogram/render/index.js +2 -2
- package/dist/presets/configs/miniprogram/service/index.js +0 -1
- package/dist/utils/tagTransformMap.d.ts +1 -0
- package/dist/utils/tagTransformMap.js +2 -1
- package/package.json +12 -26
- package/dist/compilerImpl.d.ts +0 -1
- package/dist/compilerImplChildProcess.js +0 -33
- package/dist/compilerImplThreadWorker.d.ts +0 -1
- package/dist/compilerImplThreadWorker.js +0 -30
- package/dist/compilerImplWebWorker.d.ts +0 -6
- package/dist/compilerImplWebWorker.js +0 -25
- package/dist/dev-server/compatibleAPI.d.ts +0 -25
- package/dist/dev-server/compatibleAPI.js +0 -56
- package/dist/dev-server/escapeHtml.d.ts +0 -5
- package/dist/dev-server/escapeHtml.js +0 -50
- package/dist/dev-server/etag.d.ts +0 -10
- package/dist/dev-server/etag.js +0 -69
- package/dist/dev-server/getFilenameFromUrl.d.ts +0 -9
- package/dist/dev-server/getFilenameFromUrl.js +0 -102
- package/dist/dev-server/getPaths.d.ts +0 -6
- package/dist/dev-server/getPaths.js +0 -20
- package/dist/dev-server/index.d.ts +0 -98
- package/dist/dev-server/index.js +0 -90
- package/dist/dev-server/memorize.d.ts +0 -7
- package/dist/dev-server/memorize.js +0 -23
- package/dist/dev-server/middleware.d.ts +0 -2
- package/dist/dev-server/middleware.js +0 -477
- package/dist/dev-server/ready.d.ts +0 -4
- package/dist/dev-server/ready.js +0 -11
- package/dist/sharedFs.d.ts +0 -2
- package/dist/sharedFs.js +0 -4
- package/dist/utils/workerPool.d.ts +0 -29
- package/dist/utils/workerPool.js +0 -115
- /package/dist/{compilerImplChildProcess.d.ts → compilerCP.d.ts} +0 -0
package/dist/compiler.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node/child_process" />
|
|
2
|
+
/// <reference types=".pnpm/artifactory.devops.xiaohongshu.com+@types+node@20.12.2/node_modules/@types/node/child_process" />
|
|
2
3
|
/// <reference types="node/stream" />
|
|
4
|
+
/// <reference types=".pnpm/artifactory.devops.xiaohongshu.com+@types+node@20.12.2/node_modules/@types/node/stream" />
|
|
3
5
|
/**
|
|
4
6
|
* 在子进程执行编译
|
|
5
7
|
*/
|
|
@@ -29,28 +31,24 @@ export interface ICheckOptions {
|
|
|
29
31
|
enableV2?: boolean;
|
|
30
32
|
enableV1?: boolean;
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
declare abstract class AbstractCompiler extends EventEmitter {
|
|
33
35
|
protected inspectPort: any;
|
|
34
|
-
private
|
|
35
|
-
protected _implType: 'thread_worker' | 'web_worker' | 'cp';
|
|
36
|
+
private _cp;
|
|
36
37
|
private compilerOpts;
|
|
37
|
-
private
|
|
38
|
+
private cpArgs;
|
|
38
39
|
private logger;
|
|
39
40
|
private _handlerMap;
|
|
40
41
|
constructor(opts: ICompilerOption, args?: ICompilerArgs);
|
|
41
|
-
get
|
|
42
|
-
protected
|
|
43
|
-
protected
|
|
44
|
-
protected createThreadWorker: (passData?: {}) => any;
|
|
45
|
-
protected createWebWorker: (passData?: {}) => any;
|
|
46
|
-
private postMessage;
|
|
42
|
+
get cp(): any;
|
|
43
|
+
protected createSp: (passData?: {}) => any;
|
|
44
|
+
protected create: (passData?: {}) => ChildProcess;
|
|
47
45
|
close(): void;
|
|
48
46
|
kill(): void;
|
|
49
47
|
private handleMessage;
|
|
50
48
|
call: (method: any, data: any) => Promise<unknown>;
|
|
51
49
|
send: (method: any, data: any) => void;
|
|
52
50
|
}
|
|
53
|
-
|
|
51
|
+
declare class MPPackDevCompiler extends AbstractCompiler {
|
|
54
52
|
private pending;
|
|
55
53
|
private pendingPkgs;
|
|
56
54
|
private readyPkgs;
|
|
@@ -64,17 +62,17 @@ export declare class MPPackDevCompiler extends AbstractCompiler {
|
|
|
64
62
|
makePkgsReady(opts: ICheckOptions): Promise<void>;
|
|
65
63
|
reCompilePkgs(options: any): Promise<void>;
|
|
66
64
|
}
|
|
67
|
-
|
|
65
|
+
declare class WebPackDevCompiler extends AbstractCompiler {
|
|
68
66
|
private watching;
|
|
69
67
|
private pendingTask?;
|
|
70
|
-
constructor(props: any
|
|
68
|
+
constructor(props: any);
|
|
71
69
|
makePkgsReady(opts: any): Promise<unknown>;
|
|
72
70
|
reCompilePkgs(opts: any): Promise<void>;
|
|
73
71
|
}
|
|
74
|
-
|
|
72
|
+
declare class BuildCompiler extends AbstractCompiler {
|
|
75
73
|
cps: any;
|
|
76
74
|
constructor(props: any, args: any);
|
|
77
75
|
build(option: ICheckOptions): Promise<unknown>;
|
|
78
76
|
}
|
|
79
|
-
export declare function
|
|
77
|
+
export declare function getProcessCompilerClass(compilerType: any): typeof MPPackDevCompiler | typeof WebPackDevCompiler | typeof BuildCompiler;
|
|
80
78
|
export {};
|
package/dist/compiler.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.getProcessCompilerClass = void 0;
|
|
16
16
|
/**
|
|
17
17
|
* 在子进程执行编译
|
|
18
18
|
*/
|
|
@@ -26,42 +26,23 @@ const isMac = process.platform === 'darwin';
|
|
|
26
26
|
class AbstractCompiler extends stream_1.EventEmitter {
|
|
27
27
|
constructor(opts, args = {}) {
|
|
28
28
|
super();
|
|
29
|
-
// ide侧用web_worker,cli用thread_worker
|
|
30
|
-
this._implType = 'web_worker';
|
|
31
29
|
this._handlerMap = {};
|
|
32
|
-
this.
|
|
33
|
-
if (!this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this._impl.on('message', this.handleMessage);
|
|
40
|
-
}
|
|
41
|
-
else if (this._implType === 'web_worker') {
|
|
42
|
-
this._impl = this.createWebWorker(passData);
|
|
43
|
-
this._impl.onerror = err => {
|
|
44
|
-
console.error(err);
|
|
45
|
-
};
|
|
46
|
-
this._impl.onmessage = this.handleMessage;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this._impl = this.createCP(passData);
|
|
50
|
-
this._impl.on('exit', code => {
|
|
51
|
-
this._impl = null;
|
|
52
|
-
});
|
|
53
|
-
this._impl.on('message', this.handleMessage);
|
|
54
|
-
}
|
|
55
|
-
// console.log('create impl done:', this._impl)
|
|
30
|
+
this.createSp = (passData = {}) => {
|
|
31
|
+
if (!this._cp) {
|
|
32
|
+
this._cp = this.create(Object.assign({}, passData));
|
|
33
|
+
this._cp.on('exit', code => {
|
|
34
|
+
this._cp = null;
|
|
35
|
+
});
|
|
36
|
+
this._cp.on('message', this.handleMessage);
|
|
56
37
|
}
|
|
57
|
-
return this.
|
|
38
|
+
return this._cp;
|
|
58
39
|
};
|
|
59
|
-
this.
|
|
40
|
+
this.create = (passData = {}) => {
|
|
60
41
|
var _a, _b;
|
|
61
|
-
const { type = 'keepalive', inspectPort = this.inspectPort, maxSpaceSaze = 12288, nodeJsPath } = this.
|
|
42
|
+
const { type = 'keepalive', inspectPort = this.inspectPort, maxSpaceSaze = 12288, nodeJsPath, } = this.cpArgs;
|
|
62
43
|
// const presistent = type === 'keepalive'
|
|
63
|
-
const entry = (0, path_1.join)(__dirname, './
|
|
64
|
-
const execArgv = ['--expose-gc'];
|
|
44
|
+
const entry = (0, path_1.join)(__dirname, './compilerCP.js');
|
|
45
|
+
const execArgv = [`--max-old-space-size=${maxSpaceSaze}`, '--expose-gc'];
|
|
65
46
|
const customNodeJs = nodeJsPath && fs_extra_1.default.existsSync(nodeJsPath);
|
|
66
47
|
if (process.env.DEV_IDE_SP) {
|
|
67
48
|
execArgv.push(`--inspect=${inspectPort}`);
|
|
@@ -78,7 +59,7 @@ class AbstractCompiler extends stream_1.EventEmitter {
|
|
|
78
59
|
stdio: 'pipe',
|
|
79
60
|
execArgv,
|
|
80
61
|
// detached: presistent,
|
|
81
|
-
windowsHide: true
|
|
62
|
+
windowsHide: true,
|
|
82
63
|
};
|
|
83
64
|
if (customNodeJs) {
|
|
84
65
|
options.execPath = nodeJsPath;
|
|
@@ -94,36 +75,18 @@ class AbstractCompiler extends stream_1.EventEmitter {
|
|
|
94
75
|
this.logger.error('[compiler stderr]', msg.toString());
|
|
95
76
|
});
|
|
96
77
|
child.on('error', err => {
|
|
97
|
-
this.logger.error('
|
|
78
|
+
this.logger.error('sp error:', err);
|
|
98
79
|
});
|
|
99
80
|
child.on('exit', code => {
|
|
100
81
|
if (code !== 0 && code !== null) {
|
|
101
|
-
this.logger.error('
|
|
82
|
+
this.logger.error('sp exit:', code);
|
|
102
83
|
this.emit('unexpectedExit', code);
|
|
103
84
|
}
|
|
104
85
|
});
|
|
105
86
|
return child;
|
|
106
87
|
};
|
|
107
|
-
this.createThreadWorker = (passData = {}) => {
|
|
108
|
-
const { Worker } = require('worker_threads');
|
|
109
|
-
const entry = (0, path_1.join)(__dirname, './compilerImplThreadWorker.js');
|
|
110
|
-
const worker = new Worker(entry, { workerData: passData });
|
|
111
|
-
return worker;
|
|
112
|
-
};
|
|
113
|
-
// electron渲染进程不能使用worker_threads
|
|
114
|
-
this.createWebWorker = (passData = {}) => {
|
|
115
|
-
const entry = (0, path_1.join)(__dirname, './compilerImplWebWorker.js');
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
const worker = new Worker(entry);
|
|
118
|
-
worker.postMessage(JSON.stringify({ passData }));
|
|
119
|
-
return worker;
|
|
120
|
-
};
|
|
121
88
|
this.handleMessage = msg => {
|
|
122
89
|
var _a, _b, _c, _d;
|
|
123
|
-
if (this._implType === 'web_worker') {
|
|
124
|
-
msg = msg.data;
|
|
125
|
-
}
|
|
126
|
-
// console.log('handle compielr message', msg)
|
|
127
90
|
let data = {};
|
|
128
91
|
try {
|
|
129
92
|
data = JSON.parse(`${msg}`);
|
|
@@ -145,7 +108,7 @@ class AbstractCompiler extends stream_1.EventEmitter {
|
|
|
145
108
|
return;
|
|
146
109
|
}
|
|
147
110
|
if (method === 'debugger') {
|
|
148
|
-
|
|
111
|
+
console.log(`[debugger]:`, ...(data.data || []));
|
|
149
112
|
return;
|
|
150
113
|
}
|
|
151
114
|
this.emit(method, data);
|
|
@@ -155,54 +118,40 @@ class AbstractCompiler extends stream_1.EventEmitter {
|
|
|
155
118
|
const final = {
|
|
156
119
|
uuid: id,
|
|
157
120
|
method,
|
|
158
|
-
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data)
|
|
121
|
+
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
|
|
159
122
|
};
|
|
160
123
|
this._handlerMap[id] = {
|
|
161
124
|
resolve,
|
|
162
|
-
reject
|
|
125
|
+
reject,
|
|
163
126
|
};
|
|
164
|
-
this.
|
|
127
|
+
this.cp.send(JSON.stringify(final));
|
|
165
128
|
});
|
|
166
129
|
this.send = (method, data) => {
|
|
167
130
|
const final = {
|
|
168
131
|
method,
|
|
169
|
-
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data)
|
|
132
|
+
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
|
|
170
133
|
};
|
|
171
|
-
this.
|
|
134
|
+
this.cp.send(JSON.stringify(final));
|
|
172
135
|
};
|
|
173
136
|
this.compilerOpts = opts;
|
|
174
|
-
this.
|
|
137
|
+
this.cpArgs = args;
|
|
175
138
|
this.logger = args.logger || console;
|
|
176
139
|
}
|
|
177
|
-
get
|
|
178
|
-
return this.
|
|
179
|
-
}
|
|
180
|
-
postMessage(msg) {
|
|
181
|
-
if (this._implType === 'thread_worker' || this._implType === 'web_worker') {
|
|
182
|
-
this.impl.postMessage(msg);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
this.impl.send(msg);
|
|
186
|
-
}
|
|
140
|
+
get cp() {
|
|
141
|
+
return this.createSp();
|
|
187
142
|
}
|
|
188
143
|
close() {
|
|
189
|
-
if (this.
|
|
190
|
-
this.
|
|
144
|
+
if (this._cp) {
|
|
145
|
+
this._cp.send(JSON.stringify({ method: 'close' }));
|
|
191
146
|
}
|
|
192
147
|
}
|
|
193
148
|
kill() {
|
|
194
|
-
if (this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
this._impl.terminate();
|
|
200
|
-
}
|
|
201
|
-
this._impl = null;
|
|
149
|
+
if (this._cp) {
|
|
150
|
+
this._cp.kill();
|
|
151
|
+
this._cp = null;
|
|
202
152
|
}
|
|
203
153
|
}
|
|
204
154
|
}
|
|
205
|
-
exports.AbstractCompiler = AbstractCompiler;
|
|
206
155
|
class MPPackDevCompiler extends AbstractCompiler {
|
|
207
156
|
constructor(props, args) {
|
|
208
157
|
super(props, args);
|
|
@@ -210,9 +159,8 @@ class MPPackDevCompiler extends AbstractCompiler {
|
|
|
210
159
|
this.pendingPkgs = {};
|
|
211
160
|
this.readyPkgs = [];
|
|
212
161
|
this.watching = false;
|
|
213
|
-
this._implType = (args === null || args === void 0 ? void 0 : args.implType) || 'web_worker';
|
|
214
162
|
this.inspectPort = 9227;
|
|
215
|
-
this.
|
|
163
|
+
this.createSp();
|
|
216
164
|
}
|
|
217
165
|
reset() {
|
|
218
166
|
this.pendingPkgs = {};
|
|
@@ -221,6 +169,7 @@ class MPPackDevCompiler extends AbstractCompiler {
|
|
|
221
169
|
this.pending = false;
|
|
222
170
|
}
|
|
223
171
|
doCompilePkgs(opts) {
|
|
172
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
224
173
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
225
174
|
const { compilePkgs = [constant_config_1.MAIN_PKG_ROOT] } = opts;
|
|
226
175
|
const todoPkgs = [];
|
|
@@ -238,7 +187,7 @@ class MPPackDevCompiler extends AbstractCompiler {
|
|
|
238
187
|
}
|
|
239
188
|
this.pendingPkgs[pkg] = {
|
|
240
189
|
resolve: [resolve],
|
|
241
|
-
reject: [reject]
|
|
190
|
+
reject: [reject],
|
|
242
191
|
};
|
|
243
192
|
todoPkgs.push(pkg);
|
|
244
193
|
});
|
|
@@ -328,14 +277,12 @@ class MPPackDevCompiler extends AbstractCompiler {
|
|
|
328
277
|
});
|
|
329
278
|
}
|
|
330
279
|
}
|
|
331
|
-
exports.MPPackDevCompiler = MPPackDevCompiler;
|
|
332
280
|
class WebPackDevCompiler extends AbstractCompiler {
|
|
333
|
-
constructor(props
|
|
281
|
+
constructor(props) {
|
|
334
282
|
super(props);
|
|
335
283
|
this.watching = false;
|
|
336
|
-
this._implType = (args === null || args === void 0 ? void 0 : args.implType) || 'web_worker';
|
|
337
284
|
this.inspectPort = 9230;
|
|
338
|
-
this.
|
|
285
|
+
this.createSp();
|
|
339
286
|
}
|
|
340
287
|
makePkgsReady(opts) {
|
|
341
288
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -356,12 +303,12 @@ class WebPackDevCompiler extends AbstractCompiler {
|
|
|
356
303
|
this.emit('buildStart');
|
|
357
304
|
yield this.call('runTask', Object.assign({ scene: 'watch', action: 'dev' }, opts));
|
|
358
305
|
this.watching = true;
|
|
359
|
-
(_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
|
|
306
|
+
(_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach((fn) => fn());
|
|
360
307
|
this.emit('buildSuccess');
|
|
361
308
|
}
|
|
362
309
|
catch (error) {
|
|
363
310
|
this.watching = false;
|
|
364
|
-
(_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach(fn => fn());
|
|
311
|
+
(_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach((fn) => fn());
|
|
365
312
|
this.kill();
|
|
366
313
|
this.emit('buildError', error);
|
|
367
314
|
}
|
|
@@ -387,14 +334,12 @@ class WebPackDevCompiler extends AbstractCompiler {
|
|
|
387
334
|
});
|
|
388
335
|
}
|
|
389
336
|
}
|
|
390
|
-
exports.WebPackDevCompiler = WebPackDevCompiler;
|
|
391
337
|
class BuildCompiler extends AbstractCompiler {
|
|
392
338
|
constructor(props, args) {
|
|
393
339
|
super(props, args);
|
|
394
340
|
this.cps = [];
|
|
395
|
-
this._implType = (args === null || args === void 0 ? void 0 : args.implType) || 'cp';
|
|
396
341
|
this.inspectPort = 9228;
|
|
397
|
-
this.
|
|
342
|
+
this.createSp();
|
|
398
343
|
}
|
|
399
344
|
build(option) {
|
|
400
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -409,8 +354,7 @@ class BuildCompiler extends AbstractCompiler {
|
|
|
409
354
|
});
|
|
410
355
|
}
|
|
411
356
|
}
|
|
412
|
-
|
|
413
|
-
function getProjectCompilerClass(compilerType) {
|
|
357
|
+
function getProcessCompilerClass(compilerType) {
|
|
414
358
|
const CompilerClass = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev
|
|
415
359
|
? WebPackDevCompiler
|
|
416
360
|
: compilerType === constant_config_1.COMPILER_TYPE.dev
|
|
@@ -418,4 +362,4 @@ function getProjectCompilerClass(compilerType) {
|
|
|
418
362
|
: BuildCompiler;
|
|
419
363
|
return CompilerClass;
|
|
420
364
|
}
|
|
421
|
-
exports.
|
|
365
|
+
exports.getProcessCompilerClass = getProcessCompilerClass;
|
|
@@ -9,17 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.runCompilerImpl = void 0;
|
|
13
12
|
const packs_1 = require("./packs");
|
|
14
|
-
let globalConfig =
|
|
13
|
+
let globalConfig = JSON.parse(process.argv[2]);
|
|
14
|
+
let hadWatchBuilt = false;
|
|
15
15
|
let projectCompiler;
|
|
16
|
-
|
|
16
|
+
/* 发送消息给父进程 */
|
|
17
|
+
const sendToMaster = (method, data = {}) => {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, JSON.stringify(Object.assign({ method }, data)));
|
|
20
|
+
};
|
|
17
21
|
const tryGC = () => {
|
|
18
22
|
if (global.gc) {
|
|
19
23
|
global.gc();
|
|
20
24
|
}
|
|
21
25
|
};
|
|
22
|
-
function
|
|
26
|
+
function formatWebpackMessages(err, stats) {
|
|
23
27
|
if (err) {
|
|
24
28
|
return { errors: [err.message], warnings: [] };
|
|
25
29
|
}
|
|
@@ -45,7 +49,7 @@ const handlers = {
|
|
|
45
49
|
const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
|
|
46
50
|
if (hasError) {
|
|
47
51
|
sendToMaster('emitCompileStats', {
|
|
48
|
-
stats:
|
|
52
|
+
stats: formatWebpackMessages(err, stats)
|
|
49
53
|
});
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
@@ -57,10 +61,11 @@ const handlers = {
|
|
|
57
61
|
sendToMaster('callback', {
|
|
58
62
|
uuid,
|
|
59
63
|
success: false,
|
|
60
|
-
stats:
|
|
64
|
+
stats: formatWebpackMessages(err, stats)
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
else {
|
|
68
|
+
hadWatchBuilt = true;
|
|
64
69
|
sendToMaster('callback', {
|
|
65
70
|
uuid,
|
|
66
71
|
success: true
|
|
@@ -82,10 +87,11 @@ const handlers = {
|
|
|
82
87
|
sendToMaster('callback', {
|
|
83
88
|
uuid,
|
|
84
89
|
success: false,
|
|
85
|
-
stats:
|
|
90
|
+
stats: formatWebpackMessages(err, stats)
|
|
86
91
|
});
|
|
87
92
|
}
|
|
88
93
|
else {
|
|
94
|
+
hadWatchBuilt = true;
|
|
89
95
|
sendToMaster('callback', {
|
|
90
96
|
uuid,
|
|
91
97
|
success: true
|
|
@@ -98,15 +104,17 @@ const handlers = {
|
|
|
98
104
|
if (!projectCompiler) {
|
|
99
105
|
projectCompiler = (0, packs_1.createCompiler)(data);
|
|
100
106
|
}
|
|
101
|
-
projectCompiler.on('progress',
|
|
102
|
-
sendToMaster('compilePercent',
|
|
107
|
+
projectCompiler.on('progress', progress => {
|
|
108
|
+
sendToMaster('compilePercent', {
|
|
109
|
+
percentage: progress
|
|
110
|
+
});
|
|
103
111
|
});
|
|
104
112
|
projectCompiler.build((err, stats) => {
|
|
105
113
|
var _a;
|
|
106
114
|
const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
|
|
107
115
|
console.log('sp run build finish', stats);
|
|
108
116
|
if (hasError) {
|
|
109
|
-
const statsInfo =
|
|
117
|
+
const statsInfo = formatWebpackMessages(err, stats);
|
|
110
118
|
sendToMaster('callback', {
|
|
111
119
|
uuid,
|
|
112
120
|
success: false,
|
|
@@ -140,23 +148,28 @@ const handlers = {
|
|
|
140
148
|
projectCompiler = null;
|
|
141
149
|
}
|
|
142
150
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
process.on('message', (message) => {
|
|
152
|
+
let objData = {};
|
|
153
|
+
try {
|
|
154
|
+
objData = JSON.parse(message);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
// do something
|
|
158
|
+
}
|
|
159
|
+
const { uuid, method, data = {} } = objData;
|
|
160
|
+
if (!handlers[method]) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
handlers[method](objData);
|
|
164
|
+
});
|
|
165
|
+
process.on('uncaughtException', error => {
|
|
166
|
+
console.error(error);
|
|
167
|
+
sendToMaster('emitCompileStats', {
|
|
168
|
+
stats: {
|
|
169
|
+
errors: [error.message]
|
|
157
170
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
process.on('disconnect', () => {
|
|
174
|
+
process.exit(-1);
|
|
175
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/// <reference types="node/events" />
|
|
2
|
+
/// <reference types=".pnpm/artifactory.devops.xiaohongshu.com+@types+node@20.12.2/node_modules/@types/node/events" />
|
|
2
3
|
import { COMPILE_ENTRY } from './config/constant.config';
|
|
3
4
|
import { Project } from 'xhs-mp-project';
|
|
4
5
|
import EventEmitter from 'events';
|
|
5
6
|
import { Logger } from 'xhs-mp-utils';
|
|
6
|
-
import {
|
|
7
|
+
import { getProcessCompilerClass } from './compiler';
|
|
7
8
|
interface ILibFeatures {
|
|
8
9
|
supportV2?: boolean;
|
|
9
10
|
supportVdom?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export { COMPILE_ENTRY,
|
|
12
|
+
export { COMPILE_ENTRY, getProcessCompilerClass };
|
|
12
13
|
export type ICompileOpts = {
|
|
13
14
|
logger?: any;
|
|
14
15
|
compileDir?: string;
|
|
@@ -50,7 +51,7 @@ export interface ISubPackages {
|
|
|
50
51
|
root: string;
|
|
51
52
|
pages: string;
|
|
52
53
|
}
|
|
53
|
-
export declare class
|
|
54
|
+
export declare class Compiler extends EventEmitter {
|
|
54
55
|
projectPath: string;
|
|
55
56
|
compilerProps: ICompilerProps;
|
|
56
57
|
project: Project;
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.Compiler = exports.getProcessCompilerClass = exports.COMPILE_ENTRY = void 0;
|
|
16
16
|
const constant_config_1 = require("./config/constant.config");
|
|
17
17
|
Object.defineProperty(exports, "COMPILE_ENTRY", { enumerable: true, get: function () { return constant_config_1.COMPILE_ENTRY; } });
|
|
18
18
|
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
@@ -24,8 +24,8 @@ const zip_1 = require("./utils/zip");
|
|
|
24
24
|
const project_1 = require("./utils/project");
|
|
25
25
|
const dir_config_1 = require("./config/dir.config");
|
|
26
26
|
const compiler_1 = require("./compiler");
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
class
|
|
27
|
+
Object.defineProperty(exports, "getProcessCompilerClass", { enumerable: true, get: function () { return compiler_1.getProcessCompilerClass; } });
|
|
28
|
+
class Compiler extends events_1.default {
|
|
29
29
|
constructor(props) {
|
|
30
30
|
super();
|
|
31
31
|
this.compilerImplMap = {};
|
|
@@ -202,7 +202,7 @@ class ProjectCompiler extends events_1.default {
|
|
|
202
202
|
};
|
|
203
203
|
this.removeDistDir(entryType);
|
|
204
204
|
this.removeCacheDir(entryType);
|
|
205
|
-
const CompilerClass = (0, compiler_1.
|
|
205
|
+
const CompilerClass = (0, compiler_1.getProcessCompilerClass)(compilerType);
|
|
206
206
|
const compilerImpl = new CompilerClass(options, {
|
|
207
207
|
logger: this.logger,
|
|
208
208
|
nodeJsPath
|
|
@@ -452,4 +452,4 @@ class ProjectCompiler extends events_1.default {
|
|
|
452
452
|
delete this.compilerImplMap[entryType];
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
|
-
exports.
|
|
455
|
+
exports.Compiler = Compiler;
|
|
@@ -11,6 +11,7 @@ const apm_1 = require("../../utils/apm");
|
|
|
11
11
|
const const_1 = __importDefault(require("../../utils/const"));
|
|
12
12
|
const { PACK_MODE } = const_1.default;
|
|
13
13
|
const createCompiler = (startConfig) => {
|
|
14
|
+
// const {action, enableDevServer} = startConfig
|
|
14
15
|
const mppack = new xhs_mp_pack_1.MPPack(startConfig);
|
|
15
16
|
const compilerOptions = {
|
|
16
17
|
project: mppack.project,
|
|
@@ -19,7 +19,6 @@ const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
|
|
|
19
19
|
const presets_1 = require("../../../presets");
|
|
20
20
|
const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
const { packSetting } = config;
|
|
22
|
-
// @ts-ignore
|
|
23
22
|
const { distDir } = packSetting;
|
|
24
23
|
const webpackConfigs = (0, presets_1.createConfigs)(config);
|
|
25
24
|
const compiler = (0, webpack_1.default)(webpackConfigs);
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createCompiler = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const dev_server_1 = __importDefault(require("./dev-server"));
|
|
9
10
|
const projectConfig_1 = require("../../utils/projectConfig");
|
|
10
11
|
const common_1 = require("../../utils/common");
|
|
11
12
|
const types_1 = require("../../types");
|
|
@@ -90,9 +91,9 @@ const createCompiler = (startConfig) => {
|
|
|
90
91
|
// cli的node_modules路径
|
|
91
92
|
(_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../../'));
|
|
92
93
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
if (action === 'dev' && enableDevServer) {
|
|
95
|
+
return (0, dev_server_1.default)(compilerOptions);
|
|
96
|
+
}
|
|
96
97
|
return new webpack_1.WebPack(webpackConfig, compilerOptions);
|
|
97
98
|
};
|
|
98
99
|
exports.createCompiler = createCompiler;
|
|
@@ -10,7 +10,7 @@ export declare class WebPack extends AbstractMPPack {
|
|
|
10
10
|
packSetting: MPPackSetting;
|
|
11
11
|
hadWatch: boolean;
|
|
12
12
|
constructor(configs: any, options: IPresetOptions);
|
|
13
|
-
handleProgress: (
|
|
13
|
+
handleProgress: (progress: any) => void;
|
|
14
14
|
get hooks(): any;
|
|
15
15
|
watch(config: any, callback?: any): Promise<unknown>;
|
|
16
16
|
changeCompileOptions(config: any): void;
|
|
@@ -25,12 +25,8 @@ class WebPack extends xhs_mp_pack_1.AbstractMPPack {
|
|
|
25
25
|
this.compiler = null;
|
|
26
26
|
this.watcher = null;
|
|
27
27
|
this.hadWatch = false;
|
|
28
|
-
this.handleProgress =
|
|
29
|
-
this.emit('progress',
|
|
30
|
-
percentage,
|
|
31
|
-
status,
|
|
32
|
-
info
|
|
33
|
-
});
|
|
28
|
+
this.handleProgress = progress => {
|
|
29
|
+
this.emit('progress', progress);
|
|
34
30
|
};
|
|
35
31
|
this.project = options.project;
|
|
36
32
|
this.packSetting = options.packSetting;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Config } from '../../../../packs';
|
|
2
2
|
import { IPresetOptions } from '../../../../types';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
declare const getRenderEntry: (options: IPresetOptions) => () => {};
|
|
4
|
+
declare const presetRender: (chain: Config, options: IPresetOptions) => void;
|
|
5
|
+
export { getRenderEntry, presetRender };
|
|
@@ -13,8 +13,8 @@ const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
|
|
|
13
13
|
const types_1 = require("../../../../types");
|
|
14
14
|
const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
|
|
15
15
|
const getRenderEntry = (options) => () => {
|
|
16
|
-
const
|
|
17
|
-
return
|
|
16
|
+
const res = Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options));
|
|
17
|
+
return res;
|
|
18
18
|
};
|
|
19
19
|
exports.getRenderEntry = getRenderEntry;
|
|
20
20
|
const presetRender = (chain, options) => {
|
|
@@ -33,6 +33,7 @@ const tagTransformMap = {
|
|
|
33
33
|
editor: 'xhs-vue-editor',
|
|
34
34
|
'movable-area': 'xhs-vue-movable-area',
|
|
35
35
|
'movable-view': 'xhs-vue-movable-view',
|
|
36
|
-
canvas: 'xhs-vue-canvas'
|
|
36
|
+
canvas: 'xhs-vue-canvas',
|
|
37
|
+
camera: 'xhs-vue-camera',
|
|
37
38
|
};
|
|
38
39
|
exports.default = tagTransformMap;
|