-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Inject manifest into client for turbopack builds #16902
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
73e0637
build manifest function
chargome 9b28d79
tests
chargome 657dd55
rename file
chargome a82b977
simplify page check
chargome 7d6e198
que
chargome 71b1121
fix handling optional catchall routes
chargome 3114f5c
update if else block
chargome 75305f5
..
chargome 4ad310f
inject manifest
chargome e105620
update interface + rename func
chargome 685bf04
Merge branch 'cg-next-client-manifest' into cg-next-manifest-webpack
chargome f593c49
Merge branch 'develop' into cg-next-client-manifest
chargome 2a4a35c
Merge branch 'cg-next-client-manifest' into cg-next-manifest-webpack
chargome f9430fe
rename option
chargome 4c0d008
add valueinjection to turbopack
chargome de44fe0
merge stuff
chargome 6071f76
split routes again
chargome e416a2c
add option for route-groups
chargome 78ff933
Merge branch 'cg-next-client-manifest' into cg-next-manifest-webpack
chargome 06be02e
Merge branch 'cg-next-manifest-webpack' into cg-next-manifest-turbopack
chargome aeb2e6d
Merge branch 'develop' into cg-next-manifest-webpack
chargome 1d9089f
Merge branch 'cg-next-manifest-webpack' into cg-next-manifest-turbopack
chargome b01ddc7
conditionally add turbo
chargome b62bdb6
Update packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts
chargome 16eb903
Update packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts
chargome f4dbaca
add log for existing matcher
chargome 7159fcb
windows path + update tests
chargome 36322c3
.
chargome 87910e6
Merge branch 'develop' into cg-next-manifest-turbopack
chargome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/nextjs/src/config/turbopack/constructTurbopackConfig.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { logger } from '@sentry/core'; | ||
import * as chalk from 'chalk'; | ||
import * as path from 'path'; | ||
import type { RouteManifest } from '../manifest/types'; | ||
import type { NextConfigObject, TurbopackOptions, TurbopackRuleConfigItemOrShortcut } from '../types'; | ||
|
||
/** | ||
* Construct a Turbopack config object from a Next.js config object and a Turbopack options object. | ||
* | ||
* @param userNextConfig - The Next.js config object. | ||
* @param turbopackOptions - The Turbopack options object. | ||
* @returns The Turbopack config object. | ||
*/ | ||
export function constructTurbopackConfig({ | ||
userNextConfig, | ||
routeManifest, | ||
}: { | ||
userNextConfig: NextConfigObject; | ||
routeManifest?: RouteManifest; | ||
}): TurbopackOptions { | ||
const newConfig: TurbopackOptions = { | ||
...userNextConfig.turbopack, | ||
}; | ||
|
||
if (routeManifest) { | ||
newConfig.rules = safelyAddTurbopackRule(newConfig.rules, { | ||
matcher: '**/instrumentation-client.*', | ||
rule: { | ||
loaders: [ | ||
{ | ||
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'), | ||
options: { | ||
values: { | ||
_sentryRouteManifest: JSON.stringify(routeManifest), | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
return newConfig; | ||
} | ||
|
||
/** | ||
* Safely add a Turbopack rule to the existing rules. | ||
* | ||
* @param existingRules - The existing rules. | ||
* @param matcher - The matcher for the rule. | ||
* @param rule - The rule to add. | ||
* @returns The updated rules object. | ||
*/ | ||
export function safelyAddTurbopackRule( | ||
existingRules: TurbopackOptions['rules'], | ||
{ matcher, rule }: { matcher: string; rule: TurbopackRuleConfigItemOrShortcut }, | ||
): TurbopackOptions['rules'] { | ||
if (!existingRules) { | ||
return { | ||
[matcher]: rule, | ||
}; | ||
} | ||
|
||
// If the rule already exists, we don't want to mess with it. | ||
if (existingRules[matcher]) { | ||
logger.info( | ||
`${chalk.cyan( | ||
'info', | ||
)} - Turbopack rule already exists for ${matcher}. Please remove it from your Next.js config in order for Sentry to work properly.`, | ||
); | ||
return existingRules; | ||
} | ||
|
||
return { | ||
...existingRules, | ||
[matcher]: rule, | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './constructTurbopackConfig'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.