Browse Source

Fixes an error of missing context after logging in while deploying. (#498)

```
> Error! Unknown error: TypeError: Cannot read property 'username' of undefined
TypeError: Cannot read property 'username' of undefined
    at /usr/local/lib/node_modules/now/build/bin/now-deploy.js:316:115
    at Generator.next (<anonymous>)
    at c (/usr/local/lib/node_modules/now/build/bin/now-deploy.js:760:99)
```
master
Jarmo Isotalo 8 years ago
committed by Matheus Fernandes
parent
commit
b67e683f38
  1. 73
      bin/now-deploy.js

73
bin/now-deploy.js

@ -73,8 +73,7 @@ const argv = minimist(process.argv.slice(2), {
})
const help = () => {
console.log(
`
console.log(`
${chalk.bold(`${logo} now`)} [options] <command | path>
${chalk.dim('Commands:')}
@ -148,8 +147,7 @@ const help = () => {
${chalk.gray('–')} Displays comprehensive help for the subcommand ${chalk.dim('`list`')}
${chalk.cyan('$ now help list')}
`
)
`)
}
let path = argv._[0]
@ -187,9 +185,7 @@ if (argv.config) {
}
if (Array.isArray(autoAliases)) {
console.log(
`${chalk.red('Deprecated!')} The option ${chalk.grey('--alias')} will be removed soon.`
)
console.log(`${chalk.red('Deprecated!')} The option ${chalk.grey('--alias')} will be removed soon.`)
console.log('Read more about the new way here: http://bit.ly/2l2v5Fg\n')
}
@ -204,7 +200,7 @@ if (deploymentName || wantsPublic) {
let alwaysForwardNpm
Promise.resolve().then(async () => {
const config = await cfg.read()
let config = await cfg.read()
alwaysForwardNpm = config.forwardNpm
if (argv.h || argv.help) {
@ -217,6 +213,7 @@ Promise.resolve().then(async () => {
let token
try {
token = await login(apiUrl)
config = await cfg.read()
} catch (err) {
error(`Authentication error – ${err.message}`)
process.exit(1)
@ -284,14 +281,10 @@ async function sync({ token, config: { currentTeam, user } }) {
// once the deployment has finished
Object.assign(gitRepo, repo)
} else if (isValidRepo === 'no-valid-url') {
stopDeployment(
`This URL is neither a valid repository from GitHub, nor from GitLab.`
)
stopDeployment(`This URL is neither a valid repository from GitHub, nor from GitLab.`)
} else if (isValidRepo) {
const gitRef = gitRepo.ref ? `with "${chalk.bold(gitRepo.ref)}" ` : ''
stopDeployment(
`There's no repository named "${chalk.bold(gitRepo.main)}" ${gitRef}on ${gitRepo.type}`
)
stopDeployment(`There's no repository named "${chalk.bold(gitRepo.main)}" ${gitRef}on ${gitRepo.type}`)
} else {
stopDeployment(`Could not read directory ${chalk.bold(path)}`)
}
@ -308,13 +301,9 @@ async function sync({ token, config: { currentTeam, user } }) {
if (!quiet) {
if (gitRepo.main) {
const gitRef = gitRepo.ref ? ` at "${chalk.bold(gitRepo.ref)}" ` : ''
console.log(
`> Deploying ${gitRepo.type} repository "${chalk.bold(gitRepo.main)}" ${gitRef} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
console.log(`> Deploying ${gitRepo.type} repository "${chalk.bold(gitRepo.main)}" ${gitRef} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
} else {
console.log(
`> Deploying ${chalk.bold(toHumanPath(path))} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
console.log(`> Deploying ${chalk.bold(toHumanPath(path))} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
}
}
@ -372,9 +361,7 @@ async function sync({ token, config: { currentTeam, user } }) {
if (isTTY) {
try {
console.log(
`> Two manifests found. Press [${chalk.bold('n')}] to deploy or re-run with --flag`
)
console.log(`> Two manifests found. Press [${chalk.bold('n')}] to deploy or re-run with --flag`)
deploymentType = await promptOptions([
[
'npm',
@ -488,9 +475,7 @@ async function sync({ token, config: { currentTeam, user } }) {
}
if (/[^A-z0-9_]/i.test(key)) {
error(
`Invalid ${chalk.dim('-e')} key ${chalk.bold(`"${chalk.bold(key)}"`)}. Only letters, digits and underscores are allowed.`
)
error(`Invalid ${chalk.dim('-e')} key ${chalk.bold(`"${chalk.bold(key)}"`)}. Only letters, digits and underscores are allowed.`)
return process.exit(1)
}
@ -501,15 +486,11 @@ async function sync({ token, config: { currentTeam, user } }) {
if (val === undefined) {
if (key in process.env) {
console.log(
`> Reading ${chalk.bold(`"${chalk.bold(key)}"`)} from your env (as no value was specified)`
)
console.log(`> Reading ${chalk.bold(`"${chalk.bold(key)}"`)} from your env (as no value was specified)`)
// Escape value if it begins with @
val = process.env[key].replace(/^@/, '\\@')
} else {
error(
`No value specified for env ${chalk.bold(`"${chalk.bold(key)}"`)} and it was not found in your env.`
)
error(`No value specified for env ${chalk.bold(`"${chalk.bold(key)}"`)} and it was not found in your env.`)
return process.exit(1)
}
}
@ -519,19 +500,13 @@ async function sync({ token, config: { currentTeam, user } }) {
const secrets = await findSecret(uidOrName)
if (secrets.length === 0) {
if (uidOrName === '') {
error(
`Empty reference provided for env key ${chalk.bold(`"${chalk.bold(key)}"`)}`
)
error(`Empty reference provided for env key ${chalk.bold(`"${chalk.bold(key)}"`)}`)
} else {
error(
`No secret found by uid or name ${chalk.bold(`"${uidOrName}"`)}`
)
error(`No secret found by uid or name ${chalk.bold(`"${uidOrName}"`)}`)
}
return process.exit(1)
} else if (secrets.length > 1) {
error(
`Ambiguous secret ${chalk.bold(`"${uidOrName}"`)} (matches ${chalk.bold(secrets.length)} secrets)`
)
error(`Ambiguous secret ${chalk.bold(`"${uidOrName}"`)} (matches ${chalk.bold(secrets.length)} secrets)`)
return process.exit(1)
}
@ -580,9 +555,7 @@ async function sync({ token, config: { currentTeam, user } }) {
if (clipboard) {
try {
await copy(url)
console.log(
`${chalk.cyan('> Ready!')} ${chalk.bold(url)} (copied to clipboard) [${elapsed}]`
)
console.log(`${chalk.cyan('> Ready!')} ${chalk.bold(url)} (copied to clipboard) [${elapsed}]`)
} catch (err) {
console.log(`${chalk.cyan('> Ready!')} ${chalk.bold(url)} [${elapsed}]`)
}
@ -613,9 +586,7 @@ async function sync({ token, config: { currentTeam, user } }) {
if (plan.id === 'oss') {
if (isTTY) {
info(
`${chalk.bold((currentTeam && `${currentTeam.slug} is`) || `You (${user.username || user.email}) are`)} on the OSS plan. Your code will be made ${chalk.bold('public')}.`
)
info(`${chalk.bold((currentTeam && `${currentTeam.slug} is`) || `You (${user.username || user.email}) are`)} on the OSS plan. Your code will be made ${chalk.bold('public')}.`)
let proceed
try {
@ -658,9 +629,7 @@ async function sync({ token, config: { currentTeam, user } }) {
now.on('upload', ({ names, data }) => {
const amount = data.length
if (debug) {
console.log(
`> [debug] Uploaded: ${names.join(' ')} (${bytes(data.length)})`
)
console.log(`> [debug] Uploaded: ${names.join(' ')} (${bytes(data.length)})`)
}
bar.tick(amount)
})
@ -692,9 +661,7 @@ function printLogs(host, token, currentTeam, user) {
logger.on('error', async err => {
if (!quiet) {
if (err && err.type === 'BUILD_ERROR') {
error(
`The build step of your project failed. To retry, run ${cmd('now --force')}.`
)
error(`The build step of your project failed. To retry, run ${cmd('now --force')}.`)
} else {
error('Deployment failed')
}

Loading…
Cancel
Save