@@ -111,7 +111,8 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
111
111
handler ?: (
112
112
args : yargs . Arguments ,
113
113
cmd : ( args : yargs . Arguments ) => void
114
- ) => void
114
+ ) => void ,
115
+ nodeEnv ?: string | undefined
115
116
) : ( argv : yargs . Arguments ) => void {
116
117
return ( argv : yargs . Arguments ) : void => {
117
118
report . setVerbose ( ! ! argv . verbose )
@@ -124,6 +125,12 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
124
125
process . env . gatsby_executing_command = command
125
126
report . verbose ( `set gatsby_executing_command: "${ command } "` )
126
127
128
+ // This is to make sure that the NODE_ENV is set before resolveLocalCommand is called
129
+ // This way, cache-lmdb uses the same DB files in main & workers
130
+ if ( nodeEnv ) {
131
+ process . env . NODE_ENV = nodeEnv
132
+ }
133
+
127
134
const localCmd = resolveLocalCommand ( command )
128
135
const args = { ...argv , ...siteInfo , report, useYarn, setStore }
129
136
@@ -202,8 +209,6 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
202
209
getCommandHandler (
203
210
`develop` ,
204
211
( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => unknown ) => {
205
- process . env . NODE_ENV = process . env . NODE_ENV || `development`
206
-
207
212
if ( Object . prototype . hasOwnProperty . call ( args , `inspect` ) ) {
208
213
args . inspect = args . inspect || 9229
209
214
}
@@ -216,7 +221,8 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
216
221
// The development server shouldn't ever exit until the user directly
217
222
// kills it so this is fine.
218
223
return new Promise ( ( ) => { } )
219
- }
224
+ } ,
225
+ process . env . NODE_ENV || `development`
220
226
)
221
227
) ,
222
228
} )
@@ -270,10 +276,9 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
270
276
handler : handlerP (
271
277
getCommandHandler (
272
278
`build` ,
273
- ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) => {
274
- process . env . NODE_ENV = `production`
275
- return cmd ( args )
276
- }
279
+ ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) =>
280
+ cmd ( args ) ,
281
+ `production`
277
282
)
278
283
) ,
279
284
} )
@@ -313,10 +318,9 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
313
318
314
319
handler : getCommandHandler (
315
320
`serve` ,
316
- ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) => {
317
- process . env . NODE_ENV = process . env . NODE_ENV || `production`
318
- return cmd ( args )
319
- }
321
+ ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) =>
322
+ cmd ( args ) ,
323
+ process . env . NODE_ENV || `production`
320
324
) ,
321
325
} )
322
326
@@ -385,10 +389,9 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
385
389
describe : `Get a node repl with context of Gatsby environment, see (https://www.gatsbyjs.com/docs/gatsby-repl/)` ,
386
390
handler : getCommandHandler (
387
391
`repl` ,
388
- ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) => {
389
- process . env . NODE_ENV = process . env . NODE_ENV || `development`
390
- return cmd ( args )
391
- }
392
+ ( args : yargs . Arguments , cmd : ( args : yargs . Arguments ) => void ) =>
393
+ cmd ( args ) ,
394
+ process . env . NODE_ENV || `development`
392
395
) ,
393
396
} )
394
397
0 commit comments