Skip to content

Commit

Permalink
fix(importer): handle the case where productName doesn't exist
Browse files Browse the repository at this point in the history
`yarn init` and `npm init` don't add a `productName` to `package.json`, and when running import on a project without a `productName`, the config setup would throw an exception, so guard against that. This also implements a very basic import unit test -- maybe we want more, but this at least covers this bug fix and other sanity-check-level issues.
  • Loading branch information
Ben Demboski authored and malept committed Dec 4, 2017
1 parent a39011b commit 23f191a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/util/forge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ const proxify = (object, envPrefix) => {
* Sets sensible defaults for the `config.forge` object.
*/
export function setInitialForgeConfig(packageJSON) {
const { name = '', productName = '' } = packageJSON;

/* eslint-disable no-param-reassign */
packageJSON.config.forge.electronWinstallerConfig.name = packageJSON.name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = packageJSON.productName.replace(/-/g, '');
packageJSON.config.forge.electronWinstallerConfig.name = name.replace(/-/g, '_');
packageJSON.config.forge.windowsStoreConfig.name = productName.replace(/-/g, '');
packageJSON.config.forge.electronPackagerConfig.packageManager = yarnOrNpm();
/* eslint-enable no-param-reassign */
}
Expand Down
19 changes: 17 additions & 2 deletions test/slow/api_spec_slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import installDeps from '../../src/util/install-dependencies';
import readPackageJSON from '../../src/util/read-package-json';
import yarnOrNpm from '../../src/util/yarn-or-npm';

const installer = process.argv.find(arg => arg.startsWith('--installer=')) || `--installer=${yarnOrNpm()}`;
const installerArg = process.argv.find(arg => arg.startsWith('--installer=')) || `--installer=${yarnOrNpm()}`;
const installer = installerArg.substr(12);
const forge = proxyquire.noCallThru().load('../../src/api', {
'./install': async () => {},
});

describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
describe(`electron-forge API (with installer=${installer})`, () => {
let dir;
let dirID = Date.now();

Expand Down Expand Up @@ -156,6 +157,20 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
});
});

describe('import', () => {
before(async () => {
await ensureTestDirIsNonexistent();
await fs.mkdir(dir);
execSync(`${installer} init -y`, {
cwd: dir,
});
});

it('works', async () => {
await forge.import({ dir });
});
});

describe('after init', () => {
before(async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-test-${dirID}/electron-forge-test`);
Expand Down

0 comments on commit 23f191a

Please sign in to comment.