Update
This commit is contained in:
34
src/check-imports.ts
Executable file
34
src/check-imports.ts
Executable 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);
|
Reference in New Issue
Block a user