Skip to content

Commit fd8d3fc

Browse files
stipsankmelverexxarsbjoerge
committed
feat: full Node.js ESM runtime support
BREAKING CHANGE: We have removed the default export and replaced it with a named one: ```diff -import SanityClient from '@sanity/client' +import {createClient} from '@sanity/client' ``` [The migration guide outlines every breaking change and how to migrate your code](https://github.com/sanity-io/client#from-v4) - feat: full ESM support in modern runtimes and tooling (Bun, Deno, Edge, without breaking Node.js ESM and CJS compatibility) - feat: codebase rewritten in TypeScript, typings are generated and no longer manually maintained - feat: make `httpRequest` on `SanityClient` configurable, intended for libraries wishing to extend the client - feat: shipping modern syntax, reducing bundlesize Co-Authored-By: Knut Melvær <[email protected]> Co-Authored-By: Espen Hovlandsdal <[email protected]> Co-Authored-By: Bjørge Næss <[email protected]>
1 parent 371515b commit fd8d3fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+20937
-20634
lines changed

.babelrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.eslintignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
dist
2-
lib
32
umd
43
coverage
5-
.nyc_output
64
runtimes/deno
5+
runtimes/node

.eslintrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
},
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:prettier/recommended',
10+
'plugin:@typescript-eslint/eslint-recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
parser: '@typescript-eslint/parser',
14+
parserOptions: {
15+
ecmaVersion: 2018,
16+
},
17+
plugins: ['@typescript-eslint', 'simple-import-sort', 'prettier'],
18+
rules: {
19+
'@typescript-eslint/no-explicit-any': 'error', // use the FIXME alias instead
20+
'@typescript-eslint/member-delimiter-style': 'off',
21+
'@typescript-eslint/no-empty-interface': 'off',
22+
'simple-import-sort/imports': 'warn',
23+
'simple-import-sort/exports': 'warn',
24+
'no-console': 'error',
25+
'no-shadow': 'error',
26+
'no-warning-comments': ['warn', {location: 'start', terms: ['todo', '@todo', 'fixme']}],
27+
'prettier/prettier': 'warn',
28+
},
29+
30+
overrides: [
31+
{
32+
files: ['**/*.js'],
33+
rules: {
34+
'@typescript-eslint/explicit-module-boundary-types': 'off',
35+
},
36+
},
37+
{
38+
files: ['test/**/*.ts'],
39+
rules: {
40+
'@typescript-eslint/no-non-null-assertion': 'off',
41+
'@typescript-eslint/no-explicit-any': 'off',
42+
},
43+
},
44+
],
45+
}

.github/workflows/bun.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
16-
- uses: antongolub/action-setup-bun@bc198f5cb868ce282f0a72bdd7da3a06a5387f83 # tag=v1
16+
- uses: antongolub/action-setup-bun@bc198f5cb868ce282f0a72bdd7da3a06a5387f83 # v1
1717
- run: bun install
18-
- uses: EndBug/add-and-commit@61a88be553afe4206585b31aa72387c64295d08b # tag=v9
18+
- uses: EndBug/add-and-commit@61a88be553afe4206585b31aa72387c64295d08b # v9
1919
with:
2020
message: 'chore(bun): update bun lockfile'
2121
default_author: github_actions

.github/workflows/ci.yml

Lines changed: 109 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,65 @@ concurrency:
2424
cancel-in-progress: true
2525

