Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
fix: file protocol import statement not work. close #146
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Apr 29, 2020
1 parent 2ba8078 commit 67897bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/module_resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ test("core / module_resolver: resolve module from local", () => {
"./module_not_exist.ts",
"https://module.not.exist.com/mod.ts",
"https://example.com/x-typescript-types",
`file://${path.join(__dirname, "cache.ts")}`,
`file://./cache.ts`,
`file://../client/src/extension.ts`,
])
).toEqual([
{
Expand Down Expand Up @@ -128,6 +131,22 @@ test("core / module_resolver: resolve module from local", () => {
"7617203222d94a074bea3e57a893d74af5546f17c1f90760f37f46299faf0cb0"
),
},
{
extension: ".ts",
origin:
"file:///Users/axetroy/gpm/github.com/axetroy/vscode-deno/core/cache.ts",
filepath: path.join(__dirname, "cache.ts"),
},
{
extension: ".ts",
origin: "file://./cache.ts",
filepath: path.join(__dirname, "cache.ts"),
},
{
extension: ".ts",
origin: "file://../client/src/extension.ts",
filepath: path.join(__dirname, "..", "client", "src", "extension.ts"),
},
] as ResolvedModule[]);
});

Expand Down
8 changes: 8 additions & 0 deletions core/module_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export class ModuleResolver implements ModuleResolverInterface {
return this.resolveFromRemote(moduleName, originModuleName);
}

if (moduleName.startsWith("file://")) {
// file protocol is always a unix style path
// eg: file:///Users/deno/project/mod.ts in MacOS
// eg: file:///Home/deno/project/mod.ts in Linux
// eg: file://d:/project/mod.ts in Window
moduleName = moduleName.replace(/^file:\/\//, "");
}

const moduleFilepath = path.resolve(
path.dirname(this.containingFile),
normalizeFilepath(moduleName)
Expand Down

0 comments on commit 67897bc

Please sign in to comment.