| 72 | } |
| 73 | |
| 74 | async process( |
| 75 | filePath: string, |
| 76 | mode: TransformMode, |
| 77 | target: string | string[], |
| 78 | ): Promise<ProcessedFile[] | null> { |
| 79 | // Pre-check if we have any transformer for this file at all |
| 80 | let hasTransformer = false; |
| 81 | for (let i = 0; i < this.#transformers.length; i++) { |
| 82 | if (this.#transformers[i].options.filter.test(filePath)) { |
| 83 | hasTransformer = true; |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (!hasTransformer) { |
| 89 | return null; |
| 90 | } |
| 91 | |
| 92 | let content: Uint8Array; |
| 93 | try { |
| 94 | content = await this.#fs.readFile(filePath); |
| 95 | } catch (err) { |
| 96 | if (err instanceof Deno.errors.NotFound) { |
| 97 | return null; |
| 98 | } |
| 99 | |
| 100 | throw err; |
| 101 | } |
| 102 | |
| 103 | const queue: TransformReq[] = [{ |
| 104 | newFile: false, |
| 105 | content, |
| 106 | filePath, |
| 107 | map: null, |
| 108 | inputFiles: [filePath], |
| 109 | }]; |
| 110 | const outFiles: ProcessedFile[] = []; |
| 111 | |
| 112 | const seen = new Set<string>(); |
| 113 | |
| 114 | let req: TransformReq | undefined = undefined; |
| 115 | while ((req = queue.pop()) !== undefined) { |
| 116 | if (seen.has(req.filePath)) continue; |
| 117 | seen.add(req.filePath); |
| 118 | |
| 119 | let transformed = false; |
| 120 | outer: for (let i = 0; i < this.#transformers.length; i++) { |
| 121 | const transformer = this.#transformers[i]; |
| 122 | |
| 123 | const { options, fn } = transformer; |
| 124 | options.filter.lastIndex = 0; |
| 125 | if (!options.filter.test(req.filePath)) { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | // Check if file is excluded |
| 130 | if (options.exclude !== undefined) { |
| 131 | for (let j = 0; j < options.exclude.length; j++) { |