pubber-subber v0.1.0
Getting started
This small library is bundled via webpack and the bundles is output to a lib
folder.
To run this project locally you can:
npm install
will install all necessary packages - be sure you are using Node >= 10
npm start
will start webpack and evaluate changes in real time. This can be useful when linking with another app to test a new component or change.
Versioning and Publishing
In order to publish your own version of this library, you will need to create an NPM account https://www.npmjs.com/
Now, change the name
and version
of your library:
After making the proper changes, you can run the one of the following commands to create a new version of your library and publish it to the npm registry so others can use it.
npm version minor
should be used for the majority of changes which should be any NON-BREAKING change
npm version major
should be used for any BREAKING change and you and the reviewer should agree on whether this version upgrade is appropriate or not
npm version patch
should be reserved for small bugfixes.
After successfully creating the new version, publish it to npm using the following command:
npm publish
How to npm-link
You will want to test your changes as they would appear in the front end using this library. You can achieve this using npm link
. Basically a way to test your changes before publishing by creating a link in your file system.
Use this app for testing npm-linking: https://github.com/CodeCoachJS/js_pro_npm_library
In this library terminal - npm link
and then npm start
In the front end application terminal - npm link my-pubsub
or whatever the name
area in your package.json
file contains.
If you run into issues it's best to nuke all node_modules in your front end app, reinstall and then re-link the library.
TODO
Uh oh, looks like someone published a version of this library with a broken test.
Fix the broken test by implementing the logic then npm link
this project with the following repo: https://github.com/CodeCoachJS/js_pro_npm_library to ensure it works.
Once you've confirmed the functionality is working as expected, publish a new version (minor version).
To publish your own version of this library:
- Create an account on npmjs.com
- In your terminal
npm login
and follow the prompts to login - Change the name of the app in
package.json
to whatever you want your app to be named npm version [minor | major | patch]
npm publish
- Navigate to your account on npmjs.com and check that your library has been successfully published
How can you ensure that this kind of mistake does not happen again? Try adding a code-pipeline using Github Actions or a simple check before the npm version
command to make sure tests pass.
BONUS: update the webpack config to exclude any test files in the bundle. I mean why include tests when they're not needed for the end user?
1 year ago