* Is the given exports object using the shorthand syntax? * @param {import('internal/modules/esm/package_config.js').PackageConfig['exports']} exports * @param {URL} packageJSONUrl The URL of the package.json file. * @param {string | URL | undefined} base The base URL. * @returns {boolean}
(exports, packageJSONUrl, base)
| 555 | * @returns {boolean} |
| 556 | */ |
| 557 | function isConditionalExportsMainSugar(exports, packageJSONUrl, base) { |
| 558 | if (typeof exports === 'string' || ArrayIsArray(exports)) { return true; } |
| 559 | if (typeof exports !== 'object' || exports === null) { return false; } |
| 560 | |
| 561 | const keys = ObjectGetOwnPropertyNames(exports); |
| 562 | let isConditionalSugar = false; |
| 563 | let i = 0; |
| 564 | for (let j = 0; j < keys.length; j++) { |
| 565 | const key = keys[j]; |
| 566 | const curIsConditionalSugar = key === '' || key[0] !== '.'; |
| 567 | if (i++ === 0) { |
| 568 | isConditionalSugar = curIsConditionalSugar; |
| 569 | } else if (isConditionalSugar !== curIsConditionalSugar) { |
| 570 | throw new ERR_INVALID_PACKAGE_CONFIG( |
| 571 | fileURLToPath(packageJSONUrl), base, |
| 572 | '"exports" cannot contain some keys starting with \'.\' and some not.' + |
| 573 | ' The exports object must either be an object of package subpath keys' + |
| 574 | ' or an object of main entry condition name keys only.'); |
| 575 | } |
| 576 | } |
| 577 | return isConditionalSugar; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Resolves the exports of a package. |
no test coverage detected
searching dependent graphs…