Skip to content

Commit 404a1fb

Browse files
committed
docs(openfeature): document CommonJS and ESM entrypoints
Node 18 and 20 require the `.js` suffix for ESM package subpaths, while CommonJS resolves the extensionless form. The full-root nft assertion exceeded Mocha's timeout under coverage; the runtime-wrapper trace keeps the automatic nft contract pinned without tracing the whole package again.
1 parent 78bff46 commit 404a1fb

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ If you would like to trace your bundled application then please read this page o
9696
When using the experimental OpenFeature provider, file-traced deployments can force the optional provider and
9797
its dependencies into the output with a side-effect import before accessing `tracer.openfeature`:
9898

99+
CommonJS:
100+
101+
```js
102+
require('dd-trace/openfeature')
103+
```
104+
105+
ES modules:
106+
99107
```js
100108
import 'dd-trace/openfeature.js'
101109
```

packages/dd-trace/test/openfeature/file-tracing.spec.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ async function assertTracesProvider (entrypoint) {
2828
}
2929

3030
describe('OpenFeature file tracing', () => {
31-
it('traces the provider dependency tree through the default entrypoint', async () => {
32-
await assertTracesProvider(path.join(repoRoot, 'index.js'))
33-
})
34-
3531
it('traces the provider dependency tree through the runtime wrapper', async () => {
3632
await assertTracesProvider(path.join(repoRoot, 'packages/dd-trace/src/openfeature/flagging_provider.js'))
3733
})
@@ -44,20 +40,26 @@ describe('OpenFeature file tracing', () => {
4440
require(path.join(repoRoot, 'openfeature.js'))
4541
})
4642

47-
it('loads the explicit entrypoint as an ESM package subpath', () => {
43+
it('loads the explicit entrypoint as a CommonJS and ESM package subpath', () => {
4844
const fixtureRoot = mkdtempSync(path.join(tmpdir(), 'dd-trace-openfeature-'))
4945
const nodeModulesPath = path.join(fixtureRoot, 'node_modules')
5046

5147
try {
5248
mkdirSync(nodeModulesPath)
5349
symlinkSync(repoRoot, path.join(nodeModulesPath, 'dd-trace'), 'junction')
54-
const result = spawnSync(
50+
const commonJsResult = spawnSync(
5551
process.execPath,
56-
['--input-type=module', '--eval', "import 'dd-trace/openfeature.js'"],
52+
['--eval', "require('dd-trace/openfeature')"],
5753
{ cwd: fixtureRoot, encoding: 'utf8' }
5854
)
55+
assert.strictEqual(commonJsResult.status, 0, commonJsResult.stderr)
5956

60-
assert.strictEqual(result.status, 0, result.stderr)
57+
const esmResult = spawnSync(
58+
process.execPath,
59+
['--input-type=module', '--eval', "import 'dd-trace/openfeature.js'"],
60+
{ cwd: fixtureRoot, encoding: 'utf8' }
61+
)
62+
assert.strictEqual(esmResult.status, 0, esmResult.stderr)
6163
} finally {
6264
rmSync(fixtureRoot, { recursive: true, force: true })
6365
}

0 commit comments

Comments
 (0)