-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: No sub-module imports in type definitions (#958)
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { promises as fs } from 'node:fs'; | ||
import * as path from 'node:path'; | ||
|
||
async function walk(dir, ty) { | ||
let files = await fs.readdir(dir); | ||
files = await Promise.all( | ||
files.map(async (file) => { | ||
const filePath = path.join(dir, file); | ||
const stats = await fs.stat(filePath); | ||
if (stats.isDirectory()) { | ||
return filePath.endsWith('node_modules') ? [] : walk(filePath, ty); | ||
} else if (stats.isFile() && file.endsWith(ty)) { | ||
return filePath; | ||
} | ||
}), | ||
); | ||
|
||
return files.filter(Boolean).reduce((all, f) => all.concat(f), []); | ||
} | ||
|
||
// Find all the .d.ts files in the project | ||
const typeDefs = await walk(process.cwd(), '.d.ts'); | ||
|
||
// Check for any sub-module imports in the type definitions | ||
const regex = /import\("@sentry\/.+\//gi; | ||
let failed = false; | ||
|
||
for (const file of typeDefs) { | ||
const content = await fs.readFile(file, 'utf-8'); | ||
const matches = content.match(regex); | ||
if (matches) { | ||
console.log(`Sub-module import in type def file '${file}':\n`, matches); | ||
failed = true; | ||
} | ||
} | ||
|
||
if (failed) { | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters