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.
Files changed (46) hide show
  1. package/dist/compiler.d.ts +13 -15
  2. package/dist/compiler.js +40 -96
  3. package/dist/{compilerImpl.js → compilerCP.js} +42 -29
  4. package/dist/index.d.ts +4 -3
  5. package/dist/index.js +5 -5
  6. package/dist/packs/mp-pack/index.js +1 -0
  7. package/dist/packs/webpack/dev-server/index.js +0 -1
  8. package/dist/packs/webpack/index.d.ts +1 -1
  9. package/dist/packs/webpack/index.js +4 -3
  10. package/dist/packs/webpack/webpack.d.ts +1 -1
  11. package/dist/packs/webpack/webpack.js +2 -6
  12. package/dist/presets/configs/miniprogram/render/index.d.ts +3 -2
  13. package/dist/presets/configs/miniprogram/render/index.js +2 -2
  14. package/dist/presets/configs/miniprogram/service/index.js +0 -1
  15. package/dist/utils/tagTransformMap.d.ts +1 -0
  16. package/dist/utils/tagTransformMap.js +2 -1
  17. package/package.json +12 -26
  18. package/dist/compilerImpl.d.ts +0 -1
  19. package/dist/compilerImplChildProcess.js +0 -33
  20. package/dist/compilerImplThreadWorker.d.ts +0 -1
  21. package/dist/compilerImplThreadWorker.js +0 -30
  22. package/dist/compilerImplWebWorker.d.ts +0 -6
  23. package/dist/compilerImplWebWorker.js +0 -25
  24. package/dist/dev-server/compatibleAPI.d.ts +0 -25
  25. package/dist/dev-server/compatibleAPI.js +0 -56
  26. package/dist/dev-server/escapeHtml.d.ts +0 -5
  27. package/dist/dev-server/escapeHtml.js +0 -50
  28. package/dist/dev-server/etag.d.ts +0 -10
  29. package/dist/dev-server/etag.js +0 -69
  30. package/dist/dev-server/getFilenameFromUrl.d.ts +0 -9
  31. package/dist/dev-server/getFilenameFromUrl.js +0 -102
  32. package/dist/dev-server/getPaths.d.ts +0 -6
  33. package/dist/dev-server/getPaths.js +0 -20
  34. package/dist/dev-server/index.d.ts +0 -98
  35. package/dist/dev-server/index.js +0 -90
  36. package/dist/dev-server/memorize.d.ts +0 -7
  37. package/dist/dev-server/memorize.js +0 -23
  38. package/dist/dev-server/middleware.d.ts +0 -2
  39. package/dist/dev-server/middleware.js +0 -477
  40. package/dist/dev-server/ready.d.ts +0 -4
  41. package/dist/dev-server/ready.js +0 -11
  42. package/dist/sharedFs.d.ts +0 -2
  43. package/dist/sharedFs.js +0 -4
  44. package/dist/utils/workerPool.d.ts +0 -29
  45. package/dist/utils/workerPool.js +0 -115
  46. /package/dist/{compilerImplChildProcess.d.ts → compilerCP.d.ts} +0 -0
