Skip to content

Commit 9a7ed4a

Browse files
authored
chore: ensure Rollup reacts to changes in lean4-infoview-api (#737)
1 parent a9abc9e commit 9a7ed4a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lean4-infoview/rollup.config.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,32 @@ 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+
// Skip this sourcemap if any source is inaccessible.
38+
if (!map.sources) return null
39+
const srcDir = path.dirname(id)
40+
for (const s of map.sources) {
41+
try {
42+
const pathAbs = path.resolve(srcDir, s)
43+
await fs.promises.access(pathAbs)
44+
} catch {
45+
return null
46+
}
47+
}
48+
49+
// React to changes to the source file in watch mode.
50+
this.addWatchFile(id)
51+
return { code, map }
3352
},
3453
})
3554

0 commit comments

Comments
 (0)