Skip to content

Commit 537a4a7

Browse files
authored
fix: restore the try catch in esubild because could fail using yarn (#6774)
1 parent e955673 commit 537a4a7

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

integration-tests/esbuild/build.esm-hono-output-cjs.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const external = [
1818
// required if you use profiling
1919
'@datadog/pprof',
2020

21-
// @openfeature/core is a peer dependency of @openfeature/server-sdk
22-
// which is used by @datadog/openfeature-node-server
23-
'@openfeature/core',
24-
2521
// required if you use Datadog security features
2622
'@datadog/native-appsec',
2723
'@datadog/native-iast-taint-tracking',

integration-tests/esbuild/build.esm-hono-output-esm.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const external = [
1818
// required if you use profiling
1919
'@datadog/pprof',
2020

21-
// @openfeature/core is a peer dependency of @openfeature/server-sdk
22-
// which is used by @datadog/openfeature-node-server
23-
'@openfeature/core',
24-
2521
// required if you use Datadog security features
2622
'@datadog/native-appsec',
2723
'@datadog/native-iast-taint-tracking',

integration-tests/esbuild/build.esm-http-output-cjs.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const external = [
1818
// required if you use profiling
1919
'@datadog/pprof',
2020

21-
// @openfeature/core is a peer dependency of @openfeature/server-sdk
22-
// which is used by @datadog/openfeature-node-server
23-
'@openfeature/core',
24-
2521
// required if you use Datadog security features
2622
'@datadog/native-appsec',
2723
'@datadog/native-iast-taint-tracking',

integration-tests/esbuild/build.esm-http-output-esm.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ const external = [
1818
// required if you use profiling
1919
'@datadog/pprof',
2020

21-
// @openfeature/core is a peer dependency of @openfeature/server-sdk
22-
// which is used by @datadog/openfeature-node-server
23-
'@openfeature/core',
24-
2521
// required if you use Datadog security features
2622
'@datadog/native-appsec',
2723
'@datadog/native-iast-taint-tracking',
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
3+
const { execSync } = require('node:child_process')
4+
const path = require('node:path')
5+
6+
const { FakeAgent, createSandbox } = require('../helpers')
7+
8+
// This should switch to our withVersion helper. The order here currently matters.
9+
const esbuildVersions = ['latest', '0.16.12']
10+
11+
esbuildVersions.forEach((version) => {
12+
describe('OpenFeature', () => {
13+
let sandbox, agent, cwd
14+
15+
before(async () => {
16+
sandbox = await createSandbox([`esbuild@${version}`, 'hono', '@hono/node-server'], false, [__dirname])
17+
cwd = sandbox.folder
18+
// remove all node_modules and bun.lock file and install with yarn
19+
// TODO add this in createSandbox if it's need in more places
20+
execSync(`rm -rf ${path.join(cwd, 'node_modules')}`, { cwd })
21+
execSync(`rm -rf ${path.join(cwd, 'bun.lock')}`, { cwd })
22+
execSync('npm install -g yarn', { cwd })
23+
24+
execSync('yarn', { cwd })
25+
})
26+
27+
beforeEach(async () => {
28+
agent = await new FakeAgent().start()
29+
})
30+
31+
after(() => {
32+
sandbox.remove()
33+
})
34+
35+
afterEach(() => {
36+
agent.stop()
37+
})
38+
39+
it('should not crash build after installing with yarn', () => {
40+
execSync('node esbuild/build.esm-hono-output-esm.mjs', { cwd })
41+
})
42+
})
43+
})

packages/datadog-esbuild/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ module.exports.setup = function (build) {
113113
${build.initialOptions.banner.js}`
114114
}
115115

116+
try {
117+
// eslint-disable-next-line n/no-unpublished-require
118+
require.resolve('@openfeature/core')
119+
} catch (error) {
120+
build.initialOptions.external ??= []
121+
build.initialOptions.external.push('@openfeature/core')
122+
}
123+
116124
const esmBuild = isESMBuild(build)
117125
if (esmBuild) {
118126
if (!build.initialOptions.banner.js.includes('import { createRequire as $dd_createRequire } from \'module\'')) {

0 commit comments

Comments
 (0)