Skip to content

Commit 7a3603a

Browse files
authored
chore: remove @openfeature/server-sdk as a runtime dependency (#356)
* Custom EventEmitter * Bundle type declarations to remove @openfeature devDependencies from .d.ts output Add dts-bundle-generator to inline all @openfeature/core and @openfeature/server-sdk types into a single bundled index.d.ts. This eliminates unresolved import type references in the published .d.ts files, which previously caused 'Cannot find module' errors for TypeScript consumers since neither package is declared as a runtime dependency or peerDependency. Changes: - package.json: types field now points to bundled index.d.ts - package.json: build script runs build:types after tsc builds - package.json: added dts-bundle-generator to devDependencies - index.d.ts: generated bundled type declarations (642 lines, zero @openfeature references, node:diagnostics_channel imported externally) * Fix yarn install: pin TypeScript to 5.9.3 via resolutions dts-bundle-generator declares typescript >=5.0.2 as a regular dependency, causing yarn to resolve TypeScript 7.0.2 for its nested copy. The built-in compat/typescript patch then fails with ENOENT trying to lstat an incorrect path. Adding a resolutions field in the root package.json forces all TypeScript resolutions to 5.9.3, matching the existing devDependency constraint. Also includes yarn.lock update for dts-bundle-generator and devDependencies reordering by yarn. * Don't export inlined OpenFeature types from bundled declarations Use --export-referenced-types false so inlined types like Provider, ResolutionDetails, ServerProviderEvents, ProviderEventEmitter, etc. are used in DatadogNodeServerProvider's method signatures but not exported as standalone types. This prevents consumers from accidentally importing our bundled copy of these types instead of getting them from their own @openfeature/server-sdk installation. The bundled index.d.ts now exports only: - UniversalFlagConfigurationV1 - DatadogNodeServerProviderOptions - DatadogNodeServerProvider All OpenFeature types remain inlined (zero @openfeature references) for SSI compatibility, but are invisible to consumers' import statements. TypeScript still performs structural comparison when the customer passes the provider to their own OpenFeature SDK. * Fix dependency build metadata * Fix build:types temp file cleanup and add index.d.ts to clean script - Use trap EXIT in build:types to ensure src/.dts-entry.ts is removed even if dts-bundle-generator fails - Add src/.dts-entry.ts to .gitignore as a safety net - Add index.d.ts to the clean script so all generated artifacts are removed consistently * Add prepack guard to prevent @openfeature/server-sdk runtime dependency Adds a pre-publish script that fails if @openfeature/server-sdk or @openfeature/core appear in dependencies/peerDependencies, or if the compiled .js files contain any runtime @openfeature imports. This prevents accidentally reintroducing the runtime dependency that would break SSI compatibility with dd-trace-js, where dd-trace is installed outside the application's node_modules tree and would get a separate copy of the SDK with a different event emitter identity. See DataDog/dd-trace-js#9570 for context. * Fix duplicate resolutions block in root package.json The earlier TypeScript resolution was added as a second resolutions block instead of merging with the existing one, causing yarn to ignore the typescript@npm:>=5.0.2 pin and crash on TS 7.0.2's compat patch. Merged into a single resolutions block. * Add comment explaining why build:types is needed * formatting * test: add TypeScript consumer test for node-server package The node-server package's bundled index.d.ts (generated by dts-bundle-generator) had no TypeScript consumer test to verify it compiles correctly from a consumer's perspective. The existing test-app-node/test.js only tested runtime require() behavior. This adds: - test-app-node/tsconfig.json: consumer-style TypeScript config - test-app-node/typecheck.ts: imports and exercises the public API (DatadogNodeServerProvider, UniversalFlagConfigurationV1, etc.) - test-app-node/package.json: adds typescript + @types/node devDeps - scripts/test-node-package-install.sh: runs tsc --noEmit before runtime tests The type check runs in both scenarios: 1. Without @openfeature/* installed (SSI/dd-trace) — verifies the bundled index.d.ts is self-contained with no dangling references 2. With @openfeature/* installed (normal consumer) — verifies type compatibility with the real OpenFeature SDK * test: add tests for NodeProviderEventEmitter Cover emit/addHandler, handler error isolation (incl. async rejections and a throwing logger), removeHandler LIFO semantics, removeAllHandlers scoping, getHandlers, and setLogger chaining/current-logger routing. * format * test: verify OpenFeature.setProvider(provider) type-checks against minimum SDK version Add Test 11 to typecheck.ts that calls OpenFeature.setProvider(provider) to catch type drift between the bundled index.d.ts and the Provider interface expected by @openfeature/server-sdk. Uses @ts-ignore on the import so the file still compiles in the SSI/dd-trace scenario where @openfeature/server-sdk is not installed. Add CI step to run the node install test against the minimum supported OpenFeature SDK versions (server-sdk 1.15.0, core 1.3.0) per COMPATIBILITY.md, ensuring the type check catches regressions at the lower bound of the supported range.
1 parent 03cf986 commit 7a3603a

17 files changed

Lines changed: 1311 additions & 87 deletions

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ jobs:
6161

6262
- name: Test node package installation (with OpenFeature)
6363
run: yarn test:node-install:with-of
64+
65+
- name: Test node package installation (with minimum OpenFeature)
66+
run: OF_SERVER_SDK_VERSION=1.15.0 OF_CORE_VERSION=1.3.0 yarn test:node-install:with-of

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ esm/
1515
bundle/
1616
*.tgz
1717
*.tar.gz
18+
packages/node-server/src/.dts-entry.ts
1819

1920
# IDEs
2021
.idea/

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ test-app/dist
1111
test-app/node_modules
1212
test-app/*.tgz
1313
packages/core/test/ffe-system-test-data
14+
packages/node-server/index.d.ts

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@
360360
"dot-prop","dot-prop","['MIT']","['Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)']"
361361
"dotenv","dotenv","['BSD-2-Clause']","['Scott Motte']"
362362
"dotenv-expand","dotenv-expand","['BSD-2-Clause']","['Scott Motte']"
363+
"dts-bundle-generator","dts-bundle-generator","['MIT']","['Evgeniy Timokhov']"
363364
"dunder-proto","dunder-proto","['MIT']","['ECMAScript Shims']"
364365
"eastasianwidth","eastasianwidth","['MIT']","['Masaki Komagata']"
365366
"ejs","ejs","['Apache-2.0']","['Joyent, Inc. and other Node contributors']"

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
"webpack": "5.106.2"
4747
},
4848
"packageManager": "yarn@4.10.3",
49+
"resolutions": {
50+
"tar@npm:7.5.11": "npm:^7.5.22",
51+
"minimatch@npm:10.1.1": "npm:^10.2.6",
52+
"js-yaml@npm:4.1.1": "npm:^4.3.1",
53+
"typescript@npm:>=5.0.2": "npm:5.9.3"
54+
},
4955
"dependencies": {
5056
"emoji-name-map": "^2.0.3"
5157
},
@@ -56,10 +62,5 @@
5662
"jest>@jest/core>jest-resolve>unrs-resolver": true,
5763
"lerna>nx": true
5864
}
59-
},
60-
"resolutions": {
61-
"tar@npm:7.5.11": "npm:^7.5.22",
62-
"minimatch@npm:10.1.1": "npm:^10.2.6",
63-
"js-yaml@npm:4.1.1": "npm:^4.3.1"
6465
}
6566
}

packages/node-server/COMPATIBILITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ The provider interface requires features introduced in `@openfeature/server-sdk@
1717

1818
### Installation
1919

20-
For most users, install the latest versions:
20+
Install the OpenFeature SDK if your application uses this package as an OpenFeature provider:
2121

2222
```bash
2323
npm install @openfeature/server-sdk @openfeature/core
2424
# or
2525
yarn add @openfeature/server-sdk @openfeature/core
2626
```
2727

28-
The packages will resolve compatible versions automatically.
28+
`@datadog/openfeature-node-server` does not install either OpenFeature package as a runtime dependency.
2929

3030
### For dd-trace Users
3131

32-
If you're using `dd-trace` and don't need OpenFeature functionality directly, you don't need to install these packages. The `@datadog/openfeature-node-server` peer dependency is optional.
32+
If you're using `dd-trace` and don't need OpenFeature functionality directly, you don't need to install these packages.

0 commit comments

Comments
 (0)