Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: full Node.js ESM runtime support (#54)
BREAKING CHANGE: umd builds are removed and all middleware imports are moved to `get-it/middleware`. Imports such as `import promise from 'get-it/lib-node/middleware/promise'` are no longer supported. The default import is replaced with a named one: change `import getIt from 'get-it'` to `import {getIt} from 'get-it'` Other changes - Migrated codebase to TypeScript, moving away from using `any` is out of scope for this PR but linter rules are setup to make it easier to do this refactor in a later PR. - The required Node.js version is moved from 12 to 14, as 12 does not support `pkg.exports`. - Tooling have moved to `@sanity/pkg-utils`, gone is `@babel/cli`, `browserify`, `esbuild`, `uglifyjs`, and more. - Replaced `mocha` testing suite with `vitest` to ensure the new ESM codebase runs the same way it'll run in production with codebases such as `sanity`. - The `pkg.exports` are refactored to follow our updated ESM best practices, spearheaded by `@sanity/pkg-utils`. It implements the Node.js `dual package hazard` technique to steer the Node.js ESM runtime back into CJS mode as half our `dependencies` aren't shipping ESM-runtime code yet. - The `pkg.exports` and build setup is also configured to generate browser code that is picked up by modern and legacy bundlers alike. It no longer uses `pkg.browser` to redirect package imports, instead there's `index.ts` and `index.browser.ts` entrypoints, and `middleware.ts` and `middleware.browser.ts`. These entrypoints use different imports on things that diverge depending on wether it's a `node` or `browser` runtime environment. The generated bundles are then self-contained and have much wider support than today's [super-complex `pkg.exports`](https://github.com/sanity-io/get-it/blob/8fecf9ff77e8805bb9ae1aac74b74d4d786a11ca/package.json#L42-L154) and [`pkg.browser`](https://github.com/sanity-io/get-it/blob/8fecf9ff77e8805bb9ae1aac74b74d4d786a11ca/package.json#L18-L41). - `pkg.type` is changed from `commonjs` to `module`. - Added `pkg.sideEffects: false` to enable much better tree-shaking in bundlers such as `webpack`. - Now shipping TypeScript types. - The `Deno` testing suite is updated to follow current best practice for deno's node.js interop. - Generated JS is now using the same `browserslist` setup as we do in the rest of our modern ecosystem as well as `sanity`. - All dependencies have been updated, to their latest version that still ships code that can run in both Node.js CJS and ESM runtimes. - Some packages have been inlined as they proved too problematic to use with TypeScript, such as `@sanity/timed-out` and `simple-concat` - Adds a `Lock thread` workflow that locks closed issues and PRs to avoid people commenting on them as we don't get notified by that, and it's best to help nudge people towards making new issues instead. - Also adds a prettier workflow that runs prettier if a push to `main` forgot to apply it.
- Loading branch information
Showing
141 changed files
with
8,365 additions
and
18,812 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
/coverage | ||
/dist | ||
/lib | ||
/lib-node | ||
/umd | ||
# ESLint isn't configured to deal with ESM yet | ||
/test-esm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:prettier/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
}, | ||
plugins: ['@typescript-eslint', 'simple-import-sort', 'prettier'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/member-delimiter-style': 'off', | ||
'@typescript-eslint/no-empty-interface': 'off', | ||
'simple-import-sort/imports': 'warn', | ||
'simple-import-sort/exports': 'warn', | ||
'no-console': 'error', | ||
'no-shadow': 'error', | ||
'no-warning-comments': ['warn', {location: 'start', terms: ['todo', '@todo', 'fixme']}], | ||
}, | ||
|
||
overrides: [ | ||
{ | ||
files: ['**/*.js'], | ||
rules: { | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: 'Lock Threads' | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
action: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: dessant/lock-threads@c1b35aecc5cdb1a34539d14196df55838bb2f836 # v4 | ||
with: | ||
issue-inactive-days: 0 | ||
pr-inactive-days: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
name: Prettier | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
run: | ||
name: 🤔 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3 | ||
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3 | ||
with: | ||
cache: npm | ||
node-version: lts/* | ||
- run: npm ci --ignore-scripts --only-dev | ||
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3 | ||
with: | ||
path: node_modules/.cache/prettier/.prettier-cache | ||
key: prettier-${{ hashFiles('package-lock.json') }}-${{ hashFiles('.gitignore') }} | ||
- name: check if workflows needs prettier | ||
run: npx prettier --cache --check ".github/workflows/**/*.yml" || (echo "An action can't make changes to actions, you'll have to run prettier manually" && exit 1) | ||
- run: npx prettier --ignore-path .gitignore --cache --write . | ||
- uses: EndBug/add-and-commit@61a88be553afe4206585b31aa72387c64295d08b # tag=v9 | ||
with: | ||
default_author: github_actions | ||
commit: --no-verify | ||
message: 'chore(prettier): 🤖 ✨' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
legacy-peer-deps=true |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.