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

Commit

Permalink
chore: windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiahdz committed Mar 26, 2020
1 parent a96c71a commit 073a522
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 100 deletions.
7 changes: 3 additions & 4 deletions index.js
Expand Up @@ -6,13 +6,12 @@ const path = require('path')
const util = require('util')
const pacote = require('pacote')
const npa = require('npm-package-arg')

const mv = require('move-concurrently')
const runScript = require('@npmcli/run-script')

const mkdtemp = util.promisify(fs.mkdtemp)
const rimraf = util.promisify(require('rimraf'))
const mkdtemp = util.promisify(fs.mkdtemp)

const mv = require('./utils/mv')
const { getContents, logTar } = require('./utils/tar')

async function pack (spec = 'file:.', opts = {}) {
Expand Down Expand Up @@ -49,7 +48,7 @@ async function pack (spec = 'file:.', opts = {}) {

// moves tarball to dest
await mv(tmpTarget, dest)
rimraf(tmpDir)
await rimraf(tmpDir)

if (spec.type === 'directory') {
// postpack
Expand Down
31 changes: 11 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"@npmcli/run-script": "^1.3.0",
"byte-size": "^6.2.0",
"columnify": "^1.5.4",
"move-concurrently": "^1.0.1",
"npm-package-arg": "^8.0.0",
"pacote": "^11.1.2",
"rimraf": "^3.0.2",
Expand Down
94 changes: 53 additions & 41 deletions test/index.js
Expand Up @@ -2,13 +2,16 @@

const t = require('tap')
const fs = require('fs')
const util = require('util')
const ssri = require('ssri')
const pacote = require('pacote')

const pack = require('../index.js')
const tnock = require('./fixtures/tnock.js')

const rimraf = util.promisify(require('rimraf'))

const OPTS = {
registry: 'https://mock.reg/'
registry: 'http://mock.reg/'
}

const REG = OPTS.registry
Expand All @@ -23,7 +26,9 @@ t.test('packs from local directory', async t => {
})
const target = `${testDir}/my-cool-pkg-1.0.0.tgz`

const cwd = process.cwd()
process.chdir(testDir)

const tarContents = await pack()
const integrity = await ssri.fromStream(fs.createReadStream(target), {
algorithms: ['sha512']
Expand All @@ -49,12 +54,18 @@ t.test('packs from local directory', async t => {
t.deepEqual(tarContents, contents,
'packed directory matches expectations'
)

t.teardown(async () => {
process.chdir(cwd)
await rimraf(target)
await rimraf(testDir)
})
})

t.test('packs from local directory on target', async t => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
name: 'my-local-pkg',
version: '1.0.0',
bundledDependencies: ['a']
}, null, 2),
Expand All @@ -69,26 +80,26 @@ t.test('packs from local directory on target', async t => {
}
})

const target = `${testDir}/my-cool-pkg-1.0.0.tgz`
const target = `${testDir}/my-local-pkg-1.0.0.tgz`

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

const contents = {
id: 'my-cool-pkg@1.0.0',
name: 'my-cool-pkg',
id: 'my-local-pkg@1.0.0',
name: 'my-local-pkg',
version: '1.0.0',
size: 260,
unpackedSize: 133,
shasum: '535bdcc05fd4a1b7f2603c5527a7c63ba5b88cff',
size: 261,
unpackedSize: 134,
shasum: 'dbbd93ed67b3c2941dc8096c5ec66b10f5606690',
integrity: ssri.parse(integrity.sha512[0]),
filename: 'my-cool-pkg-1.0.0.tgz',
filename: 'my-local-pkg-1.0.0.tgz',
files: [
{ path: 'index.js', size: 5, mode: 420 },
{ path: 'node_modules/a/package.json', size: 39, mode: 420 },
{ path: 'package.json', size: 89, mode: 420 }
{ path: 'package.json', size: 90, mode: 420 }
],
entryCount: 3,
bundled: ['a']
Expand All @@ -97,38 +108,36 @@ t.test('packs from local directory on target', async t => {
t.deepEqual(tarContents, contents,
'packed directory matches expectations'
)

t.teardown(async () => {
await rimraf(target)
await rimraf(testDir)
})
})

t.test('packs from registry spec', async t => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
version: '1.0.0'
}, null, 2),
'index.js': 'hello'
})
const target = `${testDir}/my-cool-pkg-1.0.0.tgz`
const spec = 'my-cool-pkg'
const spec = 'my-pkg'
const testDir = t.testdir()
const target = `${testDir}/my-pkg-1.0.0.tgz`

const tarData = await pacote.tarball(`file:${testDir}`)
const integrity = ssri.fromData(tarData, { algorithms: ['sha512'] })
const integrity = ssri.fromData('', { algorithms: ['sha512'] })
const packument = {
_id: 'my-cool-pkg',
name: 'my-cool-pkg',
_id: 'my-pkg',
name: 'my-pkg',
description: 'some stuff',
'dist-tags': {
latest: '1.0.0'
},
versions: {
'1.0.0': {
_nodeVersion: process.versions.node,
name: 'my-cool-pkg',
name: 'my-pkg',
version: '1.0.0',
description: 'some stuff',
dist: {
shasum: 'some-shasum',
integrity: integrity.toString(),
tarball: testDir
integrity: '123',
tarball: 'http://mock.reg/my-pkg/-/my-pkg-1.0.0.tgz'
}
}
},
Expand All @@ -137,34 +146,37 @@ t.test('packs from registry spec', async t => {
_attachments: {
'my-cool-pkg-1.0.0.tgz': {
content_type: 'application/octet-stream',
data: tarData.toString('base64'),
length: tarData.length
data: '',
length: '0'
}
}
}

const srv = tnock(t, REG)
srv.get('/my-cool-pkg').reply(200, packument)
srv.get('/my-pkg').reply(200, packument)
srv.get('/my-pkg/-/my-pkg-1.0.0.tgz').reply(200, '')

const tarContents = await pack(spec, { ...OPTS, target })
const contents = {
id: 'my-cool-pkg@1.0.0',
name: 'my-cool-pkg',
id: 'my-pkg@1.0.0',
name: 'my-pkg',
version: '1.0.0',
size: 187,
unpackedSize: 54,
shasum: 'e4db5fa79b694e5f94cb7a48250eb5a728f9669f',
size: 0,
unpackedSize: 0,
shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
integrity,
filename: 'my-cool-pkg-1.0.0.tgz',
files: [
{ path: 'index.js', size: 5, mode: 420 },
{ path: 'package.json', size: 49, mode: 420 }
],
entryCount: 2,
filename: 'my-pkg-1.0.0.tgz',
files: [],
entryCount: 0,
bundled: []
}

t.deepEqual(tarContents, contents,
'packed directory matches expectations'
)

t.teardown(async () => {
await rimraf(target)
await rimraf(testDir)
})
})
35 changes: 0 additions & 35 deletions utils/mv.js

This file was deleted.

0 comments on commit 073a522

Please sign in to comment.