Skip to content

Commit

Permalink
Ship npm@3 with hyperterm
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Oct 23, 2016
1 parent 698cdb0 commit 6ccb764
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 37 deletions.
104 changes: 67 additions & 37 deletions app/plugins.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const {exec} = require('child_process');
const {app, dialog} = require('electron');
const {homedir} = require('os');
const {resolve, basename} = require('path');
const {writeFileSync} = require('fs');

const {app, dialog} = require('electron');
const {writeFileSync, readFileSync} = require('fs');
const cp = require('child_process');
const {sync: mkdirpSync} = require('mkdirp');
const Config = require('electron-config');
const ms = require('ms');
const shellEnv = require('shell-env');
const queue = require('queue');

const spawnQueue = queue({concurrency: 1});

const config = require('./config');
const notify = require('./notify');
Expand Down Expand Up @@ -78,17 +79,10 @@ function updatePlugins({force = false} = {}) {

if (err) {
console.error(err.stack);
if (/not a recognized/.test(err.message) || /command not found/.test(err.message)) {
notify(
'Error updating plugins.',
'We could not find the `npm` command. Make sure it\'s in $PATH'
);
} else {
notify(
'Error updating plugins.',
'Check `~/.hyper_plugins/npm-debug.log` for more information.'
);
}
notify(
'Error updating plugins.',
'Check `~/.hyperterm_plugins/npm-debug.log` for more information.'
);
} else {
// flag successful plugin update
cache.set('hyper.plugins', id_);
Expand Down Expand Up @@ -223,30 +217,66 @@ function toDependencies(plugins) {
}

function install(fn) {
const {shell: cfgShell, npmRegistry} = exports.getDecoratedConfig();
const {npmRegistry: registry} = exports.getDecoratedConfig();

/* eslint-disable camelcase */
const env = {
NODE_ENV: 'production',
ELECTRON_RUN_AS_NODE: 'true',
npm_config_prefix: path,
npm_config_runtime: 'electron',
npm_config_target: require('../package.json').devDependencies.electron,
npm_config_disturl: 'https://atom.io/download/atom-shell',
npm_config_color: 'false',
npm_config_progress: 'false',
npm_config_loglevel: 'verbose'
};

if (registry) {
env.npm_config_registry = registry;
}
/* eslint-enable camelcase */

const electronPath = resolve(
__dirname, '..', 'node_modules', 'electron',
readFileSync(resolve(__dirname, '..', 'node_modules', 'electron', 'path.txt')).toString().trim()
);

const npmPath = resolve(__dirname, '..', 'node_modules', '.bin', 'npm');

function npm(args, cb) {
spawnQueue.push(end => {
const fullcmd = [electronPath, npmPath].concat(args).join(' ');

cp.exec(fullcmd, {
cwd: path,
env,
shell: true,
timeout: 1000 * 60 * 5,
stdio: ['ignore', 'ignore', 'inherit']
}, err => {
console.log('Done!');

if (err) {
cb(err);
} else {
cb(null);
}

const shell = cfgShell && cfgShell !== '' ? cfgShell : undefined;
end();
spawnQueue.start();
});
});

spawnQueue.start();
}

shellEnv(shell).then(env => {
if (npmRegistry) {
env.NPM_CONFIG_REGISTRY = npmRegistry;
npm(['install'], err => {
if (err) {
return fn(err);
}
/* eslint-disable camelcase */
env.npm_config_runtime = 'electron';
env.npm_config_target = '1.3.0';
env.npm_config_disturl = 'https://atom.io/download/atom-shell';
/* eslint-enable camelcase */
exec('npm prune; npm install --production', {
cwd: path,
env,
shell
}, err => {
if (err) {
return fn(err);
}
fn(null);
});
}).catch(fn);
fn(null);
});
}

exports.subscribe = function (fn) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
"json-loader": "0.5.4",
"mousetrap": "1.6.0",
"ms": "0.7.1",
"npm": "^3.10.7",
"object-values": "1.0.0",
"php-escape-shell": "1.0.0",
"queue": "4.0.0",
"react": "15.3.2",
"react-addons-pure-render-mixin": "15.3.2",
"react-deep-force-update": "2.0.1",
Expand Down

0 comments on commit 6ccb764

Please sign in to comment.