CLI: better existence check (#2700)

This commit is contained in:
CHaBou 2018-02-25 14:18:45 -06:00 committed by GitHub
parent 76beaa32f5
commit e17aab656d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 46 deletions

View file

@ -1,6 +1,7 @@
const fs = require('fs'); const fs = require('fs');
const os = require('os'); const os = require('os');
const npmName = require('npm-name'); const got = require('got');
const registryUrl = require('registry-url')();
const pify = require('pify'); const pify = require('pify');
const recast = require('recast'); const recast = require('recast');
@ -62,12 +63,10 @@ function save() {
} }
function existsOnNpm(plugin) { function existsOnNpm(plugin) {
plugin = plugin.split('#')[0].split('@')[0]; const name = plugin.split('#')[0].split('@')[0];
return npmName(plugin).then(unavailable => { return got.get(registryUrl + name.toLowerCase(), {timeout: 10000, json: true}).then(res => {
if (unavailable) { if (!res.body.versions) {
const err = new Error(`${plugin} not found on npm`); return Promise.reject(res);
err.code = 'NOT_FOUND_ON_NPM';
throw err;
} }
}); });
} }
@ -87,11 +86,11 @@ function install(plugin, locally) {
.catch(err => reject(err)); .catch(err => reject(err));
}) })
.catch(err => { .catch(err => {
if (err.code === 'NOT_FOUND_ON_NPM') { const {statusCode} = err;
reject(err.message); if (statusCode && (statusCode === 404 || statusCode === 200)) {
} else { return reject(`${plugin} not found on npm`);
reject(err);
} }
return reject(`${err.message}\nPlugin check failed. Check your internet connection or retry later.`);
}); });
}); });
} }

View file

