Skip to content

Commit 2abfa2c

Browse files
committed
Add script to remove source maps from lib and invoke it in build
1 parent 33ca8fe commit 2abfa2c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"typecheck": "tsc --noEmit",
1212
"clean": "git clean -dfX",
1313
"release": "semantic-release",
14-
"build": "npm run typecheck && bob build",
14+
"build": "npm run typecheck && bob build && node ./scripts/remove-source-maps.cjs",
1515
"codegen": "nitrogen --logLevel=\"debug\" && npm run build && node post-script.js",
1616
"prepublish": "yarn codegen"
1717
},

scripts/remove-source-maps.cjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
const path = require('path')
4+
const { promises: fs } = require('fs')
5+
6+
async function removeMaps(directory) {
7+
const entries = await fs.readdir(directory, { withFileTypes: true })
8+
9+
await Promise.all(
10+
entries.map(async (entry) => {
11+
const entryPath = path.join(directory, entry.name)
12+
13+
if (entry.isDirectory()) {
14+
await removeMaps(entryPath)
15+
return
16+
}
17+
18+
if (entry.isFile() && entry.name.endsWith('.map')) {
19+
await fs.unlink(entryPath)
20+
}
21+
})
22+
)
23+
}
24+
25+
async function main() {
26+
const libPath = path.join(__dirname, '..', 'lib')
27+
28+
try {
29+
await fs.access(libPath)
30+
} catch {
31+
return
32+
}
33+
34+
await removeMaps(libPath)
35+
}
36+
37+
main().catch((error) => {
38+
console.error('Failed to remove source maps from lib directory:', error)
39+
process.exitCode = 1
40+
})

0 commit comments

Comments
 (0)