From 0b88d1980e46181f68f5306717380b3b6b4e2eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20H=C3=B6ser?= Date: Fri, 1 Jul 2022 12:29:07 +0200 Subject: [PATCH] #1312 Improve situation for dependency monitoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds a "PathNormalizer" with tests which converts all paths to be unix compatible (replace "\" with "/"). That way auto reloading dependencies of the config also works on windows. Sadly nested dependencies still always lag exactly one update behind, so if you have the following dependency graph: - .eleventy.js depends on - middle.js depends on - nested.js and you update nested, you see the following: - do update 1 -> no result - do update 2 -> see update 1 - do update 3 -> see update 2 During a short lookaround, I was unable to resolve this issue. Signed-off-by: Raphael Höser --- src/EleventyWatch.js | 5 ++++- src/Util/PathNormalizer.js | 12 ++++++++++++ src/Util/PathPrefixer.js | 6 ++---- test/PathNormalizerTest.js | 10 ++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/Util/PathNormalizer.js create mode 100644 test/PathNormalizerTest.js 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); +});