Open geekeren opened 9 months ago
You'll need to run isomorphic-git https://isomorphic-git.org
You'll need to run isomorphic-git https://isomorphic-git.org
Thank you. I go through the document, but don't know how to integrate it with web container
A webcontainer is really just a nodejs runtime in the browser. You can install isomorphic-git in your project or globally using npm.
A quick Google reveals that isomorphic-git also ships with a CLI. You likely use it like you would use any Node/npm CLI. Assuming you have an interactive shell session running for your webcontainer.
@YeomansIII I try to connect isomorphic-git with web-container fs, but found web-container does not implement apis: unlink\stat\lstat\readlink\symlink So I transform the ws fs api with a fake implementation, like
stat: () => {
console.log("stat not implemented");
},
but when run git clone in webcontainer, a error thrown
The following is my code:
export const webContainerFS = (rawFS: FileSystemAPI): PromiseFsClient => ({
promises: {
readFile: rawFS.readFile.bind(rawFS),
writeFile: rawFS.writeFile.bind(rawFS),
readdir: rawFS.readdir.bind(rawFS),
mkdir: rawFS.mkdir.bind(rawFS),
rmdir: rawFS.rm.bind(rawFS),
unlink: () => {
console.log("stat not implemented");
},
stat: () => {
console.log("stat not implemented");
},
lstat: () => {
console.log("lstat not implemented");
},
readlink: () => {
console.log("readlink not implemented");
},
symlink: () => {
console.log("symlink not implemented");
},
},
});
useEffect(() => {
(async () => {
const webcontainerInstance = await WebContainer.boot({
coep: "credentialless",
});
webcontainerInstance.fs.mkdir("/tutorial/.git", {
recursive: true
});
await webcontainerInstance.fs.writeFile('/tutorial/.git/config', `[user]
email = jcubic@onet.pl
name = Jakub Jankiewicz`);
const fs = webContainerFS(webcontainerInstance.fs);
await git.clone({
fs,
http,
dir: "/tutorial",
corsProxy: "https://cors.isomorphic-git.org",
url: "https://github.com/isomorphic-git/isomorphic-git",
singleBranch: true,
depth: 1,
onMessage: console.log,
});
})();
}, []);
I think you will have much better luck running isogit INSIDE of the webcontainer
Currently we don't allow using git
through WebContainer API. One of the reasons (but not the only reason) is the fact that you need a way to securely use authentication tokens. For now, your best bet is to use isomorphic-git
as already suggested. You can npm install
it inside WebContainer and use the isogit CLI to initiate a clone.
How to run git using webcontainer api? or is it possible to add custom binary in webcontainer?