Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit ddb0dba

Browse files
committed
no rimraf
1 parent 6dc4002 commit ddb0dba

File tree

7 files changed

+44
-62
lines changed

7 files changed

+44
-62
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ const path = require('path')
66
const util = require('util')
77
const pacote = require('pacote')
88
const npa = require('npm-package-arg')
9-
9+
const rimraf = util.promisify(require('rimraf'))
1010
const runScript = require('@npmcli/run-script')
1111

1212
const mkdtemp = util.promisify(fs.mkdtemp)
13-
const rimraf = util.promisify(require('rimraf'))
1413

1514
const mv = require('./utils/mv')
1615
const { getContents, logTar } = require('./utils/tar')
@@ -49,6 +48,7 @@ async function pack (spec = 'file:.', opts = {}) {
4948

5049
// moves tarball to dest
5150
await mv(tmpTarget, dest)
51+
// removes tmpDir
5252
await rimraf(tmpDir)
5353

5454
if (spec.type === 'directory') {

package-lock.json

Lines changed: 11 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"check-coverage": true
2424
},
2525
"devDependencies": {
26+
"mkdirp": "^1.0.3",
2627
"nock": "^12.0.2",
2728
"standard": "^14.3.1",
2829
"tap": "^14.10.6"

test/.DS_Store

6 KB
Binary file not shown.

test/index.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const ssri = require('ssri')
66
const pacote = require('pacote')
77
const pack = require('../index.js')
88
const tnock = require('./fixtures/tnock.js')
9-
const { promisify } = require('util')
10-
const rimraf = promisify(require('rimraf'))
119

1210
const OPTS = {
1311
registry: 'https://mock.reg/'
@@ -23,7 +21,7 @@ t.test('packs from local directory', async t => {
2321
}, null, 2),
2422
'index.js': 'hello'
2523
})
26-
const target = `${__dirname}/my-cool-pkg-1.0.0.tgz`
24+
const target = `${testDir}/my-cool-pkg-1.0.0.tgz`
2725

2826
const cwd = process.cwd()
2927
process.chdir(testDir)
@@ -57,14 +55,12 @@ t.test('packs from local directory', async t => {
5755
t.deepEqual(tarContents, contents,
5856
'packed directory matches expectations'
5957
)
60-
61-
await rimraf(target)
6258
})
6359

6460
t.test('packs from local directory on target', async t => {
6561
const testDir = t.testdir({
6662
'package.json': JSON.stringify({
67-
name: 'my-cool-pkg',
63+
name: 'my-local-pkg',
6864
version: '1.0.0',
6965
bundledDependencies: ['a']
7066
}, null, 2),
@@ -79,26 +75,26 @@ t.test('packs from local directory on target', async t => {
7975
}
8076
})
8177

82-
const target = `${__dirname}/my-cool-pkg-1.0.0.tgz`
78+
const target = `${testDir}/my-local-pkg-1.0.0.tgz`
8379

8480
const tarContents = await pack(testDir, { target })
8581
const integrity = await ssri.fromStream(fs.createReadStream(target), {
8682
algorithms: ['sha512']
8783
})
8884

8985
const contents = {
90-
id: 'my-cool[email protected]',
91-
name: 'my-cool-pkg',
86+
id: 'my-local[email protected]',
87+
name: 'my-local-pkg',
9288
version: '1.0.0',
93-
size: 260,
94-
unpackedSize: 133,
95-
shasum: '535bdcc05fd4a1b7f2603c5527a7c63ba5b88cff',
89+
size: 261,
90+
unpackedSize: 134,
91+
shasum: 'dbbd93ed67b3c2941dc8096c5ec66b10f5606690',
9692
integrity: ssri.parse(integrity.sha512[0]),
97-
filename: 'my-cool-pkg-1.0.0.tgz',
93+
filename: 'my-local-pkg-1.0.0.tgz',
9894
files: [
9995
{ path: 'index.js', size: 5, mode: 420 },
10096
{ path: 'node_modules/a/package.json', size: 39, mode: 420 },
101-
{ path: 'package.json', size: 89, mode: 420 }
97+
{ path: 'package.json', size: 90, mode: 420 }
10298
],
10399
entryCount: 3,
104100
bundled: ['a']
@@ -107,37 +103,33 @@ t.test('packs from local directory on target', async t => {
107103
t.deepEqual(tarContents, contents,
108104
'packed directory matches expectations'
109105
)
110-
111-
await rimraf(target)
112106
})
113107

114108
t.test('packs from registry spec', async t => {
115109
const testDir = t.testdir({
116110
'package.json': JSON.stringify({
117-
name: 'my-cool-pkg',
111+
name: 'my-pkg',
118112
version: '1.0.0'
119113
}, null, 2),
120114
'index.js': 'hello'
121115
})
122-
// weird windows thing. when we write the file into the testdir
123-
// on this test, it breaks all kinds of stuff when it tries to
124-
// clean it up.
125-
const target = `${__dirname}/my-cool-pkg-1.0.0.tgz`
126-
const spec = 'my-cool-pkg'
116+
117+
const spec = 'my-pkg'
118+
const target = `${testDir}/my-pkg-1.0.0.tgz`
127119

128120
const tarData = await pacote.tarball(`file:${testDir}`)
129121
const integrity = ssri.fromData(tarData, { algorithms: ['sha512'] })
130122
const packument = {
131-
_id: 'my-cool-pkg',
132-
name: 'my-cool-pkg',
123+
_id: 'my-pkg',
124+
name: 'my-pkg',
133125
description: 'some stuff',
134126
'dist-tags': {
135127
latest: '1.0.0'
136128
},
137129
versions: {
138130
'1.0.0': {
139131
_nodeVersion: process.versions.node,
140-
name: 'my-cool-pkg',
132+
name: 'my-pkg',
141133
version: '1.0.0',
142134
description: 'some stuff',
143135
dist: {
@@ -159,21 +151,21 @@ t.test('packs from registry spec', async t => {
159151
}
160152

161153
const srv = tnock(t, REG)
162-
srv.get('/my-cool-pkg').reply(200, packument)
154+
srv.get('/my-pkg').reply(200, packument)
163155

164156
const tarContents = await pack(spec, { ...OPTS, target })
165157
const contents = {
166-
id: 'my-cool-[email protected]',
167-
name: 'my-cool-pkg',
158+
159+
name: 'my-pkg',
168160
version: '1.0.0',
169-
size: 187,
170-
unpackedSize: 54,
171-
shasum: 'e4db5fa79b694e5f94cb7a48250eb5a728f9669f',
161+
size: 183,
162+
unpackedSize: 49,
163+
shasum: 'fb8fce241a824279f95f16648dade6f760b85087',
172164
integrity,
173-
filename: 'my-cool-pkg-1.0.0.tgz',
165+
filename: 'my-pkg-1.0.0.tgz',
174166
files: [
175167
{ path: 'index.js', size: 5, mode: 420 },
176-
{ path: 'package.json', size: 49, mode: 420 }
168+
{ path: 'package.json', size: 44, mode: 420 }
177169
],
178170
entryCount: 2,
179171
bundled: []
@@ -182,6 +174,4 @@ t.test('packs from registry spec', async t => {
182174
t.deepEqual(tarContents, contents,
183175
'packed directory matches expectations'
184176
)
185-
186-
await rimraf(target)
187177
})

test/test.copy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ const pack = require('../index')
1515
t.test('other errors', async t => {
1616
const testDir = t.testdir({
1717
'package.json': JSON.stringify({
18-
name: 'my-cool-pkg',
18+
name: 'my-other-pkg',
1919
version: '1.0.0'
2020
}, null, 2),
2121
'index.js': 'hello'
2222
})
2323

2424
err.code = 'EPERM'
2525

26-
const target = `${testDir}/my-cool-pkg-1.0.0.tgz`
26+
const target = `${__dirname}/my-other-pkg-1.0.0.tgz`
2727
await t.rejects(pack(testDir, { target }))
2828
})

utils/mv.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ function copy (oldPath, newPath) {
2020
return new Promise((resolve, reject) => {
2121
const readStream = fs.createReadStream(oldPath)
2222
const writeStream = fs.createWriteStream(newPath)
23+
const stream = readStream.pipe(writeStream)
2324

2425
readStream.on('error', reject)
2526
writeStream.on('error', reject)
26-
writeStream.on('close', () => {
27+
stream.on('error', reject)
28+
stream.on('close', () => {
2729
resolve(rimraf(oldPath))
2830
})
29-
30-
readStream.pipe(writeStream)
3131
})
3232
}

0 commit comments

Comments
 (0)