From d6fb69a862ae172125c832d416deb647085885d0 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 9 Apr 2024 07:55:46 +0000 Subject: [PATCH 1/2] feat: Rename ESM loader hooks to `import-hook` and `loader-hook` --- .../esm-loader-node-express-app/package.json | 2 +- ...mplate.js => otelEsmImportHookTemplate.js} | 0 ...mplate.js => otelEsmLoaderHookTemplate.js} | 0 .../code/sentryNodeEsmHooksLoaderTemplate.js | 1 - ....js => sentryNodeEsmImportHookTemplate.js} | 2 +- .../code/sentryNodeEsmLoaderHookTemplate.js | 1 + dev-packages/rollup-utils/npmHelpers.mjs | 20 +++++++++---------- packages/astro/package.json | 8 ++++---- packages/aws-serverless/package.json | 8 ++++---- packages/google-cloud-serverless/package.json | 8 ++++---- packages/nextjs/package.json | 8 ++++---- packages/node/package.json | 8 ++++---- packages/remix/package.json | 8 ++++---- 13 files changed, 37 insertions(+), 37 deletions(-) rename dev-packages/rollup-utils/code/{otelEsmRegisterLoaderTemplate.js => otelEsmImportHookTemplate.js} (100%) rename dev-packages/rollup-utils/code/{otelEsmHooksLoaderTemplate.js => otelEsmLoaderHookTemplate.js} (100%) delete mode 100644 dev-packages/rollup-utils/code/sentryNodeEsmHooksLoaderTemplate.js rename dev-packages/rollup-utils/code/{sentryNodeEsmRegisterLoaderTemplate.js => sentryNodeEsmImportHookTemplate.js} (87%) create mode 100644 dev-packages/rollup-utils/code/sentryNodeEsmLoaderHookTemplate.js diff --git a/dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/package.json b/dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/package.json index 70055cdf8159..056929e63a76 100644 --- a/dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/package.json +++ b/dev-packages/e2e-tests/test-applications/esm-loader-node-express-app/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { - "start": "node --import=@sentry/node/register src/app.mjs", + "start": "node --import=@sentry/node/import-hook src/app.mjs", "clean": "npx rimraf node_modules,pnpm-lock.yaml", "test:build": "pnpm install", "test:assert": "playwright test" diff --git a/dev-packages/rollup-utils/code/otelEsmRegisterLoaderTemplate.js b/dev-packages/rollup-utils/code/otelEsmImportHookTemplate.js similarity index 100% rename from dev-packages/rollup-utils/code/otelEsmRegisterLoaderTemplate.js rename to dev-packages/rollup-utils/code/otelEsmImportHookTemplate.js diff --git a/dev-packages/rollup-utils/code/otelEsmHooksLoaderTemplate.js b/dev-packages/rollup-utils/code/otelEsmLoaderHookTemplate.js similarity index 100% rename from dev-packages/rollup-utils/code/otelEsmHooksLoaderTemplate.js rename to dev-packages/rollup-utils/code/otelEsmLoaderHookTemplate.js diff --git a/dev-packages/rollup-utils/code/sentryNodeEsmHooksLoaderTemplate.js b/dev-packages/rollup-utils/code/sentryNodeEsmHooksLoaderTemplate.js deleted file mode 100644 index 06fb71a76860..000000000000 --- a/dev-packages/rollup-utils/code/sentryNodeEsmHooksLoaderTemplate.js +++ /dev/null @@ -1 +0,0 @@ -import '@sentry/node/hook'; diff --git a/dev-packages/rollup-utils/code/sentryNodeEsmRegisterLoaderTemplate.js b/dev-packages/rollup-utils/code/sentryNodeEsmImportHookTemplate.js similarity index 87% rename from dev-packages/rollup-utils/code/sentryNodeEsmRegisterLoaderTemplate.js rename to dev-packages/rollup-utils/code/sentryNodeEsmImportHookTemplate.js index 5a9fa441f106..a071457406a7 100644 --- a/dev-packages/rollup-utils/code/sentryNodeEsmRegisterLoaderTemplate.js +++ b/dev-packages/rollup-utils/code/sentryNodeEsmImportHookTemplate.js @@ -1,2 +1,2 @@ -import { getFormat, getSource, load, resolve } from '@sentry/node/register'; +import { getFormat, getSource, load, resolve } from '@sentry/node/loader-hook'; export { getFormat, getSource, load, resolve }; diff --git a/dev-packages/rollup-utils/code/sentryNodeEsmLoaderHookTemplate.js b/dev-packages/rollup-utils/code/sentryNodeEsmLoaderHookTemplate.js new file mode 100644 index 000000000000..d5167fd15bf9 --- /dev/null +++ b/dev-packages/rollup-utils/code/sentryNodeEsmLoaderHookTemplate.js @@ -0,0 +1 @@ +import '@sentry/node/import-hook'; diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index ed6cc4492756..f984cbf518b9 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -151,23 +151,23 @@ export function makeOtelLoaders(outputFolder, hookVariant) { throw new Error('hookVariant is neither "otel" nor "sentry-node". Pick one.'); } - const expectedRegisterLoaderLocation = `${outputFolder}/register.mjs`; + const expectedRegisterLoaderLocation = `${outputFolder}/import-hook.mjs`; const foundRegisterLoaderExport = Object.keys(packageDotJSON.exports ?? {}).some(key => { return packageDotJSON?.exports?.[key]?.import?.default === expectedRegisterLoaderLocation; }); if (!foundRegisterLoaderExport) { throw new Error( - `You used the makeOtelLoaders() rollup utility without specifying the register loader inside \`exports[something].import.default\`. Please add "${expectedRegisterLoaderLocation}" as a value there (maybe check for typos - it needs to be "${expectedRegisterLoaderLocation}" exactly).`, + `You used the makeOtelLoaders() rollup utility without specifying the import hook inside \`exports[something].import.default\`. Please add "${expectedRegisterLoaderLocation}" as a value there (maybe check for typos - it needs to be "${expectedRegisterLoaderLocation}" exactly).`, ); } - const expectedHooksLoaderLocation = `${outputFolder}/hook.mjs`; + const expectedHooksLoaderLocation = `${outputFolder}/loader-hook.mjs`; const foundHookLoaderExport = Object.keys(packageDotJSON.exports ?? {}).some(key => { return packageDotJSON?.exports?.[key]?.import?.default === expectedHooksLoaderLocation; }); if (!foundHookLoaderExport) { throw new Error( - `You used the makeOtelLoaders() rollup utility without specifying the hook loader inside \`exports[something].import.default\`. Please add "${expectedHooksLoaderLocation}" as a value there (maybe check for typos - it needs to be "${expectedHooksLoaderLocation}" exactly).`, + `You used the makeOtelLoaders() rollup utility without specifying the loader hook inside \`exports[something].import.default\`. Please add "${expectedHooksLoaderLocation}" as a value there (maybe check for typos - it needs to be "${expectedHooksLoaderLocation}" exactly).`, ); } @@ -190,12 +190,12 @@ export function makeOtelLoaders(outputFolder, hookVariant) { input: path.join( __dirname, 'code', - hookVariant === 'otel' ? 'otelEsmRegisterLoaderTemplate.js' : 'sentryNodeEsmRegisterLoaderTemplate.js', + hookVariant === 'otel' ? 'otelEsmImportHookTemplate.js' : 'sentryNodeEsmImportHookTemplate.js', ), - external: ['@opentelemetry/instrumentation/hook.mjs', '@sentry/node/register'], + external: /.*/, output: { format: 'esm', - file: path.join(outputFolder, 'register.mjs'), + file: path.join(outputFolder, 'import-hook.mjs'), }, }, // --loader hook @@ -203,12 +203,12 @@ export function makeOtelLoaders(outputFolder, hookVariant) { input: path.join( __dirname, 'code', - hookVariant === 'otel' ? 'otelEsmHooksLoaderTemplate.js' : 'sentryNodeEsmHooksLoaderTemplate.js', + hookVariant === 'otel' ? 'otelEsmLoaderHookTemplate.js' : 'sentryNodeEsmLoaderHookTemplate.js', ), - external: ['@opentelemetry/instrumentation/hook.mjs', '@sentry/node/hook'], + external: /.*/, output: { format: 'esm', - file: path.join(outputFolder, 'hook.mjs'), + file: path.join(outputFolder, 'loader-hook.mjs'), }, }, ]); diff --git a/packages/astro/package.json b/packages/astro/package.json index 457cdc36925f..62e10adbe07a 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -42,14 +42,14 @@ "require": "./build/cjs/integration/middleware/index.js", "types": "./build/types/integration/middleware/index.types.d.ts" }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, diff --git a/packages/aws-serverless/package.json b/packages/aws-serverless/package.json index e74dff71ce72..cb0fc503afe2 100644 --- a/packages/aws-serverless/package.json +++ b/packages/aws-serverless/package.json @@ -25,14 +25,14 @@ "default": "./build/npm/cjs/index.js" } }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, diff --git a/packages/google-cloud-serverless/package.json b/packages/google-cloud-serverless/package.json index 06ca935cd97c..2807a40b73e4 100644 --- a/packages/google-cloud-serverless/package.json +++ b/packages/google-cloud-serverless/package.json @@ -26,14 +26,14 @@ "default": "./build/cjs/index.js" } }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 293401d7d41e..f22e478d79e3 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -43,14 +43,14 @@ "import": "./build/esm/index.server.js", "types": "./build/types/index.types.d.ts" }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, diff --git a/packages/node/package.json b/packages/node/package.json index 187384f24b89..38d26bd86a28 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -31,14 +31,14 @@ "default": "./build/cjs/index.js" } }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, diff --git a/packages/remix/package.json b/packages/remix/package.json index d336a3288d4f..790161acb611 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -34,14 +34,14 @@ "node": "./build/cjs/index.server.js", "types": "./build/types/index.types.d.ts" }, - "./register": { + "./import-hook": { "import": { - "default": "./build/register.mjs" + "default": "./build/import-hook.mjs" } }, - "./hook": { + "./loader-hook": { "import": { - "default": "./build/hook.mjs" + "default": "./build/loader-hook.mjs" } } }, From 9f725aaaefeb8ccd6622ddb1c3d73bd434391f8c Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 11 Apr 2024 06:42:17 +0000 Subject: [PATCH 2/2] Rename subpath exports --- packages/astro/package.json | 4 ++-- packages/aws-serverless/package.json | 4 ++-- packages/google-cloud-serverless/package.json | 4 ++-- packages/nextjs/package.json | 4 ++-- packages/node/package.json | 4 ++-- packages/remix/package.json | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index 62e10adbe07a..9cb714697126 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -42,12 +42,12 @@ "require": "./build/cjs/integration/middleware/index.js", "types": "./build/types/integration/middleware/index.types.d.ts" }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" } diff --git a/packages/aws-serverless/package.json b/packages/aws-serverless/package.json index cb0fc503afe2..762f8422b549 100644 --- a/packages/aws-serverless/package.json +++ b/packages/aws-serverless/package.json @@ -25,12 +25,12 @@ "default": "./build/npm/cjs/index.js" } }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" } diff --git a/packages/google-cloud-serverless/package.json b/packages/google-cloud-serverless/package.json index 2807a40b73e4..e575aecee51f 100644 --- a/packages/google-cloud-serverless/package.json +++ b/packages/google-cloud-serverless/package.json @@ -26,12 +26,12 @@ "default": "./build/cjs/index.js" } }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" } diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index f22e478d79e3..7247e1af4835 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -43,12 +43,12 @@ "import": "./build/esm/index.server.js", "types": "./build/types/index.types.d.ts" }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" } diff --git a/packages/node/package.json b/packages/node/package.json index 38d26bd86a28..c711fc35b620 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -31,12 +31,12 @@ "default": "./build/cjs/index.js" } }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" } diff --git a/packages/remix/package.json b/packages/remix/package.json index 790161acb611..1146d9421531 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -34,12 +34,12 @@ "node": "./build/cjs/index.server.js", "types": "./build/types/index.types.d.ts" }, - "./import-hook": { + "./import": { "import": { "default": "./build/import-hook.mjs" } }, - "./loader-hook": { + "./loader": { "import": { "default": "./build/loader-hook.mjs" }