Merge pull request #723 from trheyi/main
feat: Add support for directory mapping from tsconfig in TS import
This commit is contained in:
commit
bdc97d334a
4 changed files with 44 additions and 5 deletions
|
|
@ -65,8 +65,5 @@ type Runtime struct {
|
||||||
HeapSizeRelease uint64 `json:"heapSizeRelease,omitempty" env:"YAO_RUNTIME_HEAP_RELEASE" envDefault:"52428800"` // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M)
|
HeapSizeRelease uint64 `json:"heapSizeRelease,omitempty" env:"YAO_RUNTIME_HEAP_RELEASE" envDefault:"52428800"` // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M)
|
||||||
HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty" env:"YAO_RUNTIME_HEAP_AVAILABLE" envDefault:"524288000"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M)
|
HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty" env:"YAO_RUNTIME_HEAP_AVAILABLE" envDefault:"524288000"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M)
|
||||||
Precompile bool `json:"precompile,omitempty" env:"YAO_RUNTIME_PRECOMPILE" envDefault:"false"` // if true compile scripts when the VM is created. this will increase the load time, but the script will run faster. the default value is false
|
Precompile bool `json:"precompile,omitempty" env:"YAO_RUNTIME_PRECOMPILE" envDefault:"false"` // if true compile scripts when the VM is created. this will increase the load time, but the script will run faster. the default value is false
|
||||||
|
Import bool `json:"import,omitempty" env:"YAO_RUNTIME_IMPORT" envDefault:"true"` // If false the import statement will be disabled, the default value is true.
|
||||||
// The following options are experimental features and not stable.
|
|
||||||
// They may be removed once the features become stable. Please do not use them in a production environment.
|
|
||||||
Import bool `json:"import,omitempty" env:"YAO_RUNTIME_IMPORT" envDefault:"false"` // If true, TypeScript import will be enabled. Default value is false.
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"github.com/yaoapp/gou/application"
|
||||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
)
|
)
|
||||||
|
|
@ -22,6 +26,23 @@ func Start(cfg config.Config) error {
|
||||||
Import: cfg.Runtime.Import,
|
Import: cfg.Runtime.Import,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the tsconfig.json
|
||||||
|
if cfg.Runtime.Import && application.App != nil {
|
||||||
|
if exist, _ := application.App.Exists("tsconfig.json"); exist {
|
||||||
|
var tsconfig v8.TSConfig
|
||||||
|
raw, err := application.App.Read("tsconfig.json")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("tsconfig.json is not a valid json file %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = jsoniter.Unmarshal(raw, &tsconfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("tsconfig.json is not a valid json file %s", err)
|
||||||
|
}
|
||||||
|
option.TSConfig = &tsconfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := v8.Start(option)
|
err := v8.Start(option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,36 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/yaoapp/gou/application"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStart(t *testing.T) {
|
func TestStart(t *testing.T) {
|
||||||
|
testPrepare(t)
|
||||||
defer Stop()
|
defer Stop()
|
||||||
err := Start(config.Conf)
|
err := Start(config.Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPrepare(t *testing.T, rootEnv ...string) {
|
||||||
|
|
||||||
|
appRootEnv := "YAO_TEST_APPLICATION"
|
||||||
|
if len(rootEnv) > 0 {
|
||||||
|
appRootEnv = rootEnv[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
root := os.Getenv(appRootEnv)
|
||||||
|
var app application.Application
|
||||||
|
var err error
|
||||||
|
|
||||||
|
app, err = application.OpenFromDisk(root) // Load app from Disk
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
application.Load(app)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/yaoapp/yao/share"
|
"github.com/yaoapp/yao/share"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load 加载共享库
|
// Load load all scripts and services
|
||||||
func Load(cfg config.Config) error {
|
func Load(cfg config.Config) error {
|
||||||
v8.CLearModules()
|
v8.CLearModules()
|
||||||
exts := []string{"*.js", "*.ts"}
|
exts := []string{"*.js", "*.ts"}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue