diff --git a/src/EleventyWatch.js b/src/EleventyWatch.js index 36107ad93..9f8e15889 100755 --- a/src/EleventyWatch.js +++ b/src/EleventyWatch.js @@ -1,4 +1,5 @@ const { TemplatePath } = require("@11ty/eleventy-utils"); +const PathNormalizer = require("./Util/PathNormalizer.js"); /* Decides when to watch and in what mode to watch * Incremental builds don’t batch changes, they queue. @@ -87,7 +88,9 @@ class EleventyWatch { addToPendingQueue(path) { if (path) { - path = TemplatePath.addLeadingDotSlash(path); + path = PathNormalizer.normalizeSeperator( + TemplatePath.addLeadingDotSlash(path) + ); this.pendingQueue.push(path); } } diff --git a/src/Util/PathNormalizer.js b/src/Util/PathNormalizer.js new file mode 100644 index 000000000..255e2eb19 --- /dev/null +++ b/src/Util/PathNormalizer.js @@ -0,0 +1,12 @@ +const path = require("path"); + +class PathNormalizer { + static normalizeSeperator(inputPath) { + if (!inputPath) { + return inputPath; + } + return inputPath.split(path.sep).join("/"); + } +} + +module.exports = PathNormalizer; diff --git a/src/Util/PathPrefixer.js b/src/Util/PathPrefixer.js index 0f5f78831..6b0a4be80 100644 --- a/src/Util/PathPrefixer.js +++ b/src/Util/PathPrefixer.js @@ -1,4 +1,5 @@ const path = require("path"); +const PathNormalizer = require("./PathNormalizer.js"); class PathPrefixer { static normalizePathPrefix(pathPrefix) { @@ -12,10 +13,7 @@ class PathPrefixer { } static joinUrlParts(...parts) { - return path - .join(...parts) - .split(path.sep) - .join("/"); + return PathNormalizer.normalizeSeperator(path.join(...parts)); } } diff --git a/test/PathNormalizerTest.js b/test/PathNormalizerTest.js new file mode 100644 index 000000000..a33d2525d --- /dev/null +++ b/test/PathNormalizerTest.js @@ -0,0 +1,10 @@ +const test = require("ava"); +const PathNormalizer = require("../src/Util/PathNormalizer"); + +test("PathNormalize Seperator", (t) => { + t.is(PathNormalizer.normalizeSeperator("."), "."); + t.is(PathNormalizer.normalizeSeperator("a/b"), "a/b"); + t.is(PathNormalizer.normalizeSeperator("a\\b"), "a/b"); + t.is(PathNormalizer.normalizeSeperator("a\\b/c"), "a/b/c"); + t.is(PathNormalizer.normalizeSeperator(undefined), undefined); +});