@@ -23,6 +23,7 @@ const CLOSE = Symbol('close')
23
23
const MODE = Symbol ( 'mode' )
24
24
const warner = require ( './warn-mixin.js' )
25
25
const winchars = require ( './winchars.js' )
26
+ const stripAbsolutePath = require ( './strip-absolute-path.js' )
26
27
27
28
const modeFix = require ( './mode-fix.js' )
28
29
@@ -52,12 +53,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
52
53
this . on ( 'warn' , opt . onwarn )
53
54
54
55
let pathWarn = false
55
- if ( ! this . preservePaths && path . win32 . isAbsolute ( p ) ) {
56
- // absolutes on posix are also absolutes on win32
57
- // so we only need to test this one to get both
58
- const parsed = path . win32 . parse ( p )
59
- this . path = p . substr ( parsed . root . length )
60
- pathWarn = parsed . root
56
+ if ( ! this . preservePaths ) {
57
+ const [ root , stripped ] = stripAbsolutePath ( this . path )
58
+ if ( root ) {
59
+ this . path = stripped
60
+ pathWarn = root
61
+ }
61
62
}
62
63
63
64
this . win32 = ! ! opt . win32 || process . platform === 'win32'
@@ -351,10 +352,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
351
352
this . on ( 'warn' , opt . onwarn )
352
353
353
354
let pathWarn = false
354
- if ( path . isAbsolute ( this . path ) && ! this . preservePaths ) {
355
- const parsed = path . parse ( this . path )
356
- pathWarn = parsed . root
357
- this . path = this . path . substr ( parsed . root . length )
355
+ if ( ! this . preservePaths ) {
356
+ const [ root , stripped ] = stripAbsolutePath ( this . path )
357
+ if ( root ) {
358
+ this . path = stripped
359
+ pathWarn = root
360
+ }
358
361
}
359
362
360
363
this . remain = readEntry . size
0 commit comments