File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,6 +144,18 @@ describe("Package", () => {
144144 } ) ;
145145 } ) ;
146146
147+ describe ( "get .tarball" , ( ) => {
148+ it ( "generates the destination filename of npm pack output" , ( ) => {
149+ const pkg = factory ( { name : "pack-me" , version : "1.2.3" } ) ;
150+ expect ( pkg . tarball ) . toBe ( "pack-me-1.2.3.tgz" ) ;
151+ } ) ;
152+
153+ it ( "normalizes package scopes" , ( ) => {
154+ const pkg = factory ( { name : "@scoped/pack-me" , version : "4.5.6" } ) ;
155+ expect ( pkg . tarball ) . toBe ( "scoped-pack-me-4.5.6.tgz" ) ;
156+ } ) ;
157+ } ) ;
158+
147159 describe ( ".toJSON()" , ( ) => {
148160 it ( "should return clone of internal package for serialization" , ( ) => {
149161 const json = {
Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ function binSafeName({ name, scope }) {
88 return scope ? name . substring ( scope . length + 1 ) : name ;
99}
1010
11+ function packedFileName ( pkg ) {
12+ // copied almost verbatim from https://git.io/fNobb
13+ const name =
14+ pkg . name [ 0 ] === "@"
15+ ? // scoped packages get special treatment
16+ pkg . name . substr ( 1 ) . replace ( / \/ / g, "-" )
17+ : pkg . name ;
18+
19+ return `${ name } -${ pkg . version } .tgz` ;
20+ }
21+
1122// package.json files are not that complicated, so this is intentionally naïve
1223function shallowCopy ( json ) {
1324 return Object . keys ( json ) . reduce ( ( obj , key ) => {
@@ -116,6 +127,12 @@ class Package {
116127 serialize : {
117128 value : ( ) => writePkg ( this . manifestLocation , pkg ) ,
118129 } ,
130+ // compute result of `npm pack` filename
131+ tarball : {
132+ get ( ) {
133+ return packedFileName ( pkg ) ;
134+ } ,
135+ } ,
119136 } ) ;
120137 }
121138
You can’t perform that action at this time.
0 commit comments