Skip to content

Commit

Permalink
fix(initializer): electron versions for babel-preset-env should be st…
Browse files Browse the repository at this point in the history
…rings

Removes the following warning when running `electron-forge start`:

> Warning, the following targets are using a decimal version:
>
>   electron: 1.7
>
> We recommend using a string for minor/patch versions to avoid numbers like 6.10
> getting parsed as 6.1, which can lead to unexpected behavior.
  • Loading branch information
malept committed Dec 17, 2017
1 parent 0e18fe3 commit 35120b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/init/init-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default async (dir, lintStyle) => {
const envTarget = content.env[profile]['application/javascript'].presets.find(x => x[0] === 'env');
// parseFloat strips the patch version
// parseFloat('1.3.2') === 1.3
envTarget[1].targets.electron = parseFloat(electronPrebuilt.version);
envTarget[1].targets.electron = parseFloat(electronPrebuilt.version).toString();
}

await fs.writeFile(path.join(dir, '.compilerc'), JSON.stringify(content, null, 2), 'utf8');
Expand Down
6 changes: 4 additions & 2 deletions test/slow/api_spec_slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {
expect(await fs.pathExists(path.resolve(dir, 'node_modules/electron-forge')), 'electron-forge should exist').to.equal(true);
});

it('should have set the .compilerc electron version to be a float', async () => {
it('should have set the .compilerc electron version to be a string', async () => {
expectProjectPathExists('.compilerc', 'file');
const compilerc = JSON.parse(await fs.readFile(path.resolve(dir, '.compilerc')));
expect(compilerc.env.development['application/javascript'].presets[0][1].targets.electron).to.be.a('number');
const electronVersion = compilerc.env.development['application/javascript'].presets[0][1].targets.electron;
expect(electronVersion).to.be.a('string');
expect(electronVersion.split('.').length).to.equal(2);
});

describe('lint', () => {
Expand Down
4 changes: 2 additions & 2 deletions tmpl/_compilerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"development": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": 1.4 } }],
["env", { "targets": { "electron": "1.4" } }],
"react"
],
"plugins": ["transform-async-to-generator"],
Expand All @@ -13,7 +13,7 @@
"production": {
"application/javascript": {
"presets": [
["env", { "targets": { "electron": 1.4 } }],
["env", { "targets": { "electron": "1.4" } }],
"react"
],
"plugins": ["transform-async-to-generator"],
Expand Down

0 comments on commit 35120b1

Please sign in to comment.