Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert #7582, fix #7721 and #7736 #7737

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/playground/resolve/__tests__/resolve.spec.ts
Expand Up @@ -61,14 +61,8 @@ test('dont add extension to directory name (./dir-with-ext.js/index.js)', async
expect(await page.textContent('.dir-with-ext')).toMatch('[success]')
})

test('resolve to the `browser` field instead of `module` when the importer is a `require` call', async () => {
expect(
await page.textContent('.require-pkg-with-browser-and-module-field')
).toMatch('[success]')
})

test('resolve to the `main` field instead of `module` when the importer is a `require` call', async () => {
expect(await page.textContent('.require-pkg-with-esm-entries')).toMatch(
test('do not resolve to the `module` field if the importer is a `require` call', async () => {
expect(await page.textContent('.require-pkg-with-module-field')).toMatch(
'[success]'
)
})
Expand Down
20 changes: 4 additions & 16 deletions packages/playground/resolve/index.html
Expand Up @@ -58,17 +58,8 @@ <h2>Resolve file name containing dot</h2>
<h2>Browser Field</h2>
<p class="browser">fail</p>

<h2>
Resolve to the `browser` field instead of `module` when the importer is a
`require` call
</h2>
<p class="require-pkg-with-browser-and-module-field">fail</p>

<h2>
Resolve to the `main` field instead of `module` when the importer is a
`require` call
</h2>
<p class="require-pkg-with-esm-entries">fail</p>
<h2>Don't resolve to the `module` field if the importer is a `require` call</h2>
<p class="require-pkg-with-module-field">fail</p>

<h2>CSS Entry</h2>
<p class="css"></p>
Expand Down Expand Up @@ -194,11 +185,8 @@ <h2>resolve package that contains # in path</h2>
text('.browser', main)
}

import { msg as requireBrowserMsg } from 'require-pkg-with-browser-and-module-field'
text('.require-pkg-with-browser-and-module-field', requireBrowserMsg)

import { msg as requireMainMsg } from 'require-pkg-with-esm-entries'
text('.require-pkg-with-esm-entries', requireMainMsg)
import { msg as requireButWithModuleFieldMsg } from 'require-pkg-with-module-field'
text('.require-pkg-with-module-field', requireButWithModuleFieldMsg)

import { msg as customExtMsg } from './custom-ext'
text('.custom-ext', customExtMsg)
Expand Down
3 changes: 1 addition & 2 deletions packages/playground/resolve/package.json
Expand Up @@ -12,8 +12,7 @@
"@babel/runtime": "^7.16.0",
"es5-ext": "0.10.53",
"normalize.css": "^8.0.1",
"require-pkg-with-browser-and-module-field": "link:./require-pkg-with-browser-and-module-field",
"require-pkg-with-esm-entries": "link:./require-pkg-with-esm-entries",
"require-pkg-with-module-field": "link:./require-pkg-with-module-field",
"resolve-browser-field": "link:./browser-field",
"resolve-custom-condition": "link:./custom-condition",
"resolve-custom-main-field": "link:./custom-main-field",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,8 @@
const dep = require('./dep.cjs')

const msg =
dep === '1.111222233334444555566e+21'
? '[success] require-pkg-with-module-field'
: '[failed] require-pkg-with-module-field'

exports.msg = msg
@@ -1,5 +1,5 @@
{
"name": "require-pkg-with-browser-and-module-field",
"name": "require-pkg-with-module-field",
"private": true,
"version": "1.0.0",
"main": "./index.cjs",
Expand Down
5 changes: 1 addition & 4 deletions packages/playground/resolve/vite.config.js
Expand Up @@ -42,9 +42,6 @@ module.exports = {
}
],
optimizeDeps: {
include: [
'require-pkg-with-browser-and-module-field',
'require-pkg-with-esm-entries'
]
include: ['require-pkg-with-module-field']
}
}
15 changes: 0 additions & 15 deletions packages/vite/src/node/constants.ts
Expand Up @@ -6,21 +6,6 @@ export const DEFAULT_MAIN_FIELDS = [
'jsnext'
]

/**
* A non-exhaustive list of known-to-be-ES-module entry names.
* From <https://github.com/stereobooster/package.json#package-bundlers>
*/
export const KNOWN_ESM_MAIN_FIELDS = [
'module',
'jsnext:main',
'jsnext',
'esnext',
'es2015',
'es2020',
'fesm2015',
'fesm2020'
]

export const DEFAULT_EXTENSIONS = [
'.mjs',
'.js',
Expand Down
6 changes: 0 additions & 6 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -7,7 +7,6 @@ import {
SPECIAL_QUERY_RE,
DEFAULT_EXTENSIONS,
DEFAULT_MAIN_FIELDS,
KNOWN_ESM_MAIN_FIELDS,
OPTIMIZABLE_ENTRY_RE,
DEP_VERSION_RE
} from '../constants'
Expand Down Expand Up @@ -778,11 +777,6 @@ export function resolvePackageEntry(

if (!entryPoint || entryPoint.endsWith('.mjs')) {
for (const field of options.mainFields || DEFAULT_MAIN_FIELDS) {
// If the initiator is a `require` call, don't use the ESM entries
if (options.isRequire && KNOWN_ESM_MAIN_FIELDS.includes(field)) {
continue
}

if (typeof data[field] === 'string') {
entryPoint = data[field]
break
Expand Down
24 changes: 3 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.