Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/tiny-points-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(build): Improve regex in copy traced files to skip symbolic links
10 changes: 8 additions & 2 deletions packages/open-next/src/build/copyTracedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ const EXCLUDED_PACKAGES = [
"next/dist/compiled/amphtml-validator",
];

function isExcluded(srcPath: string): boolean {
export function isExcluded(srcPath: string): boolean {
return EXCLUDED_PACKAGES.some((excluded) =>
srcPath.match(getCrossPlatformPathRegex(`/node_modules/${excluded}/`)),
// `pnpm` can create a symbolic link that points to the pnpm store folder
// This will live under `/node_modules/sharp`. We need to handle this in our regex
srcPath.match(
getCrossPlatformPathRegex(`/node_modules/${excluded}(?:/|$)`, {
escape: false,
}),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/build/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function installDependencies(
fs.rmSync(tempInstallDir, { recursive: true, force: true });
logger.info(`Dependencies installed for ${name}`);
} catch (e: any) {
logger.error(e.stdout.toString());
logger.error(e.toString());
logger.error("Could not install dependencies");
}
}
42 changes: 42 additions & 0 deletions packages/tests-unit/tests/build/copyTracedFiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { isExcluded } from "@opennextjs/aws/build/copyTracedFiles.js";

describe("isExcluded", () => {
test("should exclude sharp", () => {
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/sharp/lib/index.js",
),
).toBe(true);
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/.pnpm/sharp/4.1.3/node_modules/sharp/lib/index.js",
),
).toBe(true);
expect(
isExcluded("/home/user/git/my-opennext-project/node_modules/sharp"),
).toBe(true);
});

test("should not exclude other packages", () => {
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/other-package/lib/index.js",
),
).toBe(false);
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/.pnpm/other-package/4.1.3/node_modules/other-package/lib/index.js",
),
).toBe(false);
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/.pnpm/other-package/4.1.3/node_modules/sharp-other-package/lib/index.js",
),
).toBe(false);
expect(
isExcluded(
"/home/user/git/my-opennext-project/node_modules/.pnpm/other-package/4.1.3/node_modules/sharp-other",
),
).toBe(false);
});
});
Loading