Skip to content

Commit 82f1f7b

Browse files
committed
chore: SAVEPOINT
1 parent 2037de0 commit 82f1f7b

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

subsystems/sidecar/ops/dump.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
} = require('pear-errors')
1414
const Pod = require('../lib/pod')
1515
const Opstream = require('../lib/opstream')
16+
const { isWindows } = require('which-runtime')
1617

1718
module.exports = class Dump extends Opstream {
1819
constructor(...args) {
@@ -39,8 +40,16 @@ module.exports = class Dump extends Opstream {
3940
const parsed = plink.parse(link)
4041

4142
const isFileLink = parsed.protocol === 'file:'
43+
const fsPathname = isWindows
44+
? (parsed.pathname.startsWith('/')
45+
? parsed.pathname.slice(1)
46+
: parsed.pathname
47+
)
48+
.split(path.posix.sep)
49+
.join(path.win32.sep)
50+
: parsed.pathname
4251
const isFile =
43-
isFileLink && (await fsp.stat(parsed.pathname)).isDirectory() === false
52+
isFileLink && (await fsp.stat(fsPathname)).isDirectory() === false
4453

4554
const key = parsed.drive.key
4655
checkout =
@@ -69,12 +78,15 @@ module.exports = class Dump extends Opstream {
6978
}
7079
} else {
7180
const state = new State({
72-
dir: isFile ? path.dirname(parsed.pathname) : parsed.pathname
81+
dir: isFile ? path.dirname(fsPathname) : fsPathname
7382
})
7483
await State.localPkg(state)
75-
prefix = path.join('/', path.relative(state.dir, parsed.pathname))
84+
prefix = path.join('/', path.relative(state.dir, fsPathname))
7685
drive = new LocalDrive(state.dir, { followLinks: true })
77-
if (state.dir === '/') throw ERR_NOT_FOUND('No pear project found')
86+
const isRoot = isWindows
87+
? /[a-zA-Z]:\\$/.test(state.dir)
88+
: state.dir === '/'
89+
if (isRoot) throw ERR_NOT_FOUND('No pear project found')
7890
}
7991
const pathname = prefix === '/' ? '' : prefix
8092

test/06-dump.test.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const tmp = require('test-tmp')
44
const Localdrive = require('localdrive')
55
const fs = require('bare-fs')
66
const path = require('bare-path')
7+
const { isWindows } = require('which-runtime')
78

89
const 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

test/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ async function runTests() {
77

88
test.pause()
99

10-
await import('./00-inspect.test.js')
11-
await import('./01-smoke.test.js')
12-
await import('./02-teardown.test.js')
13-
await import('./03-stage.test.js')
14-
await import('./04-updates.test.js')
15-
await import('./05-run.test.js')
10+
// await import('./00-inspect.test.js')
11+
// await import('./01-smoke.test.js')
12+
// await import('./02-teardown.test.js')
13+
// await import('./03-stage.test.js')
14+
// await import('./04-updates.test.js')
15+
// await import('./05-run.test.js')
1616
await import('./06-dump.test.js')
17-
await import('./07-data.test.js')
18-
await import('./08-drop.test.js')
19-
await import('./09-shift.test.js')
20-
await import('./10-shutdown.test.js')
21-
await import('./11-presets.test.js')
17+
// await import('./07-data.test.js')
18+
// await import('./08-drop.test.js')
19+
// await import('./09-shift.test.js')
20+
// await import('./10-shutdown.test.js')
21+
// await import('./11-presets.test.js')
2222

2323
test.resume()
2424
}

0 commit comments

Comments
 (0)