-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(profiling): Don't put
require
, __filename
and __dirname
on …
…global object (#14470) Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
- Loading branch information
Showing
9 changed files
with
72 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
dev-packages/e2e-tests/test-applications/node-profiling/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,20 @@ | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import replace from '@rollup/plugin-replace'; | ||
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; | ||
|
||
export const ESMShim = ` | ||
import cjsUrl from 'node:url'; | ||
import cjsPath from 'node:path'; | ||
import cjsModule from 'node:module'; | ||
if(typeof __filename === 'undefined'){ | ||
globalThis.__filename = cjsUrl.fileURLToPath(import.meta.url); | ||
} | ||
if(typeof __dirname === 'undefined'){ | ||
globalThis.__dirname = cjsPath.dirname(__filename); | ||
} | ||
if(typeof require === 'undefined'){ | ||
globalThis.require = cjsModule.createRequire(import.meta.url); | ||
} | ||
`; | ||
|
||
function makeESMShimPlugin(shim) { | ||
return { | ||
transform(code) { | ||
const SHIM_REGEXP = /\/\/ #START_SENTRY_ESM_SHIM[\s\S]*?\/\/ #END_SENTRY_ESM_SHIM/; | ||
return code.replace(SHIM_REGEXP, shim); | ||
}, | ||
}; | ||
} | ||
|
||
const variants = makeNPMConfigVariants( | ||
export default makeNPMConfigVariants( | ||
makeBaseNPMConfig({ | ||
packageSpecificConfig: { | ||
output: { dir: 'lib', preserveModules: false }, | ||
plugins: [commonjs()], | ||
plugins: [ | ||
commonjs(), | ||
replace({ | ||
preventAssignment: false, | ||
values: { | ||
__IMPORT_META_URL_REPLACEMENT__: 'import.meta.url', | ||
}, | ||
}), | ||
], | ||
}, | ||
}), | ||
); | ||
|
||
for (const variant of variants) { | ||
if (variant.output.format === 'esm') { | ||
variant.plugins.push(makeESMShimPlugin(ESMShim)); | ||
} else { | ||
// Remove the ESM shim comment | ||
variant.plugins.push(makeESMShimPlugin('')); | ||
} | ||
} | ||
|
||
export default variants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ | |
}, | ||
"include": ["src/**/*"] | ||
} | ||
|