From 71f078a69624b28c44aecc1540f0cad4f0265501 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 15 Oct 2021 00:29:00 +0200 Subject: [PATCH] fix old conditions test `exports` is only supported withing a module directory, so the "fake modules" needs to reside within `node_modules` --- .../__tests__/browser.test.mjs | 2 +- .../__tests__/node.test.mjs | 2 +- .../__tests__/resolveCjs.test.cjs | 2 +- .../__tests__/resolveEsm.test.mjs | 2 +- .../{ => node_modules}/fake-dep/module.cjs | 0 .../{ => node_modules}/fake-dep/module.mjs | 0 .../{ => node_modules}/fake-dep/package.json | 0 .../fake-dual-dep/browser.mjs | 0 .../{ => node_modules}/fake-dual-dep/node.mjs | 0 .../fake-dual-dep/package.json | 0 e2e/resolve-conditions/package.json | 1 - e2e/resolve-conditions/resolver.js | 36 ------------------- 12 files changed, 4 insertions(+), 41 deletions(-) rename e2e/resolve-conditions/{ => node_modules}/fake-dep/module.cjs (100%) rename e2e/resolve-conditions/{ => node_modules}/fake-dep/module.mjs (100%) rename e2e/resolve-conditions/{ => node_modules}/fake-dep/package.json (100%) rename e2e/resolve-conditions/{ => node_modules}/fake-dual-dep/browser.mjs (100%) rename e2e/resolve-conditions/{ => node_modules}/fake-dual-dep/node.mjs (100%) rename e2e/resolve-conditions/{ => node_modules}/fake-dual-dep/package.json (100%) delete mode 100644 e2e/resolve-conditions/resolver.js diff --git a/e2e/resolve-conditions/__tests__/browser.test.mjs b/e2e/resolve-conditions/__tests__/browser.test.mjs index 12b397aa5afc..4edfaa7ffdaa 100644 --- a/e2e/resolve-conditions/__tests__/browser.test.mjs +++ b/e2e/resolve-conditions/__tests__/browser.test.mjs @@ -7,7 +7,7 @@ * @jest-environment /browser-env.js */ -import {fn} from '../fake-dual-dep'; +import {fn} from 'fake-dual-dep'; test('returns correct message', () => { expect(fn()).toEqual('hello from browser'); diff --git a/e2e/resolve-conditions/__tests__/node.test.mjs b/e2e/resolve-conditions/__tests__/node.test.mjs index fb86c2a8eeac..f71ed5a69e2e 100644 --- a/e2e/resolve-conditions/__tests__/node.test.mjs +++ b/e2e/resolve-conditions/__tests__/node.test.mjs @@ -7,7 +7,7 @@ * @jest-environment /node-env.js */ -import {fn} from '../fake-dual-dep'; +import {fn} from 'fake-dual-dep'; test('returns correct message', () => { expect(fn()).toEqual('hello from node'); diff --git a/e2e/resolve-conditions/__tests__/resolveCjs.test.cjs b/e2e/resolve-conditions/__tests__/resolveCjs.test.cjs index 5a9ba6b23b88..43409fed5939 100644 --- a/e2e/resolve-conditions/__tests__/resolveCjs.test.cjs +++ b/e2e/resolve-conditions/__tests__/resolveCjs.test.cjs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -const {fn} = require('../fake-dep'); +const {fn} = require('fake-dep'); test('returns correct message', () => { expect(fn()).toEqual('hello from CJS'); diff --git a/e2e/resolve-conditions/__tests__/resolveEsm.test.mjs b/e2e/resolve-conditions/__tests__/resolveEsm.test.mjs index d46c700f2cf2..2303cef9e418 100644 --- a/e2e/resolve-conditions/__tests__/resolveEsm.test.mjs +++ b/e2e/resolve-conditions/__tests__/resolveEsm.test.mjs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {fn} from '../fake-dep'; +import {fn} from 'fake-dep'; test('returns correct message', () => { expect(fn()).toEqual('hello from ESM'); diff --git a/e2e/resolve-conditions/fake-dep/module.cjs b/e2e/resolve-conditions/node_modules/fake-dep/module.cjs similarity index 100% rename from e2e/resolve-conditions/fake-dep/module.cjs rename to e2e/resolve-conditions/node_modules/fake-dep/module.cjs diff --git a/e2e/resolve-conditions/fake-dep/module.mjs b/e2e/resolve-conditions/node_modules/fake-dep/module.mjs similarity index 100% rename from e2e/resolve-conditions/fake-dep/module.mjs rename to e2e/resolve-conditions/node_modules/fake-dep/module.mjs diff --git a/e2e/resolve-conditions/fake-dep/package.json b/e2e/resolve-conditions/node_modules/fake-dep/package.json similarity index 100% rename from e2e/resolve-conditions/fake-dep/package.json rename to e2e/resolve-conditions/node_modules/fake-dep/package.json diff --git a/e2e/resolve-conditions/fake-dual-dep/browser.mjs b/e2e/resolve-conditions/node_modules/fake-dual-dep/browser.mjs similarity index 100% rename from e2e/resolve-conditions/fake-dual-dep/browser.mjs rename to e2e/resolve-conditions/node_modules/fake-dual-dep/browser.mjs diff --git a/e2e/resolve-conditions/fake-dual-dep/node.mjs b/e2e/resolve-conditions/node_modules/fake-dual-dep/node.mjs similarity index 100% rename from e2e/resolve-conditions/fake-dual-dep/node.mjs rename to e2e/resolve-conditions/node_modules/fake-dual-dep/node.mjs diff --git a/e2e/resolve-conditions/fake-dual-dep/package.json b/e2e/resolve-conditions/node_modules/fake-dual-dep/package.json similarity index 100% rename from e2e/resolve-conditions/fake-dual-dep/package.json rename to e2e/resolve-conditions/node_modules/fake-dual-dep/package.json diff --git a/e2e/resolve-conditions/package.json b/e2e/resolve-conditions/package.json index 987f46111b8a..af0b73eb6223 100644 --- a/e2e/resolve-conditions/package.json +++ b/e2e/resolve-conditions/package.json @@ -6,7 +6,6 @@ "mjs", "json" ], - "resolver": "/resolver.js", "testMatch": [ "/**/*.test.*" ], diff --git a/e2e/resolve-conditions/resolver.js b/e2e/resolve-conditions/resolver.js deleted file mode 100644 index 98c8aed1bf67..000000000000 --- a/e2e/resolve-conditions/resolver.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -'use strict'; - -const {resolve: resolveExports} = require('resolve.exports'); - -module.exports = (path, options) => { - return options.defaultResolver(path, { - ...options, - pathFilter: options.conditions - ? createPathFilter(options.conditions) - : undefined, - }); -}; - -function createPathFilter(conditions) { - return function pathFilter(pkg, _path, relativePath) { - // this `index` thing can backfire, but `resolve` adds it: https://github.com/browserify/resolve/blob/f1b51848ecb7f56f77bfb823511d032489a13eab/lib/sync.js#L192 - const path = relativePath === 'index' ? '.' : relativePath; - - return ( - resolveExports(pkg, path, { - // `resolve.exports adds `node` unless `browser` is `false`, so let's add this ugly thing - browser: conditions.includes('browser'), - conditions, - // `resolve.exports adds `import` unless `require` is `false`, so let's add this ugly thing - require: conditions.includes('require'), - }) || relativePath - ); - }; -}