mirror of
https://github.com/nvms/esr.git
synced 2025-12-15 22:40:52 +00:00
runner fixes
This commit is contained in:
parent
76d0188dc4
commit
94d84f51f1
@ -120,8 +120,7 @@ func InitProject() {
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "ES2022",
|
"module": "ES2022",
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"experimentalDecorators": true,
|
"allowSyntheticDefaultImports": true
|
||||||
"emitDecoratorMetadata": true
|
|
||||||
}
|
}
|
||||||
}`), 0644); err != nil {
|
}`), 0644); err != nil {
|
||||||
Die("failed to write tsconfig.json: %v", err)
|
Die("failed to write tsconfig.json: %v", err)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ func ModeOptions(config *config.Config, mode ModeType, entryPoint, tempFilePath
|
|||||||
}
|
}
|
||||||
return api.SourceMapNone
|
return api.SourceMapNone
|
||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case ModeBuilder:
|
case ModeBuilder:
|
||||||
buildOptions.Bundle = config.Build.Bundle
|
buildOptions.Bundle = config.Build.Bundle
|
||||||
@ -96,46 +96,73 @@ func ModeOptions(config *config.Config, mode ModeType, entryPoint, tempFilePath
|
|||||||
fmt.Printf("Unknown JSX: %s, using default\n", config.JSX)
|
fmt.Printf("Unknown JSX: %s, using default\n", config.JSX)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply loader
|
var loaders = map[string]api.Loader{
|
||||||
buildOptions.Loader = make(map[string]api.Loader)
|
".js": api.LoaderJS,
|
||||||
for k, v := range config.Loader {
|
".mjs": api.LoaderJS,
|
||||||
switch v {
|
".cjs": api.LoaderJS,
|
||||||
case "file":
|
".jsx": api.LoaderJSX,
|
||||||
buildOptions.Loader[k] = api.LoaderFile
|
".ts": api.LoaderTS,
|
||||||
case "dataurl":
|
".tsx": api.LoaderTSX,
|
||||||
buildOptions.Loader[k] = api.LoaderDataURL
|
".mts": api.LoaderTS,
|
||||||
case "binary":
|
".css": api.LoaderCSS,
|
||||||
buildOptions.Loader[k] = api.LoaderBinary
|
".json": api.LoaderJSON,
|
||||||
case "base64":
|
".txt": api.LoaderText,
|
||||||
buildOptions.Loader[k] = api.LoaderBase64
|
".html": api.LoaderText,
|
||||||
case "copy":
|
".md": api.LoaderText,
|
||||||
buildOptions.Loader[k] = api.LoaderCopy
|
".svg": api.LoaderDataURL,
|
||||||
case "text":
|
".png": api.LoaderDataURL,
|
||||||
buildOptions.Loader[k] = api.LoaderText
|
".webp": api.LoaderDataURL,
|
||||||
case "js":
|
".gif": api.LoaderDataURL,
|
||||||
buildOptions.Loader[k] = api.LoaderJS
|
".ttf": api.LoaderDataURL,
|
||||||
case "jsx":
|
".eot": api.LoaderDataURL,
|
||||||
buildOptions.Loader[k] = api.LoaderJSX
|
".woff": api.LoaderDataURL,
|
||||||
case "tsx":
|
".woff2": api.LoaderDataURL,
|
||||||
buildOptions.Loader[k] = api.LoaderTSX
|
|
||||||
case "ts":
|
|
||||||
buildOptions.Loader[k] = api.LoaderTS
|
|
||||||
case "json":
|
|
||||||
buildOptions.Loader[k] = api.LoaderJSON
|
|
||||||
case "css":
|
|
||||||
buildOptions.Loader[k] = api.LoaderCSS
|
|
||||||
case "globalcss":
|
|
||||||
buildOptions.Loader[k] = api.LoaderGlobalCSS
|
|
||||||
case "localcss":
|
|
||||||
buildOptions.Loader[k] = api.LoaderLocalCSS
|
|
||||||
case "empty":
|
|
||||||
buildOptions.Loader[k] = api.LoaderEmpty
|
|
||||||
case "default":
|
|
||||||
buildOptions.Loader[k] = api.LoaderDefault
|
|
||||||
default:
|
|
||||||
buildOptions.Loader[k] = api.LoaderNone
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildOptions.Loader = loaders
|
||||||
|
|
||||||
|
// Apply loader
|
||||||
|
// buildOptions.Loader = make(map[string]api.Loader)
|
||||||
|
// for k, v := range config.Loader {
|
||||||
|
// switch v {
|
||||||
|
// case ".woff2":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderDataURL
|
||||||
|
// case "file":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderFile
|
||||||
|
// case "dataurl":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderDataURL
|
||||||
|
// case "binary":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderBinary
|
||||||
|
// case "base64":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderBase64
|
||||||
|
// case "copy":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderCopy
|
||||||
|
// case "text":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderText
|
||||||
|
// case "js":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderJS
|
||||||
|
// case "jsx":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderJSX
|
||||||
|
// case "tsx":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderTSX
|
||||||
|
// case "ts":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderTS
|
||||||
|
// case "json":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderJSON
|
||||||
|
// case "css":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderCSS
|
||||||
|
// case "globalcss":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderGlobalCSS
|
||||||
|
// case "localcss":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderLocalCSS
|
||||||
|
// case "empty":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderEmpty
|
||||||
|
// case "default":
|
||||||
|
// buildOptions.Loader[k] = api.LoaderDefault
|
||||||
|
// default:
|
||||||
|
// buildOptions.Loader[k] = api.LoaderNone
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return &buildOptions
|
return &buildOptions
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -22,14 +23,18 @@ func NewRunner(c *config.Config, b *Builder, e string) *Runner {
|
|||||||
Config: c,
|
Config: c,
|
||||||
EntryPoint: e,
|
EntryPoint: e,
|
||||||
Builder: b,
|
Builder: b,
|
||||||
TempFilePath: newTempFilePath(),
|
TempFilePath: newTempFilePath(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTempFilePath() string {
|
func newTempFilePath(entry string) string {
|
||||||
timestamp := time.Now().UnixNano()
|
timestamp := time.Now().UnixNano()
|
||||||
tempDir := os.TempDir()
|
// tempDir := os.TempDir()
|
||||||
return filepath.Join(tempDir, fmt.Sprintf("esr-%d.mjs", timestamp))
|
// return filepath.Join(tempDir, fmt.Sprintf("esr-%d.mjs", timestamp))
|
||||||
|
return filepath.Join(
|
||||||
|
filepath.Dir(entry),
|
||||||
|
fmt.Sprintf("esr-%d.mjs", timestamp),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) Run(entryPoint string) {
|
func (r *Runner) Run(entryPoint string) {
|
||||||
@ -44,18 +49,31 @@ func (r *Runner) Run(entryPoint string) {
|
|||||||
cmd := exec.Command(r.Config.Run.Runtime, r.TempFilePath)
|
cmd := exec.Command(r.Config.Run.Runtime, r.TempFilePath)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
fmt.Println("Error starting process:", err)
|
fmt.Println("Error starting process:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
if err := cmd.Wait(); err != nil {
|
if err := cmd.Wait(); err != nil {
|
||||||
fmt.Printf("Process finished with error: %v\n", err)
|
fmt.Printf("Process finished with error: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Process finished successfully")
|
fmt.Println("Process finished successfully")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
// Finally, remove the temp file we created
|
||||||
|
|
||||||
|
if err := os.Remove(r.TempFilePath); err != nil {
|
||||||
|
fmt.Printf("Failed to remove temp file: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) Stop(cmd *exec.Cmd) error {
|
func (r *Runner) Stop(cmd *exec.Cmd) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user