( id: string, importer: string | undefined, module: Module )
| 271 | } |
| 272 | |
| 273 | private async addModuleSource( |
| 274 | id: string, |
| 275 | importer: string | undefined, |
| 276 | module: Module |
| 277 | ): Promise<void> { |
| 278 | let source: LoadResult; |
| 279 | try { |
| 280 | source = await this.graph.fileOperationQueue.run(async () => { |
| 281 | const content = await this.pluginDriver.hookFirst('load', [ |
| 282 | id, |
| 283 | { attributes: module.info.attributes } |
| 284 | ]); |
| 285 | if (content !== null) { |
| 286 | if (typeof content === 'object' && content.attributes) { |
| 287 | warnDeprecation( |
| 288 | 'Returning attributes from the "load" hook is forbidden.', |
| 289 | URL_LOAD, |
| 290 | false, |
| 291 | this.options |
| 292 | ); |
| 293 | } |
| 294 | return content; |
| 295 | } |
| 296 | this.graph.watchFiles[id] = true; |
| 297 | return (await this.options.fs.readFile(id, { encoding: 'utf8' })) as string; |
| 298 | }); |
| 299 | } catch (error_: any) { |
| 300 | let message = `Could not load ${id}`; |
| 301 | if (importer) message += ` (imported by ${relativeId(importer)})`; |
| 302 | message += `: ${error_.message}`; |
| 303 | error_.message = message; |
| 304 | throw error_; |
| 305 | } |
| 306 | const sourceDescription = |
| 307 | typeof source === 'string' |
| 308 | ? { code: source } |
| 309 | : source != null && typeof source === 'object' && typeof source.code === 'string' |
| 310 | ? source |
| 311 | : error(logBadLoader(id)); |
| 312 | sourceDescription.code = stripBom(sourceDescription.code); |
| 313 | const cachedModule = this.graph.cachedModules.get(id); |
| 314 | if ( |
| 315 | cachedModule && |
| 316 | !cachedModule.customTransformCache && |
| 317 | cachedModule.originalCode === sourceDescription.code && |
| 318 | !(await this.pluginDriver.hookFirst('shouldTransformCachedModule', [ |
| 319 | { |
| 320 | ast: cachedModule.ast, |
| 321 | attributes: cachedModule.attributes, |
| 322 | code: cachedModule.code, |
| 323 | id: cachedModule.id, |
| 324 | meta: cachedModule.meta, |
| 325 | moduleSideEffects: cachedModule.moduleSideEffects, |
| 326 | resolvedSources: cachedModule.resolvedIds, |
| 327 | syntheticNamedExports: cachedModule.syntheticNamedExports |
| 328 | } |
| 329 | ])) |
| 330 | ) { |
no test coverage detected