32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
||
const path = require('path');
|
||
const reqs = new Set();
|
||
const builtinModules = require('module').builtinModules;
|
||
|
||
function scan(dir) {
|
||
fs.readdirSync(dir).forEach(file => {
|
||
const fullPath = path.join(dir, file);
|
||
if (fs.statSync(fullPath).isDirectory()) {
|
||
if (file !== 'node_modules' && file !== '.git') scan(fullPath);
|
||
} else if (file.endsWith('.js')) {
|
||
const content = fs.readFileSync(fullPath, 'utf8');
|
||
const matches = content.match(/require\(['"]([^'"]+)['"]\)/g);
|
||
if (matches) {
|
||
matches.forEach(m => {
|
||
const pkg = m.match(/require\(['"]([^'"]+)['"]\)/)[1];
|
||
if (!pkg.startsWith('.') && !pkg.startsWith('/') && !builtinModules.includes(pkg)) {
|
||
reqs.add(pkg.split('/')[0]);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
if (fs.existsSync('./server')) {
|
||
scan('./server');
|
||
console.log('=== 代码中实际引用的第三方包 ===');
|
||
console.log([...reqs].join('\n'));
|
||
} else {
|
||
console.log('未找到 server 目录,请确保在项目根目录(D:\\StampingMES)下执行此脚本。');
|
||
} |