hvigor-dependency-policy-plugin 0.2.0-beta → 0.2.1-beta
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/dist/index.d.ts +5 -6
- package/dist/index.js +85 -33
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export declare function hasOverridesDiff(diff: OverridesDiff): boolean;
|
|
1
|
+
import type { HvigorPlugin } from '@ohos/hvigor';
|
|
2
|
+
import type { DependencyPolicyPluginOptions } from './types';
|
|
3
|
+
export declare function dependencyPolicyPlugin(options?: DependencyPolicyPluginOptions): HvigorPlugin;
|
|
4
|
+
export default dependencyPolicyPlugin;
|
|
5
|
+
export type { AppRule, ApplyStrategy, ConflictPolicy, DependencyMap, DependencyPolicyConfig, DependencyPolicyPluginOptions, DependencyProfile, LoadedPolicyConfig, LogLevel, OverridesDiff, OverridesReport, PathBase } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
else if (before[name] !== afterValue) {
|
|
14
|
-
changed[name] = {
|
|
15
|
-
from: before[name],
|
|
16
|
-
to: afterValue
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
for (const [name, beforeValue] of Object.entries(before)) {
|
|
21
|
-
if (after[name] === undefined) {
|
|
22
|
-
removed[name] = beforeValue;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
3
|
+
exports.dependencyPolicyPlugin = dependencyPolicyPlugin;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const policy_loader_1 = require("./policy-loader");
|
|
6
|
+
const project_root_1 = require("./project-root");
|
|
7
|
+
const oh_package_editor_1 = require("./oh-package-editor");
|
|
8
|
+
const overrides_applier_1 = require("./overrides-applier");
|
|
9
|
+
const diff_1 = require("./diff");
|
|
10
|
+
const report_1 = require("./report");
|
|
11
|
+
const PLUGIN_ID = '@didi/hvigor-dependency-policy-plugin';
|
|
12
|
+
function dependencyPolicyPlugin(options = {}) {
|
|
25
13
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
pluginId: PLUGIN_ID,
|
|
15
|
+
apply(currentNode) {
|
|
16
|
+
const logger = new logger_1.Logger(options.logLevel ?? 'info');
|
|
17
|
+
const projectRoot = (0, project_root_1.resolveProjectRoot)(currentNode);
|
|
18
|
+
logger.debug('apply called', {
|
|
19
|
+
currentNodeName: (0, project_root_1.safeCallString)(currentNode, 'getNodeName') ??
|
|
20
|
+
(0, project_root_1.safeCallString)(currentNode, 'getName'),
|
|
21
|
+
currentNodePath: (0, project_root_1.safeCallString)(currentNode, 'getNodeDir') ??
|
|
22
|
+
(0, project_root_1.safeCallString)(currentNode, 'getNodePath'),
|
|
23
|
+
projectRoot,
|
|
24
|
+
options: sanitizeOptionsForLog(options)
|
|
25
|
+
});
|
|
26
|
+
try {
|
|
27
|
+
const loaded = (0, policy_loader_1.loadPolicyConfig)(projectRoot, options);
|
|
28
|
+
const profileName = (0, policy_loader_1.resolveProfileName)(loaded.config, options);
|
|
29
|
+
const projectOhPackagePath = (0, overrides_applier_1.resolveProjectOhPackagePath)(projectRoot, loaded, options.projectOhPackagePath);
|
|
30
|
+
logger.info(`using profile: ${profileName}`);
|
|
31
|
+
logger.debug('resolved inputs', {
|
|
32
|
+
configPath: loaded.configPath,
|
|
33
|
+
projectOhPackagePath,
|
|
34
|
+
projectRoot
|
|
35
|
+
});
|
|
36
|
+
const projectOhPackage = (0, oh_package_editor_1.readProjectOhPackage)(projectOhPackagePath);
|
|
37
|
+
const buildResult = (0, overrides_applier_1.buildProjectOverrides)(projectOhPackage.overrides, loaded, profileName, projectRoot, logger);
|
|
38
|
+
const changed = (0, diff_1.hasOverridesDiff)(buildResult.diff);
|
|
39
|
+
const dryRun = options.dryRun ?? false;
|
|
40
|
+
const report = {
|
|
41
|
+
pluginId: PLUGIN_ID,
|
|
42
|
+
schemaVersion: loaded.config.schemaVersion,
|
|
43
|
+
profile: profileName,
|
|
44
|
+
dryRun,
|
|
45
|
+
projectRoot,
|
|
46
|
+
projectOhPackagePath,
|
|
47
|
+
configPath: loaded.configPath,
|
|
48
|
+
changed,
|
|
49
|
+
warnings: buildResult.warnings,
|
|
50
|
+
overrides: buildResult.diff
|
|
51
|
+
};
|
|
52
|
+
if (!changed) {
|
|
53
|
+
logger.info('project oh-package.json5 overrides are already up to date.');
|
|
54
|
+
}
|
|
55
|
+
else if (dryRun) {
|
|
56
|
+
logger.info('dryRun=true, skip writing project oh-package.json5.');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const wrote = (0, oh_package_editor_1.writeProjectOverrides)(projectOhPackagePath, projectOhPackage.text, buildResult.after, options.backup ?? false);
|
|
60
|
+
logger.info(wrote
|
|
61
|
+
? `updated project oh-package.json5 overrides: ${projectOhPackagePath}`
|
|
62
|
+
: 'project oh-package.json5 content did not change after rendering.');
|
|
63
|
+
}
|
|
64
|
+
const shouldWriteReport = options.report ?? loaded.config.report ?? true;
|
|
65
|
+
if (shouldWriteReport) {
|
|
66
|
+
const reportPath = (0, report_1.writeOverridesReport)(projectRoot, report);
|
|
67
|
+
logger.info(`overrides report: ${reportPath}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const message = error instanceof Error
|
|
72
|
+
? error.stack ?? error.message
|
|
73
|
+
: String(error);
|
|
74
|
+
logger.fatal(message);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
32
78
|
};
|
|
33
79
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
function sanitizeOptionsForLog(options) {
|
|
81
|
+
return {
|
|
82
|
+
configPath: options.configPath,
|
|
83
|
+
profile: options.profile,
|
|
84
|
+
dryRun: options.dryRun,
|
|
85
|
+
report: options.report,
|
|
86
|
+
logLevel: options.logLevel,
|
|
87
|
+
projectOhPackagePath: options.projectOhPackagePath,
|
|
88
|
+
backup: options.backup
|
|
89
|
+
};
|
|
39
90
|
}
|
|
91
|
+
exports.default = dependencyPolicyPlugin;
|