| 40 | |
| 41 | // what reads options is a file at the project's root, like a bundler's config |
| 42 | export const pluginCallsIn = (cwd: string): PluginCall[] => { |
| 43 | const project = projectOf(resolve(cwd)) |
| 44 | const root = |
| 45 | existsSync(join(project, "package.json")) ? project : resolve(cwd) |
| 46 | const result: PluginCall[] = [] |
| 47 | for (const entry of readdirSync(root, { withFileTypes: true })) { |
| 48 | if (!entry.isFile() || !scriptFile.test(entry.name)) continue |
| 49 | const file = join(root, entry.name) |
| 50 | const source = readFileSync(file, "utf8") |
| 51 | if (!mentionsEntry.test(source)) continue |
| 52 | const module = new SourceModule( |
| 53 | file, |
| 54 | source, |
| 55 | printablePathOf(cwd, file) || entry.name |
| 56 | ) |
| 57 | if (!module.parseErrors.length) result.push(...callsIn(module)) |
| 58 | } |
| 59 | return result |
| 60 | } |
| 61 | |
| 62 | const callsIn = (module: SourceModule): PluginCall[] => { |
| 63 | const result: PluginCall[] = [] |