MCPcopy Index your code
hub / github.com/nodejs/node / isConditionalExportsMainSugar

Function isConditionalExportsMainSugar

lib/internal/modules/esm/resolve.js:557–578  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

555 * @returns {boolean}
556 */
557function 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.

Callers 1

packageExportsResolveFunction · 0.85

Calls 1

fileURLToPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…