Leo Lamprecht
7 years ago
76 changed files with 2212 additions and 451 deletions
File diff suppressed because it is too large
@ -0,0 +1,49 @@ |
|||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"name": "", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
||||
|
woot |
@ -0,0 +1 @@ |
|||||
|
woot |
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"name": "directory-main", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"main": "./a", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
CMD echo 'world' |
@ -0,0 +1 @@ |
|||||
|
// this should be included
|
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"name": "extensionless-main", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"main": "./index", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
should-be-excluded.js |
||||
|
./build/a/should-be-excluded.js |
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"files": [ |
||||
|
"build" |
||||
|
] |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"files": [ |
||||
|
"build" |
||||
|
] |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
ignore-me.js |
||||
|
test.json |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"files": [ |
||||
|
"test.js", |
||||
|
"test.json" |
||||
|
] |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
// include me
|
After Width: | Height: | Size: 167 KiB |
After Width: | Height: | Size: 167 KiB |
@ -0,0 +1 @@ |
|||||
|
woot |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"name": "hashes", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
CMD echo 'world' |
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"name": "simple" |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
// should include it
|
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"name": "negation", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": { |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
**/node_modules |
@ -0,0 +1 @@ |
|||||
|
// this should be included
|
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"name": "nested-node_modules" |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
console.log('index'); |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"name": "no-node_modules", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1,2 @@ |
|||||
|
ignore-me.js |
||||
|
test.json |
@ -0,0 +1 @@ |
|||||
|
// this should be ignored
|
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"now": { |
||||
|
"files": [ |
||||
|
"test.js", |
||||
|
"test.json" |
||||
|
] |
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
// include me
|
@ -0,0 +1 @@ |
|||||
|
{ "include": "me" } |
@ -0,0 +1 @@ |
|||||
|
// should not be included
|
@ -0,0 +1 @@ |
|||||
|
// should be included
|
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"name": "woot", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {}, |
||||
|
"files": [ |
||||
|
"a.js" |
||||
|
], |
||||
|
"now": { |
||||
|
"files": [ |
||||
|
"b.js" |
||||
|
] |
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
CMD echo 'world' |
@ -0,0 +1 @@ |
|||||
|
// should not be included
|
@ -0,0 +1 @@ |
|||||
|
// should be included
|
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"files": [ |
||||
|
"b.js" |
||||
|
] |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"alias": "bar.com" |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"name": "woot", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {}, |
||||
|
"now": { |
||||
|
"alias": "foo.com" |
||||
|
} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
// should not be included
|
@ -0,0 +1 @@ |
|||||
|
// should be included
|
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"files": [ |
||||
|
"b.js" |
||||
|
] |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
{ |
||||
|
"name": "woot", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {}, |
||||
|
"files": [ |
||||
|
"a.js" |
||||
|
] |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
woot |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"name": "prefix-regression", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
// hello
|
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"name": "simple-with-main", |
||||
|
"version": "0.0.1", |
||||
|
"description": "", |
||||
|
"main": "./index.js", |
||||
|
"dependencies": {} |
||||
|
} |
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"name": "simple" |
||||
|
} |
@ -0,0 +1 @@ |
|||||
|
CMD echo 'world' |
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"now": { |
||||
|
"type": "npm" |
||||
|
} |
||||
|
} |
@ -0,0 +1,240 @@ |
|||||
|
// Native
|
||||
|
const { join, resolve } = require('path') |
||||
|
|
||||
|
// Packages
|
||||
|
const test = require('ava') |
||||
|
const { asc: alpha } = require('alpha-sort') |
||||
|
|
||||
|
// Utilities
|
||||
|
const hash = require('../src/providers/sh/util/hash') |
||||
|
const readMetadata = require('../src/providers/sh/util/read-metadata') |
||||
|
const { |
||||
|
npm: getNpmFiles_, |
||||
|
docker: getDockerFiles |
||||
|
} = require('../src/providers/sh/util/get-files') |
||||
|
|
||||
|
const prefix = join(__dirname, '_fixtures') + '/' |
||||
|
const base = path => path.replace(prefix, '') |
||||
|
const fixture = name => resolve(`./test/_fixtures/${name}`) |
||||
|
|
||||
|
// Overload to force debugging
|
||||
|
const getNpmFiles = async dir => { |
||||
|
const { pkg, nowConfig, hasNowJson } = await readMetadata(dir, { |
||||
|
quiet: true, |
||||
|
strict: false |
||||
|
}) |
||||
|
return getNpmFiles_(dir, pkg, nowConfig, { hasNowJson }) |
||||
|
} |
||||
|
|
||||
|
test('`files`', async t => { |
||||
|
let files = await getNpmFiles(fixture('files-in-package')) |
||||
|
t.is(files.length, 3) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(base(files[0]), 'files-in-package/build/a/b/c/d.js') |
||||
|
t.is(base(files[1]), 'files-in-package/build/a/e.js') |
||||
|
t.is(base(files[2]), 'files-in-package/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('`files` + `.*.swp` + `.npmignore`', async t => { |
||||
|
let files = await getNpmFiles(fixture('files-in-package-ignore')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'files-in-package-ignore/build/a/b/c/d.js') |
||||
|
t.is(base(files[1]), 'files-in-package-ignore/build/a/e.js') |
||||
|
t.is(base(files[2]), 'files-in-package-ignore/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('`files` overrides `.gitignore`', async t => { |
||||
|
let files = await getNpmFiles(fixture('files-overrides-gitignore')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'files-overrides-gitignore/package.json') |
||||
|
t.is(base(files[1]), 'files-overrides-gitignore/test.js') |
||||
|
t.is(base(files[2]), 'files-overrides-gitignore/test.json') |
||||
|
}) |
||||
|
|
||||
|
test('`now.files` overrides `.npmignore`', async t => { |
||||
|
let files = await getNpmFiles(fixture('now-files-overrides-npmignore')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'now-files-overrides-npmignore/package.json') |
||||
|
t.is(base(files[1]), 'now-files-overrides-npmignore/test.js') |
||||
|
t.is(base(files[2]), 'now-files-overrides-npmignore/test.json') |
||||
|
}) |
||||
|
|
||||
|
test('simple', async t => { |
||||
|
let files = await getNpmFiles(fixture('simple')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 5) |
||||
|
t.is(base(files[0]), 'simple/bin/test') |
||||
|
t.is(base(files[1]), 'simple/index.js') |
||||
|
t.is(base(files[2]), 'simple/lib/woot') |
||||
|
t.is(base(files[3]), 'simple/lib/woot.jsx') |
||||
|
t.is(base(files[4]), 'simple/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('simple with main', async t => { |
||||
|
let files = await getNpmFiles(fixture('simple-main')) |
||||
|
t.is(files.length, 3) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'simple-main/build/a.js') |
||||
|
t.is(base(files[1]), 'simple-main/index.js') |
||||
|
t.is(base(files[2]), 'simple-main/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('directory main', async t => { |
||||
|
let files = await getNpmFiles(fixture('directory-main')) |
||||
|
t.is(files.length, 3) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'directory-main/a/index.js') |
||||
|
t.is(base(files[1]), 'directory-main/build/a.js') |
||||
|
t.is(base(files[2]), 'directory-main/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('extensionless main', async t => { |
||||
|
let files = await getNpmFiles(fixture('extensionless-main')) |
||||
|
t.is(files.length, 3) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'extensionless-main/build/a.js') |
||||
|
t.is(base(files[1]), 'extensionless-main/index.js') |
||||
|
t.is(base(files[2]), 'extensionless-main/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('hashes', async t => { |
||||
|
const files = await getNpmFiles(fixture('hashes')) |
||||
|
const hashes = await hash(files) |
||||
|
t.is(hashes.size, 3) |
||||
|
const many = new Set( |
||||
|
hashes.get('277c55a2042910b9fe706ad00859e008c1b7d172').names |
||||
|
) |
||||
|
t.is(many.size, 2) |
||||
|
t.is(many.has(prefix + 'hashes/dei.png'), true) |
||||
|
t.is(many.has(prefix + 'hashes/duplicate/dei.png'), true) |
||||
|
t.is( |
||||
|
hashes.get('56c00d0466fc6bdd41b13dac5fc920cc30a63b45').names[0], |
||||
|
prefix + 'hashes/index.js' |
||||
|
) |
||||
|
t.is( |
||||
|
hashes.get('706214f42ae940a01d2aa60c5e32408f4d2127dd').names[0], |
||||
|
prefix + 'hashes/package.json' |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
test('ignore node_modules', async t => { |
||||
|
let files = await getNpmFiles(fixture('no-node_modules')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'no-node_modules/index.js') |
||||
|
t.is(base(files[1]), 'no-node_modules/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('ignore nested `node_modules` with .npmignore **', async t => { |
||||
|
let files = await getNpmFiles(fixture('nested-node_modules')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'nested-node_modules/index.js') |
||||
|
t.is(base(files[1]), 'nested-node_modules/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('support whitelisting with .npmignore and !', async t => { |
||||
|
let files = await getNpmFiles(fixture('negation')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'negation/a.js') |
||||
|
t.is(base(files[1]), 'negation/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('support `now.files`', async t => { |
||||
|
let files = await getNpmFiles(fixture('now-files')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'now-files/b.js') |
||||
|
t.is(base(files[1]), 'now-files/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('support docker', async t => { |
||||
|
let files = await getDockerFiles(fixture('dockerfile')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'dockerfile/Dockerfile') |
||||
|
t.is(base(files[1]), 'dockerfile/a.js') |
||||
|
}) |
||||
|
|
||||
|
test('prefix regression', async t => { |
||||
|
let files = await getNpmFiles(fixture('prefix-regression')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 2) |
||||
|
t.is(base(files[0]), 'prefix-regression/package.json') |
||||
|
t.is(base(files[1]), 'prefix-regression/woot.js') |
||||
|
}) |
||||
|
|
||||
|
test('support `now.json` files with package.json', async t => { |
||||
|
let files = await getNpmFiles(fixture('now-json')) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'now-json/b.js') |
||||
|
t.is(base(files[1]), 'now-json/now.json') |
||||
|
t.is(base(files[2]), 'now-json/package.json') |
||||
|
}) |
||||
|
|
||||
|
test('support `now.json` files with Dockerfile', async t => { |
||||
|
const f = fixture('now-json-docker') |
||||
|
const { deploymentType, nowConfig, hasNowJson } = await readMetadata(f, { |
||||
|
quiet: true, |
||||
|
strict: false |
||||
|
}) |
||||
|
t.is(deploymentType, 'docker') |
||||
|
|
||||
|
let files = await getDockerFiles(f, nowConfig, { hasNowJson }) |
||||
|
files = files.sort(alpha) |
||||
|
t.is(files.length, 3) |
||||
|
t.is(base(files[0]), 'now-json-docker/Dockerfile') |
||||
|
t.is(base(files[1]), 'now-json-docker/b.js') |
||||
|
t.is(base(files[2]), 'now-json-docker/now.json') |
||||
|
}) |
||||
|
|
||||
|
test('throws when both `now.json` and `package.json:now` exist', async t => { |
||||
|
let e |
||||
|
try { |
||||
|
await readMetadata(fixture('now-json-throws'), { |
||||
|
quiet: true, |
||||
|
strict: false |
||||
|
}) |
||||
|
} catch (err) { |
||||
|
e = err |
||||
|
} |
||||
|
t.is(e.name, 'Error') |
||||
|
t.is(e.userError, true) |
||||
|
t.pass( |
||||
|
/please ensure there's a single source of configuration/i.test(e.message) |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
test('throws when `package.json` and `Dockerfile` exist', async t => { |
||||
|
let e |
||||
|
try { |
||||
|
await readMetadata(fixture('multiple-manifests-throws'), { |
||||
|
quiet: true, |
||||
|
strict: false |
||||
|
}) |
||||
|
} catch (err) { |
||||
|
e = err |
||||
|
} |
||||
|
t.is(e.userError, true) |
||||
|
t.is(e.code, 'MULTIPLE_MANIFESTS') |
||||
|
t.pass(/ambiguous deployment/i.test(e.message)) |
||||
|
}) |
||||
|
|
||||
|
test('support `package.json:now.type` to bypass multiple manifests error', async t => { |
||||
|
const f = fixture('type-in-package-now-with-dockerfile') |
||||
|
const { type, nowConfig, hasNowJson } = await readMetadata(f, { |
||||
|
quiet: true, |
||||
|
strict: false |
||||
|
}) |
||||
|
t.is(type, 'npm') |
||||
|
t.is(nowConfig.type, 'npm') |
||||
|
t.is(hasNowJson, false) |
||||
|
}) |
@ -0,0 +1,62 @@ |
|||||
|
// Native
|
||||
|
const path = require('path') |
||||
|
|
||||
|
// Packages
|
||||
|
const crossSpawn = require('cross-spawn') |
||||
|
const test = require('ava') |
||||
|
|
||||
|
// Utilities
|
||||
|
const logo = require('../src/util/output/logo') |
||||
|
|
||||
|
test.serial('make binary', async t => { |
||||
|
if (!process.env.CI) { |
||||
|
t.true(true) |
||||
|
return |
||||
|
} |
||||
|
const result = await spawn('npm', ['run', 'pack']) |
||||
|
t.is(result.code, 0) |
||||
|
}) |
||||
|
|
||||
|
const binary = { |
||||
|
darwin: 'now-macos', |
||||
|
linux: 'now-linux', |
||||
|
win32: 'now-win.exe' |
||||
|
}[process.platform] |
||||
|
|
||||
|
const binaryPath = path.resolve(__dirname, '../packed/' + binary) |
||||
|
const deployHelpMessage = `${logo} now [options] <command | path>` |
||||
|
|
||||
|
test.serial('packed "now help" prints deploy help message', async t => { |
||||
|
if (!process.env.CI) { |
||||
|
t.true(true) |
||||
|
return |
||||
|
} |
||||
|
const result = await spawn(binaryPath, ['help']) |
||||
|
|
||||
|
t.is(result.code, 0) |
||||
|
const stdout = result.stdout.split('\n') |
||||
|
t.true(stdout.length > 1) |
||||
|
t.true(stdout[1].includes(deployHelpMessage)) |
||||
|
}) |
||||
|
|
||||
|
function spawn(command, args) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const child = crossSpawn.spawn(command, args) |
||||
|
|
||||
|
let stdout = '' |
||||
|
child.stdout.on('data', data => { |
||||
|
stdout += data |
||||
|
}) |
||||
|
|
||||
|
child.on('error', err => { |
||||
|
reject(err) |
||||
|
}) |
||||
|
|
||||
|
child.on('close', code => { |
||||
|
resolve({ |
||||
|
code, |
||||
|
stdout |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
// Packages
|
||||
|
const test = require('ava') |
||||
|
|
||||
|
// Utilities
|
||||
|
const toHost = require('../src/providers/sh/util/to-host') |
||||
|
|
||||
|
test('simple', t => { |
||||
|
t.is(toHost('zeit.co'), 'zeit.co') |
||||
|
}) |
||||
|
|
||||
|
test('leading //', t => { |
||||
|
t.is(toHost('//zeit-logos-rnemgaicnc.now.sh'), 'zeit-logos-rnemgaicnc.now.sh') |
||||
|
}) |
||||
|
|
||||
|
test('leading http://', t => { |
||||
|
t.is( |
||||
|
toHost('http://zeit-logos-rnemgaicnc.now.sh'), |
||||
|
'zeit-logos-rnemgaicnc.now.sh' |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
test('leading https://', t => { |
||||
|
t.is( |
||||
|
toHost('https://zeit-logos-rnemgaicnc.now.sh'), |
||||
|
'zeit-logos-rnemgaicnc.now.sh' |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
test('leading https:// and path', t => { |
||||
|
t.is( |
||||
|
toHost('https://zeit-logos-rnemgaicnc.now.sh/path'), |
||||
|
'zeit-logos-rnemgaicnc.now.sh' |
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
test('simple and path', t => { |
||||
|
t.is(toHost('zeit.co/test'), 'zeit.co') |
||||
|
}) |
Loading…
Reference in new issue