Skip to content

Commit 8614793

Browse files
committed
1 parent dc05a5a commit 8614793

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ const EXCLUDED_PACKAGES = [
4343
"next/dist/compiled/amphtml-validator",
4444
];
4545

46+
const NON_LINUX_PLATFORMS = ["darwin", "win32", "freebsd"];
47+
const platformPattern = NON_LINUX_PLATFORMS.join("|");
48+
const nonLinuxPlatformRegex = getCrossPlatformPathRegex(
49+
`/node_modules/(?:@[^/]+/)?(?:[^/]+-)?(${platformPattern})-[^/]+/`,
50+
{ escape: false }
51+
);
52+
53+
export function isNonLinuxPlatformPackage(srcPath: string): boolean {
54+
return nonLinuxPlatformRegex.test(srcPath);
55+
}
56+
4657
export function isExcluded(srcPath: string): boolean {
4758
return EXCLUDED_PACKAGES.some((excluded) =>
4859
// `pnpm` can create a symbolic link that points to the pnpm store folder
@@ -254,6 +265,14 @@ File ${serverPath} does not exist
254265
if (isExcluded(from)) {
255266
return;
256267
}
268+
// Skip non-Linux platform-specific native binaries (e.g. @swc/core-darwin-arm64)
269+
if (!process.env.OPEN_NEXT_SKIP_PLATFORM_FILTER && isNonLinuxPlatformPackage(from)) {
270+
const match = from.match(/node_modules\/(.+\/)?([^/]+-(?:darwin|win32|freebsd)-[^/]+)/);
271+
if (match) {
272+
logger.debug(`Skipping non-Linux platform package: ${match[2]}`);
273+
}
274+
return;
275+
}
257276
tracedFiles.push(to);
258277
mkdirSync(path.dirname(to), { recursive: true });
259278
let symlink = null;

packages/tests-unit/tests/build/copyTracedFiles.test.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isExcluded } from "@opennextjs/aws/build/copyTracedFiles.js";
1+
import { isExcluded, isNonLinuxPlatformPackage } from "@opennextjs/aws/build/copyTracedFiles.js";
22

33
describe("isExcluded", () => {
44
test("should exclude sharp", () => {
@@ -32,3 +32,84 @@ describe("isExcluded", () => {
3232
).toBe(false);
3333
});
3434
});
35+
36+
describe("isNonLinuxPlatformPackage", () => {
37+
test("should identify Darwin (macOS) platform packages", () => {
38+
expect(
39+
isNonLinuxPlatformPackage(
40+
"/home/user/project/node_modules/@swc/core-darwin-arm64/swc.darwin-arm64.node"
41+
)
42+
).toBe(true);
43+
expect(isNonLinuxPlatformPackage("/home/user/project/node_modules/@esbuild/darwin-x64/bin/esbuild")).toBe(
44+
true
45+
);
46+
expect(isNonLinuxPlatformPackage("/home/user/project/node_modules/turbo-darwin-arm64/bin/turbo")).toBe(
47+
true
48+
);
49+
});
50+
51+
test("should identify Windows platform packages", () => {
52+
expect(
53+
isNonLinuxPlatformPackage(
54+
"/home/user/project/node_modules/@swc/core-win32-x64-msvc/swc.win32-x64-msvc.node"
55+
)
56+
).toBe(true);
57+
expect(
58+
isNonLinuxPlatformPackage(
59+
"/home/user/project/node_modules/@rollup/rollup-win32-x64-msvc/rollup.win32-x64-msvc.node"
60+
)
61+
).toBe(true);
62+
});
63+
64+
test("should identify FreeBSD platform packages", () => {
65+
expect(
66+
isNonLinuxPlatformPackage(
67+
"/home/user/project/node_modules/@rollup/rollup-freebsd-x64/rollup.freebsd-x64.node"
68+
)
69+
).toBe(true);
70+
});
71+
72+
test("should NOT identify Linux platform packages", () => {
73+
expect(
74+
isNonLinuxPlatformPackage(
75+
"/home/user/project/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node"
76+
)
77+
).toBe(false);
78+
expect(isNonLinuxPlatformPackage("/home/user/project/node_modules/@esbuild/linux-x64/bin/esbuild")).toBe(
79+
false
80+
);
81+
expect(
82+
isNonLinuxPlatformPackage(
83+
"/home/user/project_modules/@swc/core-linux-arm64-gnu/swc.linux-arm64-gnu.node"
84+
)
85+
).toBe(false);
86+
});
87+
88+
test("should NOT identify non-platform packages", () => {
89+
expect(isNonLinuxPlatformPackage("/home/user/project/node_modules/@swc/core/package.json")).toBe(false);
90+
expect(isNonLinuxPlatformPackage("/home/user/project/node_modules/next/dist/server/next-server.js")).toBe(
91+
false
92+
);
93+
expect(
94+
isNonLinuxPlatformPackage("/home/user/project/node_modules/react/cjs/react.production.min.js")
95+
).toBe(false);
96+
});
97+
98+
test("should handle pnpm store paths", () => {
99+
expect(
100+
isNonLinuxPlatformPackage(
101+
"/home/user/project/node_modules/.pnpm/@swc+core-darwin-arm64@1.0.0/node_modules/@swc/core-darwin-arm64/swc.darwin-arm64.node"
102+
)
103+
).toBe(true);
104+
expect(
105+
isNonLinuxPlatformPackage(
106+
"/home/user/project/node_modules/.pnpm/@esbuild+darwin-x64@0.19.0/node_modules/@esbuild/darwin-x64/bin/esbuild"
107+
)
108+
).toBe(true);
109+
expect(
110+
isNonLinuxPlatformPackage(
111+
"/home/user/project/node_modules/.pnpm/@swc+core-linux-x64-gnu@1.0.0/node_modules/@swc/core-linux-x64-gnu/swc.linux-x64-gnu.node"
112+
)
113+
).toBe(false);
114+
});
115+
});

0 commit comments

Comments
 (0)