-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore '--json' argument to 'npm pack' command
PR-URL: #3217 Credit: @mrmlnc Close: #3217 Reviewed-by: @isaacs, @wraithgar, @ruyadorno
- Loading branch information
Showing
5 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ t.test('should pack given directory', (t) => { | |
const npm = mockNpm({ | ||
config: { | ||
unicode: true, | ||
json: true, | ||
json: false, | ||
'dry-run': true, | ||
}, | ||
output, | ||
|
@@ -108,7 +108,7 @@ t.test('should pack given directory for scoped package', (t) => { | |
const npm = mockNpm({ | ||
config: { | ||
unicode: true, | ||
json: true, | ||
json: false, | ||
'dry-run': true, | ||
}, | ||
output, | ||
|
@@ -158,6 +158,93 @@ t.test('should log pack contents', (t) => { | |
}) | ||
}) | ||
|
||
t.test('should log output as valid json', (t) => { | ||
const testDir = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
name: 'my-cool-pkg', | ||
version: '1.0.0', | ||
main: './index.js', | ||
}, null, 2), | ||
'README.md': 'text', | ||
'index.js': 'void', | ||
}) | ||
|
||
const Pack = t.mock('../../lib/pack.js', { | ||
libnpmpack, | ||
'../../lib/utils/tar.js': { | ||
getContents: async () => ({ | ||
id: '@ruyadorno/[email protected]', | ||
name: '@ruyadorno/redact', | ||
version: '1.0.0', | ||
size: 2450, | ||
unpackedSize: 4911, | ||
shasum: '044c7574639b923076069d6e801e2d1866430f17', | ||
// mocks exactly how ssri Integrity works: | ||
integrity: { | ||
sha512: [ | ||
{ | ||
source: 'sha512-JSdyskeR2qonBUaQ4vdlU/vQGSfgCxSq5O+vH+d2yVWRqzso4O3gUzd6QX/V7OWV//zU7kA5o63Zf433jUnOtQ==', | ||
digest: 'JSdyskeR2qonBUaQ4vdlU/vQGSfgCxSq5O+vH+d2yVWRqzso4O3gUzd6QX/V7OWV//zU7kA5o63Zf433jUnOtQ==', | ||
algorithm: 'sha512', | ||
options: [], | ||
}, | ||
], | ||
toJSON () { | ||
return 'sha512-JSdyskeR2qonBUaQ4vdlU/vQGSfgCxSq5O+vH+d2yVWRqzso4O3gUzd6QX/V7OWV//zU7kA5o63Zf433jUnOtQ==' | ||
}, | ||
}, | ||
filename: '@ruyadorno/redact-1.0.0.tgz', | ||
files: [ | ||
{ path: 'LICENSE', size: 1113, mode: 420 }, | ||
{ path: 'README.md', size: 2639, mode: 420 }, | ||
{ path: 'index.js', size: 719, mode: 493 }, | ||
{ path: 'package.json', size: 440, mode: 420 }, | ||
], | ||
entryCount: 4, | ||
bundled: [], | ||
}), | ||
}, | ||
npmlog: { | ||
notice: () => {}, | ||
showProgress: () => {}, | ||
clearProgress: () => {}, | ||
}, | ||
}) | ||
const npm = mockNpm({ | ||
config: { | ||
unicode: true, | ||
json: true, | ||
'dry-run': true, | ||
}, | ||
output, | ||
}) | ||
const pack = new Pack(npm) | ||
|
||
pack.exec([testDir], err => { | ||
t.error(err, { bail: true }) | ||
|
||
t.match(JSON.parse(OUTPUT), [{ | ||
id: '@ruyadorno/[email protected]', | ||
name: '@ruyadorno/redact', | ||
version: '1.0.0', | ||
size: 2450, | ||
unpackedSize: 4911, | ||
shasum: '044c7574639b923076069d6e801e2d1866430f17', | ||
integrity: 'sha512-JSdyskeR2qonBUaQ4vdlU/vQGSfgCxSq5O+vH+d2yVWRqzso4O3gUzd6QX/V7OWV//zU7kA5o63Zf433jUnOtQ==', | ||
filename: '@ruyadorno/redact-1.0.0.tgz', | ||
files: [ | ||
{ path: 'LICENSE' }, | ||
{ path: 'README.md' }, | ||
{ path: 'index.js' }, | ||
{ path: 'package.json' }, | ||
], | ||
entryCount: 4, | ||
}], 'pack details output as valid json') | ||
|
||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('invalid packument', (t) => { | ||
const mockPacote = { | ||
manifest: () => { | ||
|
@@ -176,7 +263,7 @@ t.test('invalid packument', (t) => { | |
const npm = mockNpm({ | ||
config: { | ||
unicode: true, | ||
json: true, | ||
json: false, | ||
'dry-run': true, | ||
}, | ||
output, | ||
|