@@ -37,16 +37,48 @@ function _mkdirp(p: string) {
37
37
fs . mkdirSync ( p ) ;
38
38
}
39
39
40
+ function _recursiveFileList ( p : string ) : string [ ] {
41
+ if ( ! fs . statSync ( p ) . isDirectory ( ) ) {
42
+ return [ ] ;
43
+ }
44
+
45
+ const list = fs . readdirSync ( p ) ;
46
+
47
+ return list
48
+ . map ( subpath => {
49
+ const subpathList = _recursiveFileList ( path . join ( p , subpath ) ) ;
50
+
51
+ return [ subpath , ...subpathList . map ( sp => path . join ( subpath , sp ) ) ] ;
52
+ } )
53
+ // Flatten.
54
+ . reduce ( ( acc , curr ) => [ ...acc , ...curr ] , [ ] )
55
+ // Filter out directories.
56
+ . filter ( sp => ! fs . statSync ( path . join ( p , sp ) ) . isDirectory ( ) ) ;
57
+ }
40
58
59
+
60
+ // This method mimics how npm pack tars packages.
41
61
function _tar ( out : string , dir : string ) {
62
+ // NOTE: node-tar does some Magic Stuff depending on prefixes for files
63
+ // specifically with @ signs, so we just neutralize that one
64
+ // and any such future "features" by prepending `./`
65
+
66
+ // Without this, the .tar file cannot be opened on Windows.
67
+
68
+ const files = _recursiveFileList ( dir ) . map ( ( f ) => `./${ f } ` ) ;
69
+
42
70
return tar . create ( {
43
71
gzip : true ,
44
72
strict : true ,
45
73
portable : true ,
46
74
cwd : dir ,
75
+ prefix : 'package/' ,
47
76
file : out ,
48
77
sync : true ,
49
- } , [ '.' ] ) ;
78
+ // Provide a specific date in the 1980s for the benefit of zip,
79
+ // which is confounded by files dated at the Unix epoch 0.
80
+ mtime : new Date ( '1985-10-26T08:15:00.000Z' ) ,
81
+ } , files ) ;
50
82
}
51
83
52
84
0 commit comments