-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfix-build.js
More file actions
36 lines (30 loc) · 1011 Bytes
/
fix-build.js
File metadata and controls
36 lines (30 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import fs from 'fs'
import path from 'path'
// Delete empty TypeScript declarations
deleteEmptyTypeScriptDeclarations('dist/types')
/**
* Delete empty TypeScript declarations
* @param {string} folderPath
*/
function deleteEmptyTypeScriptDeclarations(folderPath) {
const folderItems = fs.readdirSync(folderPath)
for (const folderItem of folderItems) {
// if map file it could be already deleted, we need to skip
if (folderItem.endsWith('.d.ts.map')) {
continue
}
const itemPath = path.join(folderPath, folderItem)
const stat = fs.statSync(itemPath)
if (stat.isFile() && folderItem.endsWith('.d.ts')) {
if (fs.readFileSync(itemPath, { encoding: 'utf8' }).includes('export {};')) {
fs.unlinkSync(itemPath)
fs.unlinkSync(itemPath.replace('.d.ts', '.d.ts.map'))
}
} else if (stat.isDirectory()) {
deleteEmptyTypeScriptDeclarations(itemPath)
}
}
if (fs.readdirSync(folderPath).length === 0) {
fs.rmdirSync(folderPath)
}
}