| 70 | */ |
| 71 | @injectable() |
| 72 | export class VueFileMapper implements IVueFileMapper { |
| 73 | constructor( |
| 74 | @inject(VueComponentPaths) private readonly files: FileGlobList, |
| 75 | @inject(ISearchStrategy) private readonly search: ISearchStrategy, |
| 76 | ) {} |
| 77 | |
| 78 | private readonly getMapping = once(async () => { |
| 79 | const basenameToPath = new Map<string, string>(); |
| 80 | await this.search.streamAllChildren(this.files, file => |
| 81 | basenameToPath.set(basename(file), file), |
| 82 | ); |
| 83 | |
| 84 | return basenameToPath; |
| 85 | }); |
| 86 | |
| 87 | /** |
| 88 | * @inheritdoc |
| 89 | */ |
| 90 | public async lookup(sourceUrl: string) { |
| 91 | const match = vueSourceUrlRe.exec(sourceUrl); |
| 92 | if (!match) { |
| 93 | return undefined; |
| 94 | } |
| 95 | |
| 96 | const basenameToPath = await this.getMapping(); |
| 97 | return basenameToPath.get(match[1]); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @inheritdoc |
| 102 | */ |
| 103 | public getVueHandling(sourceUrl: string) { |
| 104 | if (this.files.empty) { |
| 105 | return VueHandling.Unhandled; |
| 106 | } |
| 107 | |
| 108 | return vueSourceUrlRe.test(sourceUrl) |
| 109 | ? VueHandling.Lookup |
| 110 | : vueGeneratedRe.test(sourceUrl) |
| 111 | ? VueHandling.Omit |
| 112 | : VueHandling.Unhandled; |
| 113 | } |
| 114 | } |
nothing calls this directly
no test coverage detected