On Postman, we made use of a local node module to share code between frontend
, backend
& worker
. It is similar to how one would install npm modules from npm registry or github, except that the path is pointed to a local folder.
ie: "postman-templating": "file:../modules/postman-templating"
.
We wanted to find a way to share the templating logic because:
- Used in frontend, backend & worker.
- Better consistency, we just have to change the code in one place rather than three.
There are several options that we considered:
- npm install from separate repo (postmangovsg-js-tools?)
- npm pack and copy tarball into respective folders
- Publish to npm registry
- Separate branch (sdk branch)
- Use lerna to manage multi-package repo
- local node module
We decided to use local shared module as the rest of the options are more complicated or requires alot more time & effort to set them up.
Any shared module can be installed using npm install ../modules/postman-templating
.
To test the changes you want to make to a module like postman-templating
:
- Make changes to the module.
- Run
npm start build
inpostman-templating
.
npm start build
will remove & replace the build
folder in postman-templating
with the updated change.
If there are any new dependencies installed in the local node module, the parent folder's package-lock.json
needs to be updated. This can be done through deleting the node_modules
and running npm install
.
- Install dependency in
postman-templating
. - Run
npm start build
inpostman-templating
. - Delete
node_modules
in the parent folder. egbackend
orfrontend
. - Run
npm install
in the parent folder - Parent folder's
package-lock.json
should be updated.
Any dependencies that are needed to build the local module should be installed as a dependency
instead of a dev-dependency
because when we deploy, we will run npm ci
before building the module. npm ci
do not install dev-dependency
, which will cause the build to fail.