@cloudcare/hvigor-ohos-plugin 0.1.0-alpha.2 → 0.1.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.0-alpha.3] - 2026-09-11
4
+
5
+ - Added build-time registration of the installed plugin version in SDK `sdk_pkg_info.track`.
6
+
3
7
  ## [0.1.0-alpha.2] - 2026-09-11
4
8
 
5
9
  - Added GitHub Actions trusted npm publishing triggered by plugin version tags.
package/README.md CHANGED
@@ -11,7 +11,7 @@ This is a Hvigor tool package, so declare it in the project-level `hvigor/hvigor
11
11
  ```json5
12
12
  {
13
13
  "dependencies": {
14
- "@cloudcare/hvigor-ohos-plugin": "0.1.0-alpha.2"
14
+ "@cloudcare/hvigor-ohos-plugin": "0.1.0-alpha.3"
15
15
  }
16
16
  }
17
17
  ```
@@ -38,10 +38,10 @@ export default {
38
38
  }
39
39
  ```
40
40
 
41
- The plugin preserves the original console/HiLog output and does not modify application files on disk. It injects cold-launch application initialization into Ability `onCreate()` methods, first-UIAbility creation into `UIAbility.onCreate()`, and first-frame observation into `UIAbility.onWindowStageCreate()`. Do not add manual cold-launch timing calls to application code.
41
+ The plugin preserves the original console/HiLog output and does not modify application files on disk. It injects its installed package version into the SDK's `sdk_pkg_info.track` tag at build time, so rebuilding after a plugin upgrade reports the matching version. It injects cold-launch application initialization into Ability `onCreate()` methods, first-UIAbility creation into `UIAbility.onCreate()`, and first-frame observation into `UIAbility.onWindowStageCreate()`. Do not add manual cold-launch timing calls to application code.
42
42
 
43
43
  ## Compatibility
44
44
 
45
- The `0.1.0-alpha.2` prerelease is verified with Node.js 18 or newer, Hvigor and `@ohos/hvigor-ohos-plugin` 6.23.5, and HarmonyOS SDK 6.0.2 (API 22). It supports `@guancecloud/ft_sdk` `0.1.17` and later releases.
45
+ The `0.1.0-alpha.3` prerelease is verified with Node.js 18 or newer, Hvigor and `@ohos/hvigor-ohos-plugin` 6.23.5, and HarmonyOS SDK 6.0.2 (API 22). It supports `@guancecloud/ft_sdk` `0.1.17` and later releases.
46
46
 
47
47
  `@ohos/hvigor-ohos-plugin` is supplied by DevEco Studio's Hvigor runtime. `@guancecloud/ft_sdk` must still be declared as the application's runtime HAR dependency because the generated imports target that package.
@@ -10,6 +10,7 @@ declare const require: {
10
10
  require(moduleName: string): any;
11
11
  };
12
12
  };
13
+ declare const __dirname: string;
13
14
 
14
15
  type TypeScriptApi = any;
15
16
  type AbilityClassKind = 'stage' | 'ui' | 'other';
@@ -73,6 +74,22 @@ function selectBridgeName(identifiers: Set<string>): string {
73
74
  return bridgeName;
74
75
  }
75
76
 
77
+ function getPluginVersion(): string {
78
+ try {
79
+ const fileSystem = require.main.require('fs');
80
+ const path = require.main.require('path');
81
+ const packagePath = path.resolve(__dirname, '..', 'package.json');
82
+ const packageInfo = JSON.parse(fileSystem.readFileSync(packagePath, 'utf8')) as { version?: string };
83
+ if (typeof packageInfo.version === 'string') {
84
+ return packageInfo.version.trim();
85
+ }
86
+ } catch (_) {
87
+ // Do not inject a guessed version when a custom package layout prevents
88
+ // reading package.json. A missing entry is more accurate than fake data.
89
+ }
90
+ return '';
91
+ }
92
+
76
93
  function findImportInsertionOffset(ts: TypeScriptApi, sourceFile: any): number {
77
94
  let offset = 0;
78
95
  sourceFile.statements.forEach((statement: any) => {
@@ -212,9 +229,10 @@ function createFirstFrameRetryInjections(ts: TypeScriptApi, sourceFile: any, cod
212
229
  }
213
230
 
214
231
  function createColdLaunchInjections(ts: TypeScriptApi, sourceFile: any, code: string,
215
- bridgeName: string): ColdLaunchInjection[] {
232
+ bridgeName: string, pluginVersion: string): ColdLaunchInjection[] {
216
233
  const injections: ColdLaunchInjection[] = [];
217
234
  const abilityBindings = collectAbilityBindings(ts, sourceFile);
235
+ const pluginVersionArgument = pluginVersion.length > 0 ? `, ${JSON.stringify(pluginVersion)}` : '';
218
236
  visit(ts, sourceFile, (node: any) => {
219
237
  if (!ts.isClassDeclaration(node)) {
220
238
  return;
@@ -232,7 +250,7 @@ function createColdLaunchInjections(ts: TypeScriptApi, sourceFile: any, code: st
232
250
  const position = member.body.getStart(sourceFile) + 1;
233
251
  if (member.name.text === 'onCreate') {
234
252
  hasOnCreate = true;
235
- let content = `\n${indentation}${bridgeName}.recordApplicationInit(this.context);`;
253
+ let content = `\n${indentation}${bridgeName}.recordApplicationInit(this.context${pluginVersionArgument});`;
236
254
  if (kind === 'ui') {
237
255
  content += `\n${indentation}${bridgeName}.recordFirstUIAbilityCreate();`;
238
256
  }
@@ -269,7 +287,7 @@ function createColdLaunchInjections(ts: TypeScriptApi, sourceFile: any, code: st
269
287
  injections.push({
270
288
  position: node.end - 1,
271
289
  content: `\n${indentation} onCreate(): void {\n` +
272
- `${indentation} ${bridgeName}.recordApplicationInit(this.context);\n` +
290
+ `${indentation} ${bridgeName}.recordApplicationInit(this.context${pluginVersionArgument});\n` +
273
291
  `${indentation} }\n`
274
292
  });
275
293
  }
@@ -299,7 +317,8 @@ function rewriteSource(ts: TypeScriptApi, id: string, code: string): string {
299
317
  }
300
318
  const sourceFile = ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
301
319
  const bridgeName = selectBridgeName(collectIdentifierNames(ts, sourceFile));
302
- const injections = createColdLaunchInjections(ts, sourceFile, code, bridgeName);
320
+ const version = getPluginVersion();
321
+ const injections = createColdLaunchInjections(ts, sourceFile, code, bridgeName, version);
303
322
  if (injections.length === 0) {
304
323
  return code;
305
324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/hvigor-ohos-plugin",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Guance HarmonyOS Hvigor plugin for automatic console, HiLog, and cold-launch collection.",
5
5
  "main": "index.js",
6
6
  "files": [