diff --git a/lib/package-reader.js b/lib/package-reader.js index 9712adb..9ce91e9 100644 --- a/lib/package-reader.js +++ b/lib/package-reader.js @@ -398,13 +398,20 @@ function pickCondition(obj) { let env = process.env.NODE_ENV || ''; if (env === 'undefined') env = ''; + if (Array.isArray(obj)) { + for (const a of obj) { + const result = pickCondition(a); + if (result) return result; + } + } + // use env (NODE_ENV) to support "development" and "production" for (const condition of ['import', 'module', 'browser', 'require', env, 'default']) { // Recursive call to support nested conditions. if (condition && condition in obj) return pickCondition(obj[condition]); } - return null; + throw new Error("Unexpected exports condition: " + JSON.stringify(obj)); } function _exportsMain(exports) { diff --git a/package.json b/package.json index 113988d..12608a7 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dumber-module-loader": "^1.2.5", "eslint-scope": "^8.0.2", "events": "^3.3.0", - "fs-browser-stub": "^1.0.1", + "fs-browser-stub": "^1.1.1", "https-browserify": "^1.0.0", "meriyah": "^6.0.1", "modify-code": "^2.1.4", diff --git a/test/package-reader.spec.js b/test/package-reader.spec.js index da1c294..3f1bf0f 100644 --- a/test/package-reader.spec.js +++ b/test/package-reader.spec.js @@ -1723,7 +1723,7 @@ test('packageReader reads exports subpaths in package.json', async t => { ".": "./index.js", "./package.json": "./package.json", "./a": "./a.js", - "./b": "./be.js", + "./b": ["./be.js"], "./c": {"import": "./lib/c.js"}, "./d/*": "./lib/d/*.js", "./e": null