Files
test-repo/tests/integration/path-serializer.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
645 B
JavaScript
Raw Normal View History

const replaceCWD = (text) => {
const cwd = process.cwd();
const variants = /^[a-z]:\\/i.test(cwd)
? [
cwd.charAt(0).toLowerCase() + cwd.slice(1),
cwd.charAt(0).toUpperCase() + cwd.slice(1),
]
: [cwd];
for (const variant of variants) {
while (text.includes(variant)) {
text = text.replace(variant, "<cwd>");
}
}
return text;
};
const pathSerializer = {
2017-09-03 21:31:33 +08:00
test: (value) =>
2017-09-28 19:30:51 +10:00
typeof value === "string" &&
2019-11-17 18:06:14 +08:00
(value.includes("\\") || value.includes(process.cwd())),
2017-09-03 21:31:33 +08:00
print: (value, serializer) =>
serializer(replaceCWD(value).replace(/\\/g, "/")),
2017-09-03 21:31:33 +08:00
};
export default pathSerializer;