Files
Bug, Ltd. 17380c173f Bootstrap (#1)
bootstrap repo with files from local
2025-01-14 16:15:47 +01:00

21 lines
555 B
JavaScript

/**
* Replace the paths within the '.mock' folder into the relative path expected at runtime.
* We use a RegExp to achieve this, could be another approach
*/
const re = /[^'"`]*\/\.mock\//
export default function mockReplacer({
orig,
// file,
// config,
}) {
if (re.test(orig)) {
// console.log({ orig })
// count the number of '..' before '.mock' folder
const nbParents = (orig.match(/\.\.\//g) || []).length
const replaced = orig.replace(re, '../'.repeat(3 + nbParents))
// console.log({ replaced })
return replaced
}
return orig
}