@aiot-toolkit/aiotpack 2.0.4-beta.2 → 2.0.4-beta.4

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.
@@ -164,7 +164,7 @@ class UxAfterCompile {
164
164
  outputPath,
165
165
  completeFeature
166
166
  } = compilerOption;
167
- const content = _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot);
167
+ const content = _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot);
168
168
  const translateCache = context.translateCache;
169
169
  if (!content.minAPILevel) {
170
170
  content.minAPILevel = 1;
@@ -232,7 +232,7 @@ class UxAfterCompile {
232
232
  const content = Object.keys(comment).map(key => `${key}=${comment[key]}`).join('\n');
233
233
  _fsExtra.default.outputFileSync(_path.default.join(outputAbsPath, _ZipUtil.default.BUILD_FILE_PATH), content);
234
234
  // cert
235
- const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot));
235
+ const files = _ZipUtil.default.getSortedFiles(outputAbsPath, compilerOption, _UxFileUtils.default.getManifestInfo(projectPath, sourceRoot));
236
236
  const digestDic = Object.fromEntries(files.map(item => [item, _sharedUtils.CommonUtil.calcDataDigest(_fsExtra.default.readFileSync(_path.default.join(outputAbsPath, item))).toString('hex')]));
237
237
  const hashJson = [{
238
238
  path: _ZipUtil.default.DIGEST_HASH_JSON,
@@ -16,31 +16,37 @@ class JavascriptCompiler {
16
16
  QUICKAPP_CONFIG = 'quickapp.config.js';
17
17
  async compile(param) {
18
18
  return new Promise(async (resolve, reject) => {
19
- await this.clean(param);
20
- const config = this.createWebpackConfig(param);
21
- (0, _core.rspack)(config, (error, stats) => {
22
- if (error) {
23
- reject({
24
- errors: [error]
25
- });
26
- } else {
27
- const statsObj = stats?.toJson({});
28
- if (statsObj) {
29
- const {
30
- errors,
31
- warnings
32
- } = statsObj;
33
- if (errors?.length || warnings?.length) {
34
- reject({
19
+ try {
20
+ await this.clean(param);
21
+ const config = this.createWebpackConfig(param);
22
+ (0, _core.rspack)(config, (error, stats) => {
23
+ if (error) {
24
+ reject({
25
+ errors: [error]
26
+ });
27
+ } else {
28
+ const statsObj = stats?.toJson({});
29
+ if (statsObj) {
30
+ const {
35
31
  errors,
36
32
  warnings
37
- });
38
- } else {
39
- resolve();
33
+ } = statsObj;
34
+ if (errors?.length || warnings?.length) {
35
+ reject({
36
+ errors,
37
+ warnings
38
+ });
39
+ } else {
40
+ resolve();
41
+ }
40
42
  }
41
43
  }
42
- }
43
- });
44
+ });
45
+ } catch (error) {
46
+ reject({
47
+ errors: [error]
48
+ });
49
+ }
44
50
  });
45
51
  }
46
52
  createWebpackConfig(param) {
@@ -62,7 +68,7 @@ class JavascriptCompiler {
62
68
  } = param;
63
69
  const buildPath = _path.default.resolve(projectPath, outputPath);
64
70
  const quickAppConfig = _sharedUtils.CommonUtil.requireModule(_path.default.join(param.projectPath, this.QUICKAPP_CONFIG));
65
- const result = {
71
+ let result = {
66
72
  context: projectPath,
67
73
  mode,
68
74
  devtool: devtool,
@@ -128,12 +134,19 @@ class JavascriptCompiler {
128
134
  configurator.hook(result);
129
135
  }
130
136
 
131
- // 数组,则全部数组(默认合并数组中相同序号的项)
132
- return _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
137
+ // 合并用户自定义的webpack配置
138
+ // 数组,则合并数组(默认合并数组中相同序号的项)
139
+ result = _lodash.default.mergeWith({}, result, quickAppConfig?.webpack, (source, target) => {
133
140
  if (Array.isArray(target) && Array.isArray(source)) {
134
141
  return [...target, ...source];
135
142
  }
136
143
  });
144
+
145
+ // 触发用户配置的posthook
146
+ if (quickAppConfig?.postHook) {
147
+ quickAppConfig.postHook(result);
148
+ }
149
+ return result;
137
150
  }
138
151
  getConfigurator(param) {
139
152
  const {
@@ -77,7 +77,7 @@ class WrapPlugin {
77
77
  return new _webpackSources.ConcatSource(`
78
78
  (function () {
79
79
  var $app_define_wrap$ = $app_define_wrap$ || function () {};
80
- var manifestJson =${JSON.stringify(_UxFileUtils.default.getMainfestInfo(projectPath, sourceRoot))}
80
+ var manifestJson =${JSON.stringify(_UxFileUtils.default.getManifestInfo(projectPath, sourceRoot))}
81
81
  var createAppHandler = function () {
82
82
  `, source, `
83
83
  }
@@ -22,7 +22,7 @@ class VelaWebpackConfigurator {
22
22
  return result;
23
23
  }
24
24
  createWrapPlugin() {
25
- return new _WrapPlugin.default();
25
+ return new _WrapPlugin.default(this.param);
26
26
  }
27
27
  createBundleAnalyzerPlugin() {
28
28
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
@@ -1,6 +1,10 @@
1
1
  import { Compiler } from '@rspack/core';
2
+ import IJavascriptCompileOption from '../../interface/IJavascriptCompileOption';
2
3
  declare class WrapPlugin {
4
+ private compilerOption;
5
+ constructor(compilerOption: IJavascriptCompileOption);
3
6
  apply(compiler: Compiler): void;
4
7
  private wrap;
8
+ private translateStyleFunc;
5
9
  }
6
10
  export default WrapPlugin;
@@ -7,6 +7,9 @@ exports.default = void 0;
7
7
  var _core = require("@rspack/core");
8
8
  var _webpackSources = require("webpack-sources");
9
9
  class WrapPlugin {
10
+ constructor(compilerOption) {
11
+ this.compilerOption = compilerOption;
12
+ }
10
13
  apply(compiler) {
11
14
  // 给入口文件加上包裹函数
12
15
  compiler.hooks.compilation.tap('WrapPlugin', compilation => {
@@ -19,12 +22,17 @@ class WrapPlugin {
19
22
  });
20
23
  }
21
24
  wrap(compilation) {
25
+ const {
26
+ enableE2e
27
+ } = this.compilerOption;
22
28
  // 获取入口文件
23
29
  const entrys = Object.keys(compilation.options.entry).map(item => `${item}.js`);
24
30
  // 从chunk找到所有入口文件,添加包裹函数
25
31
  entrys.forEach(entry => {
26
32
  if (compilation.assets[entry]) {
27
33
  const source = compilation.assets[entry];
34
+ const isApp = entry === 'app.js';
35
+ const createFuncnName = isApp ? 'createAppHandler' : 'createPageHandler';
28
36
  compilation.assets[entry] = new _webpackSources.ConcatSource(`
29
37
  export default function(global, globalThis, window, $app_exports$, $app_evaluate$){
30
38
  var org_app_require = $app_require$;
@@ -36,29 +44,45 @@ class WrapPlugin {
36
44
  var clearInterval = global.clearInterval;
37
45
  var $app_require$ = global.$app_require$ || org_app_require
38
46
 
47
+ ${enableE2e ? `globalThis = undefined; \n global = typeof window === "undefined" ? global.__proto__ : window;` : ''}
39
48
  // 转换动态 style 的函数
40
- var $translateStyle$ = function (value) {
41
- if (typeof value === 'string') {
42
- return Object.fromEntries(value.split(';').filter(item => Boolean(item && item.trim())).map(
43
- item => {
44
- const matchs = item.match(/([^:]+):(.*)/)
45
- if (matchs && matchs.length> 2) {
46
- return [matchs[1].trim().replace(/-([a-z])/g, (_, match) => match.toUpperCase()), matchs[2].trim()]
47
- }
48
- return []
49
- }))}
50
- return value
51
- }
52
-
53
- var createPageHandler = function() {
49
+ ${isApp ? this.translateStyleFunc() : ''}
50
+ var ${createFuncnName} = function() {
54
51
  return `, source, `
55
52
  }
56
53
 
57
- return createPageHandler();
54
+ return ${createFuncnName}();
58
55
  })(global, globalThis, window, $app_exports$, $app_evaluate$)
59
56
  }`);
60
57
  }
61
58
  });
62
59
  }
60
+ translateStyleFunc() {
61
+ return `
62
+ var $translateStyle$ = function (value) {
63
+ if (typeof value === 'string') {
64
+ return Object.fromEntries(
65
+ value
66
+ .split(';')
67
+ .filter((item) => Boolean(item && item.trim()))
68
+ .map((item) => {
69
+ const matchs = item.match(/([^:]+):(.*)/);
70
+ if (matchs && matchs.length > 2) {
71
+ return [
72
+ matchs[1]
73
+ .trim()
74
+ .replace(/-([a-z])/g, (_, match) => match.toUpperCase()),
75
+ matchs[2].trim(),
76
+ ];
77
+ }
78
+ return [];
79
+ })
80
+ );
81
+ }
82
+ return value;
83
+ };
84
+ global.$translateStyle$ = $translateStyle$
85
+ `;
86
+ }
63
87
  }
64
88
  var _default = exports.default = WrapPlugin;
@@ -58,7 +58,7 @@ class ZipUtil {
58
58
  * @returns 生成的 rpk 文件名
59
59
  */
60
60
  static async createRpk(dist, param) {
61
- const config = _UxFileUtils.default.getMainfestInfo(param.projectPath, param.sourceRoot);
61
+ const config = _UxFileUtils.default.getManifestInfo(param.projectPath, param.sourceRoot);
62
62
 
63
63
  // 1
64
64
  const files = this.getSortedFiles(dist, param, config);
@@ -33,7 +33,7 @@ class BeforeCompileUtils {
33
33
  } = context;
34
34
  const srcPath = _path.default.join(projectPath, compilerOption.sourceRoot);
35
35
  // 判断路径是否真实存在
36
- const manifestContent = _UxFileUtils.default.getMainfestInfo(projectPath);
36
+ const manifestContent = _UxFileUtils.default.getManifestInfo(projectPath);
37
37
  // 存储entries
38
38
  let entryList = [];
39
39
  const {
@@ -15,7 +15,7 @@ export declare class UxFileUtils {
15
15
  * @param sourceRoot
16
16
  * @returns
17
17
  */
18
- static getMainfestInfo(projectPath: string, sourceRoot?: string): IManifest;
18
+ static getManifestInfo(projectPath: string, sourceRoot?: string): IManifest;
19
19
  /**
20
20
  * 检查 manifest文件,并显示错误信息
21
21
  *
@@ -30,7 +30,7 @@ class UxFileUtils {
30
30
  * @param sourceRoot
31
31
  * @returns
32
32
  */
33
- static getMainfestInfo(projectPath) {
33
+ static getManifestInfo(projectPath) {
34
34
  let sourceRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'src';
35
35
  return _fsExtra.default.readJSONSync(UxFileUtils.getManifestFilePath(projectPath, sourceRoot));
36
36
  }
@@ -55,7 +55,7 @@ class UxFileUtils {
55
55
  }
56
56
 
57
57
  // 1
58
- const jsonData = this.getMainfestInfo(projectPath, sourceRoot);
58
+ const jsonData = this.getManifestInfo(projectPath, sourceRoot);
59
59
  const schema = _ManifestSchema.default;
60
60
  const errors = _CommonUtil.default.validateJson(jsonData, schema) || [];
61
61
 
@@ -87,7 +87,7 @@ class UxFileUtils {
87
87
  const sitemapPath = _path.default.join(projectPath, sourceRoot, 'sitemap.json');
88
88
  if (_fsExtra.default.existsSync(sitemapPath)) {
89
89
  const rules = _fsExtra.default.readJSONSync(sitemapPath).rules;
90
- const manifest = this.getMainfestInfo(projectPath, sourceRoot);
90
+ const manifest = this.getManifestInfo(projectPath, sourceRoot);
91
91
  const pages = Object.keys(manifest.router.pages || {});
92
92
  const errorList = [];
93
93
  rules.forEach((item, index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/aiotpack",
3
- "version": "2.0.4-beta.2",
3
+ "version": "2.0.4-beta.4",
4
4
  "description": "The process tool for packaging aiot projects.",
5
5
  "keywords": [
6
6
  "aiotpack"
@@ -19,16 +19,16 @@
19
19
  "test": "node ./__tests__/aiotpack.test.js"
20
20
  },
21
21
  "dependencies": {
22
- "@aiot-toolkit/generator": "2.0.4-beta.2",
23
- "@aiot-toolkit/parser": "2.0.4-beta.2",
24
- "@aiot-toolkit/shared-utils": "2.0.4-beta.2",
22
+ "@aiot-toolkit/generator": "2.0.4-beta.4",
23
+ "@aiot-toolkit/parser": "2.0.4-beta.4",
24
+ "@aiot-toolkit/shared-utils": "2.0.4-beta.4",
25
25
  "@hap-toolkit/aaptjs": "^2.0.0",
26
26
  "@rspack/core": "^1.1.8",
27
27
  "aiot-parse5": "^1.0.0",
28
28
  "archiver": "^7.0.1",
29
29
  "babel-loader": "^9.1.3",
30
30
  "fast-glob": "^3.3.2",
31
- "file-lane": "2.0.4-beta.2",
31
+ "file-lane": "2.0.4-beta.4",
32
32
  "file-loader": "^6.2.0",
33
33
  "fs-extra": "^11.2.0",
34
34
  "jsrsasign": "^11.1.0",
@@ -46,5 +46,5 @@
46
46
  "@types/jsrsasign": "^10.5.12",
47
47
  "@types/webpack-sources": "^3.2.3"
48
48
  },
49
- "gitHead": "e9015685f29790709c420a9f8c41ade936a85300"
49
+ "gitHead": "f06b80be7d99c43f88db001415c0eb15acb65286"
50
50
  }