Browse Source

Ask to re-install with `--unsafe-perm` on `EACCES` (#683)

* ask user to reinstall with --unsafe-perm on EACCES

* webpack overrides process.env totally. removed DefinePlugin

* Cleaned up the code a little

* Missing import comments added
master
Igor Klopov 8 years ago
committed by Leo Lamprecht
parent
commit
95042e1a77
  1. 1
      download/src/chmod.js
  2. 25
      download/src/index.js
  3. 7
      download/src/log.js
  4. 14
      download/webpack.js

1
download/src/chmod.js

@ -1,3 +1,4 @@
// Native
import fs from 'fs'
export default function (file) {

25
download/src/index.js

@ -10,7 +10,7 @@ import fetch from 'node-fetch'
// Utilities
import plusxSync from './chmod'
import { disableProgress, enableProgress, info, showProgress } from './log'
import { disableProgress, enableProgress, info, showProgress, warn } from './log'
const now = path.join(__dirname, 'now')
const targetWin32 = path.join(__dirname, 'now.exe')
@ -27,11 +27,22 @@ const platformToName = {
}
async function main() {
fs.writeFileSync(
now,
'#!/usr/bin/env node\n' +
'console.log("Please wait until the \'now\' installation completes!")\n'
)
try {
fs.writeFileSync(
now,
'#!/usr/bin/env node\n' +
'console.log("Please wait until the \'now\' installation completes!")\n'
)
} catch (err) {
if (err.code === 'EACCES') {
warn('Please try installing now CLI again with the `--unsafe-perm` option.')
info('Example: `npm i -g --unsafe-perm now`')
process.exit()
}
throw err
}
onDeath(() => {
fs.writeFileSync(
@ -40,7 +51,7 @@ async function main() {
'console.log("The \'now\' installation did not complete successfully.")\n' +
'console.log("Please run \'npm i -g now\' to reinstall!")\n'
)
process.exit();
process.exit()
})
info('For the source code, check out: https://github.com/zeit/now-cli')

7
download/src/log.js

@ -1,12 +1,13 @@
// Packages
import assert from 'assert'
import chalk from 'chalk'
import Progress from 'progress'
let bar
export function enableProgress(text) {
assert(!bar)
// OLD: text += ' '.repeat(28 - text.length);
bar = new Progress(`> ${text} [:bar] :percent`, {
stream: process.stdout,
width: 20,
@ -20,6 +21,10 @@ export function info(text) {
console.log(`> ${text}`)
}
export function warn(text) {
console.log(chalk.red('> Warning!'), text)
}
export function showProgress(percentage) {
assert(bar)
bar.update(percentage / 100)

14
download/webpack.js

@ -1,11 +1,12 @@
// Native
const path = require('path')
const webpack = require('webpack')
module.exports = {
target: 'node',
node: {
__dirname: false,
__filename: false
__filename: false,
process: false
},
entry: [
'./src/index.js'
@ -29,12 +30,5 @@ module.exports = {
]
}
} ]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
}
}

Loading…
Cancel
Save