diff --git a/runtime/v8/script.go b/runtime/v8/script.go index a51ac0de..4f67a1b0 100644 --- a/runtime/v8/script.go +++ b/runtime/v8/script.go @@ -41,7 +41,8 @@ var RootScripts = map[string]*Script{} var importRe = regexp.MustCompile(`import\s+\t*\n*(\*\s+as\s+\w+|\{[^}]+\}|\w+)\s+from\s+["']([^"']+)["'];?`) var exportRe = regexp.MustCompile(`export\s+(default|function|class|const|var|let)\s+`) -var internalKeepModules = []string{"/yao.ts", "/yao", "/gou", "/gou.ts"} +var internalKeepModuleSuffixes = []string{"/yao.ts", "/yao", "/gou", "/gou.ts"} +var internalKeepModules = []string{"@yao", "@yaoapps", "@yaoapp", "@gou"} // NewScript create a new script func NewScript(file string, id string, timeout ...time.Duration) *Script { @@ -339,7 +340,7 @@ func replaceImportCode(file string, source []byte) (string, []Import, error) { importClause, importPath := matches[1], matches[2] // Filter the internal keep modules - for _, keep := range internalKeepModules { + for _, keep := range internalKeepModuleSuffixes { if strings.HasSuffix(importPath, keep) { lines := strings.Split(m, "\n") for i, line := range lines { @@ -349,6 +350,15 @@ func replaceImportCode(file string, source []byte) (string, []Import, error) { return strings.Join(lines, "\n") } } + for _, keep := range internalKeepModules { + if strings.HasPrefix(importPath, keep) { + lines := strings.Split(m, "\n") + for i, line := range lines { + lines[i] = "// " + line + } + return strings.Join(lines, "\n") + } + } relImportPath, err := getImportPath(file, importPath) if err != nil {