xhs-mp-compiler-cli 1.1.2 → 1.1.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 (118) hide show
  1. package/package.json +2 -2
  2. package/dist/bin/xhs-mp-cli-build.d.ts +0 -2
  3. package/dist/bin/xhs-mp-cli-build.js +0 -40
  4. package/dist/bin/xhs-mp-cli-dev.d.ts +0 -2
  5. package/dist/bin/xhs-mp-cli-dev.js +0 -59
  6. package/dist/bin/xhs-mp-cli.d.ts +0 -2
  7. package/dist/bin/xhs-mp-cli.js +0 -16
  8. package/dist/compiler.d.ts +0 -76
  9. package/dist/compiler.js +0 -361
  10. package/dist/compilerCP.d.ts +0 -1
  11. package/dist/compilerCP.js +0 -175
  12. package/dist/config/constant.config.d.ts +0 -27
  13. package/dist/config/constant.config.js +0 -30
  14. package/dist/config/dir.config.d.ts +0 -3
  15. package/dist/config/dir.config.js +0 -16
  16. package/dist/index.d.ts +0 -84
  17. package/dist/index.js +0 -454
  18. package/dist/packs/index.d.ts +0 -14
  19. package/dist/packs/index.js +0 -31
  20. package/dist/packs/mp-pack/index.d.ts +0 -3
  21. package/dist/packs/mp-pack/index.js +0 -32
  22. package/dist/packs/webpack/dev-server/index.d.ts +0 -3
  23. package/dist/packs/webpack/dev-server/index.js +0 -64
  24. package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +0 -2
  25. package/dist/packs/webpack/dev-server/lib/ensurePort.js +0 -32
  26. package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +0 -2
  27. package/dist/packs/webpack/dev-server/lib/openBrowser.js +0 -23
  28. package/dist/packs/webpack/dev-server/lib/openChrome.applescript +0 -78
  29. package/dist/packs/webpack/index.d.ts +0 -3
  30. package/dist/packs/webpack/index.js +0 -92
  31. package/dist/packs/webpack/webpack.d.ts +0 -21
  32. package/dist/packs/webpack/webpack.js +0 -79
  33. package/dist/presets/babel.d.ts +0 -8
  34. package/dist/presets/babel.js +0 -59
  35. package/dist/presets/common.d.ts +0 -4
  36. package/dist/presets/common.js +0 -48
  37. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +0 -10
  38. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +0 -46
  39. package/dist/presets/configs/minigame/assets/index.d.ts +0 -3
  40. package/dist/presets/configs/minigame/assets/index.js +0 -65
  41. package/dist/presets/configs/minigame/service/index.d.ts +0 -3
  42. package/dist/presets/configs/minigame/service/index.js +0 -34
  43. package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +0 -8
  44. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +0 -35
  45. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +0 -9
  46. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +0 -69
  47. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +0 -10
  48. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +0 -32
  49. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +0 -12
  50. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +0 -132
  51. package/dist/presets/configs/miniprogram/assets/index.d.ts +0 -4
  52. package/dist/presets/configs/miniprogram/assets/index.js +0 -47
  53. package/dist/presets/configs/miniprogram/render/component.d.ts +0 -3
  54. package/dist/presets/configs/miniprogram/render/component.js +0 -47
  55. package/dist/presets/configs/miniprogram/render/index.d.ts +0 -5
  56. package/dist/presets/configs/miniprogram/render/index.js +0 -71
  57. package/dist/presets/configs/miniprogram/render/render.d.ts +0 -3
  58. package/dist/presets/configs/miniprogram/render/render.js +0 -49
  59. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +0 -8
  60. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +0 -55
  61. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +0 -15
  62. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +0 -163
  63. package/dist/presets/configs/miniprogram/service/index.d.ts +0 -5
  64. package/dist/presets/configs/miniprogram/service/index.js +0 -72
  65. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +0 -8
  66. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +0 -66
  67. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +0 -9
  68. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +0 -65
  69. package/dist/presets/index.d.ts +0 -2
  70. package/dist/presets/index.js +0 -95
  71. package/dist/presets/loaders/mg-entry-loader.d.ts +0 -1
  72. package/dist/presets/loaders/mg-entry-loader.js +0 -27
  73. package/dist/presets/loaders/mini-style-loader.d.ts +0 -1
  74. package/dist/presets/loaders/mini-style-loader.js +0 -72
  75. package/dist/presets/loaders/mp-entry-loader.d.ts +0 -1
  76. package/dist/presets/loaders/mp-entry-loader.js +0 -196
  77. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  78. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  79. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  80. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  81. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  82. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  83. package/dist/presets/loaders/wxss-loader.d.ts +0 -1
  84. package/dist/presets/loaders/wxss-loader.js +0 -77
  85. package/dist/presets/plugins/InjectorPlugin.d.ts +0 -7
  86. package/dist/presets/plugins/InjectorPlugin.js +0 -14
  87. package/dist/presets/prod.d.ts +0 -4
  88. package/dist/presets/prod.js +0 -80
  89. package/dist/types/index.d.ts +0 -118
  90. package/dist/types/index.js +0 -13
  91. package/dist/utils/asyncWebpack.d.ts +0 -3
  92. package/dist/utils/asyncWebpack.js +0 -38
  93. package/dist/utils/common.d.ts +0 -8
  94. package/dist/utils/common.js +0 -36
  95. package/dist/utils/const.d.ts +0 -27
  96. package/dist/utils/const.js +0 -47
  97. package/dist/utils/css.d.ts +0 -2
  98. package/dist/utils/css.js +0 -41
  99. package/dist/utils/depenedHelper.d.ts +0 -31
  100. package/dist/utils/depenedHelper.js +0 -89
  101. package/dist/utils/file.d.ts +0 -2
  102. package/dist/utils/file.js +0 -67
  103. package/dist/utils/getSuffixName.d.ts +0 -3
  104. package/dist/utils/getSuffixName.js +0 -18
  105. package/dist/utils/loader-utils.d.ts +0 -15
  106. package/dist/utils/loader-utils.js +0 -59
  107. package/dist/utils/postcssRpx2Vw.d.ts +0 -12
  108. package/dist/utils/postcssRpx2Vw.js +0 -35
  109. package/dist/utils/project.d.ts +0 -27
  110. package/dist/utils/project.js +0 -164
  111. package/dist/utils/projectConfig.d.ts +0 -1
  112. package/dist/utils/projectConfig.js +0 -20
  113. package/dist/utils/tagTransformMap.d.ts +0 -35
  114. package/dist/utils/tagTransformMap.js +0 -38
  115. package/dist/utils/utils.d.ts +0 -7
  116. package/dist/utils/utils.js +0 -50
  117. package/dist/utils/zip.d.ts +0 -28
  118. package/dist/utils/zip.js +0 -287
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -82,7 +82,7 @@
82
82
  "webpack-bundle-analyzer": "^4.4.0",
