From 3b3150835bde45f87ba04fd6ba5f92a24a4c2566 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sat, 5 Oct 2024 00:16:13 -0400 Subject: [PATCH] Fix isConditionalExports and run update script --- package-lock.json | 9 ++++---- scripts/utils/packages.js | 47 +++++++++++++-------------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef4a4ca7..6e746278 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4473,9 +4473,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001666", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001666.tgz", - "integrity": "sha512-gD14ICmoV5ZZM1OdzPWmpx+q4GyefaK06zi8hmfHV5xe4/2nOQX3+Dw5o+fSqOws2xVwL9j+anOPFwHzdEdV4g==", + "version": "1.0.30001667", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001667.tgz", + "integrity": "sha512-7LTwJjcRkzKFmtqGsibMeuXmvFDfZq/nzIjnmgCGzKKRVzjD72selLDK1oPF/Oxzmt4fNcPvTDvGqSDG4tCALw==", "dev": true, "funding": [ { @@ -4490,7 +4490,8 @@ "type": "github", "url": "https://github.com/sponsors/ai" } - ] + ], + "license": "CC-BY-4.0" }, "node_modules/chokidar": { "version": "3.6.0", diff --git a/scripts/utils/packages.js b/scripts/utils/packages.js index 0b731875..aabf6928 100644 --- a/scripts/utils/packages.js +++ b/scripts/utils/packages.js @@ -337,31 +337,7 @@ function gitHubTgzUrl(user, project, sha) { } function isConditionalExports(entryExports) { - let hasKeys = false - if (isObjectObject(entryExports)) { - const keys = Object.getOwnPropertyNames(entryExports) - const { length } = keys - hasKeys = length > 0 - for (let i = 0; i < length; i += 1) { - // Conditional entry exports do NOT contain keys starting with '.'. - // Entry exports cannot contain some keys starting with '.' and some not. - // The exports object MUST either be an object of package subpath keys OR - // an object of main entry condition name keys only. - if (keys[i].charCodeAt(0) === 46 /*'.'*/) { - return false - } - } - } - return hasKeys || isConditionalExportsMainSugar(entryExports) -} - -// Based on Node's internal helper. -// https://github.com/nodejs/node/blob/v22.9.0/lib/internal/modules/esm/resolve.js#L537 -function isConditionalExportsMainSugar(entryExports) { - if (typeof entryExports === 'string' || Array.isArray(entryExports)) { - return true - } - if (!isObject(entryExports)) { + if (!isObjectObject(entryExports)) { return false } const keys = Object.getOwnPropertyNames(entryExports) @@ -369,13 +345,17 @@ function isConditionalExportsMainSugar(entryExports) { if (!length) { return false } - let result = keys[0] === '' || keys[0].charCodeAt(0) === 46 /*'.'*/ - for (let i = 1; i < length; i += 1) { - if (result !== (keys[i] === '' || keys[i].charCodeAt(0) === 46) /*'.'*/) { + // Conditional entry exports do NOT contain keys starting with '.'. + // Entry exports cannot contain some keys starting with '.' and some not. + // The exports object MUST either be an object of package subpath keys OR + // an object of main entry condition name keys only. + for (let i = 0; i < length; i += 1) { + const key = keys[i] + if (key.length > 0 && key.charCodeAt(0) === 46 /*'.'*/) { return false } } - return result + return true } function isSubpathExports(entryExports) { @@ -523,10 +503,15 @@ function resolvePackageJsonDirname(filepath) { } function resolvePackageJsonEntryExports(entryExports) { - if (isConditionalExportsMainSugar(entryExports)) { + // If conditional exports main sugar + // https://nodejs.org/api/packages.html#exports-sugar + if (typeof entryExports === 'string' || Array.isArray(entryExports)) { return { '.': entryExports } } - return isObjectObject(entryExports) ? entryExports : undefined + if (isConditionalExports(entryExports)) { + return entryExports + } + return isObject(entryExports) ? entryExports : undefined } function resolvePackageJsonPath(filepath) {