Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 29, 2022
2 parents d44bdc9 + 3090564 commit bfe604e
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 205 deletions.
2 changes: 1 addition & 1 deletion docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The production bundle assumes support for modern JavaScript. By default, Vite ta

- Chrome >=87
- Firefox >=78
- Safari >=13
- Safari >=14
- Edge >=88

You can specify custom targets via the [`build.target` config option](/config/build-options.md#build-target), where the lowest target is `es2015`.
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@babel/types": "^7.20.5",
"@microsoft/api-extractor": "^7.33.6",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-typescript": "^10.0.1",
"@types/babel__core": "^7.1.20",
"@types/babel__standalone": "^7.1.4",
"@types/convert-source-map": "^1.5.2",
Expand Down Expand Up @@ -122,6 +122,11 @@
"peerDependencies": {
"postcss": "*"
}
},
"acorn-walk": {
"peerDependencies": {
"acorn": "*"
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,35 @@ Repository: https://github.com/acornjs/acorn.git
---------------------------------------

## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Repository: https://github.com/acornjs/acorn.git

> MIT License
>
> Copyright (C) 2012-2020 by various contributors (see AUTHORS)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
---------------------------------------

## ansi-regex
License: MIT
By: Sindre Sorhus
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@
"@rollup/plugin-dynamic-import-vars": "^2.0.1",
"@rollup/plugin-json": "^5.0.2",
"@rollup/plugin-node-resolve": "15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-typescript": "^10.0.1",
"@rollup/pluginutils": "^5.0.2",
"acorn": "^8.8.1",
"acorn-walk": "^8.2.0",
"cac": "^6.7.14",
"chokidar": "^3.5.3",
"connect": "^3.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.b {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.b {
color: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { transformGlobImport } from '../../../plugins/importMetaGlob'
import { transformWithEsbuild } from '../../../plugins/esbuild'
import type { Logger } from '../../../logger'
import { createLogger } from '../../../logger'

const __dirname = resolve(fileURLToPath(import.meta.url), '..')
Expand Down Expand Up @@ -72,4 +73,43 @@ describe('fixture', async () => {
)?.s.toString()
).toMatchSnapshot()
})

it('warn when glob css without ?inline', async () => {
const logs: string[] = []
const logger = {
warn(msg: string) {
logs.push(msg)
}
} as Logger

await transformGlobImport(
"import.meta.glob('./fixture-c/*.css', { query: '?inline' })",
fileURLToPath(import.meta.url),
root,
resolveId,
logger
)
expect(logs).toHaveLength(0)

await transformGlobImport(
"import.meta.glob('./fixture-c/*.module.css')",
fileURLToPath(import.meta.url),
root,
resolveId,
logger
)
expect(logs).toHaveLength(0)

await transformGlobImport(
"import.meta.glob('./fixture-c/*.css')",
fileURLToPath(import.meta.url),
root,
resolveId,
logger
)
expect(logs).toHaveLength(1)
expect(logs[0]).to.include(
'Globbing CSS files without the ?inline query is deprecated'
)
})
})
2 changes: 1 addition & 1 deletion packages/vite/src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ESBUILD_MODULES_TARGET = [
'edge88',
'firefox78',
'chrome87',
'safari13' // transpile nullish coalescing
'safari14'
]

export const DEFAULT_EXTENSIONS = [
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
.join('|') +
// Mustn't be followed by a char that can be part of an identifier
// or an assignment (but allow equality operators)
')(?![\\p{L}\\p{N}_$]|\\s*?=[^=])',
')(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))',
'gu'
)
: null
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
if (
!isDynamicImport &&
specifier &&
!specifier.includes('?') && // ignore custom queries
isCSSRequest(specifier) &&
!isModuleCSSRequest(specifier) &&
!specifier.includes('?') // ignore custom queries
!isModuleCSSRequest(specifier)
) {
const sourceExp = source.slice(expStart, start)
if (
Expand Down
21 changes: 9 additions & 12 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
TemplateLiteral
} from 'estree'
import { parseExpressionAt } from 'acorn'
import { findNodeAt } from 'acorn-walk'
import MagicString from 'magic-string'
import fg from 'fast-glob'
import { stringifyQuery } from 'ufo'
Expand All @@ -29,7 +30,7 @@ import {
transformStableResult
} from '../utils'
import type { Logger } from '../logger'
import { isCSSRequest } from './css'
import { isCSSRequest, isModuleCSSRequest } from './css'

const { isMatch, scan } = micromatch

Expand Down Expand Up @@ -163,15 +164,9 @@ export async function parseImportGlob(
}
}

if (ast.type === 'SequenceExpression')
ast = ast.expressions[0] as CallExpression

// immediate property access, call expression is nested
// import.meta.glob(...)['prop']
if (ast.type === 'MemberExpression') ast = ast.object as CallExpression

if (ast.type !== 'CallExpression')
throw err(`Expect CallExpression, got ${ast.type}`)
const found = findNodeAt(ast as any, start, undefined, 'CallExpression')
if (!found) throw err(`Expect CallExpression, got ${ast.type}`)
ast = found.node as unknown as CallExpression

if (ast.arguments.length < 1 || ast.arguments.length > 2)
throw err(`Expected 1-2 arguments, but got ${ast.arguments.length}`)
Expand Down Expand Up @@ -385,8 +380,10 @@ export async function transformGlobImport(
if (query && !query.startsWith('?')) query = `?${query}`

if (
!query.match(/(?:\?|&)inline\b/) &&
files.some((file) => isCSSRequest(file))
!query && // ignore custom queries
files.some(
(file) => isCSSRequest(file) && !isModuleCSSRequest(file)
)
) {
logger.warn(
`\n` +
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { modulePreloadPolyfillPlugin } from './modulePreloadPolyfill'
import { webWorkerPlugin } from './worker'
import { preAliasPlugin } from './preAlias'
import { definePlugin } from './define'
import { ssrRequireHookPlugin } from './ssrRequireHook'
import { workerImportMetaUrlPlugin } from './workerImportMetaUrl'
import { assetImportMetaUrlPlugin } from './assetImportMetaUrl'
import { ensureWatchPlugin } from './ensureWatch'
Expand Down Expand Up @@ -88,7 +87,6 @@ export async function resolvePlugins(
wasmFallbackPlugin(),
definePlugin(config),
cssPostPlugin(config),
isBuild && config.build.ssr ? ssrRequireHookPlugin(config) : null,
isBuild && buildHtmlPlugin(config),
workerImportMetaUrlPlugin(config),
assetImportMetaUrlPlugin(config),
Expand Down
3 changes: 0 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ export interface InternalResolveOptions extends Required<ResolveOptions> {
// Resolve using esbuild deps optimization
getDepsOptimizer?: (ssr: boolean) => DepsOptimizer | undefined
shouldExternalize?: (id: string) => boolean | undefined
// Check this resolve is called from `hookNodeResolve` in SSR
isHookNodeResolve?: boolean
}

export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
Expand Down Expand Up @@ -689,7 +687,6 @@ export function tryNodeResolve(
// if import can't be found, check if it's an optional peer dep.
// if so, we can resolve to a special id that errors only when imported.
if (
!options.isHookNodeResolve &&
basedir !== root && // root has no peer dep
!isBuiltin(nestedPath) &&
!nestedPath.includes('\0') &&
Expand Down
90 changes: 0 additions & 90 deletions packages/vite/src/node/plugins/ssrRequireHook.ts

This file was deleted.

0 comments on commit bfe604e

Please sign in to comment.