(fsPath)
| 236 | }, |
| 237 | ignore: config.excludeFiles, |
| 238 | async readFile(fsPath) { |
| 239 | const relPath = relative(baseDir, fsPath); |
| 240 | |
| 241 | // If this file has already been read then return from the cache |
| 242 | const cached = sourceCache.get(relPath); |
| 243 | if (typeof cached !== 'undefined') return cached; |
| 244 | |
| 245 | try { |
| 246 | let entry: File | undefined; |
| 247 | let source: string | Buffer = readFileSync(fsPath); |
| 248 | |
| 249 | const { mode } = lstatSync(fsPath); |
| 250 | if (isSymbolicLink(mode)) { |
| 251 | entry = new FileFsRef({ fsPath, mode }); |
| 252 | } |
| 253 | |
| 254 | if (isEdgeFunction && basename(fsPath) === 'package.json') { |
| 255 | // For Edge Functions, patch "main" field to prefer "browser" or "module" |
| 256 | const pkgJson = JSON.parse(source.toString()); |
| 257 | for (const prop of ['browser', 'module']) { |
| 258 | const val = pkgJson[prop]; |
| 259 | if (typeof val === 'string') { |
| 260 | debug(`Using "${prop}" field in ${fsPath}`); |
| 261 | pkgJson.main = val; |
| 262 | |
| 263 | // Create the `entry` with the original so that the output is unmodified |
| 264 | if (!entry) { |
| 265 | entry = new FileBlob({ data: source, mode }); |
| 266 | } |
| 267 | |
| 268 | // Return the modified `package.json` to nft |
| 269 | source = JSON.stringify(pkgJson); |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if ( |
| 276 | (fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) || |
| 277 | fsPath.endsWith('.tsx') || |
| 278 | fsPath.endsWith('.mts') || |
| 279 | fsPath.endsWith('.cts') |
| 280 | ) { |
| 281 | source = compileTypeScript(fsPath, source.toString()); |
| 282 | } |
| 283 | |
| 284 | if (!entry) { |
| 285 | entry = new FileBlob({ data: source, mode }); |
| 286 | } |
| 287 | fsCache.set(relPath, entry); |
| 288 | sourceCache.set(relPath, source); |
| 289 | return source; |
| 290 | } catch (error: unknown) { |
| 291 | if ( |
| 292 | isErrnoException(error) && |
| 293 | (error.code === 'ENOENT' || error.code === 'EISDIR') |
| 294 | ) { |
| 295 | // `null` represents a not found |
no test coverage detected