xhs-mp-compiler-cli 2.0.30 → 2.0.31-beta.1

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.
@@ -87,6 +87,7 @@ export declare class ProjectCompilerManager extends EventEmitter {
87
87
  reCompilePkgs(opts: ICompilePkgsConfig): Promise<void>;
88
88
  compileProject(config: ICompileProjectConfig): Promise<void>;
89
89
  compileAndZip(opts: ICompileAndZipOptions): Promise<IZipResult[]>;
90
+ checkMiniWidgetSize(zipResult: IZipResult[], resolve: any, reject: any): any;
90
91
  closeCompiler(entryType?: string): void;
91
92
  killCompiler(entryType?: string): void;
92
93
  killAll(): void;
@@ -16,7 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  if (v !== undefined) module.exports = v;
17
17
  }
18
18
  else if (typeof define === "function" && define.amd) {
19
- define(["require", "exports", "./config/constant.config", "xhs-mp-project", "events", "fs-extra", "path", "./utils/utils", "./utils/project", "./config/dir.config", "./compiler", "./sharedFs"], factory);
19
+ define(["require", "exports", "./config/constant.config", "xhs-mp-project", "events", "fs-extra", "path", "./utils/utils", "./utils/project", "./utils/file", "./config/dir.config", "./compiler", "./sharedFs"], factory);
20
20
  }
21
21
  })(function (require, exports) {
22
22
  "use strict";
@@ -30,6 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const utils_1 = require("./utils/utils");
32
32
  const project_1 = require("./utils/project");
33
+ const file_1 = require("./utils/file");
33
34
  const dir_config_1 = require("./config/dir.config");
34
35
  const compiler_1 = require("./compiler");
35
36
  Object.defineProperty(exports, "prepareDevPool", { enumerable: true, get: function () { return compiler_1.prepareDevPool; } });
@@ -337,11 +338,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
337
338
  const appJsonContent = this.project.appJsonContent;
338
339
  const settings = this.project.settings || {};
339
340
  let subPackages = appJsonContent.subPackages || appJsonContent.subpackages || [];
340
- const formatGameAppJSON = this.project.formatGameAppJSON;
341
- subPackages =
342
- this.project.appMode === constant_config_1.MiniMode.miniprogram
343
- ? subPackages
344
- : formatGameAppJSON(subPackages);
341
+ if (this.project.appMode === constant_config_1.MiniMode.minigame) {
342
+ subPackages = this.project.formatGameAppJSON(subPackages);
343
+ }
345
344
  const { enableV1, enableV2, enableVDom } = yield this.getUsingPackageType(entryType);
346
345
  let compressJs = false;
347
346
  let compressCss = false;
@@ -372,7 +371,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
372
371
  runInServiceSandbox,
373
372
  enableV1,
374
373
  enableV2,
375
- enableVDom, mpUploadOptions: this.project.appMode === constant_config_1.MiniMode.miniprogram && opts }, opts);
374
+ enableVDom, mpUploadOptions: this.project.appMode !== constant_config_1.MiniMode.minigame && opts }, opts);
376
375
  // 编译
377
376
  this.emit('compile-and-zip-status', { status: 'build-start' });
378
377
  yield this.compileProject(buildConfig);
@@ -401,6 +400,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
401
400
  const zipTask = yield Promise.all(entryZips.filter(Boolean));
402
401
  const zipResult = zipTask.flat(2);
403
402
  this.emit('compile-and-zip-status', { status: 'zip-done' });
403
+ // 小组件压缩包体积校验
404
+ if (this.project.appMode === constant_config_1.MiniMode.miniwidget) {
405
+ return this.checkMiniWidgetSize(zipResult, resolve, reject);
406
+ }
404
407
  resolve(zipResult);
405
408
  }
406
409
  catch (error) {
@@ -408,6 +411,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
408
411
  }
409
412
  }));
410
413
  }
