Skip to content

Commit

Permalink
feat: export commonjs and esm from package
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasholzer committed Oct 11, 2023
1 parent e7eaff2 commit 4da7d7a
Show file tree
Hide file tree
Showing 6 changed files with 1,327 additions and 28 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
48 changes: 48 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: prerelease
on:
push:
branches:
# releases/<tag>/<version>
# releases/rc.1/2.0.0 - will result in 2.0.0-rc.0
- releases/*/*
jobs:
prerelease:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: lts/*
cache: npm
registry-url: 'https://registry.npmjs.org'
- name: Install core dependencies
run: npm ci --no-audit
- name: Extract tag and version
id: extract
run: |-
ref=${{ github.ref }}
branch=${ref:11}
tag_version=${branch:9}
tag=${tag_version%/*}
version=${tag_version##*/}
echo "tag=${tag}" >> $GITHUB_OUTPUT
echo "version=${version}" >> $GITHUB_OUTPUT
- name: Log versions
run: |-
echo tag=${{ steps.extract.outputs.tag }}
echo version=${{ steps.extract.outputs.version }}
- name: Setup git user
run: git config --global user.name github-actions
- name: Setup git email
run: git config --global user.email [email protected]
- name: Run npm version
run: npm version ${{ steps.extract.outputs.version }}-${{ steps.extract.outputs.tag }} --allow-same-version
- name: Push changes
run: git push --follow-tags
- name: Run npm publish
run: npm publish --tag=${{ steps.extract.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
22 changes: 22 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
import { rm } from 'node:fs/promises'
import { argv } from 'process'

// eslint-disable-next-line import/no-extraneous-dependencies
import { build } from 'tsup'

const dist = './dist'

await rm(dist, { recursive: true, force: true })

/** @type {import('tsup').Options} */
const options = {
entry: ['src/main.ts'],
tsconfig: 'tsconfig.json',
bundle: true,
dts: true,
outDir: dist,
watch: argv.includes('--watch'),
}

await Promise.all(['esm', 'cjs'].map((format) => build({ ...options, format })))
Loading

0 comments on commit 4da7d7a

Please sign in to comment.