2626
jobs:
27-
test:
28-
runs-on: ubuntu-latest
29-
strategy:
30-
matrix:
31-
node-version: [lts/-3, lts/-2, lts/-1, lts/*, current]
32-
name: node ${{ matrix.node-version }}
33-
steps:
34-
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
35-
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
36-
with:
37-
node-version: ${{ matrix.node-version }}
38-
cache: 'npm'
39-
- run: npm install
40-
- run: npm test
41-
4227
build:
28+
name: Build, lint and test coverage
4329
runs-on: ubuntu-latest
4430
steps:
4531
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
46-
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
32+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
4733
with:
34+
cache: npm
4835
node-version: lts/*
49-
cache: 'npm'
5036
- run: npm ci
37+
- run: npx ls-engines
5138
- run: npm run prepublishOnly
52-
- uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # tag=v3
39+
- run: npm run lint -- --report-unused-disable-directives
40+
- run: npm run coverage
41+
- uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3
42+
name: Cache build output
5343
with:
5444
name: build-output
5545
path: |
5646
dist/
57-
lib/
5847
umd/
5948
49+
test:
50+
needs: build
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
# Run the testing suite on each major OS with the latest LTS release of Node.js
56+
os: [macos-latest, ubuntu-latest, windows-latest]
57+
node: [lts/*]
58+
# It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
59+
include:
60+
- os: ubuntu-latest
61+
# Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
62+
node: lts/-2
63+
- os: ubuntu-latest
64+
# Also test the previous LTS release
65+
node: lts/-1
66+
- os: ubuntu-latest
67+
# Test the actively developed version that will become the latest LTS release next October
68+
node: current
69+
# The `build` job already runs the testing suite in ubuntu and lts/*
70+
exclude:
71+
- os: ubuntu-latest
72+
# Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
73+
node: lts/*
74+
steps:
75+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
76+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
77+
with:
78+
cache: npm
79+
node-version: ${{ matrix.node }}
80+
- run: npm install
81+
- run: npx ls-engines
82+
- run: npm run coverage
83+
6084
prod-deps:
85+
name: Cache production dependencies
6186
runs-on: ubuntu-latest
6287
steps:
6388
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
@@ -67,70 +92,101 @@ jobs:
6792
path: ./node_modules
6893
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
6994
- if: steps.prod-deps.outputs.cache-hit != 'true'
70-
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
95+
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
7196
with:
7297
node-version: lts/*
7398
- if: steps.prod-deps.outputs.cache-hit != 'true'
7499
run: npm install --omit=dev --ignore-scripts
75100

76-
# Disabled until the jest runtime works with ESM
77-
# edge-runtime:
78-
# runs-on: ubuntu-latest
79-
# needs: [build, prod-deps]
80-
# steps:
81-
# - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
82-
# - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
83-
# with:
84-
# node-version: lts/*
85-
# cache: 'npm'
86-
# cache-dependency-path: runtimes/edge/package-lock.json
87-
# - uses: actions/cache@1c73980b09e7aea7201f325a7aa3ad00beddcdda # tag=v3
88-
# with:
89-
# path: ./node_modules
90-
# key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
91-
# - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # tag=v3
92-
# with:
93-
# name: build-output
94-
# - run: npm ci
95-
# working-directory: runtimes/edge
96-
# - run: npm test
97-
# working-directory: runtimes/edge
101+
edge-runtime:
102+
runs-on: ubuntu-latest
103+
needs: [build]
104+
steps:
105+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
106+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
107+
with:
108+
cache: npm
109+
node-version: lts/*
110+
- run: npm install
111+
- uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3
112+
name: Restore build output
113+
with:
114+
name: build-output
115+
- run: npm run test:edge-runtime -- --coverage
116+
117+
browser-runtime:
118+
runs-on: ubuntu-latest
119+
needs: [build]
120+
steps:
121+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
122+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
123+
with:
124+
cache: npm
125+
node-version: lts/*
126+
- run: npm install
127+
- uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3
128+
name: Restore build output
129+
with:
130+
name: build-output
131+
- run: npm run test:browser -- --coverage
98132

99133
deno-runtime:
100134
runs-on: ubuntu-latest
101135
needs: [build, prod-deps]
102136
steps:
103137
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
104138
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3
139+
name: Install only production dependencies
105140
with:
106141
path: ./node_modules
107142
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
108143
- uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3
144+
name: Restore build output
109145
with:
110146
name: build-output
111147
- uses: denoland/setup-deno@v1
112-
- name: deno test
113-
run: |
114-
deno fmt --check
115-
deno lint
116-
deno task test
117-
working-directory: runtimes/deno
148+
with:
149+
deno-version: vx.x.x
150+
- run: npm run test:deno
118151

119152
bun-runtime:
120153
runs-on: ubuntu-latest
121154
needs: [build, prod-deps]
122155
steps:
123156
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
124157
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3
158+
name: Install only production dependencies
125159
with:
126160
path: ./node_modules
127161
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
128-
- uses: antongolub/action-setup-bun@bc198f5cb868ce282f0a72bdd7da3a06a5387f83 # tag=v1
129-
- run: bun wiptest
130-
working-directory: runtimes/bun
162+
- uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3
163+
name: Restore build output
164+
with:
165+
name: build-output
166+
- uses: antongolub/action-setup-bun@bc198f5cb868ce282f0a72bdd7da3a06a5387f83 # v1
167+
- run: npm run test:bun
168+
169+
node-runtimes:
170+
runs-on: ubuntu-latest
171+
needs: [build, prod-deps]
172+
steps:
173+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
174+
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d # v3
175+
name: Install only production dependencies
176+
with:
177+
path: ./node_modules
178+
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
179+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
180+
with:
181+
node-version: lts/*
182+
- uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3
183+
name: Restore build output
184+
with:
185+
name: build-output
186+
- run: npm run test:node-runtimes
131187

132188
release:
133-
needs: [build, test, deno-runtime, bun-runtime]
189+
needs: [build, test, deno-runtime, bun-runtime, edge-runtime, browser-runtime, node-runtimes]
134190
# only run if opt-in during workflow_dispatch
135191
if: github.event.inputs.release == 'true'
136192
runs-on: ubuntu-latest
@@ -140,13 +196,12 @@ jobs:
140196
# Need to fetch entire commit history to
141197
# analyze every commit since last release
142198
fetch-depth: 0
143-
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
199+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
144200
with:
145201
node-version: lts/*
146202
cache: npm
147203
- run: npm ci
148204
# Branches that will release new versions are defined in .releaserc.json
149-
# @TODO remove dry-run after everything is good to go
150205
- run: npx semantic-release
151206
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
152207
# e.g. git tags were pushed but it exited before `npm publish`

.github/workflows/deno.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Maintain deno/import_map.json
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'package.json'
8+
workflow_dispatch:
9+
10+
jobs:
11+
run:
12+
name: deno run update_import_map.ts
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3
16+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3
17+
with:
18+
cache: npm
19+
node-version: lts/*
20+
- uses: denoland/setup-deno@v1
21+
with:
22+
deno-version: vx.x.x
23+
- run: npm run test:deno:update_import_map
24+
- uses: EndBug/add-and-commit@61a88be553afe4206585b31aa72387c64295d08b # v9
25+
with:
26+
message: 'chore(deno): update import_map.json'
27+
default_author: github_actions

.github/workflows/lock.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: 'Lock Threads'
3+
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
13+
concurrency:
14+
group: ${{ github.workflow }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
action:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: dessant/lock-threads@v4
22+
with:
23+
issue-inactive-days: 0
24+
pr-inactive-days: 0

0 commit comments

Comments
 (0)