@atomicservice/ascf-toolkit-hvigor-plugin 1.0.3-beta.6 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomicservice/ascf-toolkit-hvigor-plugin",
3
- "version": "1.0.3-beta.6",
3
+ "version": "1.0.3",
4
4
  "title": "ASCF toolkit hvigor plugin for atomicservice",
5
5
  "description": "ASCF toolkit hvigor plugin for atomicservice",
6
6
  "main": "index.ts",
@@ -11,7 +11,7 @@
11
11
  "@ohos/hvigor-ohos-plugin": "5.8.9"
12
12
  },
13
13
  "dependencies": {
14
- "@atomicservice/ascf-toolkit": "1.0.3-beta.6"
14
+ "@atomicservice/ascf-toolkit": "1.0.3"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -105,7 +105,8 @@
105
105
  "@jridgewell/source-map": "0.3.2",
106
106
  "browserslist": "4.24.2",
107
107
  "resolve": "1.22.8",
108
- "terser-webpack-plugin": "5.3.7"
108
+ "terser-webpack-plugin": "5.3.7",
109
+ "@swc/types": "0.1.17"
109
110
  },
110
111
  "license": "Apache-2.0",
111
112
  "licenseFilename": "LICENSE"
@@ -4,3 +4,30 @@ export enum LogLevel {
4
4
  WARN = 'warn',
5
5
  ERROR = 'error'
6
6
  }
7
+ export enum DevtoolEnum {
8
+ EVAL = 'eval',
9
+ EVAL_CHEAP_SOURCE_MAP = 'eval-cheap-source-map',
10
+ EVAL_CHEAP_MODULE_SOURCE_MAP = 'eval-cheap-module-source-map',
11
+ EVAL_SOURCE_MAP = 'eval-source-map',
12
+ CHEAP_SOURCE_MAP = 'cheap-source-map',
13
+ CHEAP_MODULE_SOURCE_MAP = 'cheap-module-source-map',
14
+ SOURCE_MAP = 'source-map',
15
+ INLINE_CHEAP_SOURCE_MAP = 'inline-cheap-source-map',
16
+ INLINE_CHEAP_MODULE_SOURCE_MAP = 'inline-cheap-module-source-map',
17
+ INLINE_SOURCE_MAP = 'inline-source-map',
18
+ EVAL_NOSOURCES_CHEAP_SOURCE_MAP = 'eval-nosources-cheap-source-map',
19
+ EVAL_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'eval-nosources-cheap-module-source-map',
20
+ EVAL_NOSOURCES_SOURCE_MAP = 'eval-nosources-source-map',
21
+ INLINE_NOSOURCES_CHEAP_SOURCE_MAP = 'inline-nosources-cheap-source-map',
22
+ INLINE_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'inline-nosources-cheap-module-source-map',
23
+ INLINE_NOSOURCES_SOURCE_MAP = 'inline-nosources-source-map',
24
+ NOSOURCES_CHEAP_SOURCE_MAP = 'nosources-cheap-source-map',
25
+ NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'nosources-cheap-module-source-map',
26
+ NOSOURCES_SOURCE_MAP = 'nosources-source-map',
27
+ HIDDEN_NOSOURCES_CHEAP_SOURCE_MAP = 'hidden-nosources-cheap-source-map',
28
+ HIDDEN_NOSOURCES_CHEAP_MODULE_SOURCE_MAP = 'hidden-nosources-cheap-module-source-map',
29
+ HIDDEN_NOSOURCES_SOURCE_MAP = 'hidden-nosources-source-map',
30
+ HIDDEN_CHEAP_SOURCE_MAP = 'hidden-cheap-source-map',
31
+ HIDDEN_CHEAP_MODULE_SOURCE_MAP = 'hidden-cheap-module-source-map',
32
+ HIDDEN_SOURCE_MAP = 'hidden-source-map',
33
+ }
@@ -1,4 +1,4 @@
1
- import { OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
1
+ import {OhosAppContext, OhosHapContext, OhosPluginId} from '@ohos/hvigor-ohos-plugin';
2
2
  import { Property } from '@ohos/hvigor-ohos-plugin/src/sdk/lib/property-get';
3
3
  import { PropertyConst } from '@ohos/hvigor-ohos-plugin/src/const/property-const';
4
4
  import { hvigor, HvigorLogger, HvigorNode, HvigorPlugin, Level } from '@ohos/hvigor';
@@ -7,7 +7,7 @@ import { exec } from 'child_process';
7
7
  import path from 'path';
8
8
  import fs from 'fs';
9
9
  import os from 'os';
10
- import { LogLevel } from '../common/common-enum';
10
+ import { DevtoolEnum, LogLevel } from '../common/common-enum';
11
11
  import { deepMerge } from '../common/common-utils';
12
12
 
13
13
  import { doModifyShareInfoPlugin } from './modifyShareInfoPlugin';
@@ -20,6 +20,7 @@ export interface AscfPluginOptions {
20
20
  installAscfHsp: boolean,
21
21
  debug: boolean,
22
22
  logging?: LogLevel,
23
+ devtool?: DevtoolEnum,
23
24
  compilerOptions: {
24
25
  swc: boolean,
25
26
  }
@@ -51,26 +52,48 @@ export default function ascfToolkitHvigorPlugin(options?: AscfPluginOptions): Hv
51
52
  },
52
53
  });
