-
Notifications
You must be signed in to change notification settings - Fork 167
chore: Exclude more packages #950
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
chore: Exclude more packages | ||
|
||
Added a debug to determine which packages that gets excluded from the final bundle's `node_modules`. Will skip these packages now aswell: | ||
|
||
- "typescript" | ||
- "next/dist/compiled/babel" | ||
- "next/dist/compiled/babel-packages" | ||
- "next/dist/compiled/amphtml-validator" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,14 @@ const EXCLUDED_PACKAGES = [ | |
// This seems to be only in Next 15 | ||
// Some of sharp deps are under the @img scope | ||
"@img", | ||
"typescript", | ||
"next/dist/compiled/babel", | ||
"next/dist/compiled/babel-packages", | ||
"next/dist/compiled/amphtml-validator", | ||
]; | ||
|
||
function isExcluded(srcPath: string) { | ||
return EXCLUDED_PACKAGES.some((excluded) => | ||
function isExcluded(srcPath: string): string | undefined { | ||
return EXCLUDED_PACKAGES.find((excluded) => | ||
srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)), | ||
); | ||
} | ||
|
@@ -250,11 +254,17 @@ File ${serverPath} does not exist | |
|
||
// Only files that are actually copied | ||
const tracedFiles: string[] = []; | ||
|
||
// Packages that are excluded and not copied | ||
const excludedPackages = new Set<string>(); | ||
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. Why a Set here ? |
||
//Actually copy the files | ||
filesToCopy.forEach((to, from) => { | ||
// We don't want to copy excluded packages (i.e sharp) | ||
if (isExcluded(from)) { | ||
// We don't want to copy excluded packages (e.g. sharp) | ||
const excluded = isExcluded(from); | ||
if (excluded) { | ||
if (excluded && !excludedPackages.has(excluded)) { | ||
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. I really don't understand the logic. What was the issue with the isExcluded from before ? 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. I just wanted to add a debug for the packages that actually gets excluded. |
||
logger.debug("Skipping excluded package:", excluded); | ||
excludedPackages.add(excluded); | ||
} | ||
return; | ||
} | ||
tracedFiles.push(to); | ||
|
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.
Why use find here ?
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.
Same reason. I wanted to keep track of the packages that gets excluded. So we can logger.debug them.