From 2fe0ba50145f3728d1845231d0aca6905a56ba5a Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 25 Jan 2019 13:14:47 +0100 Subject: [PATCH] Normalize backslash on windows --- examples/template-common.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/template-common.js b/examples/template-common.js index b67dbfce274..a46379869ed 100644 --- a/examples/template-common.js +++ b/examples/template-common.js @@ -20,11 +20,12 @@ const hashRegexp = /Hash: [a-f0-9]+/g; exports.replaceBase = (template) => { - let cwd = process.cwd(); + const cwd = process.cwd(); let webpack = path.join(__dirname, ".."); let webpackParent = path.join(__dirname, "..", ".."); - cwd = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); - cwd = new RegExp(cwd, "g"); + const cwdRegExpStr = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); + const cwdRegExp = new RegExp(cwdRegExpStr, "g"); + const cwdSlashRegExp = new RegExp(cwdRegExpStr + "[\\/\\\\]", "g"); webpack = lessStrict(webpack.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); webpack = new RegExp(webpack, "g"); webpackParent = lessStrict(webpackParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); @@ -33,7 +34,8 @@ exports.replaceBase = (template) => { return template .replace(/\r\n/g, "\n") .replace(/\r/g, "\n") - .replace(cwd, ".") + .replace(cwdSlashRegExp, "./") + .replace(cwdRegExp, ".") .replace(webpack, "(webpack)") .replace(webpackParent, "(webpack)/~") .replace(timeRegexp, "")