53
54
  } else {
54
- logger.debug('start exec ascf compile');
55
+ logger.debug('start exec ascf quickGenSub');
56
+ await ascf.quickGenerateSubpackage();
57
+ logger.debug('ascf quickGenSub completed');
55
58
  const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
56
- const buildMode = appContext.getBuildMode();
57
- const nodeExe = getNodeExe();
58
- const ascfScript = getAscfScript();
59
- let cmd = `${nodeExe} ${ascfScript} compile -c ${buildMode === 'debug' ? '-m' : ''} ${appContext.getProjectPath()}`;
60
-
61
- const hvigorLevelStr = (logger.getLevel() as Level).levelStr.toLowerCase();
62
- if (opts.debug && hvigorLevelStr === LogLevel.DEBUG) {
63
- cmd += ' --debug';
64
- }
65
- if (opts.compilerOptions.swc) {
66
- cmd += ' --swc';
67
- }
68
-
69
- const logLevel = (opts.logging ? opts.logging : hvigorLevelStr).toLowerCase();
70
- cmd += ` --logging=${logLevel}`;
71
- logger.debug(cmd);
72
- await executeCommand(cmd, hvigorLevelStr);
73
- logger.debug('ascf compile completed');
59
+ node.subNodes((subNode: HvigorNode) => {
60
+ const hapContext = subNode.getContext(OhosPluginId.OHOS_HAP_PLUGIN) as OhosHapContext;
61
+ if(hapContext && hapContext.getModuleType() === 'entry') {
62
+ subNode.registerTask({
63
+ // 任务名称
64
+ name: 'quickGenerateSubpackage',
65
+ // 任务执行逻辑主体函数
66
+ async run() {
67
+ logger.debug('start exec ascf compile');
68
+ const buildMode = appContext.getBuildMode();
69
+ const nodeExe = getNodeExe();
70
+ const ascfScript = getAscfScript();
71
+ let cmd = `${nodeExe} ${ascfScript} compile -c ${buildMode === 'debug' ? '-m' : ''} ${appContext.getProjectPath()}`;
72
+
73
+ const hvigorLevelStr = (logger.getLevel() as Level).levelStr.toLowerCase();
74
+ if (opts.debug && hvigorLevelStr === LogLevel.DEBUG) {
75
+ cmd += ' --debug';
76
+ }
77
+ if (opts.compilerOptions.swc) {
78
+ cmd += ' --swc';
79
+ }
80
+ const devtool = opts.devtool?.toLowerCase();
81
+ if (devtool) {
82
+ cmd += ` --devtool=${devtool}`;
83
+ }
84
+ const logLevel = (opts.logging ? opts.logging : hvigorLevelStr).toLowerCase();
85
+ cmd += ` --logging=${logLevel}`;
86
+ logger.debug(cmd);
87
+ await executeCommand(cmd, hvigorLevelStr);
88
+ logger.debug('ascf compile completed');
89
+ },
90
+ // 配置前置任务依赖
91
+ dependencies: ['default@PreBuild'],
92
+ // 配置任务的后置任务依赖
93
+ postDependencies: ['assembleHap']
94
+ });
95
+ }
96
+ });
74
97
  }
75
98
  } catch (err: any) {
76
99
  logger.errorExit(new Error(err));
@@ -15,40 +15,58 @@ function execSafe(cmd: string) {
15
15
  }
16
16
  }
17
17
 