414
+ checkMiniWidgetSize(zipResult, resolve, reject) {
415
+ if (this.project.appMode !== constant_config_1.MiniMode.miniwidget)
416
+ return;
417
+ const MINIWIDGET_MAX_SIZE = 2 * 1024 * 1024; // 2MB
418
+ for (const element of zipResult) {
419
+ if (element.zipSize > MINIWIDGET_MAX_SIZE) {
420
+ const error = new Error(`包体积过大,请检查代码,当前包体积大小 ${(0, file_1.fileSize)(element.zipSize)} 超过 ${(0, file_1.fileSize)(MINIWIDGET_MAX_SIZE)} 上限,请删除无用代码以及无用媒体资源`);
421
+ error.stack = '';
422
+ return reject(error);
423
+ }
424
+ }
425
+ return resolve(zipResult);
426
+ }
411
427
  closeCompiler(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
412
428
  const compiler = this.compilerImplMap[entryType];
413
429
  if (compiler) {
@@ -20,6 +20,7 @@ export declare const COMPILE_ENTRY: {
20
20
  export declare const MiniMode: {
21
21
  miniprogram: string;
22
22
  minigame: string;
23
+ miniwidget: string;
23
24
  };
24
25
  export declare const PKG_ROOT_SEP = "_XHSPKG_";
25
26
  export declare const COMPILE_FULL_PKG = "xhs-full";
@@ -31,7 +31,8 @@
31
31
  };
32
32
  exports.MiniMode = {
33
33
  miniprogram: 'miniprogram',
34
- minigame: 'minigame'
34
+ minigame: 'minigame',
35
+ miniwidget: 'miniwidget'
35
36
  };
36
37
  exports.PKG_ROOT_SEP = '_XHSPKG_';
37
38
  exports.COMPILE_FULL_PKG = 'xhs-full';
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "xhs-mp-pack", "./common", "./dev", "./prod", "./configs/miniprogram/assets", "./configs/miniprogram/service", "./configs/miniprogram/render", "./configs/minigame/assets", "./configs/minigame/service"], factory);
10
+ define(["require", "exports", "xhs-mp-pack", "./common", "./dev", "./prod", "./configs/miniprogram/assets", "./configs/miniprogram/service", "./configs/miniprogram/render", "./configs/minigame/assets", "./configs/minigame/service", "../config/constant.config"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -22,6 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  const render_1 = require("./configs/miniprogram/render");
23
23
  const assets_2 = require("./configs/minigame/assets");
24
24
  const service_2 = require("./configs/minigame/service");
25
+ const constant_config_1 = require("../config/constant.config");
25
26
  /**
26
27
  * 小程序编译配置
27
28
  */
@@ -84,11 +85,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
84
85
  // 获取编译配置
85
86
  const createConfigs = (options) => {
86
87
  const { project } = options;
87
- if (project.appMode === 'miniprogram') {
88
- return createMPConfigs(options);
88
+ if (project.appMode === constant_config_1.MiniMode.minigame) {
89
+ return createMGConfigs(options);
89
90
  }
90
91
  else {
91
- return createMGConfigs(options);
92
+ return createMPConfigs(options);
92
93
  }
93
94
  };
94
95
  exports.createConfigs = createConfigs;
@@ -40,7 +40,7 @@
40
40
  },
41
41
  ];
42
42
  };
43
- if (project.appMode === 'miniprogram') {
43
+ if (project.appMode !== constant_config_1.MiniMode.minigame) {
44
44
  chain.module
45
45
  .rule('js')
46
46
  .test(/\.js$/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "2.0.30",
3
+ "version": "2.0.31-beta.1",
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.2.0",
91
- "xhs-mp-ml-loader": "2.0.30",
92
- "xhs-mp-compiler-utils": "2.0.30",
93
- "xhs-mp-pack": "2.0.30",
94
- "xhs-mp-project": "2.0.30",
95
- "xhs-mp-shared": "2.0.30",
96
- "xhs-mp-shared-fs": "2.0.30",
97
- "xhs-mp-sjs-loader": "2.0.30",
98
- "xhs-mp-sketch-loader": "2.0.30",
91
+ "xhs-mp-ml-loader": "2.0.31-beta.1",
92
+ "xhs-mp-compiler-utils": "2.0.31-beta.1",
93
+ "xhs-mp-pack": "2.0.31-beta.1",
94
+ "xhs-mp-project": "2.0.31-beta.1",
95
+ "xhs-mp-shared": "2.0.31-beta.1",
96
+ "xhs-mp-shared-fs": "2.0.31-beta.1",
97
+ "xhs-mp-sjs-loader": "2.0.31-beta.1",
98
+ "xhs-mp-sketch-loader": "2.0.31-beta.1",
99
99
  "yauzl": "^2.10.0"
100
100
  },
101
101
  "peerDependencies": {
102
- "xhs-mp-ml-parser": "2.0.30"
102
+ "xhs-mp-ml-parser": "2.0.31-beta.1"
103
103
  },
104
104
  "devDependencies": {
105
105
  "@types/babel__generator": "7.6.3",
@@ -122,7 +122,7 @@
122
122
  "@types/node": "14",
123
123
  "typescript": "5.1.6",
124
124
  "webpack-dev-server": "4.0.0-beta.3",
125
- "xhs-mp-ml-parser": "2.0.30"
125
+ "xhs-mp-ml-parser": "2.0.31-beta.1"
126
126
  },
127
127
  "scripts": {
128
128
  "version": "formula changelog && git add .",