File tree Expand file tree Collapse file tree 6 files changed +19
-2
lines changed
Expand file tree Collapse file tree 6 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,5 @@ if [ "$NO_WATCH" = false ]; then
1616 RUNTIME_ARGS=" $RUNTIME_ARGS --watch --watch-preserve-output"
1717fi
1818
19- exec node $RUNTIME_ARGS " ${PARENT_DIR} /libnest-dev.js" " $@ "
19+ LIBNEST_INSTANCE_ID=$( head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n' ; echo) \
20+ exec node $RUNTIME_ARGS " ${PARENT_DIR} /libnest-dev.js" " $@ "
Original file line number Diff line number Diff line change @@ -35,3 +35,4 @@ export type { BaseEnv } from './schemas/env.schema.js';
3535export { $MongoEnv } from './schemas/mongo-env.schema.js' ;
3636export type { RequestUser } from './user-config.js' ;
3737export type { BaseEnvSchema } from './utils/env.utils.js' ;
38+ export { getInstanceId } from './utils/env.utils.js' ;
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ export function buildProd({
3939 logVerbose ( 'Successfully imported esbuild' ) ;
4040 logVerbose ( 'Defining global variables...' ) ;
4141 const define : { [ key : string ] : string } = {
42+ 'process.env.LIBNEST_INSTANCE_ID' : `"${ crypto . randomUUID ( ) } "` ,
4243 'process.env.NODE_ENV' : "'production'"
4344 } ;
4445 for ( const key in config . globals ) {
Original file line number Diff line number Diff line change @@ -73,7 +73,8 @@ const plugin = ({
7373 }
7474 return {
7575 define : {
76- 'process.env.LIBNEST_CONFIG_FILEPATH' : `"${ configInfo . filepath } "`
76+ 'process.env.LIBNEST_CONFIG_FILEPATH' : `"${ configInfo . filepath } "` ,
77+ 'process.env.LIBNEST_INSTANCE_ID' : `"${ crypto . randomUUID ( ) } "`
7778 }
7879 } ;
7980 } ,
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+
3+ import { getInstanceId } from '../env.utils.js' ;
4+
5+ describe ( 'getInstanceId' , ( ) => {
6+ it ( 'should return a UUID in tests' , ( ) => {
7+ expect ( getInstanceId ( ) ) . toBeTypeOf ( 'string' ) ;
8+ } ) ;
9+ } ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ import type { BaseEnv } from '../schemas/env.schema.js';
55
66export type BaseEnvSchema = z . ZodType < BaseEnv > ;
77
8+ export function getInstanceId ( ) : string {
9+ return process . env . LIBNEST_INSTANCE_ID ! ;
10+ }
11+
812export function parseEnv < TSchema extends BaseEnvSchema = BaseEnvSchema > ( schema : TSchema ) : z . output < TSchema > {
913 // this is required so that these can be statically replaced in the bundle
1014 const env = { ...process . env , NODE_ENV : process . env . NODE_ENV } ;
You can’t perform that action at this time.
0 commit comments