From dbd6399d7587b05cacd0e3051099500d7f08baca Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:54:51 -0800 Subject: [PATCH] add test --- packages/node-resolve/src/index.js | 1 - .../node-resolve/test/fixtures/dev-prod-conditions.js | 3 +++ .../fixtures/node_modules/dev-prod-conditions/dev.js | 1 + .../fixtures/node_modules/dev-prod-conditions/index.js | 1 + .../node_modules/dev-prod-conditions/package.json | 8 ++++++++ packages/node-resolve/test/package-entry-points.js | 10 ++++++++++ 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 packages/node-resolve/test/fixtures/dev-prod-conditions.js create mode 100644 packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/dev.js create mode 100644 packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/index.js create mode 100644 packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/package.json diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index 3cf0caa3a..2ce5738f1 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -180,7 +180,6 @@ export function nodeResolve(opts = {}) { const warn = (...args) => context.warn(...args); const isRequire = custom && custom['node-resolve'] && custom['node-resolve'].isRequire; const exportConditions = isRequire ? conditionsCjs : conditionsEsm; - if (useBrowserOverrides && !exportConditions.includes('browser')) exportConditions.push('browser'); diff --git a/packages/node-resolve/test/fixtures/dev-prod-conditions.js b/packages/node-resolve/test/fixtures/dev-prod-conditions.js new file mode 100644 index 000000000..525d39048 --- /dev/null +++ b/packages/node-resolve/test/fixtures/dev-prod-conditions.js @@ -0,0 +1,3 @@ +import mode from 'dev-prod-conditions'; + +export default mode; diff --git a/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/dev.js b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/dev.js new file mode 100644 index 000000000..5a230d745 --- /dev/null +++ b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/dev.js @@ -0,0 +1 @@ +export default 'DEV' diff --git a/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/index.js b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/index.js new file mode 100644 index 000000000..9373073b4 --- /dev/null +++ b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/index.js @@ -0,0 +1 @@ +export default 'PROD' diff --git a/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/package.json b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/package.json new file mode 100644 index 000000000..d681bc409 --- /dev/null +++ b/packages/node-resolve/test/fixtures/node_modules/dev-prod-conditions/package.json @@ -0,0 +1,8 @@ +{ + "name": "dev-prod-conditions", + "type": "module", + "exports": { + "development": "./dev.js", + "default": "./index.js" + } +} diff --git a/packages/node-resolve/test/package-entry-points.js b/packages/node-resolve/test/package-entry-points.js index 371a815a3..8e73d0af7 100644 --- a/packages/node-resolve/test/package-entry-points.js +++ b/packages/node-resolve/test/package-entry-points.js @@ -413,3 +413,13 @@ test('custom condition takes precedence over browser field with `browser: true`' t.deepEqual(module.exports, 'FROM WEBWORKER CONDITION'); }); + +test('production condition is used by default', async (t) => { + const bundle = await rollup({ + input: 'dev-prod-conditions.js', + plugins: [nodeResolve()] + }); + const { module } = await testBundle(t, bundle); + + t.deepEqual(module.exports, 'DEV'); +});