This commit is contained in:
Alex
2023-09-11 14:40:55 -04:00
parent 9bba0b4d03
commit 729172af89
15 changed files with 638 additions and 414 deletions

34
src/check-imports.ts Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env tsx
import glob from 'fast-glob';
import fs from 'fs';
import { builtinModules } from 'module';
import { uniq } from 'lodash';
import { dependencies, peerDependencies } from '../dist/package.json';
const deps = Object.keys({ ...dependencies, ...peerDependencies }).concat('eslint');
const builtIn = new Set(builtinModules.flatMap(module => [module, `node:${module}`]));
const files = Object.fromEntries(
glob
.sync('dist/**/*.js')
.map(path => [
path,
uniq(
Array.from(fs.readFileSync(path, 'utf8').matchAll(/require\(["']([^"']+)["']\)/g))
.map(m => m[1])
.filter(
module =>
!(
builtIn.has(module) ||
deps.includes(module) ||
deps.some(dep => module.startsWith(`${dep}/`)) ||
module.startsWith('eslint/') ||
module.startsWith('typescript/')
),
),
),
])
.filter(([, modules]) => modules.length > 0),
);
console.log(files);