Skip to content

Commit 0c1aaf5

Browse files
committed
Fixed handling for paths with windows separator during build
1 parent 3296cdf commit 0c1aaf5

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

tools/build/_/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import * as chokidar from "chokidar"
2424
import * as fs from "fs/promises"
25+
import * as path from "path"
2526
import {
2627
EMPTY,
2728
Observable,
@@ -120,7 +121,7 @@ export function resolve(
120121

121122
/* Build overrides */
122123
!process.argv.includes("--all")
123-
? filter(file => !file.startsWith(".overrides/"))
124+
? filter(file => !file.startsWith(`.overrides${path.sep}`))
124125
: identity,
125126
)
126127
}

tools/build/index.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,35 @@ function minsvg(data: string): string {
112112
return result.data
113113
}
114114

115+
/**
116+
* Return a path with POSIX style separators
117+
*
118+
* The default function assumes UNIX system, so it just returns the path.
119+
*
120+
* @param p - string path
121+
* @returns String path
122+
*/
123+
let assurePosixSep = function (p: string): string {
124+
return p
125+
};
126+
127+
/**
128+
* Return a path with POSIX style separators
129+
*
130+
* The Windows variant of this function replaces the separator with regex.
131+
*
132+
* @param p - string path
133+
* @returns String path
134+
*/
135+
const winSepRegex = new RegExp(`\\${path.win32.sep}`, "g");
136+
function assurePosixSepWin(p: string): string {
137+
return p.replace(winSepRegex, path.posix.sep)
138+
};
139+
140+
if (path.sep === path.win32.sep) {
141+
assurePosixSep = assurePosixSepWin;
142+
}
143+
115144
/* ----------------------------------------------------------------------------
116145
* Tasks
117146
* ------------------------------------------------------------------------- */
@@ -187,7 +216,7 @@ const sources$ = copyAll("**/*.py", {
187216
const stylesheets$ = resolve("**/[!_]*.scss", { cwd: "src" })
188217
.pipe(
189218
mergeMap(file => zip(
190-
of(ext(file, ".css").replace(/(overrides|templates)\//, "")),
219+
of(ext(file, ".css").replace(new RegExp(`(overrides|templates)\\${path.sep}`), "")),
191220
transformStyle({
192221
from: `src/${file}`,
193222
to: ext(`${base}/${file}`, ".css")
@@ -199,7 +228,7 @@ const stylesheets$ = resolve("**/[!_]*.scss", { cwd: "src" })
199228
const javascripts$ = resolve("**/{custom,bundle,search}.ts", { cwd: "src" })
200229
.pipe(
201230
mergeMap(file => zip(
202-
of(ext(file, ".js").replace(/(overrides|templates)\//, "")),
231+
of(ext(file, ".js").replace(new RegExp(`(overrides|templates)\\${path.sep}`), "")),
203232
transformScript({
204233
from: `src/${file}`,
205234
to: ext(`${base}/${file}`, ".js")
@@ -229,10 +258,10 @@ const manifest$ = merge(
229258
.pipe(
230259
scan((prev, mapping) => (
231260
mapping.reduce((next, [key, value]) => (
232-
next.set(key, value.replace(
233-
new RegExp(`${base}\\/(overrides|templates)\\/`),
261+
next.set(assurePosixSep(key), assurePosixSep(value.replace(
262+
new RegExp(`${base}\\/(overrides|templates)\\${path.sep}`),
234263
""
235-
))
264+
)))
236265
), prev)
237266
), new Map<string, string>()),
238267
)
@@ -291,8 +320,8 @@ const icons$ = defer(() => resolve("**/*.svg", {
291320
}))
292321
.pipe(
293322
reduce((index, file) => index.set(
294-
file.replace(/\.svg$/, "").replace(/\//g, "-"),
295-
file
323+
file.replace(/\.svg$/, "").replace(new RegExp(`\\${path.sep}`, "g"), "-"),
324+
assurePosixSep(file)
296325
), new Map<string, string>())
297326
)
298327

@@ -372,7 +401,7 @@ const schema$ = merge(
372401
"reference/icons-emojis/#search"
373402
].join("/"),
374403
"type": "string",
375-
"enum": icons.map(icon => icon.replace(".svg", ""))
404+
"enum": icons.map(icon => assurePosixSep(icon.replace(".svg", "")))
376405
})),
377406
switchMap(data => write(
378407
"docs/schema/assets/icons.json",

tools/build/transform/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ interface TransformOptions {
6060
/**
6161
* Base directory for source map resolution
6262
*/
63-
const root = new RegExp(`file://${path.resolve(".")}/`, "g")
63+
const currentPath = path.resolve(".").replace(new RegExp(`\\${path.win32.sep}`, "g"), path.posix.sep)
64+
const root = path.sep === path.posix.sep ? new RegExp(`file://${currentPath}/`, "g") : new RegExp(`file:///${currentPath}/`, "g")
6465

6566
/* ----------------------------------------------------------------------------
6667
* Helper functions

0 commit comments

Comments
 (0)