-
-
Notifications
You must be signed in to change notification settings - Fork 63
feat(dashboard, ui): Support TypeScript in the playground #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akitaSummer
wants to merge
15
commits into
lagonapp:main
Choose a base branch
from
akitaSummer:feat/playground_typescript
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
86bbe47
feat: add esbuild
akitaSummer f3f8eda
docs: add change
akitaSummer 435c146
fix: fix docker compose change
akitaSummer 87ec5ef
fix: fix git lint
akitaSummer 51ab136
Merge branch 'main' into feat/playground_typescript
akitaSummer dcc19ef
fix: fix ts deploy
akitaSummer c15a56d
feat: add DEFAULT_TS_FUNCTION
akitaSummer 8cea804
fix: fix empty catch
akitaSummer b413863
fix: add define
akitaSummer c740604
Merge branch 'main' into feat/playground_typescript
akitaSummer ba42726
feat: add deployment platform
akitaSummer 6f488ca
Merge branch 'main' into feat/playground_typescript
akitaSummer 6ae6ed3
feat: update to function
akitaSummer 689a9c7
Merge branch 'main' into feat/playground_typescript
akitaSummer 10297c9
fix: fix createDeployment
akitaSummer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
--- | ||
'@lagon/dashboard': patch | ||
'@lagon/ui': patch | ||
--- | ||
|
||
feat: add playground typescript |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
import * as esbuild from 'esbuild-wasm'; | ||
import { Plugin, Loader } from 'esbuild-wasm'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
type EsbuildFileSystem = Map< | ||
string, | ||
{ | ||
content: string; | ||
} | ||
>; | ||
|
||
const PROJECT_ROOT = '/project/'; | ||
|
||
const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.css', '.json']; | ||
|
||
const extname = (path: string): string => { | ||
const m = /(\.[a-zA-Z0-9]+)$/.exec(path); | ||
return m ? m[1] : ''; | ||
}; | ||
|
||
const inferLoader = (p: string): Loader => { | ||
const ext = extname(p); | ||
if (RESOLVE_EXTENSIONS.includes(ext)) { | ||
return ext.slice(1) as Loader; | ||
} | ||
if (ext === '.mjs' || ext === '.cjs') { | ||
return 'js'; | ||
} | ||
return 'text'; | ||
}; | ||
|
||
const resolvePlugin = (files: EsbuildFileSystem): Plugin => { | ||
return { | ||
name: 'resolve', | ||
setup(build) { | ||
build.onResolve({ filter: /.*/ }, async args => { | ||
if (args.path.startsWith(PROJECT_ROOT)) { | ||
return { | ||
path: args.path, | ||
}; | ||
} | ||
}); | ||
|
||
build.onLoad({ filter: /.*/ }, args => { | ||
if (args.path.startsWith(PROJECT_ROOT)) { | ||
const name = args.path.replace(PROJECT_ROOT, ''); | ||
const file = files.get(name); | ||
if (file) { | ||
return { | ||
contents: file.content, | ||
loader: inferLoader(args.path), | ||
}; | ||
} | ||
} | ||
}); | ||
}, | ||
}; | ||
}; | ||
|
||
export enum ESBuildStatus { | ||
Success, | ||
Fail, | ||
Loading, | ||
} | ||
|
||
class EsBuildSingleton { | ||
static isFirst = true; | ||
static getIsFirst = () => { | ||
if (EsBuildSingleton.isFirst) { | ||
EsBuildSingleton.isFirst = false; | ||
return true; | ||
} | ||
return EsBuildSingleton.isFirst; | ||
}; | ||
} | ||
|
||
export const useEsbuild = () => { | ||
const [esbuildStatus, setEsbuildStatus] = useState(ESBuildStatus.Loading); | ||
const [isEsbuildLoading, setIsEsbuildLoading] = useState(true); | ||
|
||
// React.StrictMode will cause useEffect to run twice | ||
const loadEsbuild = useCallback(async () => { | ||
try { | ||
if (EsBuildSingleton.getIsFirst()) { | ||
await esbuild.initialize({ | ||
wasmURL: `https://esm.sh/[email protected]/esbuild.wasm`, | ||
}); | ||
} | ||
|
||
setEsbuildStatus(ESBuildStatus.Success); | ||
} catch (e) { | ||
setEsbuildStatus(ESBuildStatus.Fail); | ||
console.error(e); | ||
} finally { | ||
setIsEsbuildLoading(false); | ||
} | ||
}, [isEsbuildLoading, esbuildStatus]); | ||
|
||
// these options should match the ones in crates/cli/src/utils/deployments.rs | ||
const build = useCallback( | ||
(files: EsbuildFileSystem) => | ||
esbuild.build({ | ||
entryPoints: [`${PROJECT_ROOT}index.ts`], | ||
outdir: '/dist', | ||
format: 'esm', | ||
write: false, | ||
bundle: true, | ||
target: 'esnext', | ||
platform: 'browser', | ||
conditions: ['lagon', 'worker'], | ||
define: { 'process.env.NODE_ENV': 'production' }, | ||
plugins: [resolvePlugin(files)], | ||
QuiiBz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}), | ||
[isEsbuildLoading, esbuildStatus], | ||
); | ||
|
||
useEffect(() => { | ||
loadEsbuild(); | ||
}, []); | ||
|
||
return { isEsbuildLoading, esbuildStatus, build }; | ||
}; | ||
|
||
export default useEsbuild; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.