-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple entry points (#1119)
- Loading branch information
1 parent
d517132
commit 7cbbeef
Showing
13 changed files
with
202 additions
and
74 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const path = require('path'); | ||
|
||
function getRootDir(files) { | ||
let cur = null; | ||
|
||
for (let file of files) { | ||
let parsed = path.parse(file); | ||
if (!cur) { | ||
cur = parsed; | ||
} else if (parsed.root !== cur.root) { | ||
// bail out. there is no common root. | ||
// this can happen on windows, e.g. C:\foo\bar vs. D:\foo\bar | ||
return process.cwd(); | ||
} else { | ||
// find the common path parts. | ||
let curParts = cur.dir.split(path.sep); | ||
let newParts = parsed.dir.split(path.sep); | ||
let len = Math.min(curParts.length, newParts.length); | ||
let i = 0; | ||
while (i < len && curParts[i] === newParts[i]) { | ||
i++; | ||
} | ||
|
||
cur.dir = i > 1 ? curParts.slice(0, i).join(path.sep) : cur.root; | ||
} | ||
} | ||
|
||
return cur ? cur.dir : process.cwd(); | ||
} | ||
|
||
module.exports = getRootDir; |
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
Oops, something went wrong.