Skip to content

Commit a5dfb11

Browse files
authored
Merge pull request #342 from underctrl-io/static-env-binding
feat: static env binding
2 parents dce6468 + 0c1b799 commit a5dfb11

File tree

17 files changed

+31
-17
lines changed

17 files changed

+31
-17
lines changed

packages/commandkit/spec/cache.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
23
import {
34
cache,

packages/commandkit/src/analytics/analytics-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommandKit } from '../CommandKit';
1+
import { CommandKit } from '../commandkit';
22
import { Logger } from '../logger/Logger';
33
import { warnUnstable } from '../utils/warn-unstable';
44
import {

packages/commandkit/src/app/commands/Context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Guild,
1212
TextBasedChannel,
1313
} from 'discord.js';
14-
import { CommandKit } from '../../CommandKit';
14+
import { CommandKit } from '../../commandkit';
1515
import {
1616
MessageCommandOptions,
1717
MessageCommandParser,

packages/commandkit/src/app/events/EventWorkerContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AsyncLocalStorage } from 'node:async_hooks';
22
import { ParsedEvent } from '../router';
3-
import { CommandKit } from '../../CommandKit';
3+
import { CommandKit } from '../../commandkit';
44

55
/**
66
* Context object containing information about the currently executing event.

packages/commandkit/src/app/handlers/AppCommandHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Message,
1111
SlashCommandBuilder,
1212
} from 'discord.js';
13-
import type { CommandKit } from '../../CommandKit';
13+
import type { CommandKit } from '../../commandkit';
1414
import { AsyncFunction, GenericFunction } from '../../context/async-context';
1515
import { Logger } from '../../logger/Logger';
1616
import type { CommandData } from '../../types';

packages/commandkit/src/app/handlers/AppEventsHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Collection } from 'discord.js';
2-
import { CommandKit } from '../../CommandKit';
2+
import { CommandKit } from '../../commandkit';
33
import { ListenerFunction } from '../../events/CommandKitEventsChannel';
44
import { Logger } from '../../logger/Logger';
55
import { toFileURL } from '../../utils/resolve-file-url';

packages/commandkit/src/app/register/CommandRegistrar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApplicationCommandType, REST, Routes } from 'discord.js';
2-
import { CommandKit } from '../../CommandKit';
2+
import { CommandKit } from '../../commandkit';
33
import { CommandData } from '../../types';
44
import { Logger } from '../../logger/Logger';
55

packages/commandkit/src/cli/build.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ApplicationBuildOptions {
2626
* @private
2727
* @internal
2828
*/
29-
function mergeDefinitionsIfNeeded(env: Record<string, string>) {
29+
function mergeDefinitionsIfNeeded(env: Record<string, string>, isDev: boolean) {
3030
const values = Object.fromEntries(
3131
Object.entries(process.env).filter(
3232
([k]) => !(k in env) && k.startsWith('COMMANDKIT_PUBLIC_'),
@@ -36,6 +36,19 @@ function mergeDefinitionsIfNeeded(env: Record<string, string>) {
3636
return {
3737
...env,
3838
...values,
39+
...(isDev
40+
? {
41+
NODE_ENV: 'development',
42+
COMMANDKIT_BOOTSTRAP_MODE: 'development',
43+
COMMANDKIT_IS_DEV: 'true',
44+
COMMANDKIT_IS_TEST: 'false',
45+
}
46+
: {
47+
NODE_ENV: 'production',
48+
COMMANDKIT_BOOTSTRAP_MODE: 'production',
49+
COMMANDKIT_IS_DEV: 'false',
50+
COMMANDKIT_IS_TEST: 'false',
51+
}),
3952
};
4053
}
4154

@@ -110,7 +123,7 @@ export async function buildApplication({
110123
sourcemap: true,
111124
target: 'node16',
112125
outDir: dest,
113-
env: mergeDefinitionsIfNeeded(config.env || {}),
126+
env: mergeDefinitionsIfNeeded(config.env || {}, !!isDev),
114127
entry: [
115128
'src',
116129
`!${config.distDir}`,
File renamed without changes.

packages/commandkit/src/context/async-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AsyncLocalStorage } from 'node:async_hooks';
22
import { CommandKitEnvironment } from './environment';
3-
import { CommandKit } from '../CommandKit';
3+
import { CommandKit } from '../commandkit';
44
import { isCommandKitError } from '../utils/error-codes';
55

66
const kCommandWorker = Symbol('commandkitCommandWorker');

0 commit comments

Comments
 (0)