xhs-mp-compiler-cli 1.3.5 → 1.3.8

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.
@@ -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
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
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';
package/dist/index.js CHANGED
@@ -189,11 +189,10 @@ class Compiler extends events_1.default {
189
189
  const distDir = this.getDistDir(entryType);
190
190
  const cacheDir = this.getCacheDir(entryType);
191
191
  const compilerType = this.getCompilerType(entryType);
192
- const packMode = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
192
+ compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
193
193
  ? 'webpack'
194
194
  : 'mp-pack';
195
195
  const options = {
196
- packMode,
197
196
  projectPath: this.project.projectPath,
198
197
  appMode: this.project.appMode,
199
198
  extJsonPath: this.project.extJsonDir,
@@ -8,12 +8,15 @@ const presets_1 = require("../../presets");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const xhs_mp_pack_1 = require("xhs-mp-pack");
10
10
  const apm_1 = require("../../utils/apm");
11
+ const const_1 = __importDefault(require("../../utils/const"));
12
+ const { PACK_MODE } = const_1.default;
11
13
  const createCompiler = (startConfig) => {
12
- const { action, enableDevServer } = startConfig;
14
+ // const {action, enableDevServer} = startConfig
13
15
  const mppack = new xhs_mp_pack_1.MPPack(startConfig);
14
16
  const compilerOptions = {
15
17
  project: mppack.project,
16
18
  packSetting: mppack.packSetting,
19
+ packMode: PACK_MODE.MPPACK,
17
20
  // 注入apm模块
18
21
  reporter: (0, apm_1.createReporter)(mppack.project, startConfig.mpUploadOptions)
19
22
  };
@@ -19,14 +19,14 @@ 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
- const { devServerPort, distDir } = packSetting;
22
+ const { distDir } = packSetting;
23
23
  const webpackConfigs = (0, presets_1.createConfigs)(config);
24
24
  const compiler = (0, webpack_1.default)(webpackConfigs);
25
25
  const host = 'localhost';
26
26
  const devServerConfig = {
27
27
  open: false,
28
28
  historyApiFallback: true,
29
- port: devServerPort || 1388,
29
+ port: 1388,
30
30
  hot: false,
31
31
  static: [
32
32
  // emulator entry 地址
@@ -15,6 +15,8 @@ const xhs_mp_project_1 = require("xhs-mp-project");
15
15
  const xhs_mp_pack_1 = require("xhs-mp-pack");
16
16
  const webpack_1 = require("./webpack");
17
17
  const apm_1 = require("../../utils/apm");
18
+ const const_1 = __importDefault(require("../../utils/const"));
19
+ const { PACK_MODE } = const_1.default;
18
20
  // 防御编程
19
21
  const handleVersion = (startConfig) => {
20
22
  let { action, enableV1 = true, enableV2 = false, enableVDom = false } = startConfig;
@@ -77,6 +79,7 @@ const createCompiler = (startConfig) => {
77
79
  const compilerOptions = {
78
80
  project: project,
79
81
  packSetting: mppackSetting,
82
+ packMode: PACK_MODE.WEBPACK,
80
83
  // 注入apm模块
81
84
  reporter: (0, apm_1.createReporter)(project, startConfig.mpUploadOptions)
82
85
  };
@@ -87,7 +87,7 @@ class XhsAssetsPlugin {
87
87
  });
88
88
  }
89
89
  emitAppJson(compilation, appJSON) {
90
- const { project, packSetting } = this.options;
90
+ const { project, packSetting, packMode } = this.options;
91
91
  const { compilePkgs = [const_1.default.MAIN_PKG] } = packSetting;
92
92
  // const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries()
93
93
  // 先删除,用户配置的默认不生效
@@ -109,7 +109,7 @@ class XhsAssetsPlugin {
109
109
  this.emitJson(compilation, 'v1/app.json', appJsonSource);
110
110
  }
111
111
  // 独立分包的 app.json
112
- const subPkgs = project.getSubPackages().filter(pkg => compilePkgs.includes(pkg.root));
112
+ const subPkgs = project.getSubPackages();
113
113
  subPkgs.forEach(subPkg => {
114
114
  if (subPkg === null || subPkg === void 0 ? void 0 : subPkg.independent) {
115
115
  if (packSetting.enableV2) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const packs_1 = require("../../../../packs");
4
4
  const injectCSS = `
5
- globalThis.__XHS_IS_WEBVIEW = (globalThis.localStorage && document && document.querySelectorAll)
5
+ globalThis.__XHS_IS_WEBVIEW = (globalThis.localStorage && globalThis.document && globalThis.document.querySelectorAll)
6
6
  globalThis.__XHS_APPEND_CSS = function(cssText){
7
7
  if (!globalThis.__XHS_IS_WEBVIEW) return;
8
8
  var headTags = document.getElementsByTagName('head')
@@ -113,6 +113,7 @@ export interface IStart extends Pick<ICompilerConfig, CliPick> {
113
113
  devServerPort?: number;
114
114
  }
115
115
  export type IPresetOptions = {
116
+ packMode: string;
116
117
  project: Project;
117
118
  packSetting: MPPackSetting;
118
119
  otherSetting?: any;
@@ -5,16 +5,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.createReporter = void 0;
13
+ const path_1 = __importDefault(require("path"));
10
14
  const xhs_mp_utils_1 = require("xhs-mp-utils");
15
+ const fs_extra_1 = require("fs-extra");
11
16
  const pkg = require('../../../package.json');
12
17
  function debug(...data) {
13
- return;
14
18
  // return process.send?.(JSON.stringify({ method: 'debugger', data }))
15
19
  }
16
20
  const cacheMap = {};
17
- function once(target, key, descriptor) {
21
+ function onceByParams(target, key, descriptor) {
18
22
  const originalMethod = descriptor.value;
19
23
  descriptor.value = function (...args) {
20
24
  try {
@@ -87,22 +91,22 @@ class Reporter {
87
91
  }
88
92
  }
89
93
  __decorate([
90
- once
94
+ onceByParams
91
95
  ], Reporter.prototype, "reportThirdFramework", null);
92
96
  __decorate([
93
- once
97
+ onceByParams
94
98
  ], Reporter.prototype, "reportMlFeature", null);
95
99
  __decorate([
96
- once
100
+ onceByParams
97
101
  ], Reporter.prototype, "reportMlWebComponent", null);
98
102
  __decorate([
99
- once
103
+ onceByParams
100
104
  ], Reporter.prototype, "reportJSONComponent", null);
101
105
  __decorate([
102
- once
106
+ onceByParams
103
107
  ], Reporter.prototype, "reportStyleIsolation", null);
104
108
  __decorate([
105
- once
109
+ onceByParams
106
110
  ], Reporter.prototype, "reportJSONApp", null);
107
111
  function isObject(t) {
108
112
  return t != null && typeof t === 'object';
@@ -120,18 +124,20 @@ function createReporter(project, option) {
120
124
  var _a, _b, _c;
121
125
  try {
122
126
  const app_id = option === null || option === void 0 ? void 0 : option.upload_app_id;
123
- if (!app_id) {
127
+ // 上传时有version
128
+ const version = (_a = option === null || option === void 0 ? void 0 : option.pkgInfo) === null || _a === void 0 ? void 0 : _a.version;
129
+ if (!app_id || !version) {
124
130
  return;
125
131
  }
126
132
  const apm = new xhs_mp_utils_1.APM(`mp-compiler-${pkg.version}`);
127
- (_a = apm === null || apm === void 0 ? void 0 : apm.setContext) === null || _a === void 0 ? void 0 : _a.call(apm, app_id, {
133
+ (_b = apm === null || apm === void 0 ? void 0 : apm.setContext) === null || _b === void 0 ? void 0 : _b.call(apm, app_id, {
128
134
  app_id,
129
135
  app_name: app_id,
130
136
  third_name: app_id,
131
137
  page_key: '0',
132
138
  app_env: 0,
133
139
  app_type: 0,
134
- bundle_version: ((_b = option === null || option === void 0 ? void 0 : option.pkgInfo) === null || _b === void 0 ? void 0 : _b.version) || '',
140
+ bundle_version: version,
135
141
  base_version: ((_c = project.projectJsonContent) === null || _c === void 0 ? void 0 : _c.libVersion) || ''
136
142
  });
137
143
  const reporter = new Reporter(apm);
@@ -170,8 +176,19 @@ function createReporter(project, option) {
170
176
  }
171
177
  }
172
178
  }
173
- // 延时上报
174
- setTimeout(reportJSON);
179
+ reportJSON();
180
+ // 统计taro版本
181
+ const vendor = path_1.default.join(project.miniprogramDir, 'vendors.js.LICENSE.txt');
182
+ const taro = path_1.default.join(project.miniprogramDir, 'taro.js');
183
+ if ((0, fs_extra_1.pathExistsSync)(taro) && (0, fs_extra_1.pathExistsSync)(vendor)) {
184
+ const txt = (0, fs_extra_1.readFileSync)(vendor, { encoding: 'utf-8' });
185
+ if (txt.includes('React') || txt.includes('react')) {
186
+ reporter.reportThirdFramework(xhs_mp_utils_1.FeatureReporter.ThirdFramework.taroReact);
187
+ }
188
+ else if (txt.includes('@vue') || txt.includes('Vue')) {
189
+ reporter.reportThirdFramework(xhs_mp_utils_1.FeatureReporter.ThirdFramework.taroVue);
190
+ }
191
+ }
175
192
  return reporter;
176
193
  }
177
194
  catch (error) {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "1.3.5",
3
+ "version": "1.3.8",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -82,11 +82,11 @@
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.3.5",
86
- "xhs-mp-compiler-utils": "1.2.5",
87
- "xhs-mp-pack": "^1.2.5",
88
- "xhs-mp-project": "^1.2.5",
89
- "xhs-mp-utils": "^1.3.5"
85
+ "xhs-mp-compiler-ml-loader": "^1.3.8",
86
+ "xhs-mp-compiler-utils": "^1.3.8",
87
+ "xhs-mp-pack": "^1.3.8",
88
+ "xhs-mp-project": "^1.3.8",
89
+ "xhs-mp-utils": "^1.3.8"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@types/babel__generator": "7.6.3",