Skip to content

Commit

Permalink
feat(core): allow no config to be present, default to an empty object (
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound authored Jul 27, 2018
1 parent a5bec3a commit c71ef16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function fromBuildIdentifier<T>(map: { [key: string]: T | undefined }) {

export default async (dir: string) => {
const packageJSON = await readRawPackageJson(dir);
let forgeConfig: ForgeConfig | string = packageJSON.config.forge;
let forgeConfig: ForgeConfig | string = (packageJSON.config && packageJSON.config.forge) ? packageJSON.config.forge : {};

if (typeof forgeConfig === 'string' && (await fs.pathExists(path.resolve(dir, forgeConfig)) || await fs.pathExists(path.resolve(dir, `${forgeConfig}.js`)))) {
try {
Expand Down
16 changes: 14 additions & 2 deletions packages/api/core/src/util/resolve-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const d = debug('electron-forge:project-resolver');
// the dir without calling getElectronVersion
export default async (dir: string) => {
let mDir = dir;
let bestGuessDir: string | null = null;
let lastError: string | null = null;

let prevDir;
while (prevDir !== mDir) {
prevDir = mDir;
Expand All @@ -24,18 +27,27 @@ export default async (dir: string) => {
const electronVersion = getElectronVersion(packageJSON);
if (electronVersion) {
if (!/[0-9]/.test(electronVersion[0])) {
throw `You must depend on an EXACT version of electron not a range (${electronVersion})`;
lastError = `You must depend on an EXACT version of electron not a range (${electronVersion})`;
}
} else {
throw 'You must depend on "electron" in your devDependencies';
lastError = 'You must depend on "electron" in your devDependencies';
}

if (packageJSON.config && packageJSON.config.forge) {
d('electron-forge compatible package.json found in', testPath);
return mDir;
}

bestGuessDir = mDir;
}
mDir = path.dirname(mDir);
}
if (bestGuessDir) {
d('guessing on the best electron-forge package.json found in', bestGuessDir);
return bestGuessDir;
}
if (lastError) {
throw lastError;
}
return null;
};

0 comments on commit c71ef16

Please sign in to comment.