diff --git a/packages/sdk/browser/contract-tests/entity/src/makeLogger.ts b/packages/sdk/browser/contract-tests/entity/src/makeLogger.ts index 6d09061d0..a8cf9f165 100644 --- a/packages/sdk/browser/contract-tests/entity/src/makeLogger.ts +++ b/packages/sdk/browser/contract-tests/entity/src/makeLogger.ts @@ -2,19 +2,19 @@ import { LDLogger } from '@launchdarkly/js-client-sdk'; export function makeLogger(tag: string): LDLogger { return { - debug(message, ...args: any[]) { + debug(message: any, ...args: any[]) { // eslint-disable-next-line no-console console.debug(`${new Date().toISOString()} [${tag}]: ${message}`, ...args); }, - info(message, ...args: any[]) { + info(message: any, ...args: any[]) { // eslint-disable-next-line no-console console.info(`${new Date().toISOString()} [${tag}]: ${message}`, ...args); }, - warn(message, ...args: any[]) { + warn(message: any, ...args: any[]) { // eslint-disable-next-line no-console console.warn(`${new Date().toISOString()} [${tag}]: ${message}`, ...args); }, - error(message, ...args: any[]) { + error(message: any, ...args: any[]) { // eslint-disable-next-line no-console console.error(`${new Date().toISOString()} [${tag}]: ${message}`, ...args); }, diff --git a/packages/sdk/browser/package.json b/packages/sdk/browser/package.json index d28c12c3e..18f934fe2 100644 --- a/packages/sdk/browser/package.json +++ b/packages/sdk/browser/package.json @@ -16,25 +16,38 @@ "feature management", "sdk" ], + "type": "module", + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { - "types": "./dist/src/index.d.ts", - "require": "./dist/index.cjs.js", - "import": "./dist/index.es.js" + "require": { + "types": "./dist/index.d.cts", + "require": "./dist/index.cjs" + }, + "import": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } }, "./compat": { - "types": "./dist/src/compat/index.d.ts", - "require": "./dist/compat.cjs.js", - "import": "./dist/compat.es.js" + "require": { + "types": "./dist/compat.d.cts", + "require": "./dist/compat.cjs" + }, + "import": { + "types": "./dist/compat.d.ts", + "import": "./dist/compat.js" + } } }, - "type": "module", "files": [ "dist" ], "scripts": { "clean": "rimraf dist", - "build": "tsc --noEmit && rollup -c rollup.config.js", + "build": "tsup", "lint": "eslint . --ext .ts,.tsx", "prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore", "test": "npx jest --runInBand", @@ -46,11 +59,6 @@ }, "devDependencies": { "@jest/globals": "^29.7.0", - "@rollup/plugin-commonjs": "^25.0.0", - "@rollup/plugin-json": "^6.1.0", - "@rollup/plugin-node-resolve": "^15.0.2", - "@rollup/plugin-terser": "^0.4.3", - "@rollup/plugin-typescript": "^11.1.1", "@trivago/prettier-plugin-sort-imports": "^4.1.1", "@types/jest": "^29.5.11", "@typescript-eslint/eslint-plugin": "^6.20.0", @@ -66,9 +74,8 @@ "jest-environment-jsdom": "^29.7.0", "prettier": "^3.0.0", "rimraf": "^5.0.5", - "rollup": "^3.23.0", - "rollup-plugin-visualizer": "^5.12.0", "ts-jest": "^29.1.1", + "tsup": "^8.3.5", "typedoc": "0.25.0", "typescript": "^5.5.3" } diff --git a/packages/sdk/browser/rollup.config.js b/packages/sdk/browser/rollup.config.js deleted file mode 100644 index f1810e932..000000000 --- a/packages/sdk/browser/rollup.config.js +++ /dev/null @@ -1,56 +0,0 @@ -import common from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; -import resolve from '@rollup/plugin-node-resolve'; -import terser from '@rollup/plugin-terser'; -import typescript from '@rollup/plugin-typescript'; -import { visualizer } from 'rollup-plugin-visualizer'; - -const getSharedConfig = (format, extension) => ({ - input: { - index: 'src/index.ts', - compat: 'src/compat/index.ts' - }, - output: - { - format: format, - sourcemap: true, - dir: 'dist', - entryFileNames: '[name]' + extension - }, -}); - -const terserOpts = { - mangle: { - properties: { - // Mangle class properties which start with an underscore. - regex: /^_/, - // Do not mangle '_meta', because this is part of our JSON - // data model. - reserved: ['_meta'], - }, - }, -}; - -export default [ - { - ...getSharedConfig('es', '.es.js'), - plugins: [ - typescript({ - module: 'esnext', - }), - common({ - transformMixedEsModules: true, - esmExternals: true, - }), - resolve(), - terser(terserOpts), - json(), - // The 'sourcemap' option allows using the minified size, not the size before minification. - visualizer({ sourcemap: true }), - ], - }, - { - ...getSharedConfig('cjs', '.cjs.js'), - plugins: [typescript(), common(), resolve(), terser(terserOpts), json()], - }, -]; diff --git a/packages/sdk/browser/tsconfig.json b/packages/sdk/browser/tsconfig.json index 929948785..7306c5b0c 100644 --- a/packages/sdk/browser/tsconfig.json +++ b/packages/sdk/browser/tsconfig.json @@ -8,18 +8,17 @@ "moduleResolution": "node", "noImplicitOverride": true, "resolveJsonModule": true, - // Uses "." so it can load package.json. "rootDir": ".", "outDir": "dist", "skipLibCheck": true, - // enables importers to jump to source - "sourceMap": true, + "sourceMap": false, "strict": true, "stripInternal": true, "target": "ES2017", "types": ["node", "jest"], "allowJs": true }, + "include": ["src"], "exclude": [ "vite.config.ts", "__tests__", @@ -27,9 +26,9 @@ "docs", "example", "node_modules", - "contract-tests", "babel.config.js", - "jestSetupFile.ts", + "setup-jest.js", + "rollup.config.js", "**/*.test.ts*" ] } diff --git a/packages/sdk/browser/tsup.config.ts b/packages/sdk/browser/tsup.config.ts new file mode 100644 index 000000000..56a856d87 --- /dev/null +++ b/packages/sdk/browser/tsup.config.ts @@ -0,0 +1,27 @@ +// It is a dev dependency and the linter doesn't understand. +// eslint-disable-next-line import/no-extraneous-dependencies +import { defineConfig } from 'tsup'; + +export default defineConfig({ + entry: { + index: 'src/index.ts', + compat: 'src/compat/index.ts', + }, + minify: true, + format: ['esm', 'cjs'], + splitting: false, + sourcemap: false, + clean: true, + noExternal: ['@launchdarkly/js-sdk-common', '@launchdarkly/js-client-sdk-common'], + dts: true, + metafile: true, + esbuildOptions(opts) { + // This would normally be `^_(?!meta|_)`, but go doesn't support negative look-ahead assertions, + // so we need to craft something that works without it. + // So start of line followed by a character that isn't followed by m or underscore, but we + // want other things that do start with m, so we need to progressively handle more characters + // of meta with exclusions. + // eslint-disable-next-line no-param-reassign + opts.mangleProps = /^_([^m|_]|m[^e]|me[^t]|met[^a])/; + }, +});