Skip to content

Commit

Permalink
fix(core): allow the forge.config property in package.json to poi…
Browse files Browse the repository at this point in the history
…nt to a non-js file (#3070)
  • Loading branch information
erikian committed Nov 16, 2022
1 parent d322e72 commit 2e5a8bc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -138,7 +138,8 @@
"typedoc-plugin-missing-exports": "^1.0.0",
"typedoc-plugin-rename-defaults": "^0.6.4",
"typescript": "^4.6.3",
"xvfb-maybe": "^0.2.1"
"xvfb-maybe": "^0.2.1",
"yaml-hook": "^1.0.0"
},
"optionalDependencies": {
"@malept/electron-installer-flatpak": "^0.11.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/api/core/package.json
Expand Up @@ -36,7 +36,8 @@
"mocha": "^9.0.1",
"proxyquire": "^2.1.3",
"sinon": "^13.0.1",
"sinon-chai": "^3.6.0"
"sinon-chai": "^3.6.0",
"yaml-hook": "^1.0.0"
},
"dependencies": {
"@electron-forge/core-utils": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/core/src/util/forge-config.ts
Expand Up @@ -109,7 +109,7 @@ export default async (dir: string): Promise<ResolvedForgeConfig> => {
const packageJSON = await readRawPackageJson(dir);
let forgeConfig: ForgeConfig | string | null = packageJSON.config && packageJSON.config.forge ? packageJSON.config.forge : null;

if (!forgeConfig) {
if (!forgeConfig || typeof forgeConfig === 'string') {
for (const extension of ['.js', ...Object.keys(interpret.extensions)]) {
const pathToConfig = path.resolve(dir, `forge.config${extension}`);
if (await fs.pathExists(pathToConfig)) {
Expand Down
6 changes: 6 additions & 0 deletions packages/api/core/test/fast/forge-config_spec.ts
Expand Up @@ -114,6 +114,12 @@ describe('forge-config', () => {
expect(conf.defaultResolved).to.equal(true);
});

it(`should resolve the yml config from forge.config.yml if it's specified in config.forge`, async () => {
type DefaultResolvedConfig = ResolvedForgeConfig;
const conf = (await findConfig(path.resolve(__dirname, '../fixture/dummy_ts_conf'))) as DefaultResolvedConfig;
expect(conf.buildIdentifier).to.equal('yml');
});

it('should resolve the TS file exports of forge.config.ts if config.forge does not exist and the TS config exists', async () => {
type DefaultResolvedConfig = ResolvedForgeConfig;
const conf = (await findConfig(path.resolve(__dirname, '../fixture/dummy_default_ts_conf'))) as DefaultResolvedConfig;
Expand Down
@@ -0,0 +1 @@
buildIdentifier: 'yml'
20 changes: 20 additions & 0 deletions packages/api/core/test/fixture/dummy_ts_conf/package.json
@@ -0,0 +1,20 @@
{
"name": "",
"productName": "",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start"
},
"keywords": [],
"author": "",
"license": "MIT",
"config": {
"forge": "./forge.config.yml"
},
"devDependencies": {
"@electron-forge/shared-types": "*",
"electron-prebuilt": "9.9.9"
}
}
10 changes: 9 additions & 1 deletion yarn.lock
Expand Up @@ -7493,7 +7493,7 @@ js-yaml@4.1.0, js-yaml@^4.1.0:
dependencies:
argparse "^2.0.1"

js-yaml@^3.10.0, js-yaml@^3.13.1:
js-yaml@^3.10.0, js-yaml@^3.12.2, js-yaml@^3.13.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537"
integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==
Expand Down Expand Up @@ -11555,6 +11555,14 @@ yallist@^4.0.0:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yaml-hook@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/yaml-hook/-/yaml-hook-1.0.0.tgz#14d682e949a9cf6f041e2af8278a4d349ccb52b7"
integrity sha512-iqSS5Mk1F3yBtrfx94hWzmEk0Wxs5QoBRvngAe39t0XA2JJ3jhQN6Snwv/shH1VoZr+ntdhf4EDLmW0WUWBjdQ==
dependencies:
js-yaml "^3.12.2"
pirates "^4.0.1"

yaml@^1.10.0, yaml@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
Expand Down

0 comments on commit 2e5a8bc

Please sign in to comment.