A tool that will help publish hybrid Deriv packages to the NPM registry.
A hybrid package is a package that is both built as part of Deriv App, but can also be published to the NPM registry by itself.
In this document
The @deriv/publisher
package exposes two things:
- An executable script that can be wrapped around your package's publish commands.
- A couple of Webpack utilities that will help set the correct
alias
andexternals
in the Webpack config.
The executable script (exposed as deriv-publisher
) takes a single argument (either prepublish
or postpublish
).
prepublish
: The script will remove any local@deriv
packages from thepackage.json
so they will not be added asdependencies
when pushed to the NPM registry. This won't break the code granted the Webpack utilities are set up in the Webpack config.postpublish
: The script will restore any local@deriv
packages to thepackage.json
.
The Webpack utilities help Webpack resolve imports to any local @deriv
dependencies:
getLocalDerivPackageAliases
: returns an object of aliases when creating a build for publishing, i.e. it will tell Webpack to ignore thenode_modules
and tells it where to look instead (in the local file path i.e. the absolute path of the executing file).getLocalDerivPackageExternals
: returns an object of externals when creating a build that won't be published, i.e. it will tell Webpack to not bundle these packages as they will be included by the consumer of this package.
Below is a simple example that could easily be extended.
- Please note the
;
afternpm publish
. This;
ensures that thepostpublish
logic is called regardless of the outcome ofnpm publish
, this is required to restore the originalpackage.json
.
{
"scripts": {
"publish_package": "deriv-publisher prepublish && npm publish; deriv-publisher postpublish"
}
}
The publish_package
command first removes local @deriv
packages using prepublish, then it publishes the package to the npm registry and restores the local @deriv
packages to package.json using postpublish
lerna exec --scope=@deriv/package -- npm i @deriv/publisher@^v0.0.1-beta4 --save-dev