|
| 1 | +# npm Publishing Setup |
| 2 | + |
| 3 | +This repository now supports publishing to both JSR (JavaScript Registry) and npm. Here's what was added: |
| 4 | + |
| 5 | +## Files Added/Modified |
| 6 | + |
| 7 | +### Build Scripts |
| 8 | +- `scripts/build_npm.ts` - Primary build script using dnt (Deno Node Transform) |
| 9 | +- `scripts/build_npm_manual.ts` - Fallback manual build script for network issues |
| 10 | + |
| 11 | +### GitHub Actions |
| 12 | +- `.github/workflows/publish.yml` - Updated to publish to both JSR and npm |
| 13 | +- `.github/workflows/npm-build-test.yml` - Tests npm build on PRs |
| 14 | + |
| 15 | +### Configuration |
| 16 | +- `deno.jsonc` - Added npm build tasks |
| 17 | +- `.gitignore` - Added npm/ directory to ignore build artifacts |
| 18 | + |
| 19 | +### Documentation |
| 20 | +- `README.md` - Updated with npm installation instructions and dual import examples |
| 21 | + |
| 22 | +## How It Works |
| 23 | + |
| 24 | +1. **Primary Method (dnt)**: Uses Deno Node Transform to automatically convert Deno TypeScript code to npm-compatible JavaScript packages with proper Node.js shims. |
| 25 | + |
| 26 | +2. **Fallback Method (manual)**: Performs basic TypeScript-to-JavaScript conversion by processing files directly. This is used when network issues prevent dnt from downloading dependencies. |
| 27 | + |
| 28 | +3. **Dual Publishing**: GitHub Actions workflow publishes to both JSR and npm when tags are pushed. |
| 29 | + |
| 30 | +## Package Structure |
| 31 | + |
| 32 | +The npm package will include: |
| 33 | +- ESM format JavaScript files |
| 34 | +- TypeScript definition files |
| 35 | +- All exports from `deno.jsonc` mapped to npm package exports |
| 36 | +- Support for both import and require (ESM/CommonJS) |
| 37 | +- Node.js compatibility shims for Deno APIs |
| 38 | + |
| 39 | +## For Repository Owner |
| 40 | + |
| 41 | +To enable npm publishing: |
| 42 | + |
| 43 | +1. Create npm account at https://www.npmjs.com/signup |
| 44 | +2. Generate automation token at https://www.npmjs.com/settings/tokens |
| 45 | +3. Add token as `NPM_TOKEN` secret in repository settings |
| 46 | +4. Push a git tag to trigger publishing to both JSR and npm |
| 47 | + |
| 48 | +The package will be published as `@cosense/std` on npm (same as JSR name). |
0 commit comments