Skip to content

Commit

Permalink
Merge pull request #40 from curveball/esm
Browse files Browse the repository at this point in the history
ESM support
  • Loading branch information
evert authored Feb 14, 2023
2 parents ccdbd5a + e207721 commit 3f29349
Show file tree
Hide file tree
Showing 11 changed files with 838 additions and 671 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Bun Test Runner

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
bun-test:
name: Bun tests

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Bun
uses: antongolub/action-setup-bun@v1
- run: bun install
- run: bun run build
- run: bun run mocha
39 changes: 24 additions & 15 deletions .github/workflows/ci.yml → .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI
name: Node.js Test Runner

on:
push:
Expand All @@ -11,47 +11,56 @@ on:

jobs:
node-test:
name: Node.js tests
name: Node.js tests (ESM)

runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test

bun-test:
name: Bun tests
cjs-test:
name: Node.js tests (CommonJS)

runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Bun
uses: antongolub/action-setup-bun@v1
- run: bun install
- run: bun run build
- run: bun run mocha
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }} (CommonJS)
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: make test-cjs

lint:
name: Lint

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm ci
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand All @@ -36,14 +36,14 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
- run: npm ci
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
registry-url: 'https://npm.pkg.github.com'
scope: '@curveball'
- run: npm publish
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
/node_modules

# typescript output
/dist
/esm
/cjs

# Directory used for running tests in CommonJS mode
/cjs-test

# vim
.*.swp

# nyc
/.nyc_output

# bun!
/bun.lockb
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2022 Bad Gateway Inc.
Copyright (c) 2019-2023 Bad Gateway Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 24 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,50 @@ SOURCE_FILES:=$(shell find src/ -type f -name '*.ts')
all: build

.PHONY:build
build: dist/build
build: cjs/build esm/build

.PHONY:test
test:
node_modules/.bin/nyc node_modules/.bin/mocha
npx nyc mocha

.PHONY:test-cjs
test-cjs:
mkdir -p cjs-test
cd test; npx tsc --module commonjs --outdir ../cjs-test
echo '{"type": "commonjs"}' > cjs-test/package.json
cd cjs-test; npx mocha --no-package

.PHONY:lint
lint:
node_modules/.bin/eslint --quiet 'src/*.ts' 'test/*.ts'
npx eslint --quiet 'src/**/*.ts' 'test/**/*.ts'

.PHONY:lint-fix
lint-fix: fix

.PHONY:fix
fix:
node_modules/.bin/eslint --quiet 'src/**/*.ts' 'test/**/*.ts' --fix
npx eslint --quiet 'src/**/*.ts' 'test/**/*.ts' --fix

.PHONY:watch
watch:
node_modules/.bin/tsc --watch
npx tsc --watch

.PHONY:start
start: build

.PHONY:clean
clean:
rm -r dist
rm -rf dist esm cjs cjs-test

cjs/build: $(SOURCE_FILES)
npx tsc --module commonjs --outDir cjs/
echo '{"type": "commonjs"}' > cjs/package.json
@# Creating a small file to keep track of the last build time
touch cjs/build


dist/build: $(SOURCE_FILES)
node_modules/.bin/tsc
esm/build: $(SOURCE_FILES)
npx tsc --module es2022 --outDir esm/
echo '{"type": "module"}' > esm/package.json
@# Creating a small file to keep track of the last build time
touch dist/build
touch esm/build
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.5.0 (????-??-??)
------------------

* This package now supports ESM and CommonJS modules.
* No longer supports Node 14. Please use Node 16 or higher.


0.4.0 (2022-09-03)
------------------

Expand Down
Loading

0 comments on commit 3f29349

Please sign in to comment.