Skip to content

Commit

Permalink
fix(nuxt): Fix dynamic import rollup plugin to work with latest nitro (
Browse files Browse the repository at this point in the history
…#14243)

With nitro 2.10.X the way we imported the server config file and
dynamically imported the nitro runtime broke. Instead of landing in the
server output entry file, the sdk init and dynamic import landed in the
nitro runtime itself.

Based on
nitrojs/nitro@8b4a408#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142
we managed to get back to the original solution by using the `\0raw`
prefix for the entry file.

__Note for internal__: This does not play well when using symlinks (like
`yarn link`) to link the sdk into a project. Haven't tested how yalc
behaves, but tarballs work.
  • Loading branch information
andreiborza authored Nov 12, 2024
1 parent 2e5fe94 commit 0aa7f1d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/nuxt/src/vite/addServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ function wrapEntryWithDynamicImport({
entrypointWrappedFunctions,
debug,
}: { resolvedSentryConfigPath: string; entrypointWrappedFunctions: string[]; debug?: boolean }): InputPluginOption {
// In order to correctly import the server config file
// and dynamically import the nitro runtime, we need to
// mark the resolutionId with '\0raw' to fall into the
// raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142
const resolutionIdPrefix = '\0raw';

return {
name: 'sentry-wrap-entry-with-dynamic-import',
async resolveId(source, importer, options) {
Expand Down Expand Up @@ -146,19 +152,19 @@ function wrapEntryWithDynamicImport({
// 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
return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)
? resolution.id
: resolution.id
: `${resolutionIdPrefix}${resolution.id
// 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)
.concat(SENTRY_WRAPPED_ENTRY)
.concat(
constructWrappedFunctionExportQuery(moduleInfo.exportedBindings, entrypointWrappedFunctions, debug),
)
.concat(QUERY_END_INDICATOR);
.concat(QUERY_END_INDICATOR)}`;
}
return null;
},
load(id: string) {
if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
const entryId = removeSentryQueryFromPath(id);
const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);

// Mostly useful for serverless `handler` functions
const reExportedFunctions =
Expand Down

0 comments on commit 0aa7f1d

Please sign in to comment.