-
Notifications
You must be signed in to change notification settings - Fork 86
fix: adjust bundling to not produce duplicate inlined internal modules #2774
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
fix: adjust bundling to not produce duplicate inlined internal modules #2774
Conversation
1b57a7b
to
2397c8a
Compare
📊 Package size report No changes
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
tools/build.js
Outdated
if (unexpectedModulesContainingFetchBeforeNextPatchedIt.length !== 0) { | ||
throw new Error( | ||
`Bundling produced unexpected duplicates of 'regional-blob-store' module in following built modules:\n${unexpectedModulesContainingFetchBeforeNextPatchedIt.map((filePath) => ` - ${filePath}`).join('\n')}`, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This produce error like this (when using just validation part of this PR, without the fix part):
Error: Bundling produced unexpected duplicates of 'regional-blob-store' module in following built modules:
- dist/esm-chunks/chunk-K4RDUZYO.js
- dist/run/next.cjs
- dist/run/handlers/cache.cjs
at ensureNoRegionalBlobsModuleDuplicates (file:///Users/misiek/dev/pgs-next-runtime/tools/build.js:154:11)
at async file:///Users/misiek/dev/pgs-next-runtime/tools/build.js:163:3
The main purpose is to prevent publishing mis-bundlend version of runtime from local machines.
With the fix validation is passing (as avoiding duplicates is working then)
@@ -39,7 +42,7 @@ async function bundle(entryPoints, format, watch) { | |||
name: 'mark-runtime-modules-as-external', | |||
setup(pluginBuild) { | |||
pluginBuild.onResolve({ filter: /^\..*\.c?js$/ }, (args) => { | |||
if (args.importer.includes(join('opennextjs-netlify', 'src'))) { | |||
if (args.importer.includes(join(repoDirectory, 'src'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main fix/adjustment - we were publishing runtime locally since move to Opennext organization and if locally repo clone directory was not named exactly opennextjs-neltify
, then we would produce duplicates.
796ba09
to
14ce8e3
Compare
…licate/inling of regional-blob-store module in unexptected built modules
ad1ad5d
to
3fbf588
Compare
…e being comma separated and not line separated
52811fa
to
14f2b98
Compare
expect(headers['cache-status'].replaceAll(', ', '\n')).toMatch(/^"Next.js"; hit$/m) | ||
expect(headers['cache-status'].replaceAll(', ', '\n')).toMatch(/^"Netlify Edge"; fwd=miss$/m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to main portion of PR - seems like we might be getting comma separated cache-status values, so I'm massing it to have each statement as separate line to match regex assumption
Co-authored-by: Eduardo Bouças <[email protected]>
Description
We are producing duplicate inlining in built package if built in directory that is not named
opennextjs-netlify
. This adjusts build script to not rely on directory name and adds some validation.This is still a bit bandaidy - ideally we don't do multiple passes and do single build emitting mix of ESM and CJS, but I couldn't find to make
esbuild
behave in this way, so to not overhaul entire setup and spend a lot of time on it - I just made some adjustments and really barebones verification/validation of built package.Tests
Adding some validation to build script
Relevant links (GitHub issues, etc.) or a picture of cute animal
https://linear.app/netlify/issue/FRB-1681/fix-next-runtime-bundling-so-we-dont-duplicateinline-internal-modules