@ -1,8 +1,7 @@
{ {
"repository": "zeit/hyper", "repository": "zeit/hyper",
"scripts": { "scripts": {
"start": "start": "echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'",
"echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'",
"app": "electron app", "app": "electron app",
"dev": "webpack -w", "dev": "webpack -w",
"build": "cross-env NODE_ENV=production webpack", "build": "cross-env NODE_ENV=production webpack",
@ -11,18 +10,21 @@
"test:unit": "ava test/unit", "test:unit": "ava test/unit",
"test:unit:watch": "yarn run test:unit -- --watch", "test:unit:watch": "yarn run test:unit -- --watch",
"prepush": "yarn test", "prepush": "yarn test",
"postinstall": "postinstall": "electron-builder install-app-deps && yarn run rebuild-node-pty && yarn --cwd node_modules/xterm",
"electron-builder install-app-deps && yarn run rebuild-node-pty && yarn --cwd node_modules/xterm", "rebuild-node-pty": "electron-rebuild -f -w app/node_modules/node-pty -m app",
"rebuild-node-pty": "dist": "yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build",
"electron-rebuild -f -w app/node_modules/node-pty -m app", "clean": "node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer"
"dist":
"yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build",
"clean":
"node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer"
}, },
"eslintConfig": { "eslintConfig": {
"plugins": ["react", "prettier"], "plugins": [
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier"], "react",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"prettier"
],
"parserOptions": { "parserOptions": {
"ecmaVersion": 8, "ecmaVersion": 8,
"sourceType": "module", "sourceType": "module",
@ -39,7 +41,10 @@
"node": true "node": true
}, },
"rules": { "rules": {
"func-names": ["error", "as-needed"], "func-names": [
"error",
"as-needed"
],
"no-shadow": "error", "no-shadow": "error",
"no-extra-semi": 0, "no-extra-semi": 0,
"react/prop-types": 0, "react/prop-types": 0,
@ -85,7 +90,9 @@
] ]
}, },
"babel": { "babel": {
"presets": ["react"], "presets": [
"react"
],
"env": { "env": {
"production": { "production": {
"plugins": [ "plugins": [
@ -122,7 +129,9 @@
{ {
"from": "./build/${os}/", "from": "./build/${os}/",
"to": "./bin/", "to": "./bin/",
"filter": ["hyper*"] "filter": [
"hyper*"
]
} }
], ],
"linux": { "linux": {
@ -130,20 +139,28 @@
"target": [ "target": [
{ {
"target": "deb", "target": "deb",
"arch": ["x64"] "arch": [
"x64"
]
}, },
{ {
"target": "AppImage", "target": "AppImage",
"arch": ["x64"] "arch": [
"x64"
]
}, },
{ {
"target": "rpm", "target": "rpm",
"arch": ["x64"] "arch": [
"x64"
]
} }
] ]
}, },
"win": { "win": {
"target": ["squirrel"] "target": [
"squirrel"
]
}, },
"mac": { "mac": {
"category": "public.app-category.developer-tools", "category": "public.app-category.developer-tools",
@ -157,7 +174,9 @@
}, },
"protocols": { "protocols": {
"name": "ssh URL", "name": "ssh URL",
"schemes": ["ssh"] "schemes": [
"ssh"
]
} }
}, },
"license": "MIT", "license": "MIT",
@ -176,7 +195,6 @@
"json-loader": "0.5.7", "json-loader": "0.5.7",
"mousetrap": "chabou/mousetrap#useCapture", "mousetrap": "chabou/mousetrap#useCapture",
"ms": "2.1.1", "ms": "2.1.1",
"npm-name": "3.1.0",
"opn": "5.1.0", "opn": "5.1.0",
"ora": "1.3.0", "ora": "1.3.0",
"parse-url": "3.0.2", "parse-url": "3.0.2",

View file

@ -3080,7 +3080,7 @@ globule@^1.0.0:
lodash "~4.17.4" lodash "~4.17.4"
minimatch "~3.0.2" minimatch "~3.0.2"
got@7.1.0, got@^7.0.0: got@7.1.0:
version "7.1.0" version "7.1.0"
resolved "https://registry.yarnpkg.com/got/-/got-7.1.0.tgz#05450fd84094e6bbea56f451a43a9c289166385a" resolved "https://registry.yarnpkg.com/got/-/got-7.1.0.tgz#05450fd84094e6bbea56f451a43a9c289166385a"
dependencies: dependencies:
@ -4018,10 +4018,6 @@ lodash.uniq@^4.5.0:
version "4.5.0" version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
lodash.zip@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"
lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.8.0, lodash@~4.17.4: lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.8.0, lodash@~4.17.4:
version "4.17.5" version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
@ -4413,14 +4409,6 @@ npm-install-package@~2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/npm-install-package/-/npm-install-package-2.1.0.tgz#d7efe3cfcd7ab00614b896ea53119dc9ab259125" resolved "https://registry.yarnpkg.com/npm-install-package/-/npm-install-package-2.1.0.tgz#d7efe3cfcd7ab00614b896ea53119dc9ab259125"
npm-name@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/npm-name/-/npm-name-3.1.0.tgz#79789afac52ae335dc3a5aa7f41f59d1b77c756f"
dependencies:
got "^7.0.0"
lodash.zip "^4.0.0"
registry-url "^3.0.0"
npm-run-path@^2.0.0: npm-run-path@^2.0.0:
version "2.0.2" version "2.0.2"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
@ -5463,7 +5451,7 @@ registry-auth-token@^3.0.1:
rc "^1.1.6" rc "^1.1.6"
safe-buffer "^5.0.1" safe-buffer "^5.0.1"
registry-url@^3.0.0, registry-url@^3.0.3: registry-url@^3.0.3:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/registry-url/-/registry-url-3.1.0.tgz#3d4ef870f73dde1d77f0cf9a381432444e174942" resolved "https://registry.yarnpkg.com/registry-url/-/registry-url-3.1.0.tgz#3d4ef870f73dde1d77f0cf9a381432444e174942"
dependencies: dependencies: