public static string module_resolve(IFileSystem fs, IFileResolver resolver, string module_base_name, string module_id) { var parent_id = module_base_name; var resolving = module_id; // 将相对目录展开 if (module_id.StartsWith("./") || module_id.StartsWith("../") || module_id.Contains("/./") || module_id.Contains("/../")) { // 显式相对路径直接从 parent 模块路径拼接 var parent_path = PathUtils.GetDirectoryName(parent_id); try { resolving = PathUtils.ExtractPath(PathUtils.Combine(parent_path, module_id), '/'); } catch { // 不能提升到源代码目录外面 throw new Exception(string.Format("invalid module path (out of sourceRoot): {0}", module_id)); } } string resolved; if (resolver.ResolvePath(fs, resolving, out resolved)) { return(resolved); } throw new Exception(string.Format("module not found: {0}", module_id)); }
public void EvalMain(string fileName) { string resolvedPath; if (_fileResolver.ResolvePath(_fileSystem, fileName, out resolvedPath)) { var source = _fileSystem.ReadAllBytes(resolvedPath); _mainContext.EvalMain(source, resolvedPath); } }
public void EvalMain(string fileName) { string resolvedPath; if (_fileResolver.ResolvePath(_fileSystem, fileName, out resolvedPath)) { var source = _fileSystem.ReadAllBytes(resolvedPath); var input_bytes = TextUtils.GetShebangNullTerminatedCommonJSBytes(source); _mainContext.EvalMain(input_bytes, resolvedPath); } }
public bool ResolvePath(IFileSystem fileSystem, string fileName, out string resolvedPath) { return(_resolver.ResolvePath(fileSystem, fileName, out resolvedPath)); }