-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix the root resolver when both a file and directory have the sa…
…me name When both a file and a directory share the same name, the resolver was wrongly resolving the path to the folder instead of the file. In Node, the resolver mechanism resolves the path to a .js file before trying to resolve the directory/index.js
- Loading branch information
Tommy Leunen
committed
Aug 27, 2016
1 parent
1f6245b
commit a4cff68
Showing
10 changed files
with
166 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
import path from 'path'; | ||
import { toPosixPath } from './utils'; | ||
|
||
function resolve(filename) { | ||
if (path.isAbsolute(filename)) return filename; | ||
return path.resolve(process.cwd(), filename); | ||
} | ||
|
||
function toPosixPath(modulePath) { | ||
return modulePath.replace(/\\/g, '/'); | ||
} | ||
|
||
export default function mapToRelative(currentFile, module) { | ||
let from = path.dirname(currentFile); | ||
let to = path.normalize(module); | ||
|
||
from = resolve(from); | ||
to = resolve(to); | ||
|
||
let moduleMapped = path.relative(from, to); | ||
|
||
moduleMapped = toPosixPath(moduleMapped); | ||
|
||
if (moduleMapped[0] !== '.') moduleMapped = `./${moduleMapped}`; | ||
|
||
return moduleMapped; | ||
const moduleMapped = path.relative(from, to); | ||
return toPosixPath(moduleMapped); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function toPosixPath(modulePath) { | ||
return modulePath.replace(/\\/g, '/'); | ||
} | ||
|
||
export function toLocalPath(p) { | ||
return (p[0] !== '.') | ||
? `./${p}` | ||
: p; | ||
} |
Empty file.
Empty file.
Empty file.
Oops, something went wrong.