Skip to content

Commit 19590ff

Browse files
committed
修复 wa init 命令会卡死的问题
1 parent c4f452b commit 19590ff

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

internal/app/appinit/appinit.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,19 @@ func InitApp(name, pkgpath string, isP5App, isWasm4App, isArduinoApp, update boo
145145
return err
146146
}
147147

148-
code, _, err := format.File(nil, path, buf.Bytes())
149-
if err != nil {
150-
code = buf.Bytes()
151-
}
152-
153-
if _, err := f.Write(code); err != nil {
154-
return err
148+
if appbase.HasExt(path, ".wa", ".wz") {
149+
code, _, err := format.File(nil, path, buf.Bytes())
150+
if err != nil {
151+
code = buf.Bytes()
152+
}
153+
154+
if _, err := f.Write(code); err != nil {
155+
return err
156+
}
157+
} else {
158+
if _, err := f.Write(buf.Bytes()); err != nil {
159+
return err
160+
}
155161
}
156162
return nil
157163
})

internal/app/appinit/misc/_example_app/wa.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
name = "{{.Name}}"
44
pkgpath = "{{.Pkgpath}}"
5-
target = {{if .IsWasiApp}}"wasi"{{else if .IsWasm4App}}"wasm4"{{else if .IsArduinoApp}}"arduino"{{else}}"js"{{end}}
5+
target = {{if .IsWasm4App}}"wasm4"{{else if .IsArduinoApp}}"arduino"{{else}}"js"{{end}}

internal/xlang/xlang.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func DetectLang(filename string, code []byte) token.LangType {
3434

3535
for {
3636
_, tok, lit := s.Scan()
37-
if tok == token.ILLEGAL {
37+
if tok == token.EOF || tok == token.ILLEGAL {
3838
break
3939
}
4040

0 commit comments

Comments
 (0)