Skip to content

Commit f64dd3c

Browse files
authored
Merge pull request #25 from playt-net/fix/esm
🐛 Fix ESM support
2 parents 9eb28cf + 2bfc92e commit f64dd3c

File tree

7 files changed

+52
-23
lines changed

7 files changed

+52
-23
lines changed

fixup

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Add package.json files to cjs/mjs subtrees
4+
#
5+
6+
cat >dist/cjs/package.json <<!EOF
7+
{
8+
"type": "commonjs"
9+
}
10+
!EOF
11+
12+
cat >dist/esm/package.json <<!EOF
13+
{
14+
"type": "module"
15+
}
16+
!EOF
17+
18+
find src -name '*.d.ts' -exec cp {} dist/cjs \;
19+
find src -name '*.d.ts' -exec cp {} dist/esm \;

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
],
1616
"main": "./dist/cjs/index.js",
1717
"module": "./dist/esm/index.js",
18+
"types": "./dist/esm/index.d.ts",
1819
"exports": {
1920
"browser": "./dist/esm/index.js",
2021
"import": "./dist/esm/index.js",
@@ -33,13 +34,13 @@
3334
"homepage": "https://github.com/playt-net/client#readme",
3435
"scripts": {
3536
"clean": "rimraf './dist'",
36-
"build": "npm run clean && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
37+
"build": "npm run clean && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json && ./fixup",
3738
"generate": "openapi-typescript https://playt-backend-xbwjl.ondigitalocean.app/v3/api-docs --output src/types.ts --prettier-config .prettierrc.json",
3839
"test": "jest",
3940
"typecheck": "tsc --noEmit --project tsconfig.json"
4041
},
4142
"dependencies": {
42-
"openapi-typescript-fetch": "git+https://github.com/ajaishankar/openapi-typescript-fetch.git"
43+
"openapi-typescript-fetch": "git+https://github.com/lmachens/openapi-typescript-fetch.git"
4344
},
4445
"devDependencies": {
4546
"@types/jest": "^27.4.1",

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import {
2-
ApiError,
1+
import type {
32
ApiResponse,
4-
Fetcher,
53
Middleware,
4+
ApiError as ApiErrorType,
65
} from 'openapi-typescript-fetch';
6+
import { ApiError, Fetcher } from 'openapi-typescript-fetch';
7+
78
import type { paths, components, operations } from './types';
89
export type { paths, components, operations, ApiResponse };
10+
911
export { ApiError };
1012

1113
export type ClientCredentials = {
@@ -49,7 +51,7 @@ export const PlaytClient = ({
4951
const response = await next(url, init);
5052
return response;
5153
} catch (error) {
52-
const { status } = error as ApiError;
54+
const { status } = error as ApiErrorType;
5355

5456
if (status === 401 && userAuth?.refreshToken && onRequestRefresh) {
5557
const refreshedUserAuth = await onRequestRefresh();

tsconfig.cjs.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "CommonJS",
4-
"outDir": "./dist/cjs"
3+
"module": "commonjs",
4+
"outDir": "dist/cjs",
5+
"target": "es2015"
56
},
67
"extends": "./tsconfig.json",
78
"include": ["src"]

tsconfig.esm.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "ES2020",
4-
"outDir": "./dist/esm"
3+
"module": "esnext",
4+
"outDir": "./dist/esm",
5+
"target": "esnext"
56
},
67
"extends": "./tsconfig.json",
78
"include": ["src"]

tsconfig.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
"baseUrl": "./src",
44
"declaration": true,
55
"esModuleInterop": true,
6-
"forceConsistentCasingInFileNames": true,
7-
"lib": ["dom", "dom.iterable", "ES2020"],
6+
"lib": ["dom", "dom.iterable", "esnext"],
87
"moduleResolution": "Node",
9-
"noImplicitReturns": true,
10-
"removeComments": true,
11-
"sourceMap": true,
128
"strict": true,
13-
"target": "ES2015",
14-
"useDefineForClassFields": true
9+
"allowJs": true,
10+
"allowSyntheticDefaultImports": true,
11+
"inlineSourceMap": false,
12+
"listEmittedFiles": false,
13+
"listFiles": false,
14+
"noFallthroughCasesInSwitch": true,
15+
"pretty": true,
16+
"resolveJsonModule": true,
17+
"skipLibCheck": true,
18+
"traceResolution": false,
19+
"types": ["node", "jest"]
1520
},
1621
"include": ["src", "test"]
1722
}

0 commit comments

Comments
 (0)