Skip to content

Commit

Permalink
Fix ESM imports and tree-shaking (#363)
Browse files Browse the repository at this point in the history
chore(packaging): update import styles to use file suffixes to support ESM and tree-shaking
  • Loading branch information
trxcllnt authored May 21, 2024
1 parent dffd344 commit d31d2c5
Show file tree
Hide file tree
Showing 714 changed files with 17,196 additions and 3,481 deletions.
7 changes: 0 additions & 7 deletions .esdoc.json

This file was deleted.

6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.eslintrc.cjs
gulp
jest.config.js
jestconfigs
targets
integration
1 change: 1 addition & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
node: true,
},
parser: "@typescript-eslint/parser",
ignorePatterns: ["spec/bundle/**/*.js"],
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Bundle

on:
workflow_call:

jobs:
test-tree-shaking-pull-request:
name: ${{ matrix.bundler }} ${{ matrix.target }} ${{ matrix.module }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
bundler: [esbuild, rollup, webpack]
target: [es5, es2015, esnext]
module: [cjs, esm, umd]
include:
- {bundler: esbuild, target: ix}
- {bundler: rollup, target: ix}
- {bundler: webpack, target: ix}
steps:
- name: Setup node v20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "20.x", "ix", "", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
- name: Cache targets
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.targets_key), '-') }}
path: targets

- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules

- name: Test ${{ matrix.bundler }} tree-shaking
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
integration/make-files-to-bundle.sh
if test "${t}" != ix; then
yarn build ${t:+-t ${t}} ${m:+-m ${m}}
fi
yarn gulp bundle${t:+:${t}}${m:+:${m}}:${{ matrix.bundler }}
8 changes: 5 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ jobs:
container: node:16.15.1-bullseye
steps:
- name: Checkout main
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: main
persist-credentials: false
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
persist-credentials: false
- name: Build Docs
working-directory: main
run: |
set -x
yarn --ignore-optional --ignore-engines --non-interactive
yarn --ignore-engines --non-interactive
yarn doc
- name: Copy Docs to gh-pages
run: |
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Lint

on:
workflow_call:

jobs:
lint-pull-request:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Setup node v20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules

- name: Check if source or test files changed
id: files_changed
uses: tj-actions/changed-files@v44
with:
files: |
src/**/*
spec/**/*
- name: Lint files
if: ${{ steps.files_changed.outputs.any_modified == 'true' }}
run: |
yarn --ignore-engines --non-interactive
yarn lint:ci
117 changes: 15 additions & 102 deletions .github/workflows/main.pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Build pull request
name: PR

concurrency:
group: pr-on-${{ github.event_name }}-from-${{ github.ref_name }}
cancel-in-progress: true

on:
pull_request:
Expand All @@ -7,106 +11,15 @@ on:

jobs:
lint-pull-request:
name: Lint pull request
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
node: [18.x]
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Checkout
uses: actions/checkout@v3

- name: Cache node_modules
uses: actions/cache@v2
with:
key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ hashFiles('package.json') }}
path: |
node_modules
- name: Check if source or test files changed
id: files_changed
uses: tj-actions/changed-files@v41
with:
files: |
src/**/*
spec/**/*
- name: Install dependencies
if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }}
run: |
yarn
- name: Lint files
if: ${{ steps.files_changed.outputs.any_changed == 'true' || steps.files_changed.outputs.any_deleted == 'true' }}
run: |
yarn lint:ci
name: Lint
uses: ./.github/workflows/lint.yml

build-and-test-pull-request:
needs:
- lint-pull-request
name: Build and test pull request
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
node: [14.x, 16.x, 18.x]
module: [cjs, esm, umd]
target: [es5, es2015, esnext]
exclude:
- {node: 14.x, target: esnext}
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Checkout
uses: actions/checkout@v3

- name: Cache targets
uses: actions/cache@v2
with:
key: ${{ runner.os }}-targets-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }}
path: |
targets
- name: Cache node_modules
uses: actions/cache@v2
with:
key: ${{ runner.os }}-node_modules-${{ matrix.node }}-${{ matrix.target }}-${{ matrix.module }}-${{ hashFiles('package.json') }}
path: |
node_modules
- name: Check if test files changed
id: test_files_changed
uses: tj-actions/changed-files@v41
with:
files: |
spec/**/*
- name: Check if source files changed
id: source_files_changed
uses: tj-actions/changed-files@v41
with:
files: |
src/**/*
- name: Install dependencies
if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }}
run: |
yarn --ignore-optional --ignore-engines --non-interactive
- name: Build package
if: ${{ steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }}
run: |
yarn build -t ${{ matrix.target }} -m ${{ matrix.module }}
- name: Test package
if: ${{ steps.test_files_changed.outputs.any_changed == 'true' || steps.test_files_changed.outputs.any_deleted == 'true' || steps.source_files_changed.outputs.any_changed == 'true' || steps.source_files_changed.outputs.any_deleted == 'true' }}
run: |
yarn test -t ${{ matrix.target }} -m ${{ matrix.module }}
name: Test
needs: lint-pull-request
uses: ./.github/workflows/test.yml

test-tree-shaking-pull-request:
needs: build-and-test-pull-request
name: Bundle
uses: ./.github/workflows/bundle.yml
Loading

0 comments on commit d31d2c5

Please sign in to comment.