Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): allow no config to be present, default to an empty object #543

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};