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
aliasandexternalsin 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@derivpackages from thepackage.jsonso they will not be added asdependencieswhen 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@derivpackages 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_modulesand 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 thepostpublishlogic 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