Skip to content

Commit

Permalink
Merge pull request #25 from losandes/feat/es-module-support
Browse files Browse the repository at this point in the history
feat: adds es module support
  • Loading branch information
losandes authored Feb 24, 2023
2 parents a9bea04 + 25f6ce3 commit 61317bb
Show file tree
Hide file tree
Showing 22 changed files with 2,057 additions and 1,792 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This workflow will publish the npm package when a release is created

name: NPM publish

on:
release:
# This specifies that the build will be triggered when we publish a release
types: [published]

jobs:
build:

# Run on latest version of ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
# "ref" specifies the branch to check out.
# "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted
ref: ${{ github.event.release.target_commitish }}
# install Node.js
- name: Use Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18
# Specifies the registry, this field is required for publishing below!
registry-url: https://registry.npmjs.org/

- name: ENVVARS
env:
EVENT_CONTEXT: ${{ toJson(github.event) }}
run: |
git config --global user.name "losandes cicd"
git config --global user.email "[email protected]"
echo "node: $(node --version)"
echo "npm: $(npm --version)"
# echo "EVENT_CONTEXT:"
# echo "$EVENT_CONTEXT"

- name: Install packages
run: |
npm i -g pnpm
pnpm install
- name: Run tests
env:
CI: true
run: pnpm run test:ci

# upgrade npm version in package.json to the tag used in the release.
- name: Set package version
run: npm version ${{ github.event.release.tag_name }}

# publish the package to NPM and set the tag name to the branch name that
# the release is targeting (i.e. latest, latest-v1, etc.)
# Note that npm publish commits a tag to git
# alsosee: https://michaelzanggl.com/articles/github-actions-cd-setup/
- name: Publish to NPM
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --tag ${{ github.event.release.target_commitish }}

- name: Push version change to latest
env:
# The secret is passed automatically. Nothing to configure.
github-token: ${{ secrets.GITHUB_TOKEN }}
run: git push
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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: tests
name: Pull Request Verification

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

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -41,6 +41,11 @@ jobs:
run: pnpm run build --if-present

- name: Run tests
run: pnpm run test:ci
env:
CI: true

- name: Run coverage
run: pnpm run test:coverage:ci
env:
CI: true
Expand Down
8 changes: 6 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
coverage
npm-debug.log
build.js
CONTRIBUTING.md
examples-typescript.js
examples-typescript.ts
index.browser.js
index-browser.js
jsconfig.json
pre-push.js
test-browser-server.js
test-browser.js
test-one.js
test.js
test-default.mjs
test-exports.mjs
test.cjs
*.test.js
tsconfig.json
.coveralls.yml
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
How to Contribute
=================

## Pull Requests

Generally we like to see pull requests that:

- Maintain the existing code style
- Include usage examples (e.g. how to use new features or before and after examples that demonstrate the change to existing features)
- Are focused on a single change (i.e. avoid large refactoring or style adjustments in untouched code if not the primary goal of the pull request)
- Have [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
- Have tests
- Don't decrease the current code coverage
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const path = require('path')
const babel = require('@babel/core')
const ignoreExpression = /.([-.]test(s?)\.js)|([-.]spec(s?)\.js)|(index.browser.js)$/i
const ignoreExpression = /.([-.]test(s?)\.js)|([-.]spec(s?)\.js)|(index-browser.js)$/i
const walkSync = (dir) =>
fs.readdirSync(dir).reduce((files, file) => {
if (ignoreExpression.test(file)) {
Expand All @@ -13,7 +13,7 @@ const walkSync = (dir) =>
return isDirectory ? [...files, ...walkSync(name)] : [...files, name]
}, [])

const template = fs.readFileSync('./index.browser.js').toString().split('// MODULES_HERE')
const template = fs.readFileSync('./index-browser.js').toString().split('// MODULES_HERE')
const beginning = template[0]
const end = template[1]
const modules = [beginning]
Expand Down
Loading

0 comments on commit 61317bb

Please sign in to comment.