Skip to content

Commit

Permalink
feat: Rename ESM loader hooks to import and loader (#11498)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Apr 11, 2024
1 parent ac803e9 commit 80c0ee6
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 };
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@sentry/node/import-hook';
20 changes: 10 additions & 10 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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).`,
);
}

Expand All @@ -190,25 +190,25 @@ 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
{
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'),
},
},
]);
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"require": "./build/cjs/integration/middleware/index.js",
"types": "./build/types/integration/middleware/index.types.d.ts"
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"default": "./build/npm/cjs/index.js"
}
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/google-cloud-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"default": "./build/cjs/index.js"
}
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"import": "./build/esm/index.server.js",
"types": "./build/types/index.types.d.ts"
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"default": "./build/cjs/index.js"
}
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"node": "./build/cjs/index.server.js",
"types": "./build/types/index.types.d.ts"
},
"./register": {
"./import": {
"import": {
"default": "./build/register.mjs"
"default": "./build/import-hook.mjs"
}
},
"./hook": {
"./loader": {
"import": {
"default": "./build/hook.mjs"
"default": "./build/loader-hook.mjs"
}
}
},
Expand Down

0 comments on commit 80c0ee6

Please sign in to comment.