18
- const BUNDLE_NAME_ASCF = 'com.huawei.hms.ascfruntime';
19
- const ERR_MSG = `${BUNDLE_NAME_ASCF} install failed, please open helloUniapp manually.`;
18
+ function checkProjectAscfVer() {
19
+ logger.debug(`Check project ascf dependency version.`);
20
+ const node = hvigor.getNodeByName('entry');
21
+ let ohPkgFile = path.resolve(node?.getNodePath(), './oh-package.json');
22
+ if (!fs.existsSync(ohPkgFile)) {
23
+ ohPkgFile += '5'; // trying module.json5
24
+ if (!fs.existsSync(ohPkgFile)) {
25
+ logger.warn(`Check oh-package failed. Not found ${ohPkgFile}.`);
26
+ return false;
27
+ }
28
+ }
29
+ const ohPkgDeps = JSON.parse(fs.readFileSync(ohPkgFile).toString())?.dependencies;
30
+ logger.debug(`ohPkgDeps: ${JSON.stringify(ohPkgDeps)}`);
31
+ return !!Object.prototype.hasOwnProperty.call(ohPkgDeps, '@atomicservice/ascf');
32
+ }
20
33
 
21
- function checkAscfHsp() {
22
- logger.debug(`Check and install ${BUNDLE_NAME_ASCF} for local development`);
23
- const sharedInfo = execSafe(`hdc shell bm dump-shared -a`);
24
- if (sharedInfo?.includes(BUNDLE_NAME_ASCF)) {
25
- const verInfo = execSafe(`hdc shell "bm dump-shared -n ${BUNDLE_NAME_ASCF} | grep versionName"`);
26
- logger.debug(`found ${BUNDLE_NAME_ASCF} ${verInfo}`);
34
+ function checkAscfHsp(ascfBundleName: string) {
35
+ logger.debug(`Check and install ${ascfBundleName} for local development`);
36
+ const sharedInfo: string = execSafe(`hdc shell bm dump-shared -a`) ?? '';
37
+ if (new RegExp(`${ascfBundleName}(\\r?\\n|$)`).test(sharedInfo)) {
38
+ const verInfo = execSafe(`hdc shell "bm dump-shared -n ${ascfBundleName} | grep versionName"`);
39
+ logger.debug(`found ${ascfBundleName} ${verInfo}`);
27
40
  return true;
28
41
  }
29
42
  return false;
30
43
  }
31
44
 
32
45
  function doInstallAscfHsp(resolve: any, reject: any) {
33
- if (checkAscfHsp()) {
46
+ const isDepOldAscf: boolean = checkProjectAscfVer();
47
+ const ascfBundleName: string = isDepOldAscf ? 'com.huawei.hms.ascf' : 'com.huawei.hms.ascfruntime';
48
+ const errMsg: string = `${ascfBundleName} install failed, please open helloUniapp manually.`;
49
+
50
+ if (checkAscfHsp(ascfBundleName)) {
34
51
  resolve();
35
52
  return;
36
53
  }
37
54
 
38
- logger.debug(`trying to install ${BUNDLE_NAME_ASCF}`);
55
+ logger.debug(`trying to install ${ascfBundleName}`);
39
56
  const configJsonPath = path.resolve(__dirname, '../config.json');
40
57
  const configJson = JSON.parse(fs.readFileSync(configJsonPath).toString());
41
- const startInfo = execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${configJson.ascfRuntimeHspUrl}"`);
58
+ const hspUrl = isDepOldAscf ? configJson.ascfHspUrl : configJson.ascfRuntimeHspUrl;
59
+ const startInfo = execSafe(`hdc shell aa start -b com.huawei.hmos.browser -a MainAbility -A ohos.want.action.viewData -U "${hspUrl}"`);
42
60
  if (!startInfo?.includes('successfully')) {
43
- logger.warn(`${ERR_MSG} errorInfo=${startInfo}`);
44
- reject(ERR_MSG);
61
+ logger.warn(`${errMsg} errorInfo=${startInfo}`);
62
+ reject(errMsg);
45
63
  return;
46
64
  }
47
65
 
48
66
  logger.debug(`begin to wait install hsp`);
49
67
  let needWait = 0;
50
68
  let timer = setInterval(() => {
51
- const found = checkAscfHsp();
69
+ const found = checkAscfHsp(ascfBundleName);
52
70
  needWait++;
53
71
 
54
72
  if (found || needWait > 5) {
@@ -56,8 +74,8 @@ function doInstallAscfHsp(resolve: any, reject: any) {
56
74
  if (found) {
57
75
  resolve();
58
76
  } else {
59
- logger.warn(ERR_MSG);
60
- reject(ERR_MSG);
77
+ logger.warn(errMsg);
78
+ reject(errMsg);
61
79
  }
62
80
  return;
63
81
  }