-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: polyfill by bundling fileURLToPath
- Loading branch information
Showing
15 changed files
with
90 additions
and
13 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
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
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,73 @@ | ||
/* eslint-disable */ | ||
// Copyright (c) 2014 Nathan Rajlich <[email protected]> | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// 'Software'), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
import { sep } from 'path'; | ||
|
||
/** | ||
* File URI to Path function. | ||
* | ||
* @param {String} uri | ||
* @return {String} path | ||
* @api public | ||
*/ | ||
|
||
export function fileURLToPath(uri: string): string { | ||
if (typeof uri !== 'string' || uri.length <= 7 || uri.substring(0, 7) !== 'file://') { | ||
throw new TypeError('must pass in a file:// URI to convert to a file path'); | ||
} | ||
|
||
const rest = decodeURI(uri.substring(7)); | ||
const firstSlash = rest.indexOf('/'); | ||
let host = rest.substring(0, firstSlash); | ||
let path = rest.substring(firstSlash + 1); | ||
|
||
// 2. Scheme Definition | ||
// As a special case, <host> can be the string "localhost" or the empty | ||
// string; this is interpreted as "the machine from which the URL is | ||
// being interpreted". | ||
if (host === 'localhost') { | ||
host = ''; | ||
} | ||
|
||
if (host) { | ||
host = sep + sep + host; | ||
} | ||
|
||
// 3.2 Drives, drive letters, mount points, file system root | ||
// Drive letters are mapped into the top of a file URI in various ways, | ||
// depending on the implementation; some applications substitute | ||
// vertical bar ("|") for the colon after the drive letter, yielding | ||
// "file:///c|/tmp/test.txt". In some cases, the colon is left | ||
// unchanged, as in "file:///c:/tmp/test.txt". In other cases, the | ||
// colon is simply omitted, as in "file:///c/tmp/test.txt". | ||
path = path.replace(/^(.+)\|/, '$1:'); | ||
|
||
// for Windows, we need to invert the path separators from what a URI uses | ||
if (sep === '\\') { | ||
path = path.replace(/\//g, '\\'); | ||
} | ||
|
||
if (/^.+:/.test(path)) { | ||
// has Windows drive at beginning of path | ||
} else { | ||
// unix path… | ||
path = sep + path; | ||
} | ||
|
||
return host + path; | ||
} |
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