Skip to content

Commit 4e1fe02

Browse files
feat: update to Node18, remove cross-fetch, and run tests on node+jsdom (#386)
Co-authored-by: Nathanael DEMACON <[email protected]>
1 parent e60bb9e commit 4e1fe02

File tree

18 files changed

+601
-307
lines changed

18 files changed

+601
-307
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
name: Check Pull Request
22
on:
33
pull_request:
4-
types: ['opened', 'edited', 'reopened', 'synchronize']
4+
types: ["opened", "edited", "reopened", "synchronize"]
55

66
jobs:
77
check-title:
88
runs-on: ubuntu-20.04
99
steps:
10-
- uses: actions/[email protected]
11-
- uses: pnpm/[email protected]
12-
- name: Use Node.js
13-
uses: actions/[email protected]
14-
with:
15-
node-version: 17
16-
check-latest: true
17-
cache: 'pnpm'
18-
- run: pnpm install
19-
- run: echo '${{ github.event.pull_request.title }}' | pnpm commitlint
10+
- uses: actions/[email protected]
11+
- uses: pnpm/[email protected]
12+
- name: Use Node.js
13+
uses: actions/[email protected]
14+
with:
15+
node-version: 18
16+
check-latest: true
17+
cache: "pnpm"
18+
- run: pnpm install
19+
- run: echo '${{ github.event.pull_request.title }}' | pnpm commitlint

.github/workflows/deploy-doc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
# Runs on tags
55
push:
66
tags:
7-
- '**'
7+
- "**"
88

99
# Allows you to run this workflow manually from the Actions tab
1010
workflow_dispatch:
@@ -39,9 +39,9 @@ jobs:
3939
- name: Setup Node
4040
uses: actions/[email protected]
4141
with:
42-
node-version: 17
42+
node-version: 18
4343
check-latest: true
44-
cache: 'pnpm'
44+
cache: "pnpm"
4545
- name: Setup Pages
4646
id: pages
4747
uses: actions/configure-pages@v2

.github/workflows/deploy-package.yml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ jobs:
1010
runs-on: ubuntu-20.04
1111
if: github.ref == 'refs/heads/main'
1212
steps:
13-
- uses: actions/[email protected]
14-
with:
15-
fetch-depth: "0"
16-
persist-credentials: false
17-
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
18-
- name: Git Identity
19-
run: |
20-
git config --global user.name 'scaleway-bot'
21-
git config --global user.email '[email protected]'
22-
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
25-
- uses: pnpm/[email protected]
26-
- name: Use Node.js
27-
uses: actions/[email protected]
28-
with:
29-
node-version: 17
30-
check-latest: true
31-
- run: pnpm install
32-
- run: pnpm run build
33-
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
34-
env:
35-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36-
- run: pnpm lerna publish -y --create-release github
37-
env:
38-
HUSKY: 0
39-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
13+
- uses: actions/[email protected]
14+
with:
15+
fetch-depth: "0"
16+
persist-credentials: false
17+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
18+
- name: Git Identity
19+
run: |
20+
git config --global user.name 'scaleway-bot'
21+
git config --global user.email '[email protected]'
22+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
25+
- uses: pnpm/[email protected]
26+
- name: Use Node.js
27+
uses: actions/[email protected]
28+
with:
29+
node-version: 18
30+
check-latest: true
31+
- run: pnpm install
32+
- run: pnpm run build
33+
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
34+
env:
35+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36+
- run: pnpm lerna publish -y --create-release github
37+
env:
38+
HUSKY: 0
39+
GH_TOKEN: ${{ secrets.GH_TOKEN }}

.github/workflows/run-tests.yml

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,51 @@ jobs:
1010
typecheck:
1111
runs-on: ubuntu-20.04
1212
steps:
13-
- uses: actions/[email protected]
14-
- uses: pnpm/[email protected]
15-
- name: Use Node.js
16-
uses: actions/[email protected]
17-
with:
18-
node-version: 17
19-
check-latest: true
20-
cache: 'pnpm'
21-
- run: pnpm install
22-
- run: pnpm run build
23-
- run: pnpm tsc --noEmit
13+
- uses: actions/[email protected]
14+
- uses: pnpm/[email protected]
15+
- name: Use Node.js
16+
uses: actions/[email protected]
17+
with:
18+
node-version: 17
19+
check-latest: true
20+
cache: "pnpm"
21+
- run: pnpm install
22+
- run: pnpm run build
23+
- run: pnpm tsc --noEmit
2424
lint:
2525
runs-on: ubuntu-20.04
2626
steps:
27-
- uses: actions/[email protected]
28-
- uses: pnpm/[email protected]
29-
- name: Use Node.js
30-
uses: actions/[email protected]
31-
with:
32-
node-version: 17
33-
check-latest: true
34-
cache: 'pnpm'
35-
- run: pnpm install
36-
- run: pnpm run build
37-
- run: pnpm run lint
27+
- uses: actions/[email protected]
28+
- uses: pnpm/[email protected]
29+
- name: Use Node.js
30+
uses: actions/[email protected]
31+
with:
32+
node-version: 18
33+
check-latest: true
34+
cache: "pnpm"
35+
- run: pnpm install
36+
- run: pnpm run build
37+
- run: pnpm run lint
3838
test:
3939
runs-on: ubuntu-20.04
4040
strategy:
4141
matrix:
42-
node: [ '14', '16', '17' ]
42+
test-environment:
43+
- node
44+
- jsdom
45+
node:
46+
- "18"
47+
- "19"
4348
steps:
44-
- uses: actions/[email protected]
45-
- uses: pnpm/[email protected]
46-
- name: Use Node.js
47-
uses: actions/[email protected]
48-
with:
49-
node-version: ${{ matrix.node }}
50-
check-latest: true
51-
cache: 'pnpm'
52-
- run: pnpm install
53-
- run: pnpm run build
54-
- run: pnpm run test:coverage
55-
- uses: codecov/[email protected]
56-
49+
- uses: actions/[email protected]
50+
- uses: pnpm/[email protected]
51+
- name: Use Node.js
52+
uses: actions/[email protected]
53+
with:
54+
node-version: ${{ matrix.node }}
55+
check-latest: true
56+
cache: "pnpm"
57+
- run: pnpm install
58+
- run: pnpm run build
59+
- run: pnpm run test:coverage --testEnvironment ${{ matrix.test-environment }}
60+
- uses: codecov/[email protected]

README.md

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const client = createClient(profile)
4545

4646
**For more advanced needs**, please check the examples.
4747

48-
## Pagination
48+
### Pagination
4949

5050
We included some pagination helpers for the methods supporting the feature. Let's take `listNamespaces()` (Registry product) as an example:
5151

@@ -67,42 +67,21 @@ for await (const page of api.listNamespaces()) {
6767
}
6868
```
6969

70-
## Types
70+
### Types
7171

7272
The project is coded with Typescript, so don't hesitate to take advantage of it.
7373

7474
1. All **types of a product** are stored in the `Product.version` namespace. For instance, the `Image` interface of Registry v1 can be accessed with `Registry.v1.Image`.
7575

7676
2. We export **errors** in the namespace `Errors`, allowing you to differentiate the cases (e.g. `Errors.PermissionsDeniedError`).
7777

78-
## Dependencies
78+
## Notes
7979

80-
This SDK is based on the [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API and uses `Request`, `Response` & `Headers` interfaces. Those interfaces are native in modern browsers, node >=18 & [deno](https://deno.land/) environments.
81-
82-
For `node` < 18 & `React Native` environments, the commonJS build requires [cross-fetch](https://www.npmjs.com/package/cross-fetch) package, it is listed in `dependencies` but not used in esm build.
83-
84-
**Troubleshooting**
85-
86-
In node environment, the commonJS module defined in `dist/index.cjs` entry file is used by default, thanks to the "main" `package.json` field.
87-
88-
If you want to use the ES module from `dist/index.js` with node < 18 & `React Native` environments, we recommend you to explicitly import [cross-fetch](https://www.npmjs.com/package/cross-fetch) polyfill:
89-
90-
```ts
91-
import 'cross-fetch/polyfill'
92-
import {...} from '@scaleway/sdk'
93-
```
94-
95-
or
96-
97-
```bash
98-
node -r cross-fetch/polyfill ./script-using-sdk.mjs
99-
```
100-
101-
## Development
80+
### Contributing Guidelines
10281

10382
This repository is at its early stage and is still in active development.
10483
If you are looking for a way to contribute please read [CONTRIBUTING.md](./CONTRIBUTING.md).
10584

106-
## Reach us
85+
### Reach us
10786

10887
We love feedback. Feel free to reach us on [Scaleway Slack community](https://slack.scaleway.com/), we are waiting for you on [#opensource](https://scaleway-community.slack.com/app_redirect?channel=opensource).
File renamed without changes.

examples/nodejs-minimal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@scaleway/sdk": "^0.1.0-beta"
1313
},
1414
"devDependencies": {
15-
"@types/node": "^17.0.45",
15+
"@types/node": "^18.11.18",
1616
"typescript": "^4.9.4"
1717
}
1818
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"packages/*"
66
],
77
"engines": {
8-
"node": ">=14.13",
8+
"node": ">=18.0",
99
"pnpm": ">=7.25.1"
1010
},
1111
"type": "module",
@@ -37,6 +37,9 @@
3737
]
3838
},
3939
"jest": {
40+
"setupFiles": [
41+
"./env-setup.ts"
42+
],
4043
"collectCoverageFrom": [
4144
"packages/*/src/**/*.{ts,tsx}"
4245
],
@@ -61,9 +64,6 @@
6164
],
6265
"transformIgnorePatterns": [
6366
"node_modules/(?!(.*(@scaleway)))"
64-
],
65-
"setupFiles": [
66-
"./setupTests.ts"
6767
]
6868
},
6969
"devDependencies": {
@@ -76,7 +76,6 @@
7676
"@jest/globals": "^29.3.1",
7777
"@rollup/plugin-babel": "^6.0.3",
7878
"@rollup/plugin-commonjs": "^24.0.1",
79-
"@rollup/plugin-inject": "^5.0.3",
8079
"@rollup/plugin-node-resolve": "^15.0.1",
8180
"@scaleway/eslint-config-react": "^3.14.1",
8281
"@types/jest": "^29.2.6",
@@ -88,6 +87,7 @@
8887
"eslint-plugin-tsdoc": "^0.2.17",
8988
"husky": "^8.0.3",
9089
"jest": "^29.3.1",
90+
"jest-environment-jsdom": "^29.4.0",
9191
"jest-junit": "^15.0.0",
9292
"lerna": "^6.4.1",
9393
"lint-staged": "^13.1.0",

packages/clients/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
},
3131
"type": "module",
3232
"dependencies": {
33-
"@scaleway/random-name": "^4.0.1",
34-
"cross-fetch": "^3.1.5"
33+
"@scaleway/random-name": "^4.0.1"
3534
},
3635
"bundledDependencies": [
3736
"@scaleway/random-name"

packages/clients/src/fetch.d.ts

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

0 commit comments

Comments
 (0)