specfy / stack-analyser

Extract 500+ technologies from any repository. Detect Languages, SaaS, Cloud, Infrastructure, Dependencies and Services
https://specfy.io
MIT License
190 stars 10 forks source link

fix(rules): explicitly import rules to trigger side effects #89

Open atkinchris opened 1 month ago

atkinchris commented 1 month ago

This adds an explicit import for the rules index file, to trigger the registration side effects of each rule being imported. Each rule file module runs register - and unless imported, that registration will not happen.

This was already happening in the CLI, as it uses autoload.ts - which contained an explicit import for the rules module index. However, when using the library programmatically, rules.loadAll would not have any registered rules to load.

Work around

You can work around this issue at the moment by using import '@specfy/stack-analyser/dist/autoload.js', or including import '@specfy/stack-analyser/dist/rules/index.js' before running rules.loadAll.

import '@specfy/stack-analyser/dist/autoload.js'

// or

import { rules } from '@specfy/stack-analyser'
import '@specfy/stack-analyser/dist/rules/index.js'

rules.loadAll()
bodinsamuel commented 1 month ago

hey, thanks for raising this issue. It was done intentionally if devs want to use the library with custom rules only. But I realize that the README does not reflect that requirement indeed. Do you think this process is problematic? Maybe we should just update the readme to clarify the situation

atkinchris commented 1 month ago

Wouldn the loadOne API satisfy the need to use custom rules? The import side effect registers them, but in the fix proposed doesn't load them.