hvigor-dependency-policy-plugin
v0.2.1-beta
Published
Apply dependency policy by materializing project-level oh-package.json5 overrides.
Readme
hvigor-dependency-policy-plugin v2
This version no longer rewrites Hvigor dependency context in memory.
It materializes the selected dependency policy into the project-level oh-package.json5 overrides field.
That means DevEco Sync, OHPM, lock files, and the build process can see the same static dependency declaration.
Usage
// root hvigorfile.ts
import { appTasks } from '@ohos/hvigor-ohos-plugin';
import { dependencyPolicyPlugin } from '@didi/hvigor-dependency-policy-plugin';
export default {
system: appTasks,
plugins: [
dependencyPolicyPlugin({
profile: 'stable',
dryRun: false,
logLevel: 'debug'
})
]
};You can also select the profile with an environment variable:
DEP_POLICY_PROFILE=gray ./hvigorw --sync
DEP_POLICY_PROFILE=gray ./hvigorw assembleApp --no-daemonConfiguration
By default the plugin reads:
<pluginRoot>/config/dependency-policy.json5You can override it:
dependencyPolicyPlugin({
configPath: './config/dependency-policy.json5'
})Schema v2
{
schemaVersion: 2,
defaultProfile: 'stable',
conflictPolicy: 'warn',
pathBase: 'projectRoot',
report: true,
profiles: {
stable: {
app: {
strategy: 'merge',
overrides: {
'@company/core': '2.4.0',
'@company/logger': 'file:./libs/logger.har'
},
remove: {
overrides: ['@company/legacy-core']
}
}
}
}
}Notes
strategy: 'merge'keeps existing project overrides and adds/updates the policy items.strategy: 'replace'rewrites the wholeoverridesobject.file:paths are written relative to the project root so they are valid inside project-leveloh-package.json5.- Module-level
profiles.<profile>.modulesrules are intentionally ignored in v2. Move dependency versions that should be forced globally intoprofiles.<profile>.app.overrides. - A report is written to
build/dependency-policy/overrides-report.json.
