-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime):
fs.watch
to support syncing new files from webcontai…
…ner (#394)
- Loading branch information
1 parent
e1e9160
commit 3beda90
Showing
15 changed files
with
208 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { webcontainer } from 'tutorialkit:core'; | ||
|
||
interface Props { | ||
filePath: string; | ||
newContent: string; | ||
|
||
// default to 'webcontainer' | ||
access?: 'store' | 'webcontainer'; | ||
testId?: string; | ||
} | ||
|
||
export function ButtonDeleteFile({ filePath, access = 'webcontainer', testId = 'delete-file' }: Props) { | ||
async function deleteFile() { | ||
switch (access) { | ||
case 'webcontainer': { | ||
const webcontainerInstance = await webcontainer; | ||
|
||
await webcontainerInstance.fs.rm(filePath); | ||
|
||
return; | ||
} | ||
case 'store': { | ||
throw new Error('Delete from store not implemented'); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<button data-testid={testId} onClick={deleteFile}> | ||
Delete File | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
e2e/src/content/tutorial/tests/filesystem/watch-glob/_files/a/b/baz.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Baz |
1 change: 1 addition & 0 deletions
1
e2e/src/content/tutorial/tests/filesystem/watch-glob/_files/bar.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Initial content |
19 changes: 19 additions & 0 deletions
19
e2e/src/content/tutorial/tests/filesystem/watch-glob/content.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
type: lesson | ||
title: Watch Glob | ||
focus: /bar.txt | ||
filesystem: | ||
watch: ['/*.txt', '/a/**/*', '/src/**/*'] | ||
--- | ||
|
||
import { ButtonWriteToFile } from '@components/ButtonWriteToFile'; | ||
import { ButtonDeleteFile } from '@components/ButtonDeleteFile'; | ||
|
||
# Watch filesystem test | ||
|
||
<ButtonWriteToFile client:load access="webcontainer" filePath="/bar.txt" newContent='Something else' /> | ||
<ButtonWriteToFile client:load access="webcontainer" filePath="/a/b/baz.txt" newContent='Foo' testId='write-to-file-in-subfolder' /> | ||
<ButtonWriteToFile client:load access="webcontainer" filePath="/src/new.txt" newContent='New' testId='write-new-file' /> | ||
<ButtonWriteToFile client:load access="webcontainer" filePath="/unknown/other.txt" newContent='Ignore this' testId='write-new-ignored-file' /> | ||
|
||
<ButtonDeleteFile client:load access="webcontainer" filePath="/bar.txt" testId='delete-file' /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
// https://github.com/micromatch/picomatch?tab=readme-ov-file#api | ||
declare module 'picomatch/posix.js' { | ||
export { default } from 'picomatch'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.