@@ -65,11 +65,15 @@ export class PluginContext {
65
65
/** Absolute path of the next runtime plugin directory */
66
66
pluginDir = PLUGIN_DIR
67
67
68
+ get relPublishDir ( ) : string {
69
+ return this . constants . PUBLISH_DIR ?? '.next'
70
+ }
71
+
68
72
/** Absolute path of the publish directory */
69
73
get publishDir ( ) : string {
70
74
// Does not need to be resolved with the package path as it is always a repository absolute path
71
75
// hence including already the `PACKAGE_PATH` therefore we don't use the `this.resolve`
72
- return resolve ( this . constants . PUBLISH_DIR )
76
+ return resolve ( this . relPublishDir )
73
77
}
74
78
75
79
/**
@@ -81,6 +85,13 @@ export class PluginContext {
81
85
return this . constants . PACKAGE_PATH || ''
82
86
}
83
87
88
+ /**
89
+ * The working directory inside the lambda that is used for monorepos to execute the serverless function
90
+ */
91
+ get lambdaWorkingDirectory ( ) : string {
92
+ return join ( '/var/task' , this . relPublishDir . replace ( / \. n e x t $ / , '' ) )
93
+ }
94
+
84
95
/**
85
96
* Retrieves the root of the `.next/standalone` directory
86
97
*/
@@ -90,7 +101,12 @@ export class PluginContext {
90
101
91
102
/** Retrieves the `.next/standalone/` directory monorepo aware */
92
103
get standaloneDir ( ) : string {
93
- return join ( this . standaloneRootDir , this . constants . PACKAGE_PATH || '' )
104
+ // the standalone directory mimics the structure of the publish directory
105
+ // that said if the publish directory is `apps/my-app/.next` the standalone directory will be `.next/standalone/apps/my-app`
106
+ // if the publish directory is .next the standalone directory will be `.next/standalone`
107
+ // for nx workspaces where the publish directory is on the root of the repository
108
+ // like `dist/apps/my-app/.next` the standalone directory will be `.next/standalone/dist/apps/my-app`
109
+ return join ( this . standaloneRootDir , this . relPublishDir . replace ( / \. n e x t $ / , '' ) )
94
110
}
95
111
96
112
/**
@@ -124,11 +140,14 @@ export class PluginContext {
124
140
}
125
141
126
142
get serverHandlerDir ( ) : string {
127
- return join ( this . serverHandlerRootDir , this . constants . PACKAGE_PATH || '' )
143
+ return join ( this . serverHandlerRootDir , this . relPublishDir . replace ( / \. n e x t $ / , '' ) || '' )
128
144
}
129
145
130
146
get nextServerHandler ( ) : string {
131
- return join ( this . constants . PACKAGE_PATH || '' , 'dist/run/handlers/server.js' )
147
+ if ( this . packagePath . length !== 0 ) {
148
+ return join ( this . lambdaWorkingDirectory , 'dist/run/handlers/server.js' )
149
+ }
150
+ return './dist/run/handlers/server.js'
132
151
}
133
152
134
153
/**
0 commit comments