| 372 | } |
| 373 | |
| 374 | private getPkgJsonSubsetForDir(dirPath: string) { |
| 375 | const pkgJsonPath = pathJoin(dirPath, "package.json"); |
| 376 | const pkg = optimisticReadJsonOrNull(pkgJsonPath); |
| 377 | if (! pkg) { |
| 378 | return null; |
| 379 | } |
| 380 | |
| 381 | // Output a JS module that exports just the "name", "version", "main", |
| 382 | // and "browser" properties (if defined) from the package.json file. |
| 383 | const pkgSubset: Partial<typeof pkg> = {}; |
| 384 | |
| 385 | if (has(pkg, "name")) { |
| 386 | pkgSubset.name = pkg.name; |
| 387 | } |
| 388 | |
| 389 | if (has(pkg, "version")) { |
| 390 | pkgSubset.version = pkg.version; |
| 391 | } |
| 392 | |
| 393 | this.mainFields.forEach(name => { |
| 394 | const value = pkg[name]; |
| 395 | if (isString(value) || |
| 396 | isObject(value)) { |
| 397 | pkgSubset[name] = value; |
| 398 | } |
| 399 | }); |
| 400 | |
| 401 | return { |
| 402 | path: pkgJsonPath, |
| 403 | pkg: pkgSubset, |
| 404 | }; |
| 405 | } |
| 406 | |
| 407 | private findPkgJsonSubsetForPath( |
| 408 | path: string, |