@cloudcare/hvigor-ohos-plugin 0.1.0-alpha.1 → 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 +9 -0
- package/README.md +5 -3
- package/hvigorCompile/ft-cold-launch-transform.ts +23 -4
- package/package.json +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
7
|
+
## [0.1.0-alpha.2] - 2026-09-11
|
|
8
|
+
|
|
9
|
+
- Added GitHub Actions trusted npm publishing triggered by plugin version tags.
|
|
10
|
+
- Added the plugin version badge to the package documentation.
|
|
11
|
+
|
|
3
12
|
## [0.1.0-alpha.1] - 2026-09-11
|
|
4
13
|
|
|
5
14
|
- Prepared the initial npm prerelease of the console/HiLog and cold-launch instrumentation plugin.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Guance HarmonyOS Hvigor Plugin
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@cloudcare/hvigor-ohos-plugin)
|
|
4
|
+
|
|
3
5
|
`@cloudcare/hvigor-ohos-plugin` is the build-time companion for `@guancecloud/ft_sdk`. It instruments direct `console.*` and `hilog.*` calls and injects cold-launch lifecycle tracking into a HAP module's `src/main/ets` sources. Runtime log collection remains controlled by `FTLoggerConfig.setEnableConsoleLog(true)` in `@guancecloud/ft_sdk`.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
@@ -9,7 +11,7 @@ This is a Hvigor tool package, so declare it in the project-level `hvigor/hvigor
|
|
|
9
11
|
```json5
|
|
10
12
|
{
|
|
11
13
|
"dependencies": {
|
|
12
|
-
"@cloudcare/hvigor-ohos-plugin": "0.1.0-alpha.
|
|
14
|
+
"@cloudcare/hvigor-ohos-plugin": "0.1.0-alpha.3"
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
```
|
|
@@ -36,10 +38,10 @@ export default {
|
|
|
36
38
|
}
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
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.
|
|
40
42
|
|
|
41
43
|
## Compatibility
|
|
42
44
|
|
|
43
|
-
The `0.1.0-alpha.
|
|
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.
|
|
44
46
|
|
|
45
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
|
|
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.
|
|
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": [
|
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "Guance",
|
|
15
15
|
"license": "Apache-2.0",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/GuanceCloud/datakit-harmonyos.git",
|
|
19
|
+
"directory": "ft_hvigor_plugin"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
16
25
|
"engines": {
|
|
17
26
|
"node": ">=18"
|
|
18
27
|
},
|