Skip to content

Commit 02d4755

Browse files
committed
gitCloneMem
1 parent f375193 commit 02d4755

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/dependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export * as recast from 'recast'
2121
export * as unionfs from 'unionfs'
2222
export * as zx from 'zx'
2323
export {arktype} from './esm-modules'
24-
export {fetchSync} from './fetch-sync'
24+
export {fetchSync, gitCloneMem} from './fetch-sync'
2525
export {makeSynchronous} from './make-synchronous'
2626

2727
export * as simplify from './simplify'

src/fetch-sync.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as memfs from 'memfs'
12
import {makeSynchronous} from './make-synchronous'
23

34
/**
@@ -16,3 +17,25 @@ export const fetchSync = makeSynchronous(async (input: RequestInfo | URL, init?:
1617
text: await res.text(),
1718
}
1819
})
20+
21+
export const gitCloneMem = (params: {repoUrl: string; ref?: string}) => {
22+
const fsJson = makeSynchronous(async (_params: typeof params) => {
23+
const dir = '/repo'
24+
const _memfs = await import('memfs')
25+
const git = await import('isomorphic-git')
26+
const fs = _memfs.Volume.fromJSON({})
27+
const gitHttp = await import('isomorphic-git/http/node')
28+
await git.clone({
29+
fs,
30+
http: gitHttp,
31+
dir,
32+
url: _params.repoUrl,
33+
ref: _params.ref || 'main',
34+
})
35+
return fs.toJSON()
36+
})
37+
38+
const fs = memfs.Volume.fromJSON(fsJson(params))
39+
// todo: sync-ified version of `isomorphic-git` like in plv8-git
40+
return {fs}
41+
}

0 commit comments

Comments
 (0)