1- import { readFileSync } from 'node:fs'
1+ import { existsSync , readFileSync } from 'node:fs'
22import { readFile } from 'node:fs/promises'
33// Here we need to actually import `resolve` from node:path as we want to resolve the paths
44// eslint-disable-next-line no-restricted-imports
@@ -62,7 +62,7 @@ export class PluginContext {
6262 * The working directory inside the lambda that is used for monorepos to execute the serverless function
6363 */
6464 get lambdaWorkingDirectory ( ) : string {
65- return join ( '/var/task' , this . distFolder )
65+ return join ( '/var/task' , this . distDirParent )
6666 }
6767
6868 /**
@@ -83,16 +83,16 @@ export class PluginContext {
8383 return relative ( process . cwd ( ) , resolve ( this . packagePath , dir ) )
8484 }
8585
86- /** The dist folder represents the parent directory of the .next folder or custom distDir */
87- get distFolder ( ) : string {
86+ /** Represents the parent directory of the .next folder or custom distDir */
87+ get distDirParent ( ) : string {
8888 // the .. is omitting the last part of the dist dir like `.next` but as it can be any custom folder
8989 // let's just move one directory up with that
9090 return join ( this . distDir , '..' )
9191 }
9292
9393 /** The `.next` folder or what the custom dist dir is set to */
9494 get nextDistDir ( ) : string {
95- return relative ( this . distFolder , this . distDir )
95+ return relative ( this . distDirParent , this . distDir )
9696 }
9797
9898 /** Retrieves the `.next/standalone/` directory monorepo aware */
@@ -102,7 +102,7 @@ export class PluginContext {
102102 // if the publish directory is .next the standalone directory will be `.next/standalone`
103103 // for nx workspaces where the publish directory is on the root of the repository
104104 // like `dist/apps/my-app/.next` the standalone directory will be `.next/standalone/dist/apps/my-app`
105- return join ( this . standaloneRootDir , this . distFolder )
105+ return join ( this . standaloneRootDir , this . distDirParent )
106106 }
107107
108108 /**
@@ -139,7 +139,7 @@ export class PluginContext {
139139 if ( this . packagePath . length === 0 ) {
140140 return this . serverHandlerRootDir
141141 }
142- return join ( this . serverHandlerRootDir , this . distFolder )
142+ return join ( this . serverHandlerRootDir , this . distDirParent )
143143 }
144144
145145 get nextServerHandler ( ) : string {
@@ -213,4 +213,17 @@ export class PluginContext {
213213 failBuild ( message : string , error ?: unknown ) : never {
214214 return this . utils . build . failBuild ( message , error instanceof Error ? { error } : undefined )
215215 }
216+
217+ verifyPublishDir ( ) {
218+ if ( ! existsSync ( this . publishDir ) ) {
219+ this . failBuild (
220+ `Your publish directory was not found at: ${ this . publishDir } , please check your build settings` ,
221+ )
222+ }
223+ if ( this . publishDir === this . resolve ( this . packagePath ) ) {
224+ this . failBuild (
225+ `Your publish directory cannot be the same as the base directory of your site, please check your build settings` ,
226+ )
227+ }
228+ }
216229}
0 commit comments