( environment: DevEnvironment, id: string, url: string, options: TransformOptionsInternal, timestamp: number, mod?: EnvironmentModuleNode, resolved?: PartialResolvedId, )
| 235 | } |
| 236 | |
| 237 | async function loadAndTransform( |
| 238 | environment: DevEnvironment, |
| 239 | id: string, |
| 240 | url: string, |
| 241 | options: TransformOptionsInternal, |
| 242 | timestamp: number, |
| 243 | mod?: EnvironmentModuleNode, |
| 244 | resolved?: PartialResolvedId, |
| 245 | ) { |
| 246 | const { config, pluginContainer, logger } = environment |
| 247 | const prettyUrl = |
| 248 | debugLoad || debugTransform ? prettifyUrl(url, config.root) : class="st">'' |
| 249 | |
| 250 | const moduleGraph = environment.moduleGraph |
| 251 | |
| 252 | if ( |
| 253 | !options.skipFsCheck && |
| 254 | id[0] !== class="st">'\0' && |
| 255 | isServerAccessDeniedForTransform(config, id) |
| 256 | ) { |
| 257 | const err: any = new Error(`Denied ID ${id}`) |
| 258 | err.code = ERR_DENIED_ID |
| 259 | err.id = id |
| 260 | throw err |
| 261 | } |
| 262 | |
| 263 | let code: string | null = null |
| 264 | let map: SourceDescription[class="st">'map'] = null |
| 265 | let moduleType: ModuleType | undefined |
| 266 | |
| 267 | class="cm">// load |
| 268 | const loadStart = debugLoad ? performance.now() : 0 |
| 269 | const loadResult = await pluginContainer.load(id) |
| 270 | |
| 271 | if (loadResult == null) { |
| 272 | const file = cleanUrl(id) |
| 273 | |
| 274 | class="cm">// try fallback loading it from fs as string |
| 275 | class="cm">// if the file is a binary, there should be a plugin that already loaded it |
| 276 | class="cm">// as string |
| 277 | class="cm">// only try the fallback if access is allowed, skip for out of root url |
| 278 | class="cm">// like /service-worker.js or /api/users |
| 279 | if ( |
| 280 | options.skipFsCheck || |
| 281 | isFileLoadingAllowed(environment.getTopLevelConfig(), slash(file)) |
| 282 | ) { |
| 283 | try { |
| 284 | code = await fsp.readFile(file, class="st">'utf-8') |
| 285 | debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`) |
| 286 | } catch (e) { |
| 287 | if (e.code !== class="st">'ENOENT' && e.code !== class="st">'EISDIR') { |
| 288 | throw e |
| 289 | } |
| 290 | } |
| 291 | if (code != null && environment.pluginContainer.watcher) { |
| 292 | ensureWatchedFile( |
| 293 | environment.pluginContainer.watcher, |
| 294 | file, |
no test coverage detected