83
83
  "webpack-chain": "^6.5.1",
84
84
  "webpack-sources": "^3.2.2",
85
- "xhs-mp-compiler-ml-loader": "1.1.1",
85
+ "xhs-mp-compiler-ml-loader": "1.1.2",
86
86
  "xhs-mp-compiler-utils": "1.1.1",
87
87
  "xhs-mp-pack": "^1.1.1",
88
88
  "xhs-mp-project": "^1.1.1",
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const path_1 = __importDefault(require("path"));
9
- const packs_1 = require("../packs");
10
- const commander = new commander_1.Command();
11
- commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
12
- commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
13
- commander.usage('[options]').option('-l, --lite <string>', '轻量编译器');
14
- commander.usage('[options]').option('-c, --compressJs <boolean>', 'compressJs');
15
- commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
16
- commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
17
- commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
18
- commander.parse(process.argv);
19
- const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
20
- const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
21
- const enableV1 = commander.opts().enableV1 === "true";
22
- const enableV2 = commander.opts().enableV2 === "true";
23
- const enableVDom = commander.opts().enableVDom === "true";
24
- const compressJs = commander.opts().compressJs === "true";
25
- const multiCompiler = (0, packs_1.createCompiler)({
26
- projectPath,
27
- action: 'build',
28
- platform,
29
- compressJs,
30
- enableSourcemap: false,
31
- enableV1,
32
- enableV2,
33
- enableVDom,
34
- });
35
- multiCompiler.run((err, stats) => {
36
- console.log(stats.toString({ warnings: true, errors: true, all: false }));
37
- multiCompiler.close(() => {
38
- // noop
39
- });
40
- });
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const path_1 = __importDefault(require("path"));
9
- const packs_1 = require("../packs");
10
- const commander = new commander_1.Command();
11
- commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
12
- commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
13
- commander.usage('[options]').option('-P, --port <string>', 'set dev server port [default: 1388]');
14
- commander.usage('[options]').option('-l, --lite <string>', 'lite compiler');
15
- commander.usage('[options]').option('-o, --out <string>', '是否输出内容');
16
- commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
17
- commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
18
- commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
19
- commander.parse(process.argv);
20
- const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
21
- const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
22
- const devServerPort = commander.opts().port ? commander.opts().port : 1388;
23
- const out = commander.opts().out === "true";
24
- const enableV1 = commander.opts().enableV1 === "true";
25
- const enableV2 = commander.opts().enableV2 === "true";
26
- const enableVDom = commander.opts().enableVDom === "true";
27
- process.env.PRETTIER_XHSML = "true";
28
- if (out) {
29
- const multiCompiler = (0, packs_1.createCompiler)({
30
- projectPath,
31
- action: 'dev',
32
- platform,
33
- compressJs: false,
34
- enableSourcemap: false,
35
- enableV1,
36
- enableV2,
37
- enableVDom,
38
- });
39
- multiCompiler.run((err, stats) => {
40
- console.log(stats.toString({ warnings: true, errors: true, all: false }));
41
- multiCompiler.close(() => {
42
- // noop
43
- });
44
- });
45
- }
46
- else {
47
- (0, packs_1.createCompiler)({
48
- projectPath,
49
- action: 'dev',
50
- enableDevServer: true,
51
- platform,
52
- compressJs: false,
53
- devServerPort,
54
- enableSourcemap: true,
55
- enableV1,
56
- enableV2,
57
- enableVDom,
58
- });
59
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- // @ts-ignore
9
- const package_json_1 = __importDefault(require("../../package.json"));
10
- const commander = new commander_1.Command();
11
- commander
12
- .version(package_json_1.default.version)
13
- .usage('<command> [options]')
14
- .command('dev', '启动开发服务')
15
- .command('build', '打包小程序')
16
- .parse(process.argv);
@@ -1,76 +0,0 @@
1
- /// <reference types="node/child_process" />
2
- /// <reference types="node/stream" />
3
- /**
4
- * 在子进程执行编译
5
- */
6
- import { ChildProcess } from 'child_process';
7
- import { EventEmitter } from 'stream';
8
- type Platform = 'wx' | 'xhs';
9
- export interface ICompilerOption {
10
- projectPath: string;
11
- appMode: string;
12
- }
13
- export interface ICompilerArgs {
14
- logger?: any;
15
- type?: string;
16
- inspectPort?: number;
17
- maxSpaceSaze?: number;
18
- nodeJsPath?: string;
19
- }
20
- export interface ForkWebpackOption {
21
- platform: Platform;
22
- extJsonPath: string;
23
- distDir: string;
24
- cacheDirectory: string | null;
25
- }
26
- export interface ICheckOptions {
27
- compilePkgs?: string[];
28
- compressJs: boolean;
29
- enableV2?: boolean;
30
- enableV1?: boolean;
31
- }
32
- declare abstract class AbstractCompiler extends EventEmitter {
33
- protected inspectPort: any;
34
- private _cp;
35
- private compilerOpts;
36
- private cpArgs;
37
- private logger;
38
- private _handlerMap;
39
- constructor(opts: ICompilerOption, args?: ICompilerArgs);
40
- get cp(): any;
41
- protected createSp: (passData?: {}) => any;
42
- protected create: (passData?: {}) => ChildProcess;
43
- close(): void;
44
- kill(): void;
45
- private handleMessage;
46
- call: (method: any, data: any) => Promise<unknown>;
47
- send: (method: any, data: any) => void;
48
- }
49
- declare class MPPackDevCompiler extends AbstractCompiler {
50
- private pending;
51
- private pendingPkgs;
52
- private readyPkgs;
53
- private watching;
54
- constructor(props: any, args: any);
55
- reset(): void;
56
- doCompilePkgs(opts: ICheckOptions): Promise<unknown>;
57
- private compilePkgsAndWatch;
58
- private addPkgsToWatch;
59
- changeCompileOptions(options: any): void;
60
- makePkgsReady(opts: ICheckOptions): Promise<void>;
61
- reCompilePkgs(options: any): Promise<void>;
62
- }
63
- declare class WebPackDevCompiler extends AbstractCompiler {
64
- private watching;
65
- private pendingTask?;
66
- constructor(props: any);
67
- makePkgsReady(opts: any): Promise<unknown>;
68
- reCompilePkgs(opts: any): Promise<void>;
69
- }
70
- declare class BuildCompiler extends AbstractCompiler {
71
- cps: any;
72
- constructor(props: any, args: any);
73
- build(option: ICheckOptions): Promise<unknown>;
74
- }
75
- export declare function getProcessCompilerClass(compilerType: any): typeof MPPackDevCompiler | typeof WebPackDevCompiler | typeof BuildCompiler;
76
- export {};
package/dist/compiler.js DELETED
@@ -1,361 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getProcessCompilerClass = void 0;
16
- /**
17
- * 在子进程执行编译
18
- */
19
- const child_process_1 = require("child_process");
20
- const path_1 = require("path");
21
- const stream_1 = require("stream");
22
- const fs_extra_1 = __importDefault(require("fs-extra"));
23
- const constant_config_1 = require("./config/constant.config");
24
- const uuid = require('uuid');
25
- const isMac = process.platform === 'darwin';
26
- class AbstractCompiler extends stream_1.EventEmitter {
27
- constructor(opts, args = {}) {
28
- super();
29
- this._handlerMap = {};
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);
37
- }
38
- return this._cp;
39
- };
40
- this.create = (passData = {}) => {
41
- var _a, _b;
42
- const { type = 'keepalive', inspectPort = this.inspectPort, maxSpaceSaze = 12288, nodeJsPath, } = this.cpArgs;
43
- // const presistent = type === 'keepalive'
44
- const entry = (0, path_1.join)(__dirname, './compilerCP.js');
45
- const execArgv = [`--max-old-space-size=${maxSpaceSaze}`, '--expose-gc'];
46
- const customNodeJs = nodeJsPath && fs_extra_1.default.existsSync(nodeJsPath);
47
- if (process.env.DEV_IDE_SP) {
48
- execArgv.push(`--inspect=${inspectPort}`);
49
- }
50
- if (customNodeJs) {
51
- try {
52
- fs_extra_1.default.chmodSync(nodeJsPath, 755);
53
- }
54
- catch (error) {
55
- // do something
56
- }
57
- }
58
- const options = {
59
- stdio: 'pipe',
60
- execArgv,
61
- // detached: presistent,
62
- windowsHide: true,
63
- };
64
- if (customNodeJs) {
65
- options.execPath = nodeJsPath;
66
- }
67
- const child = (0, child_process_1.fork)(entry, [JSON.stringify(passData)], options);
68
- // if (presistent) {
69
- // child.unref()
70
- // }
71
- (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', msg => {
72
- this.logger.debug('[compiler stdout]', msg.toString());
73
- });
74
- (_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', msg => {
75
- this.logger.error('[compiler stderr]', msg.toString());
76
- });
77
- child.on('error', err => {
78
- this.logger.error('sp error:', err);
79
- });
80
- child.on('exit', code => {
81
- if (code !== 0 && code !== null) {
82
- this.logger.error('sp exit:', code);
83
- this.emit('unexpectedExit', code);
84
- }
85
- });
86
- return child;
87
- };
88
- this.handleMessage = msg => {
89
- var _a, _b, _c, _d;
90
- let data = {};
91
- try {
92
- data = JSON.parse(`${msg}`);
93
- }
94
- catch (error) {
95
- // do something
96
- }
97
- const { uuid, method, success, stats } = data;
98
- if (method === 'callback') {
99
- if (uuid && this._handlerMap[uuid]) {
100
- if (success) {
101
- (_b = (_a = this._handlerMap[uuid]).resolve) === null || _b === void 0 ? void 0 : _b.call(_a, data.data);
102
- }
103
- else {
104
- (_d = (_c = this._handlerMap[uuid]).reject) === null || _d === void 0 ? void 0 : _d.call(_c, stats);
105
- }
106
- delete this._handlerMap[uuid];
107
- }
108
- return;
109
- }
110
- this.emit(method, data);
111
- };
112
- this.call = (method, data) => new Promise((resolve, reject) => {
113
- const id = uuid.v4();
114
- const final = {
115
- uuid: id,
116
- method,
117
- data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
118
- };
119
- this._handlerMap[id] = {
120
- resolve,
121
- reject,
122
- };
123
- this.cp.send(JSON.stringify(final));
124
- });
125
- this.send = (method, data) => {
126
- const final = {
127
- method,
128
- data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
129
- };
130
- this.cp.send(JSON.stringify(final));
131
- };
132
- this.compilerOpts = opts;
133
- this.cpArgs = args;
134
- this.logger = args.logger || console;
135
- }
136
- get cp() {
137
- return this.createSp();
138
- }
139
- close() {
140
- if (this._cp) {
141
- this._cp.send(JSON.stringify({ method: 'close' }));
142
- }
143
- }
144
- kill() {
145
- if (this._cp) {
146
- this._cp.kill();
147
- this._cp = null;
148
- }
149
- }
150
- }
151
- class MPPackDevCompiler extends AbstractCompiler {
152
- constructor(props, args) {
153
- super(props, args);
154
- this.pending = false;
155
- this.pendingPkgs = {};
156
- this.readyPkgs = [];
157
- this.watching = false;
158
- this.inspectPort = 9227;
159
- this.createSp();
160
- }
161
- reset() {
162
- this.pendingPkgs = {};
163
- this.readyPkgs = [];
164
- this.watching = false;
165
- this.pending = false;
166
- }
167
- doCompilePkgs(opts) {
168
- // eslint-disable-next-line no-async-promise-executor
169
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
170
- const { compilePkgs = [constant_config_1.MAIN_PKG_ROOT] } = opts;
171
- const todoPkgs = [];
172
- let allReady = true;
173
- compilePkgs.forEach(pkg => {
174
- var _a, _b;
175
- if (this.readyPkgs.includes(pkg)) {
176
- return;
177
- }
178
- allReady = false;
179
- if (this.pendingPkgs[pkg]) {
180
- (_a = this.pendingPkgs[pkg].resolve) === null || _a === void 0 ? void 0 : _a.push(resolve);
181
- (_b = this.pendingPkgs[pkg].reject) === null || _b === void 0 ? void 0 : _b.push(reject);
182
- return;
183
- }
184
- this.pendingPkgs[pkg] = {
185
- resolve: [resolve],
186
- reject: [reject],
187
- };
188
- todoPkgs.push(pkg);
189
- });
190
- if (allReady) {
191
- return resolve(null);
192
- }
193
- if (!todoPkgs.length) {
194
- return;
195
- }
196
- try {
197
- if (!this.pending && !this.watching) {
198
- yield this.compilePkgsAndWatch(Object.assign({ compilePkgs: todoPkgs }, opts));
199
- }
200
- else {
201
- yield this.addPkgsToWatch(Object.assign({ compilePkgs }, opts));
202
- }
203
- todoPkgs.forEach(pkg => {
204
- var _a, _b;
205
- (_b = (_a = this.pendingPkgs[pkg].resolve) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn());
206
- delete this.pendingPkgs[pkg];
207
- this.readyPkgs.push(pkg);
208
- });
209
- }
210
- catch (error) {
211
- todoPkgs.forEach(pkg => {
212
- var _a, _b;
213
- (_b = (_a = this.pendingPkgs[pkg].reject) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn());
214
- delete this.pendingPkgs[pkg];
215
- });
216
- }
217
- }));
218
- }
219
- compilePkgsAndWatch(opts) {
220
- return __awaiter(this, void 0, void 0, function* () {
221
- try {
222
- // if (this.pending || this.watching) {
223
- // return
224
- // }
225
- this.pending = true;
226
- this.emit('buildStart');
227
- yield this.call('runTask', Object.assign({ scene: 'watch', action: 'dev' }, opts));
228
- this.watching = true;
229
- this.emit('buildSuccess');
230
- }
231
- catch (error) {
232
- this.watching = false;
233
- this.emit('buildError', error);
234
- }
235
- finally {
236
- this.pending = false;
237
- }
238
- });
239
- }
240
- addPkgsToWatch(opts) {
241
- return __awaiter(this, void 0, void 0, function* () {
242
- const { compilePkgs = [] } = opts;
243
- try {
244
- this.pending = true;
245
- this.emit('buildStart');
246
- yield this.call('activatePkgs', { compilePkgs });
247
- this.emit('buildSuccess');
248
- }
249
- catch (error) {
250
- this.emit('buildError', error);
251
- }
252
- finally {
253
- this.pending = false;
254
- }
255
- });
256
- }
257
- changeCompileOptions(options) {
258
- this.call('changeCompileOptions', options);
259
- }
260
- makePkgsReady(opts) {
261
- return __awaiter(this, void 0, void 0, function* () {
262
- yield this.doCompilePkgs(opts);
263
- });
264
- }
265
- reCompilePkgs(options) {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- this.readyPkgs = [];
268
- this.changeCompileOptions(options);
269
- if (!this.pending && !this.watching) {
270
- this.pendingPkgs = {};
271
- }
272
- yield this.doCompilePkgs(options);
273
- });
274
- }
275
- }
276
- class WebPackDevCompiler extends AbstractCompiler {
277
- constructor(props) {
278
- super(props);
279
- this.watching = false;
280
- this.inspectPort = 9230;
281
- this.createSp();
282
- }
283
- makePkgsReady(opts) {
284
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
285
- var _a, _b, _c, _d;
286
- if (this.watching) {
287
- return resolve(null);
288
- }
289
- if (this.pendingTask) {
290
- (_a = this.pendingTask.resolve) === null || _a === void 0 ? void 0 : _a.push(resolve);
291
- (_b = this.pendingTask.reject) === null || _b === void 0 ? void 0 : _b.push(reject);
292
- return;
293
- }
294
- this.pendingTask = {
295
- resolve: [resolve],
296
- reject: [reject]
297
- };
298
- try {
299
- this.emit('buildStart');
300
- yield this.call('runTask', Object.assign({ scene: 'watch', action: 'dev' }, opts));
301
- this.watching = true;
302
- (_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach((fn) => fn());
303
- this.emit('buildSuccess');
304
- }
305
- catch (error) {
306
- this.watching = false;
307
- (_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach((fn) => fn());
308
- this.kill();
309
- this.emit('buildError', error);
310
- }
311
- finally {
312
- this.pendingTask = undefined;
313
- }
314
- }));
315
- }
316
- reCompilePkgs(opts) {
317
- return __awaiter(this, void 0, void 0, function* () {
318
- if (!this.watching) {
319
- yield this.makePkgsReady(opts);
320
- return;
321
- }
322
- try {
323
- this.emit('buildStart');
324
- yield this.call('runTask', Object.assign({ action: 'dev', scene: 'reWatch' }, opts));
325
- this.emit('buildSuccess');
326
- }
327
- catch (error) {
328
- this.emit('buildError', error);
329
- }
330
- });
331
- }
332
- }
333
- class BuildCompiler extends AbstractCompiler {
334
- constructor(props, args) {
335
- super(props, args);
336
- this.cps = [];
337
- this.inspectPort = 9228;
338
- this.createSp();
339
- }
340
- build(option) {
341
- return __awaiter(this, void 0, void 0, function* () {
342
- try {
343
- const res = yield this.call('runTask', Object.assign({ action: 'build' }, option));
344
- return res;
345
- }
346
- finally {
347
- // 进程不退出,手动kill下
348
- this.kill();
349
- }
350
- });
351
- }
352
- }
353
- function getProcessCompilerClass(compilerType) {
354
- const CompilerClass = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev
355
- ? WebPackDevCompiler
356
- : compilerType === constant_config_1.COMPILER_TYPE.dev
357
- ? MPPackDevCompiler
358
- : BuildCompiler;
359
- return CompilerClass;
360
- }
361
- exports.getProcessCompilerClass = getProcessCompilerClass;
@@ -1 +0,0 @@
1
- export {};