-
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
Merged
pieh
merged 4 commits into
main
from
michalpiechowiak/frb-1681-fix-next-runtime-bundling-so-we-dont-duplicateinline
Mar 17, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8c54f7b
chore: add some validation to bundling to ensure we don't produce dup…
pieh 3fbf588
chore: don't hardcode repo directory in build script
pieh 14f2b98
test: adjust assertion for case where multiple cache-status values ar…
pieh 93ef06a
Update tools/build.js
pieh 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { createWriteStream } from 'node:fs' | ||
import { cp, rm } from 'node:fs/promises' | ||
import { join, resolve } from 'node:path' | ||
import { cp, readFile, rm } from 'node:fs/promises' | ||
import { dirname, join, resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { Readable } from 'stream' | ||
import { finished } from 'stream/promises' | ||
|
||
|
@@ -11,6 +12,8 @@ import glob from 'fast-glob' | |
const OUT_DIR = 'dist' | ||
await rm(OUT_DIR, { force: true, recursive: true }) | ||
|
||
const repoDirectory = dirname(resolve(fileURLToPath(import.meta.url), '..')) | ||
|
||
const entryPointsESM = await glob('src/**/*.ts', { ignore: ['**/*.test.ts'] }) | ||
const entryPointsCJS = await glob('src/**/*.cts') | ||
|
||
|
@@ -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 commentThe 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 |
||
return { path: args.path, external: true } | ||
} | ||
}) | ||
|
@@ -126,8 +129,38 @@ await Promise.all([ | |
cp('src/build/templates', join(OUT_DIR, 'build/templates'), { recursive: true, force: true }), | ||
]) | ||
|
||
async function ensureNoRegionalBlobsModuleDuplicates() { | ||
const REGIONAL_BLOB_STORE_CONTENT_TO_FIND = 'fetchBeforeNextPatchedIt' | ||
|
||
const filesToTest = await glob(`${OUT_DIR}/**/*.{js,cjs}`) | ||
const unexpectedModulesContainingFetchBeforeNextPatchedIt = [] | ||
let foundInExpectedModule = false | ||
for (const fileToTest of filesToTest) { | ||
const content = await readFile(fileToTest, 'utf-8') | ||
if (content.includes(REGIONAL_BLOB_STORE_CONTENT_TO_FIND)) { | ||
if (fileToTest.endsWith('run/regional-blob-store.cjs')) { | ||
foundInExpectedModule = true | ||
} else { | ||
unexpectedModulesContainingFetchBeforeNextPatchedIt.push(fileToTest) | ||
} | ||
} | ||
} | ||
if (!foundInExpectedModule) { | ||
throw new Error( | ||
'Expected to find "fetchBeforeNextPatchedIt" variable in "run/regional-blob-store.cjs", but it was not found. This might indicate a setup change that requires the bundling validation in "tools/build.js" to be adjusted.', | ||
) | ||
} | ||
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')}`, | ||
) | ||
} | ||
} | ||
|
||
if (watch) { | ||
console.log('Starting compilation in watch mode...') | ||
} else { | ||
await ensureNoRegionalBlobsModuleDuplicates() | ||
|
||
console.log('Finished building 🎉') | ||
} |
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.
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