How to create and publish NPM modules.
For the time being the project scaffold expects TypeScript files.
For a full documentation of npm usage and commands see https://docs.npmjs.com
This describes how to create a new module from scratch. If you want to fork an existing project (recommended for new npm modules), see the step "Forking a project" further down.
- Create a Git repository.
- Clone the newly created repository to a folder on your machine.
- Create a folder in the project named src, all the source code will go here.
npm initfrom a console window (cmd/bash etc.) in the project root and follow the steps displayed to create package.json.
- Ensure that the package name is prefixed with
- Create an
- In the index file, export the modules from the src folder that you wish to expose.
npm publishfrom the root of the project (double check that the project name in
@seges/as prefix, otherwise the package is published outside the seges organization scope).
- Scoped packages are private by default, to make it public, run
npm publish --access publicinstead.
- Remember to also checkin changes in Git.
Now the module should be available for installation by running
npm install <name-of-your-package> from any other project.
Updating an existing package.
- Checkout the module's Git repository.
- Perform your needed changes.
- When done with your changes run
npm version major|minor|patch -m <message>from the root of the project.
- For more information on semantic versioning see: http://semver.org/.
- Publish your package by running
npm publish --access public.
- Remember to also push changes to Git.
The module should be updated.
Logging in to http://www.npmjs.org you should be able to find and see the new version of the updated package.
Unpublishing a package
In general you should not unpublish packages as other projects might depend on them.
Instead you should update the package with a new version containing fixes of the broken version by following the steps above.
But in the event you need to unpublish, you can run
npm unpublish <@scope/><package name>@<version> to unpublish that version.
Note that even though a version is unpublished, a new publish of the same version is not possible unless the entire project is taken down.
Forking a project
SEGES_NPM project can be used as a scaffold or base for a new npm module as it contains various necessary files required to run unit tests.
To fork a project:
- Create a new git repository.
- Check out the SEGES_NPM project.
- Open a console at the root of the SEGES_NPM project.
- Run the command
git remote set-url origin <url-of-the-project-created-in-step-1>
- Run the command
git push origin master
- Rename your root project folder to the name of the repository created in step 1.
- Remove the project locally and checkout the repository created in step 1.
Run through the
package.json and remove comments, as they are not valid
You should now have a new project with the contents of SEGES_NPM.