Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ESM support for common and sdk-client. #603

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ export class ClientEntity {
if (!identifyParams) {
throw malformedCommand;
}
await this.client.identify(identifyParams.user || identifyParams.context, {
waitForNetworkResults: true,
});
await this.client.identify(identifyParams.user || identifyParams.context);
return undefined;
}

Expand Down Expand Up @@ -204,7 +202,7 @@ export async function newSdkClientEntity(options: CreateInstanceParams) {
let failed = false;
try {
await Promise.race([
client.identify(initialContext, { waitForNetworkResults: true }),
client.identify(initialContext),
new Promise((_resolve, reject) => {
setTimeout(reject, timeout);
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/browser/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export default {
},
testPathIgnorePatterns: ['./dist', './src'],
testMatch: ['**.test.ts'],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
};
5 changes: 0 additions & 5 deletions packages/sdk/browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ const getSharedConfig = (format, file) => ({
file: file,
},
],
onwarn: (warning) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had copied this config and this onwarn thing was a big problem. First there should not be circular references, but second it meant the logging left out all the useful stuff. Like where the error happened. Which made all errors not useful at all.

if (warning.code !== 'CIRCULAR_DEPENDENCY') {
console.error(`(!) ${warning.message}`);
}
},
});

export default [
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/browser/src/BrowserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
LDClientImpl,
LDContext,
LDEmitter,
LDEmitterEventName,
LDHeaders,
Platform,
} from '@launchdarkly/js-client-sdk-common';
import { EventName } from '@launchdarkly/js-client-sdk-common/dist/LDEmitter';

import BrowserDataManager from './BrowserDataManager';
import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions';
Expand Down Expand Up @@ -233,12 +233,12 @@ export class BrowserClient extends LDClientImpl implements LDClient {
browserDataManager.setAutomaticStreamingState(!!this.emitter.listenerCount('change'));
}

override on(eventName: EventName, listener: Function): void {
override on(eventName: LDEmitterEventName, listener: Function): void {
super.on(eventName, listener);
this.updateAutomaticStreamingState();
}

override off(eventName: EventName, listener: Function): void {
override off(eventName: LDEmitterEventName, listener: Function): void {
super.off(eventName, listener);
this.updateAutomaticStreamingState();
}
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"jsx": "react-jsx",
"lib": ["ES2017", "dom"],
"module": "ES6",
"module": "ESNext",
"moduleResolution": "node",
"noImplicitOverride": true,
"resolveJsonModule": true,
Expand Down
16 changes: 11 additions & 5 deletions packages/shared/common/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"name": "@launchdarkly/js-sdk-common",
"version": "2.9.0",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
},
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/common",
"repository": {
"type": "git",
Expand All @@ -20,8 +25,9 @@
],
"scripts": {
"test": "npx jest --ci",
"build-types": "npx tsc --declaration true --emitDeclarationOnly true --declarationDir dist",
"build": "npx tsc",
"build": "npm run build-cjs && npm run build-esm",
"build-cjs": "npx tsc",
"build-esm": "npx tsc --project tsconfig.esm.json",
"clean": "npx tsc --build --clean",
"lint": "npx eslint . --ext .ts",
"lint:fix": "yarn run lint --fix",
Expand Down
43 changes: 0 additions & 43 deletions packages/shared/common/rollup.config.js

This file was deleted.

16 changes: 16 additions & 0 deletions packages/shared/common/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/esm",
"target": "ES2017",
"lib": ["ES2020"],
"module": "ES6",
"moduleResolution": "NodeNext",
"strict": true,
"noImplicitOverride": true,
"sourceMap": true,
"stripInternal": true,
"composite": true
},
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
}
7 changes: 3 additions & 4 deletions packages/shared/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"outDir": "dist/cjs",
"target": "ES2017",
"lib": ["es6"],
"module": "commonjs",
"strict": true,
"noImplicitOverride": true,
// Needed for CommonJS modules: markdown-it, fs-extra
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
"stripInternal": true,
"composite": true
"composite": true,
"declarationDir": "./dist/types"
},
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
}
15 changes: 11 additions & 4 deletions packages/shared/sdk-client/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"name": "@launchdarkly/js-client-sdk-common",
"version": "1.8.0",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
},
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/shared/sdk-client",
"repository": {
"type": "git",
Expand All @@ -21,7 +26,9 @@
"scripts": {
"doc": "../../../scripts/build-doc.sh .",
"test": "npx jest --ci",
"build": "npx tsc",
"build": "npm run build-cjs && npm run build-esm",
"build-cjs": "npx tsc",
"build-esm": "npx tsc --project tsconfig.esm.json",
"clean": "npx tsc --build --clean",
"lint": "npx eslint . --ext .ts",
"lint:fix": "yarn run lint -- --fix",
Expand Down
43 changes: 0 additions & 43 deletions packages/shared/sdk-client/rollup.config.js

This file was deleted.

5 changes: 2 additions & 3 deletions packages/shared/sdk-client/src/DataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ProcessStreamResponse,
subsystem,
} from '@launchdarkly/js-sdk-common';
import { LDStreamProcessor } from '@launchdarkly/js-sdk-common/dist/api/subsystem';

import { LDIdentifyOptions } from './api/LDIdentifyOptions';
import { Configuration } from './configuration/Configuration';
Expand Down Expand Up @@ -208,9 +207,9 @@ export abstract class BaseDataManager implements DataManager {
}

private decorateProcessorWithStatusReporting(
processor: LDStreamProcessor,
processor: subsystem.LDStreamProcessor,
statusManager: DataSourceStatusManager,
): LDStreamProcessor {
): subsystem.LDStreamProcessor {
return {
start: () => {
// update status before starting processor to ensure potential errors are reported after initializing
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/sdk-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LDClientInternalOptions } from './configuration/Configuration';
import DataSourceStatus, { DataSourceState } from './datasource/DataSourceStatus';
import DataSourceStatusErrorInfo from './datasource/DataSourceStatusErrorInfo';
import LDClientImpl from './LDClientImpl';
import LDEmitter from './LDEmitter';
import LDEmitter, { EventName } from './LDEmitter';
import Requestor from './polling/Requestor';

export * from '@launchdarkly/js-sdk-common';
Expand Down Expand Up @@ -38,4 +38,5 @@ export {
LDClientImpl,
LDClientInternalOptions,
DataSourceState,
EventName as LDEmitterEventName,
};
18 changes: 18 additions & 0 deletions packages/shared/sdk-client/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/esm",
"target": "ES2020",
"lib": ["es6", "DOM"],
"module": "ES6",
"moduleResolution": "NodeNext",
"strict": true,
"noImplicitOverride": true,
"sourceMap": true,
"stripInternal": true,
"resolveJsonModule": true,
"types": ["jest", "node"]
},
"include": ["src"],
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
}
7 changes: 3 additions & 4 deletions packages/shared/sdk-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"outDir": "dist/cjs",
"target": "ES2017",
"lib": ["es6", "DOM"],
"module": "commonjs",
"strict": true,
"noImplicitOverride": true,
// Needed for CommonJS modules: markdown-it, fs-extra
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
"stripInternal": true,
"resolveJsonModule": true,
"types": ["jest", "node"]
"types": ["jest", "node"],
"declarationDir": "./dist/types"
},
"include": ["src"],
"exclude": ["**/*.test.ts", "dist", "node_modules", "__tests__"]
Expand Down
Loading