Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/beige-ways-switch.md
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"
20 changes: 15 additions & 5 deletions packages/open-next/src/build/copyTracedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use find here ?

Copy link
Contributor Author

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.

srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)),
);
}
Expand Down Expand Up @@ -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>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand Down
Loading