Skip to content

Commit

Permalink
fix: give node export condition higher priority (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Apr 17, 2024
1 parent e83a669 commit f948d13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
13 changes: 11 additions & 2 deletions config/scripts/validate-esm.js
Expand Up @@ -90,7 +90,7 @@ function validatePackageExports() {
console.log('✅ Validated package.json exports')
}

function validateExportConditions(pointer, conditions) {
function validateExportConditions(pointer, conditions, level = 0) {
if (typeof conditions === 'string') {
invariant(
fs.existsSync(conditions),
Expand All @@ -103,7 +103,7 @@ function validateExportConditions(pointer, conditions) {

const keys = Object.keys(conditions)

if (conditions[keys[0]] !== null) {
if (level == 0 && conditions[keys[0]] !== null) {
invariant(keys[0] === 'types', 'FS')
}

Expand All @@ -115,6 +115,15 @@ function validateExportConditions(pointer, conditions) {
return
}

if (typeof relativeExportPath === 'object') {
validateExportConditions(
`${pointer}.${key}`,
relativeExportPath,
level + 1,
)
return
}

const exportPath = fromRoot(relativeExportPath)
invariant(
fs.existsSync(exportPath),
Expand Down
18 changes: 15 additions & 3 deletions package.json
Expand Up @@ -14,22 +14,34 @@
"default": "./lib/core/index.js"
},
"./browser": {
"node": null,
"types": "./lib/browser/index.d.ts",
"browser": {
"require": "./lib/browser/index.js",
"import": "./lib/browser/index.mjs"
},
"node": null,
"require": "./lib/browser/index.js",
"import": "./lib/browser/index.mjs",
"default": "./lib/browser/index.js"
},
"./node": {
"browser": null,
"types": "./lib/node/index.d.ts",
"node": {
"require": "./lib/node/index.js",
"import": "./lib/node/index.mjs"
},
"browser": null,
"require": "./lib/node/index.js",
"import": "./lib/node/index.mjs",
"default": "./lib/node/index.mjs"
},
"./native": {
"browser": null,
"types": "./lib/native/index.d.ts",
"react-native": {
"require": "./lib/native/index.js",
"import": "./lib/native/index.mjs"
},
"browser": null,
"require": "./lib/native/index.js",
"import": "./lib/native/index.mjs",
"default": "./lib/native/index.js"
Expand Down

0 comments on commit f948d13

Please sign in to comment.