Extend
publishConfig
to support any property
publishConfig
is a set of config values that will be used at publish-time (or
pack-time). It's especially handy if you want to set different property values in
your package.json at publish/pack time than before. Yarn by default supports only a
handful of
properties in publishConfig
.
This plugin allows yarn to support any property starting with $
.
yarn plugin import https://raw.githubusercontent.com/alizeait/yarn-plugin-publishconfig/v1.0/bundles/@yarnpkg/plugin-publishconfig.js
- Original
package.json
{
"name": "packageName",
"scripts": {
"build": "build"
},
"main": "src/index.ts",
"publishConfig": {
// yarn supports `main` by default
"main": "dist/index.js",
// yarn does not support this by default
"$oclif.commands": "dist/cli/commands"
},
"oclif": {
"commands": "./cli/commands",
"bin": "cmc"
}
}
package.json
after publishing or packing
{
"name": "packageName",
"scripts": {
"build": "build"
},
// yarn replaces `main` with `publishConfig.main` by default
"main": "./dist/index.ts",
"publishConfig": {
"main": "./dist/index.js",
"$oclif.commands": "./dist/cli/commands"
},
// yarn now supports `publishConfig.$oclif.commands` and replaces `oclif.commands` with it
"oclif": {
"commands": "./dist/cli/commands",
"bin": "cmc"
}
}
You can use any supported replacement string by
dset. But keep in mind that each
property inside publishConfig
has to start with $
to be considered (except the default ones supported by yarn).
{
"publishConfig": {
"main": "./dist/index.js",
// supports primitives
"$anyProperty": "value",
// supports nested objects
"$oclif.commands": "./dist/cli/commands",
// supports arrays as well
"$array.1.a.b.1": "./dist/cli/commands"
}
}