This guide will walk you through publishing the ngxsmk-gatekeeper library to npm.
-
npm account: You need an npm account. Create one at npmjs.com if you don't have one.
-
Login to npm:
npm login
Enter your username, password, and email when prompted.
-
Verify you're logged in:
npm whoami
Before publishing, make sure:
- Version is updated in
projects/ngxsmk-gatekeeper/package.json - Author field is filled in
projects/ngxsmk-gatekeeper/package.json - Repository URL is correct (not placeholder)
- All tests pass:
npm test - Library builds successfully:
npm run build - README.md is up to date
- No sensitive information in the package
Edit projects/ngxsmk-gatekeeper/package.json and ensure:
authorfield is filled (e.g.,"Your Name <your.email@example.com>")repository.urlpoints to your actual GitHub repositorybugs.urlpoints to your actual GitHub issues URLhomepagepoints to your actual repository
Build the library for production:
npm run buildThis will create the distributable files in dist/ngxsmk-gatekeeper/.
Check that the build output looks correct:
ls -la dist/ngxsmk-gatekeeper/You should see:
package.json(copied fromprojects/ngxsmk-gatekeeper/package.json)fesm2022/directory with compiled JavaScriptlib/directory with compiled modulesindex.d.tsand other TypeScript definition filesREADME.md(if included)
Before publishing, test the package locally:
cd dist/ngxsmk-gatekeeper
npm packThis creates a .tgz file. You can install it in another project to test:
npm install /path/to/ngxsmk-gatekeeper-1.0.0.tgzVerify the package name is available on npm:
npm view ngxsmk-gatekeeperIf it returns 404, the name is available. If it returns package info, the name is taken.
Note: If the name is taken, you'll need to:
- Choose a different name, or
- Use a scoped package name like
@your-username/ngxsmk-gatekeeper
To use a scoped package, update the name in projects/ngxsmk-gatekeeper/package.json:
{
"name": "@your-username/ngxsmk-gatekeeper"
}Navigate to the dist directory and publish:
cd dist/ngxsmk-gatekeeper
npm publishFor scoped packages (if you used @your-username/ngxsmk-gatekeeper), make it public:
npm publish --access publicCheck that your package is published:
npm view ngxsmk-gatekeeperOr visit: https://www.npmjs.com/package/ngxsmk-gatekeeper
You can use the provided npm scripts:
# Build and publish in one command
npm run build && cd dist/ngxsmk-gatekeeper && npm publish
# Or use the publish script (if added)
npm run publish:libWhen releasing a new version:
-
Update version in
projects/ngxsmk-gatekeeper/package.json:- Patch:
1.0.0→1.0.1(bug fixes) - Minor:
1.0.0→1.1.0(new features) - Major:
1.0.0→2.0.0(breaking changes)
- Patch:
-
Update version in root
package.json(optional, for consistency) -
Update CHANGELOG.md (if you have one)
-
Build and publish:
npm run build cd dist/ngxsmk-gatekeeper npm publish
- Make sure you're logged in:
npm whoami - Check if the package name is already taken by someone else
- If it's a scoped package, use
--access public
- The package name
ngxsmk-gatekeeperis already taken - Use a scoped package name:
@your-username/ngxsmk-gatekeeper - Or choose a different name
- Package names must be lowercase
- Can contain hyphens and underscores
- Cannot start with a dot or underscore
- Max 214 characters
- Make sure all dependencies are installed:
npm install - Check TypeScript compilation:
npm run build - Review error messages and fix issues
After successful publication:
-
Create a Git tag:
git tag v1.0.0 git push origin v1.0.0
-
Create a GitHub release (optional but recommended):
- Go to your GitHub repository
- Click "Releases" → "Create a new release"
- Tag:
v1.0.0 - Title:
v1.0.0 - Initial Release - Add release notes
-
Update documentation if needed
-
Announce on social media, forums, etc.
- Always test locally before publishing
- Follow semantic versioning (semver)
- Write clear release notes
- Tag releases in Git
- Keep CHANGELOG.md updated
- Test the published package in a fresh project