Skip to content

Commit e312f2f

Browse files
authored
refactor!: hybrid package [DX-4] (#535)
BREAKING CHANGE: Will allow us to provide CDA & CMA as real single CJS files instead of bundles
1 parent 52f34ea commit e312f2f

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

package-lock.json

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

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"description": "Core modules for the Contentful JS SDKs",
55
"homepage": "https://www.contentful.com/developers/docs/javascript/",
66
"type": "module",
7-
"main": "dist/index.js",
7+
"exports": {
8+
".": {
9+
"types": "./dist/types/index.d.ts",
10+
"import": "./dist/esm/index.js",
11+
"require": "./dist/cjs/index.cjs"
12+
}
13+
},
14+
"main": "./dist/cjs/index.cjs",
815
"types": "dist/types/index.d.ts",
916
"browser": {
1017
"process": "process/browser"
@@ -20,7 +27,9 @@
2027
"license": "MIT",
2128
"scripts": {
2229
"clean": "rimraf coverage && rimraf dist",
23-
"build": "npm run clean && tsc --outDir dist",
30+
"build": "npm run clean && npm run build:esm && npm run build:rollup && rm -rf dist/esm-raw",
31+
"build:esm": "tsc",
32+
"build:rollup": "NODE_ENV=production rollup -c",
2433
"lint": "eslint src test --ext '.ts'",
2534
"pretest": "npm run lint",
2635
"test": "vitest --run",
@@ -66,6 +75,7 @@
6675
"opener": "^1.4.1",
6776
"prettier": "^3.3.2",
6877
"rimraf": "^5.0.7",
78+
"rollup": "^4.28.1",
6979
"semantic-release": "^21.0.5",
7080
"typescript": "^5.4.5",
7181
"vitest": "^2.0.2"
@@ -126,4 +136,4 @@
126136
"optionalDependencies": {
127137
"@rollup/rollup-linux-x64-gnu": "^4.18.0"
128138
}
129-
}
139+
}

rollup.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const esmConfig = {
2+
input: 'dist/esm-raw/index.js',
3+
output: {
4+
dir: 'dist/esm',
5+
format: 'esm',
6+
preserveModules: true,
7+
},
8+
}
9+
10+
const cjsConfig = {
11+
input: 'dist/esm-raw/index.js',
12+
output: {
13+
dir: 'dist/cjs',
14+
format: 'cjs',
15+
preserveModules: true,
16+
entryFileNames: '[name].cjs',
17+
},
18+
}
19+
20+
export default [esmConfig, cjsConfig]

src/get-user-agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function getUserAgentHeader(
5656
integration?: string,
5757
feature?: string,
5858
): string {
59-
const headerParts = []
59+
const headerParts: string[] = []
6060

6161
if (application) {
6262
headerParts.push(`app ${application}`)
@@ -72,7 +72,7 @@ export default function getUserAgentHeader(
7272

7373
headerParts.push(`sdk ${sdk}`)
7474

75-
let platform = null
75+
let platform: string | null = null
7676
try {
7777
if (isReactNative()) {
7878
platform = getBrowserOS()

src/rate-limit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function rateLimit(instance: AxiosInstance, maxRetry = 5): void {
4646
return Promise.reject(error)
4747
}
4848

49-
let retryErrorType = null
49+
let retryErrorType: string | null = null
5050
let wait = defaultWait(doneAttempts)
5151

5252
// Errors without response did not receive anything from the server

tsconfig.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": "./",
3+
"outDir": "./dist/esm-raw",
44
"rootDir": "./src",
5-
"target": "esnext",
6-
"module": "Preserve",
7-
"moduleResolution": "bundler",
5+
"lib": ["dom", "esnext"],
6+
"target": "ES2020",
7+
"module": "es2020",
8+
"moduleResolution": "node",
9+
"allowJs": true,
810
"declarationDir": "dist/types",
911
"declaration": true,
1012
"strict": true,
11-
"esModuleInterop": true
13+
"importHelpers": true,
14+
"isolatedModules": false,
15+
"esModuleInterop": true,
16+
"noImplicitThis": false,
17+
"typeRoots": ["node_modules/@types"],
18+
"noImplicitAny": false,
19+
"skipLibCheck": true
1220
},
1321
"include": ["src/**/*", "global.d.ts"],
14-
}
22+
}

0 commit comments

Comments
 (0)