-
Notifications
You must be signed in to change notification settings - Fork 39
/
directory.js
88 lines (82 loc) · 2.36 KB
/
directory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict'
const BB = require('bluebird')
const fs = BB.promisifyAll(require('fs'))
const mkdirp = BB.promisify(require('mkdirp'))
const npmlog = require('npmlog')
const path = require('path')
const test = require('tap').test
const extract = require('../extract')
const manifest = require('../manifest')
const CACHE = require('./util/test-dir')(__filename)
npmlog.level = process.env.LOGLEVEL || 'silent'
test('supports directory deps', t => {
const pkg = {
name: 'foo',
version: '1.2.3',
dependencies: { bar: '3.2.1' },
directories: { bin: 'x' },
randomProp: 'wut'
}
const sr = {
name: 'foo',
version: '1.2.3',
dependencies: { bar: '3.2.1' }
}
const PKG = path.join(CACHE, 'pkg')
const EXT = path.join(CACHE, 'extracted')
return mkdirp(path.join(PKG, 'x')).then(() => {
return BB.join(
fs.writeFileAsync(
path.join(PKG, 'package.json'), JSON.stringify(pkg)
),
fs.writeFileAsync(
path.join(PKG, 'npm-shrinkwrap.json'), JSON.stringify(sr)
),
fs.writeFileAsync(
path.join(PKG, 'x', 'mybin'), 'console.log("hi there")'
)
)
}).then(() => {
return manifest(PKG)
}).then(manifest => {
t.deepEqual(manifest, {
name: pkg.name,
version: pkg.version,
cpu: null,
engines: null,
os: null,
dependencies: pkg.dependencies,
optionalDependencies: {},
devDependencies: {},
bundleDependencies: false,
peerDependencies: {},
peerDependenciesMeta: {},
deprecated: false,
_resolved: path.resolve(PKG).replace(/\\/g, '/'),
_shasum: null,
_integrity: null,
_shrinkwrap: sr,
bin: { mybin: path.join('x', 'mybin') },
_id: `${pkg.name}@${pkg.version}`
}, 'got a filled-out manifest')
}).then(() => {
return extract(PKG, EXT, { log: npmlog })
}).then(() => {
return BB.join(
fs.readFileAsync(
path.join(EXT, 'package.json'), 'utf8'
),
fs.readFileAsync(
path.join(EXT, 'npm-shrinkwrap.json'), 'utf8'
),
fs.readFileAsync(
path.join(EXT, 'x', 'mybin'), 'utf8'
),
(xpkg, xsr, xbin) => {
t.similar(JSON.parse(xpkg), pkg, 'extracted package.json')
t.deepEqual(JSON.parse(xsr), sr, 'extracted npm-shrinkwrap.json')
t.deepEqual(xbin, 'console.log("hi there")', 'extracted binary')
}
)
})
})