(context: ResolutionContext)
| 715 | }, |
| 716 | |
| 717 | detect(context: ResolutionContext): boolean { |
| 718 | // Primary: composer.json identifies a Drupal project/module/theme/profile. |
| 719 | // A contrib module often has an EMPTY `require` (no `drupal/*` dep) but still |
| 720 | // declares `"name": "drupal/<module>"` and `"type": "drupal-module"`, so check |
| 721 | // those too — checking deps alone misses every standalone contrib module. |
| 722 | const composer = context.readFile('composer.json'); |
| 723 | if (composer) { |
| 724 | try { |
| 725 | const json = JSON.parse(composer) as { |
| 726 | name?: string; |
| 727 | type?: string; |
| 728 | require?: Record<string, string>; |
| 729 | 'require-dev'?: Record<string, string>; |
| 730 | }; |
| 731 | if (typeof json.name === 'string' && json.name.startsWith('drupal/')) return true; |
| 732 | if (typeof json.type === 'string' && json.type.startsWith('drupal-')) return true; |
| 733 | const deps = { ...json.require, ...(json['require-dev'] ?? {}) }; |
| 734 | if (Object.keys(deps).some((k) => k.startsWith('drupal/'))) return true; |
| 735 | } catch { |
| 736 | // malformed composer.json — fall through to file-based detection |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | // Fallback (composer-less module, or a non-Drupal composer.json): the |
| 741 | // unmistakable Drupal signature is a `*.info.yml` manifest alongside a |
| 742 | // Drupal PHP/route file. Require both so a stray `.info.yml` elsewhere |
| 743 | // doesn't trigger a false positive. |
| 744 | const files = context.getAllFiles(); |
| 745 | const hasInfoYml = files.some((f) => f.endsWith('.info.yml')); |
| 746 | if (!hasInfoYml) return false; |
| 747 | return files.some( |
| 748 | (f) => |
| 749 | f.endsWith('.routing.yml') || |
| 750 | f.endsWith('.module') || |
| 751 | f.endsWith('.install') || |
| 752 | f.endsWith('.theme') |
| 753 | ); |
| 754 | }, |
| 755 | |
| 756 | resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null { |
| 757 | const name = ref.referenceName; |
nothing calls this directly
no test coverage detected