Skip to content

fix(aws-serverless): Fix loader script exports #11981

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

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
* This creates a loader file at the target location as part of the rollup build.
* This loader script can then be used in combination with various Node.js flags (like --import=...) to monkeypatch 3rd party modules.
*/
export function makeOtelLoaders(outputFolder, hookVariant) {
export function makeOtelLoaders(outputFolder, hookVariant, ignoreWarnings = false) {
if (hookVariant !== 'otel' && hookVariant !== 'sentry-node') {
throw new Error('hookVariant is neither "otel" nor "sentry-node". Pick one.');
}
Expand All @@ -160,7 +160,7 @@ export function makeOtelLoaders(outputFolder, hookVariant) {
const foundRegisterLoaderExport = Object.keys(packageDotJSON.exports ?? {}).some(key => {
return packageDotJSON?.exports?.[key]?.import?.default === expectedRegisterLoaderLocation;
});
if (!foundRegisterLoaderExport) {
if (!foundRegisterLoaderExport && !ignoreWarnings) {
throw new Error(
`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).`,
);
Expand All @@ -170,7 +170,7 @@ export function makeOtelLoaders(outputFolder, hookVariant) {
const foundHookLoaderExport = Object.keys(packageDotJSON.exports ?? {}).some(key => {
return packageDotJSON?.exports?.[key]?.import?.default === expectedHooksLoaderLocation;
});
if (!foundHookLoaderExport) {
if (!foundHookLoaderExport && !ignoreWarnings) {
throw new Error(
`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 @@ -180,7 +180,7 @@ export function makeOtelLoaders(outputFolder, hookVariant) {
const foundImportInTheMiddleDep = Object.keys(packageDotJSON.dependencies ?? {}).some(key => {
return key === requiredDep;
});
if (!foundImportInTheMiddleDep) {
if (!foundImportInTheMiddleDep && !ignoreWarnings) {
throw new Error(
`You used the makeOtelLoaders() rollup utility but didn't specify the "${requiredDep}" dependency in ${path.resolve(
process.cwd(),
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
},
"./import": {
"import": {
"default": "./build/import-hook.mjs"
"default": "./import-hook.mjs"
Copy link
Member

@Lms24 Lms24 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be changed in this way. Locally, the two files are emitted into build. So instead of removing the path here, we need to adjust the prepack.ts script to remove it when creating the tarball 😬

}
},
"./loader": {
"import": {
"default": "./build/loader-hook.mjs"
"default": "./loader-hook.mjs"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-serverless/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default [
hasBundles: true,
}),
),
...makeOtelLoaders('./build', 'sentry-node'),
...makeOtelLoaders('./build/npm', 'sentry-node', true),
];
Loading