(
output,
{
context,
targetProperties: tp,
isAffectedByBrowserslist,
outputModule,
development,
entry,
futureDefaults,
asyncWebAssembly
}
)
| 1426 | * @returns {void} |
| 1427 | */ |
| 1428 | const applyOutputDefaults = ( |
| 1429 | output, |
| 1430 | { |
| 1431 | context, |
| 1432 | targetProperties: tp, |
| 1433 | isAffectedByBrowserslist, |
| 1434 | outputModule, |
| 1435 | development, |
| 1436 | entry, |
| 1437 | futureDefaults, |
| 1438 | asyncWebAssembly |
| 1439 | } |
| 1440 | ) => { |
| 1441 | /** |
| 1442 | * Returns a readable library name. |
| 1443 | * @param {Library=} library the library option |
| 1444 | * @returns {string} a readable library name |
| 1445 | */ |
| 1446 | const getLibraryName = (library) => { |
| 1447 | const libraryName = |
| 1448 | typeof library === "object" && |
| 1449 | library && |
| 1450 | !Array.isArray(library) && |
| 1451 | "type" in library |
| 1452 | ? library.name |
| 1453 | : /** @type {LibraryName} */ (library); |
| 1454 | if (Array.isArray(libraryName)) { |
| 1455 | return libraryName.join("."); |
| 1456 | } else if (typeof libraryName === "object") { |
| 1457 | return getLibraryName(libraryName.root); |
| 1458 | } else if (typeof libraryName === "string") { |
| 1459 | return libraryName; |
| 1460 | } |
| 1461 | return ""; |
| 1462 | }; |
| 1463 | |
| 1464 | F(output, "uniqueName", () => { |
| 1465 | const libraryName = getLibraryName(output.library).replace( |
| 1466 | /^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g, |
| 1467 | (m, a, d1, d2, b, c) => { |
| 1468 | const content = a || b || c; |
| 1469 | return content.startsWith("\\") && content.endsWith("\\") |
| 1470 | ? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}` |
| 1471 | : ""; |
| 1472 | } |
| 1473 | ); |
| 1474 | if (libraryName) return libraryName; |
| 1475 | const pkgPath = path.resolve(context, "package.json"); |
| 1476 | try { |
| 1477 | const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8")); |
| 1478 | return packageInfo.name || ""; |
| 1479 | } catch (err) { |
| 1480 | if (/** @type {Error & { code: string }} */ (err).code !== "ENOENT") { |
| 1481 | /** @type {Error & { code: string }} */ |
| 1482 | (err).message += |
| 1483 | `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`; |
| 1484 | throw err; |
| 1485 | } |
no test coverage detected