Skip to content

Commit 04c21fe

Browse files
committed
fix(runner): allow dist directory for built files
1 parent 3d9b9e3 commit 04c21fe

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/bootstrap.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import path from 'path';
1+
import path from 'node:path';
2+
import assert from 'node:assert';
23

34
import dotenv from 'dotenv';
45
import readPackageUp from 'read-pkg-up';
@@ -56,6 +57,12 @@ async function getServiceDetails(argv: BootstrapArguments = {}) {
5657
};
5758
}
5859

60+
function getBuildDir(main: string): 'build' | 'dist' {
61+
const dir = /^(?:\.?\/?)(build|dist)\//.exec(main);
62+
assert(dir, 'Could not determine build directory - should be dist or build');
63+
return dir[1] as 'build' | 'dist';
64+
}
65+
5966
// Automagically start your app by using common patterns
6067
// to find your implementation and settings. This is most useful
6168
// for jobs or other scripts that need service infra but are
@@ -67,18 +74,19 @@ export async function bootstrap<
6774
const { main, rootDirectory, name } = await getServiceDetails(argv);
6875

6976
let entrypoint: string;
70-
let codepath: 'build' | 'src' = 'build';
77+
let codepath: 'build' | 'dist' | 'src' = 'build';
7178
if (isDev() && argv?.built !== true) {
7279
// eslint-disable-next-line import/no-extraneous-dependencies
7380
const { register } = await import('ts-node');
7481
register();
7582
if (main) {
76-
entrypoint = main.replace(/^(\.?\/?)build\//, '$1src/').replace(/\.js$/, '.ts');
83+
entrypoint = main.replace(/^(\.?\/?)(build|dist)\//, '$1src/').replace(/\.js$/, '.ts');
7784
} else {
7885
entrypoint = './src/index.ts';
7986
}
8087
codepath = 'src';
8188
} else if (main) {
89+
codepath = getBuildDir(main);
8290
entrypoint = main;
8391
} else {
8492
entrypoint = './build/index.js';

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface ServiceStartOptions<
9191
rootDirectory: string;
9292

9393
// Defaults to "build", but can be set to "src" to run off non-built source
94-
codepath?: 'build' | 'src';
94+
codepath?: 'build' | 'src' | 'dist';
9595

9696
// NOTE: if you use this, you need to cast it because of a Typescript error:
9797
// https://github.com/microsoft/TypeScript/issues/22229

0 commit comments

Comments
 (0)