@@ -14,11 +14,27 @@ import {
14
14
import path from "node:path" ;
15
15
16
16
import { loadConfig , loadPrerenderManifest } from "config/util.js" ;
17
+ import { getCrossPlatformPathRegex } from "utils/regex.js" ;
17
18
import logger from "../logger.js" ;
18
19
import { MIDDLEWARE_TRACE_FILE } from "./constant.js" ;
19
20
20
21
const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
21
22
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
+
22
38
function copyPatchFile ( outputDir : string ) {
23
39
const patchFile = path . join ( __dirname , "patch" , "patchedAsyncStorage.js" ) ;
24
40
const outputPatchFile = path . join ( outputDir , "patchedAsyncStorage.cjs" ) ;
@@ -194,12 +210,8 @@ File ${fullFilePath} does not exist
194
210
195
211
//Actually copy the files
196
212
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 ) ) {
203
215
return ;
204
216
}
205
217
mkdirSync ( path . dirname ( to ) , { recursive : true } ) ;
0 commit comments