Skip to content

Commit

Permalink
11ty#1312 Improve situation for dependency monitoring
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Snapstromegon committed Jul 1, 2022
1 parent 8674f34 commit 0b88d19
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/EleventyWatch.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -87,7 +88,9 @@ class EleventyWatch {

addToPendingQueue(path) {
if (path) {
path = TemplatePath.addLeadingDotSlash(path);
path = PathNormalizer.normalizeSeperator(
TemplatePath.addLeadingDotSlash(path)
);
this.pendingQueue.push(path);
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/Util/PathNormalizer.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 2 additions & 4 deletions src/Util/PathPrefixer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const PathNormalizer = require("./PathNormalizer.js");

class PathPrefixer {
static normalizePathPrefix(pathPrefix) {
Expand All @@ -12,10 +13,7 @@ class PathPrefixer {
}

static joinUrlParts(...parts) {
return path
.join(...parts)
.split(path.sep)
.join("/");
return PathNormalizer.normalizeSeperator(path.join(...parts));
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/PathNormalizerTest.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 0b88d19

Please sign in to comment.