Make paths in resulting sourcemap absolute

This commit is contained in:
yname 2024-12-26 14:38:09 -05:00
parent 133acb3e77
commit 6368707541
Signed by: yname
GPG key ID: 0F1CA0E8744D3055

View file

@ -1,4 +1,5 @@
import fs from 'fs'
import { resolve } from 'path'
import { spawn } from 'child_process'
// These are where I (yname) have my Rojo projects.
@ -43,23 +44,23 @@ function getSourcemap(root: string): Promise<RojoSourcemap> {
})
}
function prefixSourcemap(
function absoluteSourcemap(
sourcemap: RojoSourcemap,
prefix: string,
): RojoSourcemap {
return {
name: sourcemap.name,
className: sourcemap.className,
filePaths: sourcemap.filePaths?.map((path) => `${prefix}/${path}`),
filePaths: sourcemap.filePaths?.map((path) => resolve(`${prefix}/${path}`)),
children: sourcemap.children?.map((child) =>
prefixSourcemap(child, prefix),
absoluteSourcemap(child, prefix),
),
}
}
async function getPrefixedSourcemap(root: string): Promise<RojoSourcemap> {
const sourcemap = await getSourcemap(root)
const prefixed = prefixSourcemap(sourcemap, root)
const prefixed = absoluteSourcemap(sourcemap, root)
return prefixed
}