Skip to content

Commit 3511a4b

Browse files
committed
feat: Add ESM support for common and sdk-client.
1 parent 9ad25bd commit 3511a4b

File tree

13 files changed

+69
-116
lines changed

13 files changed

+69
-116
lines changed

packages/sdk/browser/rollup.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ const getSharedConfig = (format, file) => ({
1313
file: file,
1414
},
1515
],
16-
onwarn: (warning) => {
17-
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
18-
console.error(`(!) ${warning.message}`);
19-
}
20-
},
2116
});
2217

2318
export default [

packages/sdk/browser/src/BrowserClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
LDClientImpl,
1111
LDContext,
1212
LDEmitter,
13+
LDEmitterEventName,
1314
LDHeaders,
15+
LDIdentifyOptions,
1416
Platform,
1517
} from '@launchdarkly/js-client-sdk-common';
16-
import { LDIdentifyOptions } from '@launchdarkly/js-client-sdk-common/dist/api/LDIdentifyOptions';
17-
import { EventName } from '@launchdarkly/js-client-sdk-common/dist/LDEmitter';
1818

1919
import BrowserDataManager from './BrowserDataManager';
2020
import GoalManager from './goals/GoalManager';
@@ -195,12 +195,12 @@ export class BrowserClient extends LDClientImpl {
195195
browserDataManager.setAutomaticStreamingState(!!this.emitter.listenerCount('change'));
196196
}
197197

198-
override on(eventName: EventName, listener: Function): void {
198+
override on(eventName: LDEmitterEventName, listener: Function): void {
199199
super.on(eventName, listener);
200200
this.updateAutomaticStreamingState();
201201
}
202202

203-
override off(eventName: EventName, listener: Function): void {
203+
override off(eventName: LDEmitterEventName, listener: Function): void {
204204
super.off(eventName, listener);
205205
this.updateAutomaticStreamingState();
206206
}

packages/sdk/browser/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"allowSyntheticDefaultImports": true,
44
"declaration": true,
55
"declarationMap": true,
6-
"jsx": "react-jsx",
76
"lib": ["ES2017", "dom"],
8-
"module": "ES6",
7+
"module": "ESNext",
98
"moduleResolution": "node",
109
"noImplicitOverride": true,
1110
"resolveJsonModule": true,

packages/shared/common/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
"name": "@launchdarkly/js-sdk-common",
33
"version": "2.9.0",
44
"type": "commonjs",
5-
"main": "./dist/index.js",
6-
"types": "./dist/index.d.ts",
5+
"main": "./dist/cjs/index.js",
6+
"types": "./dist/types/index.d.ts",
7+
"exports": {
8+
"types": "./dist/types/index.d.ts",
9+
"require": "./dist/cjs/index.js",
10+
"import": "./dist/esm/index.js"
11+
},
712
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/common",
813
"repository": {
914
"type": "git",
@@ -20,8 +25,9 @@
2025
],
2126
"scripts": {
2227
"test": "npx jest --ci",
23-
"build-types": "npx tsc --declaration true --emitDeclarationOnly true --declarationDir dist",
24-
"build": "npx tsc",
28+
"build": "npm run build-cjs && npm run build-esm",
29+
"build-cjs": "npx tsc",
30+
"build-esm": "npx tsc --project tsconfig.esm.json",
2531
"clean": "npx tsc --build --clean",
2632
"lint": "npx eslint . --ext .ts",
2733
"lint:fix": "yarn run lint --fix",

packages/shared/common/rollup.config.js

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": "src",
4+
"outDir": "dist/esm",
5+
"target": "ES2017",
6+
"lib": ["ES2020"],
7+
"module": "ES6",
8+
"moduleResolution": "NodeNext",
9+
"strict": true,
10+
"noImplicitOverride": true,
11+
"sourceMap": true,
12+
"stripInternal": true,
13+
"composite": true
14+
},
15+
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
16+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
22
"compilerOptions": {
33
"rootDir": "src",
4-
"outDir": "dist",
4+
"outDir": "dist/cjs",
55
"target": "ES2017",
66
"lib": ["es6"],
77
"module": "commonjs",
88
"strict": true,
99
"noImplicitOverride": true,
10-
// Needed for CommonJS modules: markdown-it, fs-extra
11-
"allowSyntheticDefaultImports": true,
1210
"sourceMap": true,
1311
"declaration": true,
1412
"declarationMap": true, // enables importers to jump to source
1513
"stripInternal": true,
16-
"composite": true
14+
"composite": true,
15+
"declarationDir": "./dist/types"
1716
},
1817
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
1918
}

packages/shared/sdk-client/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
"name": "@launchdarkly/js-client-sdk-common",
33
"version": "1.8.0",
44
"type": "commonjs",
5-
"main": "./dist/index.js",
6-
"types": "./dist/index.d.ts",
5+
"main": "./dist/cjs/index.js",
6+
"types": "./dist/types/index.d.ts",
7+
"exports": {
8+
"types": "./dist/types/index.d.ts",
9+
"require": "./dist/cjs/index.js",
10+
"import": "./dist/esm/index.js"
11+
},
712
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-client",
813
"repository": {
914
"type": "git",
@@ -21,7 +26,9 @@
2126
"scripts": {
2227
"doc": "../../../scripts/build-doc.sh .",
2328
"test": "npx jest --ci",
24-
"build": "npx tsc",
29+
"build": "npm run build-cjs && npm run build-esm",
30+
"build-cjs": "npx tsc",
31+
"build-esm": "npx tsc --project tsconfig.esm.json",
2532
"clean": "npx tsc --build --clean",
2633
"lint": "npx eslint . --ext .ts",
2734
"lint:fix": "yarn run lint -- --fix",

packages/shared/sdk-client/rollup.config.js

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

packages/shared/sdk-client/src/DataManager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
ProcessStreamResponse,
1010
subsystem,
1111
} from '@launchdarkly/js-sdk-common';
12-
import { LDStreamProcessor } from '@launchdarkly/js-sdk-common/dist/api/subsystem';
1312

1413
import { LDIdentifyOptions } from './api/LDIdentifyOptions';
1514
import { Configuration } from './configuration/Configuration';
@@ -194,9 +193,9 @@ export abstract class BaseDataManager implements DataManager {
194193
}
195194

196195
private decorateProcessorWithStatusReporting(
197-
processor: LDStreamProcessor,
196+
processor: subsystem.LDStreamProcessor,
198197
statusManager: DataSourceStatusManager,
199-
): LDStreamProcessor {
198+
): subsystem.LDStreamProcessor {
200199
return {
201200
start: () => {
202201
// update status before starting processor to ensure potential errors are reported after initializing

0 commit comments

Comments
 (0)