From 99a9d0f773dd48cb4bc54dccb642d8f182a6d932 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 5 Mar 2024 14:47:17 +0000 Subject: [PATCH 1/8] feat(esm): ESM Take 10 --- packages/browser/package.json | 13 +++++++++++++ packages/bun/package.json | 13 +++++++++++++ packages/core/package.json | 13 +++++++++++++ packages/deno/package.json | 9 +++++++++ packages/feedback/package.json | 13 +++++++++++++ packages/gatsby/package.json | 13 +++++++++++++ packages/integration-shims/package.json | 13 +++++++++++++ packages/nextjs/package.json | 11 +++++++++++ packages/node-experimental/package.json | 13 +++++++++++++ packages/node/package.json | 13 +++++++++++++ packages/opentelemetry/package.json | 13 +++++++++++++ packages/profiling-node/package.json | 9 +++++++++ packages/react/package.json | 13 +++++++++++++ packages/remix/package.json | 11 +++++++++++ packages/replay-canvas/package.json | 13 +++++++++++++ packages/replay/package.json | 13 +++++++++++++ packages/serverless/package.json | 13 +++++++++++++ packages/svelte/package.json | 13 +++++++++++++ packages/tracing-internal/package.json | 13 +++++++++++++ packages/types/package.json | 13 +++++++++++++ packages/utils/package.json | 13 +++++++++++++ packages/vercel-edge/package.json | 13 +++++++++++++ packages/vue/package.json | 13 +++++++++++++ packages/wasm/package.json | 13 +++++++++++++ 24 files changed, 300 insertions(+) diff --git a/packages/browser/package.json b/packages/browser/package.json index 876e3c45889d..ca9ccfc08c00 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -18,6 +18,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm.types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/bun/package.json b/packages/bun/package.json index aa2aa15d1949..2cd604ee2aa3 100644 --- a/packages/bun/package.json +++ b/packages/bun/package.json @@ -18,6 +18,19 @@ "main": "build/esm/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/core/package.json b/packages/core/package.json index 6c58cbf762ee..b48b55674da8 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/deno/package.json b/packages/deno/package.json index 6eebb79744ef..7e8a0b73153d 100644 --- a/packages/deno/package.json +++ b/packages/deno/package.json @@ -8,6 +8,15 @@ "license": "MIT", "module": "build/index.mjs", "types": "build/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/index.d.ts", + "default": "./build/index.mjs" + } + } + }, "publishConfig": { "access": "public" }, diff --git a/packages/feedback/package.json b/packages/feedback/package.json index d9364a8c8c7a..af4e16c0e984 100644 --- a/packages/feedback/package.json +++ b/packages/feedback/package.json @@ -18,6 +18,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 102b287526fb..6dc12fe4c46f 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -26,6 +26,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/integration-shims/package.json b/packages/integration-shims/package.json index 738ea4283aa8..7f6ce335fb53 100644 --- a/packages/integration-shims/package.json +++ b/packages/integration-shims/package.json @@ -5,6 +5,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index b2007ba6a0e5..f52f12d0500c 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -13,6 +13,17 @@ "module": "build/esm/index.server.js", "browser": "build/esm/index.client.js", "types": "build/types/index.types.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "browser": { + "import": "./build/esm/index.client.js", + "require": "./build/cjs/index.client.js" + }, + "node": "./build/cjs/index.server.js", + "types": "./build/types/index.types.d.ts" + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/node-experimental/package.json b/packages/node-experimental/package.json index d3a13592ed95..99ce3ed75839 100644 --- a/packages/node-experimental/package.json +++ b/packages/node-experimental/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/node/package.json b/packages/node/package.json index dc592187497c..770136f7e211 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/opentelemetry/package.json b/packages/opentelemetry/package.json index 18580c872a98..9fd0b027ba75 100644 --- a/packages/opentelemetry/package.json +++ b/packages/opentelemetry/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/profiling-node/package.json b/packages/profiling-node/package.json index bb5bd71c9751..7d30ddaa0e0b 100644 --- a/packages/profiling-node/package.json +++ b/packages/profiling-node/package.json @@ -8,6 +8,15 @@ "license": "MIT", "main": "lib/index.js", "types": "lib/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "require": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + } + } + }, "typesVersions": { "<4.9": { "lib/types/index.d.ts": [ diff --git a/packages/react/package.json b/packages/react/package.json index 5d62912e20d5..bd064b618942 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/remix/package.json b/packages/remix/package.json index 56c384aacfc8..ea08e02a0fee 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -23,6 +23,17 @@ "module": "build/esm/index.server.js", "browser": "build/esm/index.client.js", "types": "build/types/index.types.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "browser": { + "import": "./build/esm/index.client.js", + "require": "./build/cjs/index.client.js" + }, + "node": "./build/cjs/index.server.js", + "types": "./build/types/index.types.d.ts" + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/replay-canvas/package.json b/packages/replay-canvas/package.json index c470d8fe3929..3971ab4a808e 100644 --- a/packages/replay-canvas/package.json +++ b/packages/replay-canvas/package.json @@ -5,6 +5,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/replay/package.json b/packages/replay/package.json index 408c525021fa..4666430eb086 100644 --- a/packages/replay/package.json +++ b/packages/replay/package.json @@ -5,6 +5,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/serverless/package.json b/packages/serverless/package.json index f5324520cf73..757417bf1dd3 100644 --- a/packages/serverless/package.json +++ b/packages/serverless/package.json @@ -18,6 +18,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ diff --git a/packages/svelte/package.json b/packages/svelte/package.json index 10d3772c2dd3..9fd1ce6bf55b 100644 --- a/packages/svelte/package.json +++ b/packages/svelte/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/tracing-internal/package.json b/packages/tracing-internal/package.json index e44b65b30b3a..6973e3f06fc8 100644 --- a/packages/tracing-internal/package.json +++ b/packages/tracing-internal/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/types/package.json b/packages/types/package.json index df573a2bccff..b2b619f3d88e 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/utils/package.json b/packages/utils/package.json index b6fc4521fa0b..acc09a882831 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/vercel-edge/package.json b/packages/vercel-edge/package.json index 494972f57ce0..6ae02b8570e7 100644 --- a/packages/vercel-edge/package.json +++ b/packages/vercel-edge/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/vue/package.json b/packages/vue/package.json index 9a7085225bc8..d3686a5f9adc 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -18,6 +18,19 @@ "main": "build/cjs/index.js", "module": "build/esm/index.js", "types": "build/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/types/index.d.ts", + "default": "./build/esm/index.js" + }, + "require": { + "types": "./build/types/index.d.ts", + "default": "./build/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/types/index.d.ts": [ diff --git a/packages/wasm/package.json b/packages/wasm/package.json index 9fc6f4c5d604..df154cd497ad 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -18,6 +18,19 @@ "main": "build/npm/cjs/index.js", "module": "build/npm/esm/index.js", "types": "build/npm/types/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/esm/index.js" + }, + "require": { + "types": "./build/npm/types/index.d.ts", + "default": "./build/npm/cjs/index.js" + } + } + }, "typesVersions": { "<4.9": { "build/npm/types/index.d.ts": [ From 1946283aaf7a654993e0c75ccc8138dc88046d25 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 5 Mar 2024 17:45:06 +0000 Subject: [PATCH 2/8] Fix esm... --- dev-packages/rollup-utils/npmHelpers.mjs | 3 ++- .../rollup-utils/plugins/make-esm-plugin.mjs | 16 ++++++++++++++++ .../src/integrations/tracing/prisma.ts | 5 +++-- packages/node-experimental/src/sdk/init.ts | 8 +++++--- 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 dev-packages/rollup-utils/plugins/make-esm-plugin.mjs diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 6085a502200f..89921fa7ffc4 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -17,6 +17,7 @@ import { makeSetSDKSourcePlugin, makeSucrasePlugin, } from './plugins/index.mjs'; +import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs'; import { mergePlugins } from './utils.mjs'; const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' })); @@ -120,7 +121,7 @@ export function makeBaseNPMConfig(options = {}) { export function makeNPMConfigVariants(baseConfig) { const variantSpecificConfigs = [ { output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } }, - { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } }, + { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] } }, ]; return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant)); diff --git a/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs b/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs new file mode 100644 index 000000000000..aa3f272ba2e0 --- /dev/null +++ b/dev-packages/rollup-utils/plugins/make-esm-plugin.mjs @@ -0,0 +1,16 @@ +/** + * Outputs a package.json file with {type: module} in the root of the output directory so that Node + * treats .js files as ESM. + */ +export function makePackageNodeEsm() { + return { + name: 'make-package-node-esm', + generateBundle() { + this.emitFile({ + type: 'asset', + fileName: 'package.json', + source: '{ "type": "module" }', + }); + }, + }; +} diff --git a/packages/node-experimental/src/integrations/tracing/prisma.ts b/packages/node-experimental/src/integrations/tracing/prisma.ts index 1f78262b9a3c..608865fb1de9 100644 --- a/packages/node-experimental/src/integrations/tracing/prisma.ts +++ b/packages/node-experimental/src/integrations/tracing/prisma.ts @@ -1,5 +1,6 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; -import { PrismaInstrumentation } from '@prisma/instrumentation'; +// When importing CommonJs modules into an ESM module, we import the named exports directly. +import * as prismaInstrumentation from '@prisma/instrumentation'; import { defineIntegration } from '@sentry/core'; import type { IntegrationFn } from '@sentry/types'; @@ -10,7 +11,7 @@ const _prismaIntegration = (() => { registerInstrumentations({ instrumentations: [ // does not have a hook to adjust spans & add origin - new PrismaInstrumentation({}), + new prismaInstrumentation.PrismaInstrumentation({}), ], }); }, diff --git a/packages/node-experimental/src/sdk/init.ts b/packages/node-experimental/src/sdk/init.ts index 5e62a01de6cd..712e27d35963 100644 --- a/packages/node-experimental/src/sdk/init.ts +++ b/packages/node-experimental/src/sdk/init.ts @@ -39,6 +39,10 @@ import { defaultStackParser, getSentryRelease } from './api'; import { NodeClient } from './client'; import { initOtel } from './initOtel'; +function getCjsOnlyIntegrations(isCjs = typeof require !== 'undefined'): Integration[] { + return isCjs ? [nativeNodeFetchIntegration(), modulesIntegration()] : []; +} + /** Get the default integrations for the Node Experimental SDK. */ export function getDefaultIntegrations(options: Options): Integration[] { // TODO @@ -51,7 +55,6 @@ export function getDefaultIntegrations(options: Options): Integration[] { // Native Wrappers consoleIntegration(), httpIntegration(), - nativeNodeFetchIntegration(), // Global Handlers onUncaughtExceptionIntegration(), onUnhandledRejectionIntegration(), @@ -59,9 +62,8 @@ export function getDefaultIntegrations(options: Options): Integration[] { contextLinesIntegration(), localVariablesIntegration(), nodeContextIntegration(), - modulesIntegration(), httpIntegration(), - nativeNodeFetchIntegration(), + ...getCjsOnlyIntegrations(), ...(hasTracingEnabled(options) ? getAutoPerformanceIntegrations() : []), ]; } From 758a60d2d3996d48cc7ca25bf9f68fa3d37a482a Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Tue, 5 Mar 2024 22:52:24 +0000 Subject: [PATCH 3/8] Fix nextjs router import --- .../client/routing/pagesRouterRoutingInstrumentation.ts | 8 +++++++- .../test/performance/pagesRouterInstrumentation.test.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts b/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts index fe28ad71558e..e13c51827c6e 100644 --- a/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts +++ b/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts @@ -14,7 +14,13 @@ import { stripUrlQueryAndFragment, } from '@sentry/utils'; import type { NEXT_DATA as NextData } from 'next/dist/next-server/lib/utils'; -import { default as Router } from 'next/router'; +import RouterImport from 'next/router'; + +// next/router v10 is CJS +// +// For ESM/CJS interoperability 'reasons', depending on how this file is loaded, Router might be on the default export +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any +const Router: typeof RouterImport = RouterImport.events ? RouterImport : (RouterImport as any).default; import { DEBUG_BUILD } from '../../common/debug-build'; diff --git a/packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts b/packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts index aaf7a7417c15..76cfdec677b6 100644 --- a/packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts +++ b/packages/nextjs/test/performance/pagesRouterInstrumentation.test.ts @@ -1,7 +1,7 @@ import { WINDOW } from '@sentry/react'; import { JSDOM } from 'jsdom'; import type { NEXT_DATA as NextData } from 'next/dist/next-server/lib/utils'; -import { default as Router } from 'next/router'; +import Router from 'next/router'; import { pagesRouterInstrumentation } from '../../src/client/routing/pagesRouterRoutingInstrumentation'; From 5fa62e7f909e1242cec0047a6977e6cdbba05574 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 6 Mar 2024 11:23:58 +0000 Subject: [PATCH 4/8] Use `nativeNodeFetchIntegration` for ESM too --- .../src/integrations/node-fetch.ts | 26 +++++++++---------- .../src/integrations/tracing/prisma.ts | 2 +- packages/node-experimental/src/sdk/init.ts | 3 ++- packages/node-experimental/tsconfig.json | 3 ++- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/node-experimental/src/integrations/node-fetch.ts b/packages/node-experimental/src/integrations/node-fetch.ts index 254b3f93e930..a80d015515bb 100644 --- a/packages/node-experimental/src/integrations/node-fetch.ts +++ b/packages/node-experimental/src/integrations/node-fetch.ts @@ -27,22 +27,20 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { const _breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs; const _ignoreOutgoingRequests = options.ignoreOutgoingRequests; - function getInstrumentation(): [Instrumentation] | void { + async function getInstrumentation(): Promise<[Instrumentation] | void> { // Only add NodeFetch if Node >= 16, as previous versions do not support it if (NODE_MAJOR < 16) { return; } try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { FetchInstrumentation } = require('opentelemetry-instrumentation-fetch-node'); + const pkg = await import('opentelemetry-instrumentation-fetch-node'); return [ - new FetchInstrumentation({ + new pkg.FetchInstrumentation({ ignoreRequestHook: (request: { origin?: string }) => { const url = request.origin; return _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url); }, - onRequest: ({ span }: { span: Span }) => { _updateSpan(span); @@ -50,7 +48,8 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { _addRequestBreadcrumb(span); } }, - }), + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any), ]; } catch (error) { // Could not load instrumentation @@ -60,13 +59,14 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { return { name: 'NodeFetch', setupOnce() { - const instrumentations = getInstrumentation(); - - if (instrumentations) { - registerInstrumentations({ - instrumentations, - }); - } + // eslint-disable-next-line @typescript-eslint/no-floating-promises + getInstrumentation().then(instrumentations => { + if (instrumentations) { + registerInstrumentations({ + instrumentations, + }); + } + }); }, }; }) satisfies IntegrationFn; diff --git a/packages/node-experimental/src/integrations/tracing/prisma.ts b/packages/node-experimental/src/integrations/tracing/prisma.ts index 608865fb1de9..e261e95b9196 100644 --- a/packages/node-experimental/src/integrations/tracing/prisma.ts +++ b/packages/node-experimental/src/integrations/tracing/prisma.ts @@ -1,5 +1,5 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; -// When importing CommonJs modules into an ESM module, we import the named exports directly. +// When importing CJS modules into an ESM module, we cannot import the named exports directly. import * as prismaInstrumentation from '@prisma/instrumentation'; import { defineIntegration } from '@sentry/core'; import type { IntegrationFn } from '@sentry/types'; diff --git a/packages/node-experimental/src/sdk/init.ts b/packages/node-experimental/src/sdk/init.ts index 712e27d35963..a018dbdbb435 100644 --- a/packages/node-experimental/src/sdk/init.ts +++ b/packages/node-experimental/src/sdk/init.ts @@ -40,7 +40,7 @@ import { NodeClient } from './client'; import { initOtel } from './initOtel'; function getCjsOnlyIntegrations(isCjs = typeof require !== 'undefined'): Integration[] { - return isCjs ? [nativeNodeFetchIntegration(), modulesIntegration()] : []; + return isCjs ? [modulesIntegration()] : []; } /** Get the default integrations for the Node Experimental SDK. */ @@ -55,6 +55,7 @@ export function getDefaultIntegrations(options: Options): Integration[] { // Native Wrappers consoleIntegration(), httpIntegration(), + nativeNodeFetchIntegration(), // Global Handlers onUncaughtExceptionIntegration(), onUnhandledRejectionIntegration(), diff --git a/packages/node-experimental/tsconfig.json b/packages/node-experimental/tsconfig.json index 5fc0658105eb..f85d40079e2e 100644 --- a/packages/node-experimental/tsconfig.json +++ b/packages/node-experimental/tsconfig.json @@ -4,6 +4,7 @@ "include": ["src/**/*"], "compilerOptions": { - "lib": ["es6"] + "lib": ["es6"], + "module": "Node16", } } From 1e9ea30ff895da3807137eadc04c7024a4199c3c Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 6 Mar 2024 11:47:55 +0000 Subject: [PATCH 5/8] Include `optionalDependencies` as rollup externals --- dev-packages/rollup-utils/npmHelpers.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 89921fa7ffc4..76391efebd27 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -105,6 +105,7 @@ export function makeBaseNPMConfig(options = {}) { ...builtinModules, ...Object.keys(packageDotJSON.dependencies || {}), ...Object.keys(packageDotJSON.peerDependencies || {}), + ...Object.keys(packageDotJSON.optionalDependencies || {}), ], }; From 7c6fffd3622c6ddcbb288a5da2d32150bf305c03 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 7 Mar 2024 22:14:56 +0000 Subject: [PATCH 6/8] Fix http/https issues with old no package so tests pass --- packages/node/package.json | 2 +- packages/node/src/handlers.ts | 2 ++ packages/node/src/integrations/http.ts | 2 +- packages/node/src/integrations/utils/errorhandling.ts | 1 + packages/node/src/integrations/utils/http.ts | 4 ++-- packages/node/src/proxy/helpers.ts | 4 ++-- packages/node/src/transports/http.ts | 4 ++-- packages/node/test/transports/http.test.ts | 5 ++++- packages/node/test/transports/https.test.ts | 5 ++++- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/node/package.json b/packages/node/package.json index 770136f7e211..b492c45074b2 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -51,7 +51,7 @@ "@types/cookie": "0.5.2", "@types/express": "^4.17.14", "@types/lru-cache": "^5.1.0", - "@types/node": "~10.17.0", + "@types/node": "14.18.63", "express": "^4.17.1", "nock": "^13.0.5", "undici": "^5.21.0" diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 5c1c0a26e481..826758befc75 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -141,6 +141,8 @@ export function requestHandler( if (options && options.flushTimeout && options.flushTimeout > 0) { // eslint-disable-next-line @typescript-eslint/unbound-method const _end = res.end; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore I've only updated the node types and this package will soon be removed res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void { void flush(options.flushTimeout) .then(() => { diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 75dc8e061537..941682ee0290 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -206,7 +206,7 @@ export class Http implements Integration { // It has been changed in Node 9, so for all versions equal and above, we patch `https` separately. if (NODE_VERSION.major > 8) { // eslint-disable-next-line @typescript-eslint/no-var-requires - const httpsModule = require('https'); + const httpsModule = require('node:https'); const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory( httpsModule, this._breadcrumbs, diff --git a/packages/node/src/integrations/utils/errorhandling.ts b/packages/node/src/integrations/utils/errorhandling.ts index 5d3abb90afce..fc2a2c2b8e7b 100644 --- a/packages/node/src/integrations/utils/errorhandling.ts +++ b/packages/node/src/integrations/utils/errorhandling.ts @@ -20,6 +20,7 @@ export function logAndExitProcess(error: Error): void { if (client === undefined) { DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.'); global.process.exit(1); + return; } const options = client.getOptions(); diff --git a/packages/node/src/integrations/utils/http.ts b/packages/node/src/integrations/utils/http.ts index 87982f5b3ba3..82319c2fcdb8 100644 --- a/packages/node/src/integrations/utils/http.ts +++ b/packages/node/src/integrations/utils/http.ts @@ -1,5 +1,5 @@ -import type * as http from 'http'; -import type * as https from 'https'; +import type * as http from 'node:http'; +import type * as https from 'node:https'; import { URL } from 'url'; import { NODE_VERSION } from '../../nodeVersion'; diff --git a/packages/node/src/proxy/helpers.ts b/packages/node/src/proxy/helpers.ts index 119ffd9317ce..a5064408855d 100644 --- a/packages/node/src/proxy/helpers.ts +++ b/packages/node/src/proxy/helpers.ts @@ -27,8 +27,8 @@ */ /* eslint-disable jsdoc/require-jsdoc */ -import * as http from 'http'; -import * as https from 'https'; +import * as http from 'node:http'; +import * as https from 'node:https'; import type { Readable } from 'stream'; // TODO (v8): Remove this when Node < 12 is no longer supported import type { URL } from 'url'; diff --git a/packages/node/src/transports/http.ts b/packages/node/src/transports/http.ts index 83d8bab5141a..a6a05fc07c95 100644 --- a/packages/node/src/transports/http.ts +++ b/packages/node/src/transports/http.ts @@ -1,5 +1,5 @@ -import * as http from 'http'; -import * as https from 'https'; +import * as http from 'node:http'; +import * as https from 'node:https'; import { Readable } from 'stream'; import { URL } from 'url'; import { createGzip } from 'zlib'; diff --git a/packages/node/test/transports/http.test.ts b/packages/node/test/transports/http.test.ts index 3b3d969af5e7..d7f4535b6b6d 100644 --- a/packages/node/test/transports/http.test.ts +++ b/packages/node/test/transports/http.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import * as http from 'http'; import { createGunzip } from 'zlib'; @@ -50,7 +51,9 @@ function setupTestServer( res.end(); // also terminate socket because keepalive hangs connection a bit - res.connection.end(); + if (res.connection) { + res.connection.end(); + } }); testServer.listen(18099); diff --git a/packages/node/test/transports/https.test.ts b/packages/node/test/transports/https.test.ts index 58e3cb6c7faa..d6782293e666 100644 --- a/packages/node/test/transports/https.test.ts +++ b/packages/node/test/transports/https.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import * as http from 'http'; import * as https from 'https'; import { createTransport } from '@sentry/core'; @@ -49,7 +50,9 @@ function setupTestServer( res.end(); // also terminate socket because keepalive hangs connection a bit - res.connection.end(); + if (res.connection) { + res.connection.end(); + } }); testServer.listen(8099); From 00635a954da73a4e5a11c6f315c9d234cecdf38d Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 7 Mar 2024 22:54:55 +0000 Subject: [PATCH 7/8] more http fixes --- packages/node/src/integrations/anr/index.ts | 1 + packages/node/test/handlers.test.ts | 2 ++ packages/node/test/integrations/undici.test.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/packages/node/src/integrations/anr/index.ts b/packages/node/src/integrations/anr/index.ts index bfb81557fd75..7e0de1d0badc 100644 --- a/packages/node/src/integrations/anr/index.ts +++ b/packages/node/src/integrations/anr/index.ts @@ -120,6 +120,7 @@ async function _startWorker(client: NodeClient, _options: Partial { + // eslint-disable-next-line @typescript-eslint/no-floating-promises worker.terminate(); }); diff --git a/packages/node/test/handlers.test.ts b/packages/node/test/handlers.test.ts index 861cfdf13259..ba71541acbab 100644 --- a/packages/node/test/handlers.test.ts +++ b/packages/node/test/handlers.test.ts @@ -151,6 +151,7 @@ describe('requestHandler', () => { setImmediate(() => { expect(flush).toHaveBeenCalledWith(1337); + // eslint-disable-next-line deprecation/deprecation expect(res.finished).toBe(true); done(); }); @@ -164,6 +165,7 @@ describe('requestHandler', () => { res.end('ok'); setImmediate(() => { + // eslint-disable-next-line deprecation/deprecation expect(res.finished).toBe(true); done(); }); diff --git a/packages/node/test/integrations/undici.test.ts b/packages/node/test/integrations/undici.test.ts index 86bfb98a6802..ef1f45d92ebb 100644 --- a/packages/node/test/integrations/undici.test.ts +++ b/packages/node/test/integrations/undici.test.ts @@ -498,6 +498,7 @@ function setupTestServer() { res.end(); // also terminate socket because keepalive hangs connection a bit + // eslint-disable-next-line deprecation/deprecation res.connection?.end(); }); From e94e2d79d1677b0f162b3c03ec15f09526a57276 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Fri, 8 Mar 2024 15:45:53 +0000 Subject: [PATCH 8/8] Remove bundle size job --- .github/workflows/build.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d36639039e72..843e8e764207 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -279,39 +279,6 @@ jobs: # `job_build` can't see `job_install_deps` and what it returned) dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }} - job_size_check: - name: Size Check - needs: [job_get_metadata, job_build] - timeout-minutes: 15 - runs-on: ubuntu-20.04 - if: - github.event_name == 'pull_request' || needs.job_get_metadata.outputs.is_develop == 'true' || - needs.job_get_metadata.outputs.is_release == 'true' - steps: - - name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }}) - uses: actions/checkout@v4 - with: - ref: ${{ env.HEAD_COMMIT }} - - name: Set up Node - uses: actions/setup-node@v4 - with: - # The size limit action runs `yarn` and `yarn build` when this job is executed on - # use Node 14 for now. - node-version: '14' - - name: Restore caches - uses: ./.github/actions/restore-cache - env: - DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check bundle sizes - uses: getsentry/size-limit-action@runForBranch - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - skip_step: build - main_branch: develop - # When on release branch, we want to always run - # Else, we fall back to the default handling of the action - run_for_branch: ${{ (needs.job_get_metadata.outputs.is_release == 'true' && 'true') || '' }} - job_lint: name: Lint # Even though the linter only checks source code, not built code, it needs the built code in order check that all