Skip to content

Commit 1787e1d

Browse files
authored
Merge pull request #69 from DouglasNeuroInformatics/instance-id
feat: add getInstanceId
2 parents 8edd5ad + d6c8184 commit 1787e1d

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

src/cli/bin/libnest-dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ if [ "$NO_WATCH" = false ]; then
1616
RUNTIME_ARGS="$RUNTIME_ARGS --watch --watch-preserve-output"
1717
fi
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" "$@"

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ export type { BaseEnv } from './schemas/env.schema.js';
3535
export { $MongoEnv } from './schemas/mongo-env.schema.js';
3636
export type { RequestUser } from './user-config.js';
3737
export type { BaseEnvSchema } from './utils/env.utils.js';
38+
export { getInstanceId } from './utils/env.utils.js';

src/meta/build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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) {

src/testing/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
});

src/utils/env.utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import type { BaseEnv } from '../schemas/env.schema.js';
55

66
export type BaseEnvSchema = z.ZodType<BaseEnv>;
77

8+
export function getInstanceId(): string {
9+
return process.env.LIBNEST_INSTANCE_ID!;
10+
}
11+
812
export 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 };

0 commit comments

Comments
 (0)