Skip to content

Commit 56e7852

Browse files
committed
fix: build
1 parent 16f21ec commit 56e7852

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

packages/graphql/src/bin/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resolve } from 'path';
66
import app from '../server';
77
import { requireEnv } from '../utils/requireEnv';
88

9-
const { SERVER_PORT = 4444 } = requireEnv(['SERVER_PORT']);
9+
const { SERVER_PORT } = requireEnv([['SERVER_PORT', '4444']]);
1010
const { WATCH = 'false' } = process.env;
1111

1212
const server = createServer(app);

packages/graphql/src/utils/requireEnv.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import dotenv from 'dotenv';
22
dotenv.config();
33

44
export function requireEnv<
5-
A extends string[],
6-
B extends { [key in A[number]]: string },
7-
>(keys: string[]): B {
8-
return keys.reduce((ret, key) => {
9-
if (!process.env[key]) {
10-
throw new Error(`Environment variable ${key} is required`);
11-
}
12-
ret[key] = process.env[key]!;
13-
return ret;
14-
}, {} as B);
5+
A extends (string | [key: string, defaultValue: string])[],
6+
>(keys: A) {
7+
return keys.reduce(
8+
(ret, value) => {
9+
const [key, defaultValue] = Array.isArray(value) ? value : [value];
10+
if (!process.env[key] && defaultValue == undefined) {
11+
throw new Error(`Environment variable ${key} is required`);
12+
}
13+
ret[key] = (process.env[key] ? process.env[key] : defaultValue)!;
14+
return ret;
15+
},
16+
{} as Record<string, string>
17+
);
1518
}

packages/graphql/tsup.config.mjs

+18-20
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,28 @@ export default defineConfig((options) => ({
1313
format: ['esm', 'cjs'],
1414
sourcemap: true,
1515
clean: false,
16-
dts: false,
16+
dts: true,
1717
minify: false,
1818
esbuildPlugins: [graphqlLoaderPlugin()],
1919
entry: { index: 'src/bin/index.ts' },
2020
async onSuccess() {
21-
if (options.watch) {
22-
const cmd = execa('node', ['--import', 'tsx/esm', './dist/index.js'], {
23-
stdio: 'inherit',
24-
cleanup: true,
25-
env: {
26-
SERVER_PORT: port,
27-
CODE_GEN: true,
28-
WATCH: Boolean(options.watch),
29-
FUEL_PROVIDER: process.env.FUEL_PROVIDER,
30-
},
21+
const cmd = execa('node', ['--import', 'tsx/esm', './dist/index.js'], {
22+
stdio: 'inherit',
23+
cleanup: true,
24+
env: {
25+
SERVER_PORT: port,
26+
CODE_GEN: true,
27+
WATCH: Boolean(options.watch),
28+
FUEL_PROVIDER: process.env.FUEL_PROVIDER,
29+
},
30+
});
31+
// Wait process to close until restarting
32+
return async () => {
33+
const killProcess = new Promise((resolve) => {
34+
cmd.on('close', () => resolve(true));
3135
});
32-
// Wait process to close until restarting
33-
return async () => {
34-
const killProcess = new Promise((resolve) => {
35-
cmd.on('close', () => resolve(true));
36-
});
37-
cmd.kill('SIGTERM');
38-
await killProcess;
39-
};
40-
}
36+
cmd.kill('SIGTERM');
37+
await killProcess;
38+
};
4139
},
4240
}));

0 commit comments

Comments
 (0)