Skip to content

Commit 8f5f2f3

Browse files
authored
ref(bun): Ensure bun is latest for local tests (#16244)
I noticed that my bun version locally was old, leading to weird test issues. Now, our install script will ensure this is the latest version. On CI, we already test against the latest version. (Noticed this because bun 1.0.2 which I had installed reports itself as Node 18.5.0 which lead to ESM warnings)
1 parent 5a12eed commit 8f5f2f3

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ afterAll(() => {
55
cleanupChildProcesses();
66
});
77

8-
const esmWarning =
9-
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.';
8+
const esmWarning = `[Sentry] You are using Node.js v${process.versions.node} in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.`;
109

1110
test("warns if using ESM on Node.js versions that don't support `register()`", async () => {
1211
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);

packages/bun/scripts/install-bun.js

+49-31
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,58 @@ const https = require('https');
1010
const installScriptUrl = 'https://bun.sh/install';
1111

1212
// Check if bun is installed
13-
exec('bun -version', error => {
13+
exec('bun -version', (error, version) => {
1414
if (error) {
1515
console.error('bun is not installed. Installing...');
16-
// Download and execute the installation script
17-
https
18-
.get(installScriptUrl, res => {
19-
if (res.statusCode !== 200) {
20-
console.error(`Failed to download the installation script (HTTP ${res.statusCode})`);
21-
process.exit(1);
22-
}
23-
24-
res.setEncoding('utf8');
25-
let scriptData = '';
26-
27-
res.on('data', chunk => {
28-
scriptData += chunk;
29-
});
16+
installLatestBun();
17+
} else {
18+
const versionBefore = version.trim();
3019

31-
res.on('end', () => {
32-
// Execute the downloaded script
33-
exec(scriptData, installError => {
34-
if (installError) {
35-
console.error('Failed to install bun:', installError);
36-
process.exit(1);
37-
}
38-
console.log('bun has been successfully installed.');
39-
});
40-
});
41-
})
42-
.on('error', e => {
43-
console.error('Failed to download the installation script:', e);
20+
exec('bun upgrade', (error, stdout, stderr) => {
21+
if (error) {
22+
console.error('Failed to upgrade bun:', error);
4423
process.exit(1);
45-
});
46-
} else {
47-
// Bun is installed
24+
}
25+
26+
const out = [stdout, stderr].join('\n');
27+
28+
if (out.includes("You're already on the latest version of Bun")) {
29+
return;
30+
}
31+
32+
console.log(out);
33+
});
4834
}
4935
});
36+
37+
function installLatestBun() {
38+
https
39+
.get(installScriptUrl, res => {
40+
if (res.statusCode !== 200) {
41+
console.error(`Failed to download the installation script (HTTP ${res.statusCode})`);
42+
process.exit(1);
43+
}
44+
45+
res.setEncoding('utf8');
46+
let scriptData = '';
47+
48+
res.on('data', chunk => {
49+
scriptData += chunk;
50+
});
51+
52+
res.on('end', () => {
53+
// Execute the downloaded script
54+
exec(scriptData, installError => {
55+
if (installError) {
56+
console.error('Failed to install bun:', installError);
57+
process.exit(1);
58+
}
59+
console.log('bun has been successfully installed.');
60+
});
61+
});
62+
})
63+
.on('error', e => {
64+
console.error('Failed to download the installation script:', e);
65+
process.exit(1);
66+
});
67+
}

packages/node/src/sdk/initOtel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function maybeInitializeEsmLoader(): void {
5959
consoleSandbox(() => {
6060
// eslint-disable-next-line no-console
6161
console.warn(
62-
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.',
62+
`[Sentry] You are using Node.js v${process.versions.node} in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.`,
6363
);
6464
});
6565
}

0 commit comments

Comments
 (0)