Skip to content

ref(bun): Ensure bun is latest for local tests #16244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ afterAll(() => {
cleanupChildProcesses();
});

const esmWarning =
'[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.';
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.`;

test("warns if using ESM on Node.js versions that don't support `register()`", async () => {
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
Expand Down
80 changes: 49 additions & 31 deletions packages/bun/scripts/install-bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,58 @@
const installScriptUrl = 'https://bun.sh/install';

// Check if bun is installed
exec('bun -version', error => {
exec('bun -version', (error, version) => {
if (error) {
console.error('bun is not installed. Installing...');
// Download and execute the installation script
https
.get(installScriptUrl, res => {
if (res.statusCode !== 200) {
console.error(`Failed to download the installation script (HTTP ${res.statusCode})`);
process.exit(1);
}

res.setEncoding('utf8');
let scriptData = '';

res.on('data', chunk => {
scriptData += chunk;
});
installLatestBun();
} else {
const versionBefore = version.trim();

res.on('end', () => {
// Execute the downloaded script
exec(scriptData, installError => {
if (installError) {
console.error('Failed to install bun:', installError);
process.exit(1);
}
console.log('bun has been successfully installed.');
});
});
})
.on('error', e => {
console.error('Failed to download the installation script:', e);
exec('bun upgrade', (error, stdout, stderr) => {
if (error) {
console.error('Failed to upgrade bun:', error);
process.exit(1);
});
} else {
// Bun is installed
}

const out = [stdout, stderr].join('\n');

if (out.includes("You're already on the latest version of Bun")) {
return;
}

console.log(out);
});
}
});

function installLatestBun() {
https
.get(installScriptUrl, res => {
if (res.statusCode !== 200) {
console.error(`Failed to download the installation script (HTTP ${res.statusCode})`);
process.exit(1);
}

res.setEncoding('utf8');
let scriptData = '';

res.on('data', chunk => {
scriptData += chunk;
});

res.on('end', () => {
// Execute the downloaded script
exec(scriptData, installError => {
if (installError) {
console.error('Failed to install bun:', installError);
process.exit(1);
}
console.log('bun has been successfully installed.');
});
});
})
.on('error', e => {
console.error('Failed to download the installation script:', e);
process.exit(1);
});
}
2 changes: 1 addition & 1 deletion packages/node/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function maybeInitializeEsmLoader(): void {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'[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.',
`[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.`,
);
});
}
Expand Down
Loading