Skip to content

Commit 9c8368c

Browse files
committed
chore: ensure Rollup reacts to changes in lean4-infoview-api
1 parent a9abc9e commit 9c8368c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lean4-infoview/rollup.config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,35 @@ const inputSourcemaps = () => ({
2323
name: 'input-sourcemaps',
2424
async load(id) {
2525
if (!id.endsWith('.js')) return null
26+
27+
let code = ''
28+
let map = {}
2629
try {
27-
const code = await fs.promises.readFile(id, 'utf8')
30+
code = await fs.promises.readFile(id, 'utf8')
2831
const mapJson = await fs.promises.readFile(id + '.map', 'utf8')
29-
return { code, map: JSON.parse(mapJson) }
32+
map = JSON.parse(mapJson)
3033
} catch {
3134
return null
3235
}
36+
37+
// Make source paths absolute. Skip this sourcemap if any source is inaccessible.
38+
const sourcesAbs = []
39+
if (!map.sources) return null
40+
const srcDir = path.dirname(id)
41+
for (const s of map.sources) {
42+
try {
43+
const pathAbs = path.resolve(srcDir, s)
44+
await fs.promises.access(pathAbs)
45+
sourcesAbs.push(pathAbs)
46+
} catch {
47+
return null
48+
}
49+
}
50+
map.sources = sourcesAbs
51+
52+
// React to changes to the source file in watch mode.
53+
this.addWatchFile(id)
54+
return { code, map }
3355
},
3456
})
3557

0 commit comments

Comments
 (0)