diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 13b7411..489ceae 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,8 +1,8 @@ name: publish npm package on: - release: - types: [created] + push: + tags: [v*] jobs: publish-npm: @@ -11,8 +11,9 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 - registry-url: https://registry.npmjs.org/ + node-version: 18 + - run: yarn --ignore-engines + - run: node build.js - run: npm publish env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ee5f43..b538227 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,8 @@ name: test every commit on: - - push + push: + branches: + - master jobs: test: @@ -11,5 +13,5 @@ jobs: with: node-version: 18 - run: yarn --ignore-engines - - run: node build.cjs + - run: node build.js - run: yarn test diff --git a/.gitignore b/.gitignore index e14ae2f..f9940ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,5 @@ dist yarn.lock package-lock.json .envrc -standalone -cjs -esm +lib test.html diff --git a/README.md b/README.md index c96ccf2..08d9bec 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Please consult the tests or [the source code](https://github.com/fiatjaf/nostr-t ### Using from the browser (if you don't want to use a bundler) ```html - + diff --git a/build.cjs b/build.js similarity index 71% rename from build.cjs rename to build.js index 1b0999c..8ab1ee7 100755 --- a/build.cjs +++ b/build.js @@ -15,17 +15,27 @@ let common = { } esbuild - .build({...common, outdir: 'esm/', format: 'esm', packages: 'external'}) + .build({ + ...common, + outfile: 'lib/nostr.esm.js', + format: 'esm', + packages: 'external' + }) .then(() => console.log('esm build success.')) esbuild - .build({...common, outdir: 'cjs/', format: 'cjs', packages: 'external'}) + .build({ + ...common, + outfile: 'lib/nostr.cjs.js', + format: 'cjs', + packages: 'external' + }) .then(() => console.log('cjs build success.')) esbuild .build({ ...common, - outdir: 'standalone/', + outfile: 'lib/nostr.bundle.js', format: 'iife', globalName: 'NostrTools', define: { diff --git a/event.test.js b/event.test.js index 0e77547..71e50bc 100644 --- a/event.test.js +++ b/event.test.js @@ -6,7 +6,7 @@ const { signEvent, getEventHash, getPublicKey -} = require('./cjs') +} = require('./lib/nostr.cjs') const event = { id: 'd7dd5eb3ab747e16f8d0212d53032ea2a7cadef53837e5a6c66d42849fcb9027', diff --git a/filter.test.js b/filter.test.js index ecc5002..61aa9f7 100644 --- a/filter.test.js +++ b/filter.test.js @@ -1,6 +1,6 @@ /* eslint-env jest */ -const {matchFilters} = require('./cjs') +const {matchFilters} = require('./lib/nostr.cjs') test('test if filters match', () => { ;[ diff --git a/keys.test.js b/keys.test.js index ac0e65b..2c70487 100644 --- a/keys.test.js +++ b/keys.test.js @@ -1,6 +1,6 @@ /* eslint-env jest */ -const {generatePrivateKey, getPublicKey} = require('./cjs') +const {generatePrivateKey, getPublicKey} = require('./lib/nostr.cjs') test('test private key generation', () => { expect(generatePrivateKey()).toMatch(/[a-f0-9]{64}/) diff --git a/nip04.test.js b/nip04.test.js index 0de777e..581f7a3 100644 --- a/nip04.test.js +++ b/nip04.test.js @@ -1,6 +1,6 @@ /* eslint-env jest */ -const {nip04, getPublicKey, generatePrivateKey} = require('./cjs') +const {nip04, getPublicKey, generatePrivateKey} = require('./lib/nostr.cjs') test('encrypt and decrypt message', () => { let sk1 = generatePrivateKey() diff --git a/package.json b/package.json index a8a020f..675766d 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "nostr-tools", - "version": "1.0.0-alpha", + "version": "1.0.0-alpha2", "description": "Tools for making a Nostr client.", "repository": { "type": "git", "url": "https://github.com/fiatjaf/nostr-tools.git" }, - "main": "cjs/index.js", - "module": "esm/index.js", + "main": "lib/nostr.cjs.js", + "module": "lib/nostr.esm.js", "dependencies": { "@noble/hashes": "^0.5.7", "@noble/secp256k1": "^1.7.0", @@ -40,8 +40,8 @@ "typescript": "^4.9.4" }, "scripts": { - "build": "node build.cjs", - "pretest": "node build.cjs", + "build": "node build.js", + "pretest": "node build.js", "test": "jest" } } diff --git a/relay.test.js b/relay.test.js index e9fc9b6..40a6a3b 100644 --- a/relay.test.js +++ b/relay.test.js @@ -6,7 +6,7 @@ const { getPublicKey, getEventHash, signEvent -} = require('./cjs') +} = require('./lib/nostr.cjs') describe('relay interaction', () => { let relay = relayInit('wss://nostr-pub.semisol.dev/')