(code, id, options)
| 135 | }, |
| 136 | |
| 137 | async transform(code, id, options) { |
| 138 | if (!isActive || options?.ssr || !includesAlphaTabWorker(code)) { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | let s: MagicString | undefined; |
| 143 | |
| 144 | // Match `new alphaTabWorker(new ...alphaTabUrl(...))` and any |
| 145 | // `<expr>.addModule(new ...alphaTabUrl(...))` (the worklet path, |
| 146 | // which may have its alias inlined away). Worker vs worklet is |
| 147 | // disambiguated by `getWorkerType` based on the URL string. |
| 148 | const alphaTabWorkerPattern = |
| 149 | /\b(alphaTabWorker|[\w.]+\.addModule)\s*\(\s*(new\s+[^ (]+alphaTabUrl\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg; |
| 150 | |
| 151 | let match: RegExpExecArray | null = alphaTabWorkerPattern.exec(code); |
| 152 | while (match) { |
| 153 | const workerType = getWorkerType(code, match); |
| 154 | |
| 155 | let typeActive = false; |
| 156 | switch (workerType) { |
| 157 | case AlphaTabWorkerTypes.WorkerClassic: |
| 158 | case AlphaTabWorkerTypes.WorkerModule: |
| 159 | typeActive = isWorkerActive; |
| 160 | break; |
| 161 | case AlphaTabWorkerTypes.AudioWorklet: |
| 162 | typeActive = isWorkletActive; |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | if (!typeActive) { |
| 167 | match = alphaTabWorkerPattern.exec(code); |
| 168 | continue; |
| 169 | } |
| 170 | |
| 171 | s ??= new MagicString(code); |
| 172 | |
| 173 | const url = code.slice(match.indices![3]![0] + 1, match.indices![3]![1] - 1); |
| 174 | |
| 175 | let file = path.resolve(path.dirname(id), url); |
| 176 | file = |
| 177 | tryFsResolve(file, preserveSymlinks) ?? |
| 178 | tryOptimizedDepResolve(resolvedConfig, options?.ssr === true, url, id, preserveSymlinks) ?? |
| 179 | file; |
| 180 | |
| 181 | let builtUrl: string; |
| 182 | if (isBuild) { |
| 183 | builtUrl = await workerFileToUrl(resolvedConfig, file); |
| 184 | } else { |
| 185 | builtUrl = await fileToUrl(cleanUrl(file), resolvedConfig); |
| 186 | builtUrl = injectQuery(builtUrl, `${WORKER_FILE_ID}&type=${workerType}`); |
| 187 | } |
| 188 | s.update( |
| 189 | match.indices![3]![0], |
| 190 | match.indices![3]![1], |
| 191 | // add `'' +` to skip vite:asset-import-meta-url plugin |
| 192 | `new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)` |
| 193 | ); |
| 194 |
nothing calls this directly
no test coverage detected