Skip to content

Commit 22abf7c

Browse files
committed
chore!: Build as ECMAScript module
Jest's support for ESM is lacking, so for simplicity this also changes the test suite to use Node's built-in test runner and typescript support, and jest's `expect` package. This change is breaking because any non-ESM consuming packages must now have minumum Node version of 20.19.0.
1 parent 2c885db commit 22abf7c

File tree

8 files changed

+283
-2911
lines changed

8 files changed

+283
-2911
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NODE_OPTIONS=--test-coverage-branches=100 --test-coverage-functions=100 --test-coverage-lines=100 --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=./lcov.info

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
node_modules/
66

77
# Tests
8-
/coverage/
8+
lcov.info
99

1010
# Yarn
1111
/yarn-error.log

mise.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ run = "yarn npm publish --dry-run"
2121

2222
[tasks."checks:test"]
2323
depends = ["yarn"]
24-
run = "node --run test"
24+
run = "node --run test -- --experimental-test-coverage"
2525

2626
[tasks."checks:lint"]
2727
depends = ["yarn"]

package.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"name": "expo-server-sdk",
33
"version": "5.0.0",
44
"description": "Server-side library for working with Expo using Node.js",
5-
"main": "build/ExpoClient.js",
6-
"types": "build/ExpoClient.d.ts",
5+
"type": "module",
6+
"main": "./build/ExpoClient.js",
7+
"exports": "./build/ExpoClient.js",
8+
"types": "./build/ExpoClient.d.ts",
79
"files": [
810
"build"
911
],
@@ -14,22 +16,9 @@
1416
"build": "yarn prepack",
1517
"lint": "eslint",
1618
"prepack": "tsc --project tsconfig.build.json",
17-
"test": "jest --coverage",
18-
"tsc": "tsc"
19-
},
20-
"jest": {
21-
"coverageDirectory": "<rootDir>/../coverage",
22-
"coverageThreshold": {
23-
"global": {
24-
"branches": 100,
25-
"functions": 100,
26-
"lines": 100,
27-
"statements": 0
28-
}
29-
},
30-
"preset": "ts-jest",
31-
"rootDir": "src",
32-
"testEnvironment": "node"
19+
"test": "node --test --env-file .env",
20+
"tsc": "tsc",
21+
"watch": "tsc --watch"
3322
},
3423
"repository": {
3524
"type": "git",
@@ -56,10 +45,9 @@
5645
"@types/promise-retry": "1.1.6",
5746
"eslint": "9.39.2",
5847
"eslint-config-universe": "15.0.3",
59-
"jest": "29.7.0",
48+
"expect": "30.2.0",
6049
"jiti": "2.6.1",
6150
"prettier": "3.7.4",
62-
"ts-jest": "29.4.6",
6351
"typescript": "5.9.3"
6452
},
6553
"packageManager": "yarn@4.12.0"

src/ExpoClient.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* https://expo.dev
77
*/
88
import assert from 'node:assert';
9+
import { createRequire } from 'node:module';
910
import { gzipSync } from 'node:zlib';
1011
import promiseLimit from 'promise-limit';
1112
import promiseRetry from 'promise-retry';
@@ -19,7 +20,9 @@ import {
1920
pushNotificationReceiptChunkLimit,
2021
requestRetryMinTimeout,
2122
sendApiUrl,
22-
} from './ExpoClientValues';
23+
} from './ExpoClientValues.ts';
24+
25+
const require = createRequire(import.meta.url);
2326

2427
export class Expo {
2528
static pushNotificationChunkSizeLimit = pushNotificationChunkLimit;
@@ -199,6 +202,9 @@ export class Expo {
199202
const json = JSON.stringify(options.body);
200203
assert(json != null, `JSON request body must not be null`);
201204

205+
// NOTE: This can be replaced with an import with the `{ type: "json" }`
206+
// attribute when we drop support for node versions below v20.10.0, when
207+
// import attributes were stabilized
202208
const sdkVersion = require('../package.json').version;
203209
const requestHeaders = new Headers({
204210
Accept: 'application/json',

src/__tests__/ExpoClient-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals';
1+
import { expect } from 'expect';
22
import assert from 'node:assert';
33
import { randomUUID } from 'node:crypto';
4+
import { afterEach, beforeEach, describe, test } from 'node:test';
45
import { gunzipSync } from 'node:zlib';
56
import { MockAgent, setGlobalDispatcher } from 'undici';
67

7-
import ExpoClient, { ExpoPushMessage } from '../ExpoClient';
8-
import { getReceiptsApiUrl, sendApiUrl } from '../ExpoClientValues';
8+
import ExpoClient, { type ExpoPushMessage } from '../ExpoClient.ts';
9+
import { getReceiptsApiUrl, sendApiUrl } from '../ExpoClientValues.ts';
910

1011
const apiBaseUrl = 'https://exp.host';
1112
const accessToken = 'foobar';

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"extends": [
33
"@tsconfig/bases/strictest",
4-
"@tsconfig/bases/node20" // The minimum supported major node version
4+
"@tsconfig/bases/node20", // The minimum supported major node version
5+
"@tsconfig/bases/node-ts"
56
],
67
"compilerOptions": {
78
"declaration": true,
8-
"noEmit": true,
9-
"sourceMap": true
9+
"noEmit": true
1010
},
1111
"exclude": ["build", "coverage"]
1212
}

0 commit comments

Comments
 (0)