Skip to content

Commit 60a5b5d

Browse files
committed
feat(options): added root prefix option
1 parent 75f602a commit 60a5b5d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface MapTransformOptions {
3131
rewrite: (path: string) => string;
3232
transform: Transformer;
3333
rootPath?: string;
34+
rootPrefix?: string;
3435
}
3536

3637
function scanFile(
@@ -64,7 +65,8 @@ function replacePaths(
6465
paths: TransformedPaths,
6566
stash: FileStash,
6667
search: RegExp,
67-
rootPath?: string
68+
rootPath?: string,
69+
rootPrefix?: string
6870
) {
6971
for (const p in paths) {
7072
if (paths.hasOwnProperty(p)) {
@@ -74,9 +76,13 @@ function replacePaths(
7476

7577
if (item.realPath === p) {
7678
content = content.replace(search, (match) => {
79+
const prefix = typeof rootPrefix === 'string'
80+
? rootPrefix
81+
: (rootPath ? '/' : '')
82+
7783
return match.replace(
7884
item.virtPath,
79-
(rootPath ? '/' : '') + path.relative(
85+
prefix + path.relative(
8086
rootPath || path.dirname(fromPath),
8187
paths[p]
8288
)
@@ -177,7 +183,8 @@ function mapTransform(options: MapTransformOptions) {
177183
transformedPaths,
178184
fileStash,
179185
options.search,
180-
options.rootPath
186+
options.rootPath,
187+
options.rootPrefix
181188
)
182189
);
183190
}

0 commit comments

Comments
 (0)