@@ -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
- export declare abstract class AbstractCompiler extends EventEmitter {
34
+ declare abstract class AbstractCompiler extends EventEmitter {
33
35
  protected inspectPort: any;
34
- private _impl;
35
- protected _implType: 'thread_worker' | 'web_worker' | 'cp';
36
+ private _cp;
36
37
  private compilerOpts;
37
- private implArgs;
38
+ private cpArgs;
38
39
  private logger;
39
40
  private _handlerMap;
40
41
  constructor(opts: ICompilerOption, args?: ICompilerArgs);
41
- get impl(): any;
42
- protected createImpl: (passData?: {}) => any;
43
- protected createCP: (passData?: {}) => ChildProcess;
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
- export declare class MPPackDevCompiler extends AbstractCompiler {
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
- export declare class WebPackDevCompiler extends AbstractCompiler {
65
+ declare class WebPackDevCompiler extends AbstractCompiler {
68
66
  private watching;
69
67
  private pendingTask?;
70
- constructor(props: any, args: any);
68
+ constructor(props: any);
71
69
  makePkgsReady(opts: any): Promise<unknown>;
72
70
  reCompilePkgs(opts: any): Promise<void>;
73
71
  }
74
- export declare class BuildCompiler extends AbstractCompiler {
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 getProjectCompilerClass(compilerType: any): typeof MPPackDevCompiler | typeof WebPackDevCompiler | typeof BuildCompiler;
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.getProjectCompilerClass = exports.BuildCompiler = exports.WebPackDevCompiler = exports.MPPackDevCompiler = exports.AbstractCompiler = void 0;
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.createImpl = (passData = {}) => {
33
- if (!this._impl) {
34
- if (this._implType === 'thread_worker') {
35
- this._impl = this.createThreadWorker(passData);
36
- this._impl.on('exit', code => {
37
- this._impl = null;
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._impl;
38
+ return this._cp;
58
39
  };
59
- this.createCP = (passData = {}) => {
40
+ this.create = (passData = {}) => {
60
41
  var _a, _b;
61
- const { type = 'keepalive', inspectPort = this.inspectPort, maxSpaceSaze = 12288, nodeJsPath } = this.implArgs;
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, './compilerImplChildProcess.js');
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('impl error:', err);
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('impl exit:', code);
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
- // console.log(`[debugger]:`, ...(data.data || []))
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.postMessage(JSON.stringify(final));
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.postMessage(JSON.stringify(final));
134
+ this.cp.send(JSON.stringify(final));
172
135
  };
173
136
  this.compilerOpts = opts;
174
- this.implArgs = args;
137
+ this.cpArgs = args;
175
138
  this.logger = args.logger || console;
176
139
  }
177
- get impl() {
178
- return this.createImpl();
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._impl) {
190
- this.postMessage(JSON.stringify({ method: 'close' }));
144
+ if (this._cp) {
145
+ this._cp.send(JSON.stringify({ method: 'close' }));
191
146
  }
192
147
  }
193
148
  kill() {
194
- if (this._impl) {
195
- if (this._implType === 'cp') {
196
- this._impl.kill();
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.createImpl();
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, args) {
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.createImpl();
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.createImpl();
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
- exports.BuildCompiler = BuildCompiler;
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.getProjectCompilerClass = getProjectCompilerClass;
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
- let sendToMaster;
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 formatOutputMessages(err, stats) {
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: formatOutputMessages(err, 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: formatOutputMessages(err, 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: formatOutputMessages(err, 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', (data) => {
102
- sendToMaster('compilePercent', data);
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 = formatOutputMessages(err, stats);
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
- function runCompilerImpl(initData, onMessage, _sendToMaster) {
144
- globalConfig = initData;
145
- sendToMaster = _sendToMaster;
146
- const handleMessage = objData => {
147
- objData = typeof objData === 'string' ? JSON.parse(objData) : objData;
148
- const { passData, uuid, method, data = {} } = objData;
149
- // 初始化数据
150
- if (passData) {
151
- globalConfig = passData;
152
- return;
153
- }
154
- // call handler
155
- if (!handlers[method]) {
156
- return;
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
- handlers[method](objData);
159
- };
160
- onMessage(handleMessage);
161
- }
162
- exports.runCompilerImpl = runCompilerImpl;
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 { getProjectCompilerClass } from './compiler';
7
+ import { getProcessCompilerClass } from './compiler';
7
8
  interface ILibFeatures {
8
9
  supportV2?: boolean;
9
10
  supportVdom?: boolean;
10
11
  }
11
- export { COMPILE_ENTRY, getProjectCompilerClass, };
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 ProjectCompiler extends EventEmitter {
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.ProjectCompiler = exports.getProjectCompilerClass = exports.COMPILE_ENTRY = void 0;
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, "getProjectCompilerClass", { enumerable: true, get: function () { return compiler_1.getProjectCompilerClass; } });
28
- class ProjectCompiler extends events_1.default {
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.getProjectCompilerClass)(compilerType);
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.ProjectCompiler = ProjectCompiler;
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);
@@ -1,3 +1,3 @@
1
1
  import { IStart } from '../../types';
2
2
  import { WebPack } from './webpack';
3
- export declare const createCompiler: (startConfig: IStart) => WebPack;
3
+ export declare const createCompiler: (startConfig: IStart) => Promise<void> | WebPack;
@@ -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
- // if (action === 'dev' && enableDevServer) {
94
- // return webpackDevServer(compilerOptions)
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: (percentage: any, status: any, info: any) => void;
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 = (percentage, status, info) => {
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
- export declare const getRenderEntry: (options: IPresetOptions) => () => {};
4
- export declare const presetRender: (chain: Config, options: IPresetOptions) => void;
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 entries = Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options));
17
- return entries;
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) => {
@@ -43,7 +43,6 @@ const presetService = (chain, options) => {
43
43
  const { packSetting } = options;
44
44
  const { env, distDir, cacheDirectory } = packSetting;
45
45
  chain.merge({
46
- // target: 'webworker',
47
46
  output: {
48
47
  path: distDir,
49
48
  globalObject: 'globalThis',
@@ -31,5 +31,6 @@ declare const tagTransformMap: {
31
31
  'movable-area': string;
32
32
  'movable-view': string;
33
33
  canvas: string;
34
+ camera: string;
34
35
  };
35
36
  export default tagTransformMap;
@@ -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;