@@ -14,11 +14,27 @@ import {
1414import path from "node:path" ;
1515
1616import { loadConfig , loadPrerenderManifest } from "config/util.js" ;
17+ import { getCrossPlatformPathRegex } from "utils/regex.js" ;
1718import logger from "../logger.js" ;
1819import { MIDDLEWARE_TRACE_FILE } from "./constant.js" ;
1920
2021const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
2122
23+ //TODO: we need to figure which packages we could safely remove
24+ const EXCLUDED_PACKAGES = [
25+ "caniuse-lite" ,
26+ "sharp" ,
27+ // This seems to be only in Next 15
28+ // Some of sharp deps are under the @img scope
29+ "@img" ,
30+ ] ;
31+
32+ function isExcluded ( srcPath : string ) {
33+ return EXCLUDED_PACKAGES . some ( ( excluded ) =>
34+ srcPath . match ( getCrossPlatformPathRegex ( `/node_modules/${ excluded } /` ) ) ,
35+ ) ;
36+ }
37+
2238function copyPatchFile ( outputDir : string ) {
2339 const patchFile = path . join ( __dirname , "patch" , "patchedAsyncStorage.js" ) ;
2440 const outputPatchFile = path . join ( outputDir , "patchedAsyncStorage.cjs" ) ;
@@ -194,12 +210,8 @@ File ${fullFilePath} does not exist
194210
195211 //Actually copy the files
196212 filesToCopy . forEach ( ( to , from ) => {
197- if (
198- //TODO: we need to figure which packages we could safely remove
199- from . includes ( path . join ( "node_modules" , "caniuse-lite" ) ) ||
200- // from.includes("jest-worker") || This ones seems necessary for next 12
201- from . includes ( path . join ( "node_modules" , "sharp" ) )
202- ) {
213+ // We don't want to copy excluded packages (i.e sharp)
214+ if ( isExcluded ( from ) ) {
203215 return ;
204216 }
205217 mkdirSync ( path . dirname ( to ) , { recursive : true } ) ;
0 commit comments