Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
fix: use local now, resolves #10
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnbot committed Mar 15, 2019
1 parent ed61d61 commit 1640ec6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/now.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const execa = require('execa')
const mockedEnv = require('mocked-env')
const now = require('../now')

const {NOW_BIN} = now

jest.mock('execa')
execa.mockImplementation(() => Promise.resolve({stderr: '', stdout: ''}))

Expand All @@ -17,13 +19,13 @@ describe('now()', () => {
it('calls `npx now --token=$NOW_TOKEN` with no additional args', () => {
mockEnv({NOW_TOKEN: 'xyz'})
now()
expect(execa).lastCalledWith('npx', ['now', '--token=xyz'], {stderr: 'inherit'})
expect(execa).lastCalledWith(NOW_BIN, ['--token=xyz'], {stderr: 'inherit'})
})

it('calls with additional arguments passed as an array', () => {
mockEnv({NOW_TOKEN: 'abc'})
now(['foo', 'bar'])
expect(execa).lastCalledWith('npx', ['now', '--token=abc', 'foo', 'bar'], {stderr: 'inherit'})
expect(execa).lastCalledWith(NOW_BIN, ['--token=abc', 'foo', 'bar'], {stderr: 'inherit'})
})

function mockEnv(env) {
Expand Down
9 changes: 7 additions & 2 deletions src/now.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const execa = require('execa')

const {bin: {now: NOW_BIN_PATH}} = require('now/package.json')
const NOW_BIN = require.resolve(`now/${NOW_BIN_PATH}`)

module.exports = function now(args = []) {
const {NOW_TOKEN} = process.env
if (!NOW_TOKEN) {
throw new Error(`The NOW_TOKEN env var is required`)
}
const nowArgs = ['now', `--token=${NOW_TOKEN}`, ...args]
return execa('npx', nowArgs, {stderr: 'inherit'}).then(res => res.stdout)
const nowArgs = [`--token=${NOW_TOKEN}`, ...args]
return execa(NOW_BIN, nowArgs, {stderr: 'inherit'}).then(res => res.stdout)
}

Object.assign(module.exports, {NOW_BIN})

0 comments on commit 1640ec6

Please sign in to comment.