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

Loading…
Cancel
Save