@parcel/source-map
Advanced tools
Comparing version 2.0.0-alpha.4.14 to 2.0.0-alpha.4.15
@@ -29,3 +29,3 @@ "use strict"; | ||
constructor(projectRoot = '/') { | ||
this.projectRoot = (0, _utils.normalizePath)(projectRoot); | ||
this.projectRoot = projectRoot; | ||
} | ||
@@ -32,0 +32,0 @@ /** |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.generateInlineMap = generateInlineMap; | ||
exports.isAbsolute = isAbsolute; | ||
exports.normalizePath = normalizePath; | ||
@@ -16,2 +17,7 @@ exports.relatifyPath = relatifyPath; | ||
// For some reason path.isAbsolute barely works... Regex to the rescue? | ||
// Apparently windows stuff is under `path.win32`, so yeah windows makes stuff complicated :) | ||
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/; | ||
const PATH_SEPARATOR_REGEX = /\\/g; | ||
function generateInlineMap(map) { | ||
@@ -21,21 +27,25 @@ return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString('base64')}`; | ||
function isAbsolute(filepath) { | ||
return ABSOLUTE_PATH_REGEX.test(filepath); | ||
} | ||
function normalizePath(filepath) { | ||
filepath = filepath.replace(/\\/g, '/'); // Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
if (filepath.length > 0 && filepath[0] !== '.' && !_path.default.isAbsolute(filepath)) { | ||
filepath = `./${filepath}`; | ||
} | ||
return filepath; | ||
return filepath.replace(ABSOLUTE_PATH_REGEX, '/').replace(PATH_SEPARATOR_REGEX, '/'); | ||
} | ||
function relatifyPath(filepath, rootDir) { | ||
// Sourcemaps are made for web, so replace backslashes with regular slashes | ||
rootDir = normalizePath(rootDir); | ||
filepath = normalizePath(filepath); // Make root paths relative to the rootDir | ||
if (filepath[0] === '/') { | ||
filepath = normalizePath(_path.default.relative(rootDir, filepath)); | ||
} | ||
filepath = _path.default.relative(rootDir, filepath); | ||
} // Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
return filepath; | ||
if (filepath[0] !== '.') { | ||
filepath = `./${filepath}`; | ||
} // Sourcemaps are made for web, so replace backslashes with regular slashes | ||
return normalizePath(filepath); | ||
} | ||
@@ -42,0 +52,0 @@ |
{ | ||
"name": "@parcel/source-map", | ||
"version": "2.0.0-alpha.4.14", | ||
"version": "2.0.0-alpha.4.15", | ||
"main": "./dist/node.js", | ||
@@ -64,2 +64,3 @@ "browser": "./dist/wasm-browser.js", | ||
"@babel/preset-flow": "^7.9.0", | ||
"@babel/register": "^7.11.5", | ||
"cross-env": "^7.0.2", | ||
@@ -66,0 +67,0 @@ "flow-bin": "^0.123.0", |
@@ -24,3 +24,3 @@ // @flow | ||
constructor(projectRoot: string = '/') { | ||
this.projectRoot = normalizePath(projectRoot); | ||
this.projectRoot = projectRoot; | ||
} | ||
@@ -27,0 +27,0 @@ |
@@ -6,2 +6,7 @@ // @flow | ||
// For some reason path.isAbsolute barely works... Regex to the rescue? | ||
// Apparently windows stuff is under `path.win32`, so yeah windows makes stuff complicated :) | ||
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/; | ||
const PATH_SEPARATOR_REGEX = /\\/g; | ||
export function generateInlineMap(map: string): string { | ||
@@ -11,15 +16,12 @@ return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString('base64')}`; | ||
export function isAbsolute(filepath: string): boolean { | ||
return ABSOLUTE_PATH_REGEX.test(filepath); | ||
} | ||
export function normalizePath(filepath: string): string { | ||
filepath = filepath.replace(/\\/g, '/'); | ||
// Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
if (filepath.length > 0 && filepath[0] !== '.' && !path.isAbsolute(filepath)) { | ||
filepath = `./${filepath}`; | ||
} | ||
return filepath; | ||
return filepath.replace(ABSOLUTE_PATH_REGEX, '/').replace(PATH_SEPARATOR_REGEX, '/'); | ||
} | ||
export function relatifyPath(filepath: string, rootDir: string): string { | ||
// Sourcemaps are made for web, so replace backslashes with regular slashes | ||
rootDir = normalizePath(rootDir); | ||
filepath = normalizePath(filepath); | ||
@@ -29,6 +31,12 @@ | ||
if (filepath[0] === '/') { | ||
filepath = normalizePath(path.relative(rootDir, filepath)); | ||
filepath = path.relative(rootDir, filepath); | ||
} | ||
return filepath; | ||
// Prefix relative paths with ./ as it makes it more clear and probably prevents issues | ||
if (filepath[0] !== '.') { | ||
filepath = `./${filepath}`; | ||
} | ||
// Sourcemaps are made for web, so replace backslashes with regular slashes | ||
return normalizePath(filepath); | ||
} | ||
@@ -35,0 +43,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1548770
1649
16