|
| 1 | +# Publishing the NPM Package @web-auth/webauthn-stimulus |
| 2 | + |
| 3 | +## Automatic Publishing (Recommended) |
| 4 | + |
| 5 | +The package is automatically published to NPM when a Git tag is created. The GitHub Actions workflow triggers automatically. |
| 6 | + |
| 7 | +### Process: |
| 8 | + |
| 9 | +1. Create a Git tag with the version number: |
| 10 | + ```bash |
| 11 | + git tag 5.2.3 |
| 12 | + git push origin 5.2.3 |
| 13 | + ``` |
| 14 | + |
| 15 | +2. The GitHub Actions workflow will: |
| 16 | + - Detect the new tag |
| 17 | + - Install dependencies |
| 18 | + - Run tests |
| 19 | + - Update the version in package.json |
| 20 | + - Publish to NPM |
| 21 | + - Create a GitHub release |
| 22 | + |
| 23 | +## Manual Publishing |
| 24 | + |
| 25 | +If you need to publish manually (e.g., for testing): |
| 26 | + |
| 27 | +### Prerequisites: |
| 28 | +- NPM account with write access to the `@web-auth/webauthn-stimulus` package |
| 29 | +- Configured NPM token or local NPM authentication |
| 30 | + |
| 31 | +### Steps: |
| 32 | + |
| 33 | +1. **Navigate to the project root:** |
| 34 | + ```bash |
| 35 | + cd /path/to/webauthn-framework |
| 36 | + ``` |
| 37 | + |
| 38 | +2. **Install dependencies:** |
| 39 | + ```bash |
| 40 | + npm ci |
| 41 | + ``` |
| 42 | + |
| 43 | +3. **Run tests:** |
| 44 | + ```bash |
| 45 | + # Tests must be run from the root because the project uses npm workspaces |
| 46 | + npm test |
| 47 | + # OR use castor (recommended): |
| 48 | + # php castor.php js |
| 49 | + ``` |
| 50 | + |
| 51 | +4. **Update the version:** |
| 52 | + ```bash |
| 53 | + cd src/stimulus/assets |
| 54 | + # Replace X.Y.Z with the desired version (must match the Git tag) |
| 55 | + npm version X.Y.Z --no-git-tag-version |
| 56 | + cd ../../.. |
| 57 | + ``` |
| 58 | + |
| 59 | +5. **Log in to NPM (if necessary):** |
| 60 | + ```bash |
| 61 | + npm login |
| 62 | + # OR with a token: |
| 63 | + # export NPM_TOKEN=your-npm-token |
| 64 | + # echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc |
| 65 | + ``` |
| 66 | + |
| 67 | +6. **Publish to NPM:** |
| 68 | + ```bash |
| 69 | + cd src/stimulus/assets |
| 70 | + npm publish --access public |
| 71 | + cd ../../.. |
| 72 | + ``` |
| 73 | + |
| 74 | +7. **Verify the publication:** |
| 75 | + ```bash |
| 76 | + npm view @web-auth/webauthn-stimulus |
| 77 | + ``` |
| 78 | + |
| 79 | +### Important notes on workspaces: |
| 80 | + |
| 81 | +The project uses **npm workspaces**, so: |
| 82 | +- Development dependencies (Babel, Jest, etc.) are in the root `package.json` |
| 83 | +- Tests must be run from the root with `npm test` |
| 84 | +- The package itself is in `src/stimulus/assets/` and that's where you publish from |
| 85 | + |
| 86 | +### Test Publishing (dry-run): |
| 87 | + |
| 88 | +To test the publication without actually publishing: |
| 89 | + |
| 90 | +```bash |
| 91 | +cd src/stimulus/assets |
| 92 | +npm pack --dry-run |
| 93 | +``` |
| 94 | + |
| 95 | +This will show what would be included in the package without publishing it. |
| 96 | + |
| 97 | +### Unpublish a Publication (within 72h): |
| 98 | + |
| 99 | +If you need to cancel a publication: |
| 100 | + |
| 101 | +```bash |
| 102 | +npm unpublish @web-auth/webauthn-stimulus@X.Y.Z |
| 103 | +``` |
| 104 | + |
| 105 | +⚠️ **Warning**: This should only be used in case of a critical error. |
| 106 | + |
| 107 | +## Important Notes: |
| 108 | + |
| 109 | +- The version in `package.json` is `0.0.0-dev` by default |
| 110 | +- It is replaced by the tag version during publication |
| 111 | +- The package is published from `src/stimulus/assets/` |
| 112 | +- Only files listed in the `files` property of `package.json` are included |
| 113 | +- Tests must pass before publication (enforced by CI/CD) |
| 114 | + |
| 115 | +## Post-Publication Verification: |
| 116 | + |
| 117 | +1. Check on NPM: https://www.npmjs.com/package/@web-auth/webauthn-stimulus |
| 118 | +2. Test installation in a project: |
| 119 | + ```bash |
| 120 | + npm install @web-auth/webauthn-stimulus@X.Y.Z |
| 121 | + ``` |
0 commit comments