( config: d.ValidatedConfig, inMemoryFs: InMemoryFileSystem, resolvedId: ResolveIdResult, importee: string, )
| 7 | import { DEV_MODULE_DIR } from './constants'; |
| 8 | |
| 9 | export const devNodeModuleResolveId = async ( |
| 10 | config: d.ValidatedConfig, |
| 11 | inMemoryFs: InMemoryFileSystem, |
| 12 | resolvedId: ResolveIdResult, |
| 13 | importee: string, |
| 14 | ) => { |
| 15 | if (!shouldCheckDevModule(resolvedId, importee)) { |
| 16 | return resolvedId; |
| 17 | } |
| 18 | |
| 19 | if (typeof resolvedId === 'string' || !resolvedId) { |
| 20 | return resolvedId; |
| 21 | } |
| 22 | |
| 23 | const resolvedPath = resolvedId.id; |
| 24 | |
| 25 | const pkgPath = getPackageJsonPath(resolvedPath, importee); |
| 26 | if (!pkgPath) { |
| 27 | return resolvedId; |
| 28 | } |
| 29 | |
| 30 | const pkgJsonStr = await inMemoryFs.readFile(pkgPath); |
| 31 | if (!pkgJsonStr) { |
| 32 | return resolvedId; |
| 33 | } |
| 34 | |
| 35 | let pkgJsonData: d.PackageJsonData; |
| 36 | try { |
| 37 | pkgJsonData = JSON.parse(pkgJsonStr); |
| 38 | } catch (e) {} |
| 39 | |
| 40 | if (!pkgJsonData || !pkgJsonData.version) { |
| 41 | return resolvedId; |
| 42 | } |
| 43 | |
| 44 | resolvedId.id = serializeDevNodeModuleUrl(config, pkgJsonData.name, pkgJsonData.version, resolvedPath); |
| 45 | resolvedId.external = true; |
| 46 | |
| 47 | return resolvedId; |
| 48 | }; |
| 49 | |
| 50 | const shouldCheckDevModule = (resolvedId: ResolveIdResult, importee: string) => |
| 51 | resolvedId && |
no test coverage detected