( options: esbuild.OnResolveOptions, callback: EsbuildOnResolveCallback, )
| 196 | } |
| 197 | |
| 198 | function createResolveIdHandler( |
| 199 | options: esbuild.OnResolveOptions, |
| 200 | callback: EsbuildOnResolveCallback, |
| 201 | ): ResolveIdHandler { |
| 202 | return async function (id, importer, opts) { |
| 203 | const [importerWithoutNamespace, importerNamespace] = |
| 204 | idToPathAndNamespace(importer) |
| 205 | if ( |
| 206 | options.namespace !== undefined && |
| 207 | options.namespace !== importerNamespace |
| 208 | ) { |
| 209 | return |
| 210 | } |
| 211 | if (options.filter !== undefined && !options.filter.test(id)) { |
| 212 | return |
| 213 | } |
| 214 | |
| 215 | const result = await callback({ |
| 216 | path: id, |
| 217 | importer: importerWithoutNamespace ?? '', |
| 218 | namespace: importerNamespace, |
| 219 | resolveDir: dirname(importerWithoutNamespace ?? ''), |
| 220 | kind: |
| 221 | importerWithoutNamespace === undefined |
| 222 | ? 'entry-point' |
| 223 | : opts.kind === 'new-url' || opts.kind === 'hot-accept' |
| 224 | ? 'dynamic-import' |
| 225 | : opts.kind, |
| 226 | pluginData: {}, |
| 227 | with: {}, |
| 228 | }) |
| 229 | if (!result) return |
| 230 | if (result.errors && result.errors.length > 0) { |
| 231 | throw new AggregateError(result.errors) |
| 232 | } |
| 233 | if ( |
| 234 | (result.warnings && result.warnings.length > 0) || |
| 235 | (result.watchDirs && result.watchDirs.length > 0) || |
| 236 | !result.path |
| 237 | ) { |
| 238 | throw new Error('not implemented') |
| 239 | } |
| 240 | for (const file of result.watchFiles ?? []) { |
| 241 | this.addWatchFile(file) |
| 242 | } |
| 243 | |
| 244 | return { |
| 245 | id: result.namespace ? `${result.namespace}:${result.path}` : result.path, |
| 246 | external: result.external, |
| 247 | moduleSideEffects: result.sideEffects, |
| 248 | namespace: result.namespace, |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | function createLoadHandler( |
| 254 | options: esbuild.OnLoadOptions, |
no test coverage detected