@@ -11,6 +11,7 @@ const plugin = require('../src')
11
11
const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME } = require ( '../src/constants' )
12
12
const { join } = require ( 'pathe' )
13
13
const { matchMiddleware, stripLocale, matchesRedirect, matchesRewrite } = require ( '../src/helpers/files' )
14
+ const { dirname } = require ( 'path' )
14
15
15
16
const FIXTURES_DIR = `${ __dirname } /fixtures`
16
17
const SAMPLE_PROJECT_DIR = `${ __dirname } /../demos/default`
@@ -83,19 +84,20 @@ const changeCwd = function (cwd) {
83
84
const onBuildHasRun = ( netlifyConfig ) =>
84
85
Boolean ( netlifyConfig . functions [ HANDLER_FUNCTION_NAME ] ?. included_files ?. some ( ( file ) => file . includes ( 'BUILD_ID' ) ) )
85
86
86
- const rewriteAppDir = async function ( ) {
87
- const manifest = path . join ( '.next' , 'required-server-files.json' )
87
+ const rewriteAppDir = async function ( dir = '.next' ) {
88
+ const manifest = path . join ( dir , 'required-server-files.json' )
88
89
const manifestContent = await readJson ( manifest )
89
90
manifestContent . appDir = process . cwd ( )
90
91
91
92
await writeJSON ( manifest , manifestContent )
92
93
}
93
94
94
95
// Move .next from sample project to current directory
95
- const moveNextDist = async function ( ) {
96
+ const moveNextDist = async function ( dir = '.next' ) {
96
97
await stubModules ( [ 'next' , 'sharp' ] )
97
- await copy ( path . join ( SAMPLE_PROJECT_DIR , '.next' ) , path . join ( process . cwd ( ) , '.next' ) )
98
- await rewriteAppDir ( )
98
+ await ensureDir ( dirname ( dir ) )
99
+ await copy ( path . join ( SAMPLE_PROJECT_DIR , '.next' ) , path . join ( process . cwd ( ) , dir ) )
100
+ await rewriteAppDir ( dir )
99
101
}
100
102
101
103
const stubModules = async function ( modules ) {
@@ -129,7 +131,7 @@ beforeEach(async () => {
129
131
restoreCwd = changeCwd ( tmpDir . path )
130
132
cleanup = tmpDir . cleanup
131
133
132
- netlifyConfig . build . publish = path . posix . resolve ( '.next' )
134
+ netlifyConfig . build . publish = path . resolve ( '.next' )
133
135
netlifyConfig . build . environment = { }
134
136
135
137
netlifyConfig . redirects = [ ]
@@ -183,7 +185,7 @@ describe('preBuild()', () => {
183
185
utils : { ...utils , cache : { restore } } ,
184
186
} )
185
187
186
- expect ( restore ) . toHaveBeenCalledWith ( path . posix . resolve ( '.next/cache' ) )
188
+ expect ( restore ) . toHaveBeenCalledWith ( path . resolve ( '.next/cache' ) )
187
189
} )
188
190
189
191
it ( 'forces the target to "server"' , async ( ) => {
@@ -337,6 +339,23 @@ describe('onBuild()', () => {
337
339
expect ( readFileSync ( odbHandlerPagesFile , 'utf8' ) ) . toMatchSnapshot ( )
338
340
} )
339
341
342
+ test ( 'generates a file referencing all when publish dir is a subdirectory' , async ( ) => {
343
+ const dir = 'web/.next'
344
+ await moveNextDist ( dir )
345
+ netlifyConfig . build . publish = path . resolve ( dir )
346
+ const config = {
347
+ ...defaultArgs ,
348
+ netlifyConfig,
349
+ constants : { ...constants , PUBLISH_DIR : dir } ,
350
+ }
351
+ await plugin . onBuild ( config )
352
+ const handlerPagesFile = path . join ( constants . INTERNAL_FUNCTIONS_SRC , HANDLER_FUNCTION_NAME , 'pages.js' )
353
+ const odbHandlerPagesFile = path . join ( constants . INTERNAL_FUNCTIONS_SRC , ODB_FUNCTION_NAME , 'pages.js' )
354
+
355
+ expect ( readFileSync ( handlerPagesFile , 'utf8' ) ) . toMatchSnapshot ( )
356
+ expect ( readFileSync ( odbHandlerPagesFile , 'utf8' ) ) . toMatchSnapshot ( )
357
+ } )
358
+
340
359
test ( 'generates entrypoints with correct references' , async ( ) => {
341
360
await moveNextDist ( )
342
361
await plugin . onBuild ( defaultArgs )
@@ -368,8 +387,8 @@ describe('onPostBuild', () => {
368
387
utils : { ...utils , cache : { save } , functions : { list : jest . fn ( ) . mockResolvedValue ( [ ] ) } } ,
369
388
} )
370
389
371
- expect ( save ) . toHaveBeenCalledWith ( path . posix . resolve ( '.next/cache' ) , {
372
- digests : [ path . posix . resolve ( '.next/build-manifest.json' ) ] ,
390
+ expect ( save ) . toHaveBeenCalledWith ( path . resolve ( '.next/cache' ) , {
391
+ digests : [ path . resolve ( '.next/build-manifest.json' ) ] ,
373
392
} )
374
393
} )
375
394
0 commit comments