1
- import { readFileSync } from 'node:fs'
1
+ import { existsSync , readFileSync } from 'node:fs'
2
2
import { readFile } from 'node:fs/promises'
3
3
// Here we need to actually import `resolve` from node:path as we want to resolve the paths
4
4
// eslint-disable-next-line no-restricted-imports
@@ -62,7 +62,7 @@ export class PluginContext {
62
62
* The working directory inside the lambda that is used for monorepos to execute the serverless function
63
63
*/
64
64
get lambdaWorkingDirectory ( ) : string {
65
- return join ( '/var/task' , this . distFolder )
65
+ return join ( '/var/task' , this . distDirParent )
66
66
}
67
67
68
68
/**
@@ -83,16 +83,16 @@ export class PluginContext {
83
83
return relative ( process . cwd ( ) , resolve ( this . packagePath , dir ) )
84
84
}
85
85
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 {
88
88
// the .. is omitting the last part of the dist dir like `.next` but as it can be any custom folder
89
89
// let's just move one directory up with that
90
90
return join ( this . distDir , '..' )
91
91
}
92
92
93
93
/** The `.next` folder or what the custom dist dir is set to */
94
94
get nextDistDir ( ) : string {
95
- return relative ( this . distFolder , this . distDir )
95
+ return relative ( this . distDirParent , this . distDir )
96
96
}
97
97
98
98
/** Retrieves the `.next/standalone/` directory monorepo aware */
@@ -102,7 +102,7 @@ export class PluginContext {
102
102
// if the publish directory is .next the standalone directory will be `.next/standalone`
103
103
// for nx workspaces where the publish directory is on the root of the repository
104
104
// 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 )
106
106
}
107
107
108
108
/**
@@ -139,7 +139,7 @@ export class PluginContext {
139
139
if ( this . packagePath . length === 0 ) {
140
140
return this . serverHandlerRootDir
141
141
}
142
- return join ( this . serverHandlerRootDir , this . distFolder )
142
+ return join ( this . serverHandlerRootDir , this . distDirParent )
143
143
}
144
144
145
145
get nextServerHandler ( ) : string {
@@ -213,4 +213,17 @@ export class PluginContext {
213
213
failBuild ( message : string , error ?: unknown ) : never {
214
214
return this . utils . build . failBuild ( message , error instanceof Error ? { error } : undefined )
215
215
}
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
+ }
216
229
}
0 commit comments