Skip to content

Commit 50c40f3

Browse files
feat: allow a custom out dir from forge config (#3458)
Co-authored-by: Keeley Hammond <[email protected]>
1 parent a02a5e3 commit 50c40f3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

packages/api/core/src/util/out-dir.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { ResolvedForgeConfig } from '@electron-forge/shared-types';
55
const BASE_OUT_DIR = 'out';
66

77
export default (baseDir: string, forgeConfig: ResolvedForgeConfig): string => {
8+
const baseOutDir = forgeConfig.outDir || BASE_OUT_DIR;
9+
810
if (forgeConfig.buildIdentifier) {
911
let identifier = forgeConfig.buildIdentifier;
1012
if (typeof identifier === 'function') {
1113
identifier = identifier();
1214
}
13-
if (identifier) return path.resolve(baseDir, BASE_OUT_DIR, identifier);
15+
if (identifier) return path.resolve(baseDir, baseOutDir, identifier);
1416
}
15-
return path.resolve(baseDir, BASE_OUT_DIR);
17+
18+
return path.resolve(baseDir, baseOutDir);
1619
};

packages/api/core/test/fast/out-dir_spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,35 @@ describe('out-dir', () => {
3030
});
3131
});
3232
});
33+
34+
describe('out-dir-dist', () => {
35+
const DIR = __dirname;
36+
37+
describe('getCurrentOutDir', () => {
38+
it('resolves to the dist directory when dist is declared', () => {
39+
expect(
40+
getCurrentOutDir(DIR, {
41+
outDir: 'dist',
42+
} as ResolvedForgeConfig)
43+
).to.equal(`${DIR}${path.sep}dist`);
44+
});
45+
46+
it('resolves to the provided identifier', () => {
47+
expect(
48+
getCurrentOutDir(DIR, {
49+
buildIdentifier: 'bar',
50+
outDir: 'dist',
51+
} as ResolvedForgeConfig)
52+
).to.equal(`${DIR}${path.sep}dist${path.sep}bar`);
53+
});
54+
55+
it('resolves to the return value of provided identifier getter', () => {
56+
expect(
57+
getCurrentOutDir(DIR, {
58+
buildIdentifier: () => 'thing',
59+
outDir: 'dist',
60+
} as ResolvedForgeConfig)
61+
).to.equal(`${DIR}${path.sep}dist${path.sep}thing`);
62+
});
63+
});
64+
});

packages/utils/types/src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ export interface ResolvedForgeConfig {
8585
* If a function is provided, it must synchronously return the buildIdentifier
8686
*/
8787
buildIdentifier?: string | (() => string);
88+
/**
89+
* Output directory. Default is './out'.
90+
*/
91+
outDir?: string;
8892
hooks?: ForgeHookMap;
8993
/**
9094
* @internal

0 commit comments

Comments
 (0)