Skip to content

Commit afb02ad

Browse files
committedAug 21, 2017
pack: don't drop dots from dotfiles when prefixing
1 parent 6a86ec4 commit afb02ad

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed
 

‎lib/pack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const Pack = warner(class Pack extends MiniPass {
129129
[ADDTARENTRY] (p) {
130130
const absolute = path.resolve(this.cwd, p.path)
131131
if (this.prefix)
132-
p.path = this.prefix + '/' + p.path.replace(/^\.\/*/, '')
132+
p.path = this.prefix + '/' + p.path.replace(/^\.(\/+|$)/, '')
133133

134134
// in this case, we don't have to wait for the stat
135135
if (!this.filter(p.path, p))
@@ -148,7 +148,7 @@ const Pack = warner(class Pack extends MiniPass {
148148
[ADDFSENTRY] (p) {
149149
const absolute = path.resolve(this.cwd, p)
150150
if (this.prefix)
151-
p = this.prefix + '/' + p.replace(/^\.\/*/, '')
151+
p = this.prefix + '/' + p.replace(/^\.(\/+|$)/, '')
152152

153153
this[QUEUE].push(new PackJob(p, absolute))
154154
this[PROCESS]()

‎test/fixtures/files/.dotfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

‎test/pack.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,19 @@ t.test('pack a file', t => {
9090
t.test('pack a file with a prefix', t => {
9191
const out = []
9292
new Pack({ cwd: files, prefix: 'package/' })
93-
.end('one-byte.txt')
93+
.end('.dotfile')
9494
.on('data', c => out.push(c))
9595
.on('end', _ => {
9696
const data = Buffer.concat(out)
9797
t.equal(data.length, 2048)
98-
t.match(data.slice(512).toString(), /^a\0{511}\0{1024}$/)
98+
t.match(data.slice(512).toString(), /^.\n\0{510}\0{1024}$/)
9999
const h = new Header(data)
100100
const expect = {
101101
cksumValid: true,
102102
needPax: false,
103-
path: 'package/one-byte.txt',
103+
path: 'package/.dotfile',
104104
mode: 0o644,
105-
size: 1,
105+
size: 2,
106106
mtime: mtime,
107107
cksum: Number,
108108
linkpath: '',
@@ -117,7 +117,7 @@ t.test('pack a file with a prefix', t => {
117117
}
118118
t.match(h, expect)
119119
const sync = new PackSync({ cwd: files, prefix: 'package' })
120-
.add('one-byte.txt').end().read()
120+
.add('.dotfile').end().read()
121121
t.equal(sync.slice(512).toString(), data.slice(512).toString())
122122
const hs = new Header(sync)
123123
t.match(hs, expect)

0 commit comments

Comments
 (0)
Please sign in to comment.