@@ -4,6 +4,7 @@ const tmp = require('test-tmp')
44const Localdrive = require ( 'localdrive' )
55const fs = require ( 'bare-fs' )
66const path = require ( 'bare-path' )
7+ const { isWindows } = require ( 'which-runtime' )
78
89const Helper = require ( './helper' )
910
@@ -100,8 +101,9 @@ test('pear dump dumping subdirectory from local drive', async function ({
100101 await helper . ready ( )
101102
102103 const src = Helper . fixture ( 'dump' )
103- const link = `file://${ src } /lib`
104-
104+ const link = isWindows
105+ ? `file://${ src . split ( path . win32 . sep ) . join ( path . posix . sep ) } /lib`
106+ : `file://${ src } /lib`
105107 const out = await tmp ( )
106108
107109 teardown ( ( ) => Helper . gc ( out ) )
@@ -298,7 +300,7 @@ test('pear dump dumping a single file in a subdirectory from pear drive', async
298300 is ( dirCount , 1 , 'should have only one file in the lib directory' )
299301} )
300302
301- test ( 'pear dump should throw when dumping file outisde a pear project' , async function ( {
303+ test ( 'pear dump should throw when dumping file outside a pear project' , async function ( {
302304 plan,
303305 teardown,
304306 exception
@@ -322,7 +324,30 @@ test('pear dump should throw when dumping file outisde a pear project', async fu
322324 encoding : 'utf-8'
323325 }
324326 )
325- const link = `file://${ src } /test.js`
327+ const link = isWindows
328+ ? `file://${ src . split ( path . win32 . sep ) . join ( path . posix . sep ) } /test.js`
329+ : `file://${ src } /test.js`
330+
331+ const plink = require ( 'pear-link' )
332+ const fsp = require ( 'bare-fs/promises' )
333+ const parsed = plink . parse ( link )
334+ const isFileLink = parsed . protocol === 'file:'
335+ const fsPathname = isWindows
336+ ? ( parsed . pathname . startsWith ( '/' )
337+ ? parsed . pathname . slice ( 1 )
338+ : parsed . pathname
339+ )
340+ . split ( path . posix . sep )
341+ . join ( path . win32 . sep )
342+ : parsed . pathname
343+ const isFile =
344+ isFileLink && ( await fsp . stat ( fsPathname ) ) . isDirectory ( ) === false
345+ const State = require ( 'pear-state' )
346+ const state = new State ( {
347+ dir : isFile ? path . dirname ( fsPathname ) : fsPathname
348+ } )
349+ await State . localPkg ( state )
350+ console . log ( state . dir )
326351
327352 await exception ( async ( ) => {
328353 const dump = helper . dump ( { link, dir : out } )
@@ -345,7 +370,9 @@ test('pear dump dumping a single file in a subdirectory from local drive', async
345370 await helper . ready ( )
346371
347372 const src = Helper . fixture ( 'dump' )
348- const link = `file://${ src } /lib/dump.js`
373+ const link = isWindows
374+ ? `file://${ src . split ( path . win32 . sep ) . join ( path . posix . sep ) } /lib/dump.js`
375+ : `file://${ src } /lib/dump.js`
349376
350377 const out = await tmp ( )
351378
0 commit comments