pika-plugin-package.json
v1.0.2
Published
@pika/pack build plugin to modify package.json file
Readme
pika-plugin-package.json
@pika/pack build plugin to modify package.json file.
Install
$ yarn add --dev pika-plugin-package.jsonOr using npm
$ npm install --save-dev pika-plugin-package.jsonUsage
{
"name": "example-package-json",
"version": "1.0.0",
"@pika/pack": {
"pipeline": [
// ---8<---
[
"pika-plugin-package.json",
{
"+dependencies": {
"lodash": "^"
},
"*keywords": ["+example"],
"*files": ["-bin/"],
"+author": "^",
"-devDependencies": {}
}
]
]
}
}Options
Pass any object, and it will be merged to result pkg/package.json
There are three modifiers, which you can add to properties / array items:
-: remove this property / item*: merge this property (if there is no such property - it will be added)+: add this property / item (if already exists - it will be replaced)
By default (without modifier) - merge (*) is applied. But I recomment always define modifiers for more expressness and clarity.
If you want, for some reason, add property named *prop (for example) — you can escape modifier like this - \\*prop - or just explicitly define needed modifier - +*prop - as I recommended before.
For example
"+license": "MIT"
will add (or replace) license field.
"-devDependencies": {}
will remove devDependencies (value is not really matters here).
"*dependencies": { "lodash": "^4.17.15" }
will add lodash dependency to existing dependencies (or will create dependencies with lodash, if there were no any dependencies).
"*files": ["-bin/"]
will remove bin/ item from files property.
Inheritance
You can specify special value ^ to any property, and value will be populated from original package.json. For example:
"+author": "^"
will add author field with value from original package.json (if defined).
This should work on any deep level, but only with object properties (no arrays).
Real world example
You can check this package's package.json, I use pika-plugin-package.json in pipeline to modify pika-plugin-package.json's package.json ^_^
