Skip to content

Commit

Permalink
massively lost
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Dec 12, 2024
1 parent fd618e9 commit 4d46401
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,4 @@ esbuild.buildSync({
format: 'esm',
bundle: true,
loader: { '.node': 'copy' },
banner: {
js: `
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
`,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.log('🧵 Starting ESM test');

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

function assertUnpatechedRequire() {
function assertUnpatchedRequire() {
if (typeof require !== 'undefined') {
// Test that globalThis.require is not defined by any side effects of the profiling
// https://github.com/getsentry/sentry-javascript/issues/13662
Expand All @@ -30,5 +30,5 @@ Sentry.startSpan({ name: 'Precompile test' }, async () => {
await wait(500);
});

assertUnpatechedRequire();
assertUnpatchedRequire();
console.log('✅ Require is not patched');
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"scripts": {
"typecheck": "tsc --noEmit",
"build": "node build.mjs && node build.shimmed.mjs",
"test": "node dist/index.js && node --experimental-require-module dist/index.js && node dist/index.shimmed.mjs",
"clean": "npx rimraf node_modules dist",
"test": "node dist/index.js && node --experimental-require-module dist/index.js && node dist/index.shimmed.mjs",
"test:mjs": "node index.mjs",
"test:electron": "$(pnpm bin)/electron-rebuild && playwright test",
"test:build": "pnpm run typecheck && pnpm run build",
"test:assert": "pnpm run test && pnpm run test:electron",
"test:mjs": "node index.mjs"
"test:assert": "pnpm run test:mjs && pnpm run test && pnpm run test:electron"
},
"dependencies": {
"@electron/rebuild": "^3.7.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/profiling-node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const require = createRequire(import.meta.url);
`;

const ESMDirnameShim = `
const filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const __dirname = dirname(fileURLToPath(import.meta.url));
`;

function makeESMImportShimPlugin(shim) {
Expand Down
5 changes: 2 additions & 3 deletions packages/profiling-node/src/cpu_profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
}

// #START_SENTRY_ESM_DIRNAME_SHIM
// const filename = fileURLToPath(import.meta.url);
// const __dirname = dirname(filename);
// const __dirname = dirname(fileURLToPath(import.meta.url));
// #END_SENTRY_ESM_DIRNAME_SHIM
const built_from_source_path = resolve(__dirname, '..', `./sentry_cpu_profiler-${identifier}`);
const built_from_source_path = resolve(__dirname, '..', `sentry_cpu_profiler-${identifier}`);
return require(`${built_from_source_path}.node`);
}

Expand Down

0 comments on commit 4d46401

Please sign in to comment.