Skip to content

Commit

Permalink
Update dependencies and enforce electron version checking when instal…
Browse files Browse the repository at this point in the history
…ling extensions. Fixes #8
  • Loading branch information
MarshallOfSound committed Jul 21, 2016
1 parent 1d5136d commit 69f21fc
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "airbnb-base",
"rules": {
"consistent-return": 0,
"import/no-unresolved": 0,
"consistent-return": 0
"max-len": [2, 170],
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": 0
}
}
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"chai-as-promised": "^5.3.0",
"chai-fs": "chaijs/chai-fs",
"electron-mocha": "^2.2.0",
"electron-prebuilt": "^1.2.1",
"eslint": "^2.11.1",
"eslint-config-airbnb-base": "^3.0.1",
"electron-prebuilt": "^1.2.6",
"eslint": "^3.1.1",
"eslint-config-airbnb-base": "^4.0.2",
"eslint-plugin-import": "^1.8.1",
"mocha-testdata": "^1.2.0",
"spec-xunit-file": "0.0.1-3"
Expand All @@ -48,10 +48,8 @@
"7zip": "0.0.6",
"cross-unzip": "0.0.2",
"request": "^2.72.0",
"rimraf": "^2.5.2"
},
"peerDependencies": {
"electron-prebuilt": "^1.2.1"
"rimraf": "^2.5.2",
"semver": "^5.3.0"
},
"babel": {
"presets": [
Expand Down
58 changes: 48 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import electron, { remote } from 'electron';
import fs from 'fs';
import path from 'path';
import semver from 'semver';

import downloadChromeExtension from './downloadChromeExtension';
import { getPath } from './utils';
Expand All @@ -11,12 +12,25 @@ if (fs.existsSync(IDMapPath)) {
IDMap = JSON.parse(fs.readFileSync(IDMapPath, 'utf8'));
}

export default (chromeStoreID, forceDownload = false) => {
export default (extensionReference, forceDownload = false) => {
let chromeStoreID;
if (typeof extensionReference === 'object' && extensionReference.id) {
chromeStoreID = extensionReference.id;
if (!semver.satisfies(process.versions.electron, extensionReference.electron)) {
return Promise.reject(
new Error(`Version of Electron: ${process.versions.electron} does not match required range ${extensionReference.electron} for extension ${chromeStoreID}`)
);
}
} else if (typeof extensionReference === 'string') {
chromeStoreID = extensionReference;
} else {
return Promise.reject(new Error(`Invalid extensionReference passed in: "${extensionReference}"`));
}
if (
!forceDownload &&
IDMap[chromeStoreID] &&
(remote || electron).BrowserWindow.getDevToolsExtensions &&
(remote || electron).BrowserWindow.getDevToolsExtensions().hasOwnProperty(IDMap[chromeStoreID])
(remote || electron).BrowserWindow.getDevToolsExtensions()[IDMap[chromeStoreID]]
) {
return Promise.resolve(IDMap[chromeStoreID]);
}
Expand All @@ -33,11 +47,35 @@ export default (chromeStoreID, forceDownload = false) => {
});
};

export const EMBER_INSPECTOR = 'bmdblncegkenkacieihfhpjfppoconhi';
export const REACT_DEVELOPER_TOOLS = 'fmkadmapgofadopljbjfkapdkoienihi';
export const BACKBONE_DEBUGGER = 'bhljhndlimiafopmmhjlgfpnnchjjbhd';
export const JQUERY_DEBUGGER = 'dbhhnnnpaeobfddmlalhnehgclcmjimi';
export const ANGULARJS_BATARANG = 'ighdmehidhipcmcojjgiloacoafjmpfk';
export const VUEJS_DEVTOOLS = 'nhdogjmejiglipccpnnnanhbledajbpd';
export const REDUX_DEVTOOLS = 'lmhkpmbekcpmknklioeibfkpmmfibljd';
export const REACT_PERF = 'hacmcodfllhbnekmghgdlplbdnahmhmm';
export const EMBER_INSPECTOR = {
id: 'bmdblncegkenkacieihfhpjfppoconhi',
electron: '^1.2.1',
};
export const REACT_DEVELOPER_TOOLS = {
id: 'fmkadmapgofadopljbjfkapdkoienihi',
electron: '^1.2.1',
};
export const BACKBONE_DEBUGGER = {
id: 'bhljhndlimiafopmmhjlgfpnnchjjbhd',
electron: '^1.2.1',
};
export const JQUERY_DEBUGGER = {
id: 'dbhhnnnpaeobfddmlalhnehgclcmjimi',
electron: '^1.2.1',
};
export const ANGULARJS_BATARANG = {
id: 'ighdmehidhipcmcojjgiloacoafjmpfk',
electron: '^1.2.1',
};
export const VUEJS_DEVTOOLS = {
id: 'nhdogjmejiglipccpnnnanhbledajbpd',
electron: '^1.2.1',
};
export const REDUX_DEVTOOLS = {
id: 'lmhkpmbekcpmknklioeibfkpmmfibljd',
electron: '^1.2.1',
};
export const REACT_PERF = {
id: 'hacmcodfllhbnekmghgdlplbdnahmhmm',
electron: '^1.2.6',
};
34 changes: 34 additions & 0 deletions test/compat_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Pre-run
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

// Actual Test Imports
import installExtension, { REACT_DEVELOPER_TOOLS } from '../src/';

chai.use(chaiAsPromised);
chai.should();

describe('Extension Compatability Checker', () => {
let currentVersion;

beforeEach(() => {
currentVersion = process.versions.electron;
});

describe('when using a compatable version of electron', () => {
it('should resolve the promise', () =>
installExtension(REACT_DEVELOPER_TOOLS).should.be.fulfilled
);
});

describe('when using an incompatable version of electron', () => {
it('should reject the promise', () => {
process.versions.electron = '0.37.2';
return installExtension(REACT_DEVELOPER_TOOLS).should.be.rejected;
});
});

afterEach(() => {
process.versions.electron = currentVersion;
});
});
16 changes: 8 additions & 8 deletions test/download_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import chaiFs from 'chai-fs';
import fs from 'fs';
import path from 'path';

chai.use(chaiAsPromised);
chai.use(chaiFs);
chai.should();

// Actual Test Imports
import downloadChromeExtension from '../src/downloadChromeExtension';
import { REACT_DEVELOPER_TOOLS } from '../src/';

chai.use(chaiAsPromised);
chai.use(chaiFs);
chai.should();

describe('Extension Downloader', () => {
describe('when given a valid extension ID', () => {
it('should return a valid path', (done) => {
downloadChromeExtension(REACT_DEVELOPER_TOOLS)
downloadChromeExtension(REACT_DEVELOPER_TOOLS.id)
.then((dir) => {
dir.should.be.a.directory();
done();
Expand All @@ -25,7 +25,7 @@ describe('Extension Downloader', () => {
});

it('should download a valid extension', (done) => {
downloadChromeExtension(REACT_DEVELOPER_TOOLS)
downloadChromeExtension(REACT_DEVELOPER_TOOLS.id)
.then((dir) => {
dir.should.be.a.directory();
path.resolve(dir, 'manifest.json').should.be.a.file();
Expand All @@ -36,14 +36,14 @@ describe('Extension Downloader', () => {

describe('with the force parameter', () => {
it('should always re-download the extension', (done) => {
downloadChromeExtension(REACT_DEVELOPER_TOOLS)
downloadChromeExtension(REACT_DEVELOPER_TOOLS.id)
.then((dir) => {
dir.should.be.a.directory();
fs.writeFileSync(path.resolve(dir, 'old_ext.file'), '__TEST__');
path.resolve(dir, 'manifest.json').should.be.a.file();
path.resolve(dir, 'old_ext.file').should.be.a.file();

downloadChromeExtension(REACT_DEVELOPER_TOOLS, true)
downloadChromeExtension(REACT_DEVELOPER_TOOLS.id, true)
.then((newDir) => {
newDir.should.be.equal(dir);
newDir.should.be.a.directory();
Expand Down
8 changes: 4 additions & 4 deletions test/install_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import chaiAsPromised from 'chai-as-promised';
import chaiFs from 'chai-fs';
import { given } from 'mocha-testdata';

chai.use(chaiAsPromised);
chai.use(chaiFs);
chai.should();

// Actual Test Imports
import installExtension, { REACT_DEVELOPER_TOOLS } from '../src/';
import knownExtensions from './testdata/knownExtensions';

chai.use(chaiAsPromised);
chai.use(chaiFs);
chai.should();

describe('Extension Installer', () => {
describe('when given a valid extension ID', () => {
given(...knownExtensions).it('should resolve the extension successfully', (item) =>
Expand Down

0 comments on commit 69f21fc

Please sign in to comment.