refactor(build): Simplify implementation of posixPath

This commit is contained in:
Christopher Allen
2023-08-10 12:12:18 +01:00
parent 84215386fb
commit 8bb6ac528b

View File

@@ -11,23 +11,16 @@
const path = require('path');
/**
* Escape regular expression pattern
* @param {string} pattern regular expression pattern
* @return {string} escaped regular expression pattern
*/
function escapeRegex(pattern) {
return pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}
/**
* Replaces OS-specific path with POSIX style path.
* Simplified implementation based on
* https://stackoverflow.com/a/63251716/4969945
*
* @param {string} target target path
* @return {string} posix path
*/
function posixPath(target) {
const osSpecificSep = new RegExp(escapeRegex(path.sep), 'g');
return target.replace(osSpecificSep, path.posix.sep);
return target.split(path.sep).join(path.posix.sep);
}
module.exports = {