Skip to content

test(node): Remove import.meta.url hacks #15490

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 3 commits into from
Feb 25, 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
11 changes: 1 addition & 10 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { defineConfig } from 'rollup';
import {
makeCleanupPlugin,
makeDebugBuildStatementReplacePlugin,
makeImportMetaUrlReplacePlugin,
makeNodeResolvePlugin,
makeRrwebBuildPlugin,
makeSucrasePlugin,
Expand All @@ -39,7 +38,6 @@ export function makeBaseNPMConfig(options = {}) {
const nodeResolvePlugin = makeNodeResolvePlugin();
const sucrasePlugin = makeSucrasePlugin({}, sucrase);
const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin();
const importMetaUrlReplacePlugin = makeImportMetaUrlReplacePlugin();
const cleanupPlugin = makeCleanupPlugin();
const rrwebBuildPlugin = makeRrwebBuildPlugin({
excludeShadowDom: undefined,
Expand Down Expand Up @@ -85,14 +83,7 @@ export function makeBaseNPMConfig(options = {}) {
interop: 'esModule',
},

plugins: [
nodeResolvePlugin,
sucrasePlugin,
debugBuildStatementReplacePlugin,
importMetaUrlReplacePlugin,
rrwebBuildPlugin,
cleanupPlugin,
],
plugins: [nodeResolvePlugin, sucrasePlugin, debugBuildStatementReplacePlugin, rrwebBuildPlugin, cleanupPlugin],

// don't include imported modules from outside the package in the final output
external: [
Expand Down
13 changes: 0 additions & 13 deletions dev-packages/rollup-utils/plugins/npmPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,6 @@ export function makeDebugBuildStatementReplacePlugin() {
});
}

/**
* Because jest doesn't like `import.meta` statements but we still need it in the code base we instead use a magic
* string that we replace with import.meta.url in the build.
*/
export function makeImportMetaUrlReplacePlugin() {
return replace({
preventAssignment: false,
values: {
__IMPORT_META_URL_REPLACEMENT__: 'import.meta.url',
},
});
}

/**
* Creates a plugin to replace build flags of rrweb with either a constant (if passed true/false) or with a safe statement that:
* a) evaluates to `true`
Expand Down
10 changes: 2 additions & 8 deletions packages/node/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import { SentryContextManager } from '../otel/contextManager';
import { isCjs } from '../utils/commonjs';
import type { NodeClient } from './client';

declare const __IMPORT_META_URL_REPLACEMENT__: string;

// About 277h - this must fit into new Array(len)!
const MAX_MAX_SPAN_WAIT_DURATION = 1_000_000;

Expand All @@ -45,15 +43,11 @@ export function maybeInitializeEsmLoader(): void {

// Register hook was added in v20.6.0 and v18.19.0
if (nodeMajor >= 22 || (nodeMajor === 20 && nodeMinor >= 6) || (nodeMajor === 18 && nodeMinor >= 19)) {
// We need to work around using import.meta.url directly because jest complains about it.
const importMetaUrl =
typeof __IMPORT_META_URL_REPLACEMENT__ !== 'undefined' ? __IMPORT_META_URL_REPLACEMENT__ : undefined;

if (!GLOBAL_OBJ._sentryEsmLoaderHookRegistered && importMetaUrl) {
if (!GLOBAL_OBJ._sentryEsmLoaderHookRegistered) {
try {
const { addHookMessagePort } = createAddHookMessageChannel();
// @ts-expect-error register is available in these versions
moduleModule.register('import-in-the-middle/hook.mjs', importMetaUrl, {
moduleModule.register('import-in-the-middle/hook.mjs', import.meta.url, {
data: { addHookMessagePort, include: [] },
transferList: [addHookMessagePort],
});
Expand Down
Loading