Skip to content

Commit 53552cf

Browse files
committed
Add nullbyte prefix to rollup plugin to ensure correct bundling
1 parent 43bce89 commit 53552cf

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/nitro-utils/src/rollupPlugins/wrapServerEntryWithDynamicImport.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export function wrapServerEntryWithDynamicImport(config: WrapServerEntryPluginOp
3737
debug,
3838
} = config;
3939

40+
// In order to correctly import the server config file
41+
// and dynamically import the nitro runtime, we need to
42+
// mark the resolutionId with '\0raw' to fall into the
43+
// raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142
44+
const resolutionIdPrefix = '\0raw';
45+
4046
return {
4147
name: 'sentry-wrap-server-entry-with-dynamic-import',
4248
async resolveId(source, importer, options) {
@@ -70,19 +76,19 @@ export function wrapServerEntryWithDynamicImport(config: WrapServerEntryPluginOp
7076
// The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix
7177
return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)
7278
? resolution.id
73-
: resolution.id
79+
: `${resolutionIdPrefix}${resolution.id
7480
// Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)
7581
.concat(SENTRY_WRAPPED_ENTRY)
7682
.concat(
7783
constructWrappedFunctionExportQuery(moduleInfo.exportedBindings, entrypointWrappedFunctions, debug),
7884
)
79-
.concat(QUERY_END_INDICATOR);
85+
.concat(QUERY_END_INDICATOR)}`;
8086
}
8187
return null;
8288
},
8389
load(id: string) {
8490
if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
85-
const entryId = removeSentryQueryFromPath(id);
91+
const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);
8692

8793
// Mostly useful for serverless `handler` functions
8894
const reExportedFunctions =
@@ -188,7 +194,7 @@ export function constructWrappedFunctionExportQuery(
188194
consoleSandbox(() =>
189195
// eslint-disable-next-line no-console
190196
console.warn(
191-
"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.entrypointWrappedFunctions` in `nuxt.config.ts`.",
197+
'[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to `entrypointWrappedFunctions`.',
192198
),
193199
);
194200
}

packages/nitro-utils/test/rollupPlugins/wrapServerEntryWithDynamicImport.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('constructWrappedFunctionExportQuery', () => {
9292
const result = constructWrappedFunctionExportQuery(exportedBindings, entrypointWrappedFunctions, debug);
9393
expect(result).toBe('?sentry-query-reexported-functions=handler');
9494
expect(consoleWarnSpy).toHaveBeenCalledWith(
95-
"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.entrypointWrappedFunctions` in `nuxt.config.ts`.",
95+
'[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to `entrypointWrappedFunctions`.',
9696
);
9797

9898
consoleWarnSpy.mockRestore();

0 commit comments

Comments
 (0)