Skip to content

Commit 08e5600

Browse files
committed
Fix Windows tests for #3854
1 parent 0b25470 commit 08e5600

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/Util/GlobRemap.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import path from "node:path";
22
import ProjectDirectories from "./ProjectDirectories.js";
3+
import PathNormalizer from "./PathNormalizer.js";
4+
5+
// even on Windows (in cmd.exe) these paths are normalized to forward slashes
6+
// tinyglobby expects forward slashes on Windows
7+
const SEP = "/";
38

49
class GlobRemap {
510
constructor(paths = []) {
@@ -25,7 +30,7 @@ class GlobRemap {
2530

2631
static getParentDirPrefix(filePath = "") {
2732
let count = [];
28-
for (let p of filePath.split(path.sep)) {
33+
for (let p of filePath.split(SEP)) {
2934
if (p === "..") {
3035
count.push("..");
3136
} else {
@@ -35,7 +40,7 @@ class GlobRemap {
3540

3641
if (count.length > 0) {
3742
// trailing slash
38-
return count.join(path.sep) + path.sep;
43+
return count.join(SEP) + SEP;
3944
}
4045
return "";
4146
}
@@ -62,16 +67,16 @@ class GlobRemap {
6267

6368
static remapInput(entry, cwd) {
6469
if (cwd) {
65-
if (!entry.startsWith("**" + path.sep) && !entry.startsWith(`.git${path.sep}**`)) {
66-
return ProjectDirectories.getRelativeTo(entry, cwd);
70+
if (!entry.startsWith("**" + SEP) && !entry.startsWith(`.git${SEP}**`)) {
71+
return PathNormalizer.normalizeSeperator(ProjectDirectories.getRelativeTo(entry, cwd));
6772
}
6873
}
6974
return entry;
7075
}
7176

7277
static remapOutput(entry, cwd) {
7378
if (cwd) {
74-
return path.join(cwd, entry);
79+
return PathNormalizer.normalizeSeperator(path.join(cwd, entry));
7580
}
7681
return entry;
7782
}
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from "ava";
22
import path from "node:path";
33
import GlobRemap from "../src/Util/GlobRemap.js";
4-
import { normalizeSeparatorArray, normalizeSeparatorString } from "./Util/normalizeSeparators.js";
4+
import { normalizeSeparatorString } from "./Util/normalizeSeparators.js";
55

66
test("getParentDirPrefix", (t) => {
77
t.is(GlobRemap.getParentDirPrefix(""), "");
@@ -12,11 +12,11 @@ test("getParentDirPrefix", (t) => {
1212
});
1313

1414
test("getCwd", (t) => {
15-
t.is(normalizeSeparatorString(GlobRemap.getCwd([])), "");
16-
t.is(normalizeSeparatorString(GlobRemap.getCwd(["test.njk"])), "");
17-
t.is(normalizeSeparatorString(GlobRemap.getCwd(["./test.njk"])), "");
18-
t.is(normalizeSeparatorString(GlobRemap.getCwd(["../test.njk"])), "../");
19-
t.is(normalizeSeparatorString(GlobRemap.getCwd(["../test.njk", "../../2.njk"])), "../../");
15+
t.is(GlobRemap.getCwd([]), "");
16+
t.is(GlobRemap.getCwd(["test.njk"]), "");
17+
t.is(GlobRemap.getCwd(["./test.njk"]), "");
18+
t.is(GlobRemap.getCwd(["../test.njk"]), "../");
19+
t.is(GlobRemap.getCwd(["../test.njk", "../../2.njk"]), "../../");
2020
});
2121

2222
test("Constructor (control)", t => {
@@ -31,7 +31,7 @@ test("Constructor (control)", t => {
3131
'eleventy.config.js',
3232
])
3333

34-
t.deepEqual(normalizeSeparatorArray(m.getInput()), [
34+
t.deepEqual(m.getInput(), [
3535
'**/*.{liquid,md,njk,html,11ty.js,11ty.cjs,11ty.mjs}',
3636
'**/*.txt', // passthrough copy
3737
'**/*.png',
@@ -55,7 +55,7 @@ test("Constructor (control with ./)", t => {
5555
'./eleventy.config.js',
5656
])
5757

58-
t.deepEqual(normalizeSeparatorArray(m.getInput()), [
58+
t.deepEqual(m.getInput(), [
5959
'./**/*.{liquid,md,njk,html,11ty.js,11ty.cjs,11ty.mjs}',
6060
'./**/*.txt', // passthrough copy
6161
'./**/*.png',
@@ -80,8 +80,9 @@ test("Constructor (up one dir)", t => {
8080
'./eleventy.config.js',
8181
])
8282

83-
let parentDir = path.resolve("./").split(path.sep).slice(-1).join(path.sep);
84-
t.deepEqual(normalizeSeparatorArray(m.getInput()), [
83+
let parentDir = normalizeSeparatorString(path.resolve("./").split(path.sep).slice(-1).join(path.sep));
84+
85+
t.deepEqual(m.getInput(), [
8586
'**/*.{liquid,md,njk,html,11ty.js,11ty.cjs,11ty.mjs}',
8687
'**/*.txt', // passthrough copy
8788
'**/*.png',
@@ -107,10 +108,10 @@ test("Constructor (up two dirs)", t => {
107108
'./eleventy.config.js',
108109
])
109110

110-
let childDir = path.resolve("./").split(path.sep).slice(-2).join(path.sep);
111-
let parentDir = path.resolve("./").split(path.sep).slice(-2, -1).join(path.sep);
111+
let childDir = normalizeSeparatorString(path.resolve("./").split(path.sep).slice(-2).join(path.sep));
112+
let parentDir = normalizeSeparatorString(path.resolve("./").split(path.sep).slice(-2, -1).join(path.sep));
112113

113-
t.deepEqual(normalizeSeparatorArray(m.getInput()), [
114+
t.deepEqual(m.getInput(), [
114115
'**/*.{liquid,md,njk,html,11ty.js,11ty.cjs,11ty.mjs}',
115116
`${parentDir}/**/*.txt`, // passthrough copy
116117
`${parentDir}/**/*.png`,

0 commit comments

Comments
 (0)