From c08bd72ff4f0dd32d4ff95ad381ebb141f91b9e3 Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 10 Sep 2024 18:37:09 +0200 Subject: [PATCH 01/16] chore(deps): add `tinyglobby` in `packages/vite` --- packages/vite/package.json | 1 + pnpm-lock.yaml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/packages/vite/package.json b/packages/vite/package.json index c2ef6d5321e16d..5bce034a2d2173 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -148,6 +148,7 @@ "source-map-support": "^0.5.21", "strip-ansi": "^7.1.0", "strip-literal": "^2.1.0", + "tinyglobby": "^0.2.6", "tsconfck": "^3.1.3", "tslib": "^2.7.0", "types": "link:./types", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d91b28a7751e13..37c3f85cf50320 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -403,6 +403,9 @@ importers: strip-literal: specifier: ^2.1.0 version: 2.1.0 + tinyglobby: + specifier: ^0.2.6 + version: 0.2.6 tsconfck: specifier: ^3.1.3 version: 3.1.3(typescript@5.5.3) @@ -4708,6 +4711,14 @@ packages: picomatch: optional: true + fdir@6.3.0: + resolution: {integrity: sha512-QOnuT+BOtivR77wYvCWHfGt9s4Pz1VIMbD463vegT5MLqNXy8rYFT/lPVEqf/bhYeT6qmqrNHhsX+rWwe3rOCQ==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + feed@4.2.2: resolution: {integrity: sha512-u5/sxGfiMfZNtJ3OvQpXcvotFpYkL0n9u9mM2vkui2nGo8b4wvDkJ8gAkYqbA8QpGyFCv3RK0Z+Iv+9veCS9bQ==} engines: {node: '>=0.4.0'} @@ -5851,6 +5862,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pidtree@0.6.0: resolution: {integrity: sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==} engines: {node: '>=0.10'} @@ -6646,6 +6661,10 @@ packages: tinybench@2.8.0: resolution: {integrity: sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==} + tinyglobby@0.2.6: + resolution: {integrity: sha512-NbBoFBpqfcgd1tCiO8Lkfdk+xrA7mlLR9zgvZcZWQQwU63XAfUePyd6wZBaU93Hqw347lHnwFzttAkemHzzz4g==} + engines: {node: '>=12.0.0'} + tinypool@1.0.0: resolution: {integrity: sha512-KIKExllK7jp3uvrNtvRBYBWBOAXSX8ZvoaD8T+7KB/QHIuoJW3Pmr60zucywjAlMb5TeXUkcs/MWeWLu0qvuAQ==} engines: {node: ^18.0.0 || >=20.0.0} @@ -10372,6 +10391,10 @@ snapshots: optionalDependencies: picomatch: 2.3.1 + fdir@6.3.0(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + feed@4.2.2: dependencies: xml-js: 1.6.11 @@ -11598,6 +11621,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pidtree@0.6.0: {} pify@2.3.0: {} @@ -12464,6 +12489,11 @@ snapshots: tinybench@2.8.0: {} + tinyglobby@0.2.6: + dependencies: + fdir: 6.3.0(picomatch@4.0.2) + picomatch: 4.0.2 + tinypool@1.0.0: {} tinyrainbow@1.2.0: {} From 3f4a699e1fb1124d5c2253c97ef184dac0d41c7a Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 10 Sep 2024 18:56:57 +0200 Subject: [PATCH 02/16] chore(deps): replace `fast-glob` with `tinyglobby` Only two files changed in this commit as we need to wait for `tinyglobby` to support some currently unsupported options. --- packages/vite/src/node/optimizer/resolve.ts | 20 +++++++++++--------- packages/vite/src/node/server/warmup.ts | 5 +++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/optimizer/resolve.ts b/packages/vite/src/node/optimizer/resolve.ts index 43cf52cd41467f..46c9df6370c779 100644 --- a/packages/vite/src/node/optimizer/resolve.ts +++ b/packages/vite/src/node/optimizer/resolve.ts @@ -1,6 +1,6 @@ import path from 'node:path' -import glob from 'fast-glob' import micromatch from 'micromatch' +import { globSync } from 'tinyglobby' import type { ResolvedConfig } from '../config' import { escapeRegex, getNpmPackageName } from '../utils' import { resolvePackageData } from '../packages' @@ -89,11 +89,11 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { ) possibleExportPaths.push( - ...glob - .sync(exportValuePattern, { - cwd: pkgData.dir, - ignore: ['node_modules'], - }) + ...globSync([exportValuePattern], { + cwd: pkgData.dir, + expandDirectories: false, + ignore: ['node_modules'], + }) .map((filePath) => { // ensure "./" prefix for inconsistent fast-glob result // glob.sync("./some-dir/**/*") -> "./some-dir/some-file" @@ -146,9 +146,11 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { return matched } else { // for packages without exports, we can do a simple glob - const matched = glob - .sync(pattern, { cwd: pkgData.dir, ignore: ['node_modules'] }) - .map((match) => path.posix.join(pkgName, slash(match))) + const matched = globSync([pattern], { + cwd: pkgData.dir, + expandDirectories: false, + ignore: ['node_modules'], + }).map((match) => path.posix.join(pkgName, slash(match))) matched.unshift(pkgName) return matched } diff --git a/packages/vite/src/node/server/warmup.ts b/packages/vite/src/node/server/warmup.ts index 9ef04c95af0610..8c8e300a0ccfdc 100644 --- a/packages/vite/src/node/server/warmup.ts +++ b/packages/vite/src/node/server/warmup.ts @@ -1,7 +1,7 @@ import fs from 'node:fs/promises' import path from 'node:path' -import glob from 'fast-glob' import colors from 'picocolors' +import { glob } from 'tinyglobby' import { FS_PREFIX } from '../constants' import { normalizePath } from '../utils' import type { ViteDevServer } from '../index' @@ -71,7 +71,8 @@ function fileToUrl(file: string, root: string) { function mapFiles(files: string[], root: string) { return glob(files, { - cwd: root, absolute: true, + cwd: root, + expandDirectories: false, }) } From 2fb69ab66b862b12c5b01fa7b0f2a201bb1aa440 Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 10 Sep 2024 19:03:07 +0200 Subject: [PATCH 03/16] chore(deps): use `tinyglobby` in `be-integration` --- playground/backend-integration/package.json | 2 +- playground/backend-integration/vite.config.js | 9 +++++---- pnpm-lock.yaml | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index 4cb65200886625..33837436f88ccc 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -12,6 +12,6 @@ "devDependencies": { "sass": "^1.78.0", "tailwindcss": "^3.4.10", - "fast-glob": "^3.3.2" + "tinyglobby": "^0.2.6" } } diff --git a/playground/backend-integration/vite.config.js b/playground/backend-integration/vite.config.js index d4714288cb0e68..d9dba72adfc906 100644 --- a/playground/backend-integration/vite.config.js +++ b/playground/backend-integration/vite.config.js @@ -1,5 +1,5 @@ import path from 'node:path' -import glob from 'fast-glob' +import { globSync } from 'tinyglobby' import { defineConfig, normalizePath } from 'vite' /** @@ -14,9 +14,10 @@ function BackendIntegrationExample() { const root = path.join(sourceCodeDir, 'entrypoints') const outDir = path.relative(root, path.join(projectRoot, 'dist/dev')) - const entrypoints = glob - .sync(`${normalizePath(root)}/**/*`, { onlyFiles: true }) - .map((filename) => [path.relative(root, filename), filename]) + const entrypoints = globSync([`${normalizePath(root)}/**/*`], { + expandDirectories: false, + onlyFiles: true, + }).map((filename) => [path.relative(root, filename), filename]) entrypoints.push(['tailwindcss-colors', 'tailwindcss/colors.js']) entrypoints.push(['bar.css', path.resolve(__dirname, './dir/foo.css')]) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 37c3f85cf50320..37c6a272e98a9b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -505,15 +505,15 @@ importers: playground/backend-integration: devDependencies: - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 sass: specifier: ^1.78.0 version: 1.78.0 tailwindcss: specifier: ^3.4.10 version: 3.4.10(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.3)) + tinyglobby: + specifier: ^0.2.6 + version: 0.2.6 playground/build-old: {} From 90cc40607377ab90b461887b98088d642f6d2713 Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 10 Sep 2024 19:09:07 +0200 Subject: [PATCH 04/16] chore(deps): use `tinyglobby` in `playground/css` --- playground/css/package.json | 4 ++-- playground/css/postcss.config.js | 4 ++-- pnpm-lock.yaml | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/playground/css/package.json b/playground/css/package.json index ea4992ee3552e7..4d6796951b4378 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -21,12 +21,12 @@ "@vitejs/test-css-js-dep": "file:./css-js-dep", "@vitejs/test-css-proxy-dep": "file:./css-proxy-dep", "@vitejs/test-scss-proxy-dep": "file:./scss-proxy-dep", - "fast-glob": "^3.3.2", "less": "^4.2.0", "postcss-nested": "^6.2.0", "sass": "^1.78.0", "stylus": "^0.63.0", - "sugarss": "^4.0.1" + "sugarss": "^4.0.1", + "tinyglobby": "^0.2.6" }, "imports": { "#imports": "./imports-field.css" diff --git a/playground/css/postcss.config.js b/playground/css/postcss.config.js index 4d2c144b9fa66c..e0fea600e18818 100644 --- a/playground/css/postcss.config.js +++ b/playground/css/postcss.config.js @@ -1,6 +1,6 @@ import fs from 'node:fs' import path from 'node:path' -import glob from 'fast-glob' +import { globSync } from 'tinyglobby' import { normalizePath } from 'vite' import postcssNested from 'postcss-nested' @@ -19,7 +19,7 @@ function testDirDep() { const pattern = normalizePath( path.resolve(path.dirname(result.opts.from), './glob-dep/**/*.css'), ) - const files = glob.sync(pattern) + const files = globSync([pattern], { expandDirectories: false }) const text = files.map((f) => fs.readFileSync(f, 'utf-8')).join('\n') atRule.parent.insertAfter(atRule, text) atRule.remove() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 37c6a272e98a9b..e26e91192b6553 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -561,9 +561,6 @@ importers: '@vitejs/test-scss-proxy-dep': specifier: file:./scss-proxy-dep version: file:playground/css/scss-proxy-dep - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 less: specifier: ^4.2.0 version: 4.2.0 @@ -579,6 +576,9 @@ importers: sugarss: specifier: ^4.0.1 version: 4.0.1(postcss@8.4.45) + tinyglobby: + specifier: ^0.2.6 + version: 0.2.6 playground/css-codesplit: {} From 7c04f36cce2b3941214f90169745dde427b642f5 Mon Sep 17 00:00:00 2001 From: ziebam Date: Mon, 30 Sep 2024 15:21:28 +0200 Subject: [PATCH 05/16] chore(deps): bump `tinyglobby` to 0.2.7 --- packages/vite/package.json | 2 +- playground/backend-integration/package.json | 2 +- playground/css/package.json | 2 +- pnpm-lock.yaml | 26 ++++++++++----------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 9f6420a6b4ec15..9926b3bbdda7a8 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -148,7 +148,7 @@ "source-map-support": "^0.5.21", "strip-ansi": "^7.1.0", "strip-literal": "^2.1.0", - "tinyglobby": "^0.2.6", + "tinyglobby": "^0.2.7", "tsconfck": "^3.1.3", "tslib": "^2.7.0", "types": "link:./types", diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index b5368f709b12dc..f68cf8eb69591c 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -12,6 +12,6 @@ "devDependencies": { "sass": "^1.79.4", "tailwindcss": "^3.4.13", - "tinyglobby": "^0.2.6" + "tinyglobby": "^0.2.7" } } diff --git a/playground/css/package.json b/playground/css/package.json index 0b5ca69967226e..29729bec9cafe8 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -26,7 +26,7 @@ "sass": "^1.79.4", "stylus": "^0.63.0", "sugarss": "^4.0.1", - "tinyglobby": "^0.2.6" + "tinyglobby": "^0.2.7" }, "imports": { "#imports": "./imports-field.css" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de2f81eddd0e9f..76cf63b3a04d6b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -404,8 +404,8 @@ importers: specifier: ^2.1.0 version: 2.1.0 tinyglobby: - specifier: ^0.2.6 - version: 0.2.6 + specifier: ^0.2.7 + version: 0.2.7 tsconfck: specifier: ^3.1.3 version: 3.1.3(typescript@5.5.3) @@ -512,8 +512,8 @@ importers: specifier: ^3.4.13 version: 3.4.13(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.5.3)) tinyglobby: - specifier: ^0.2.6 - version: 0.2.6 + specifier: ^0.2.7 + version: 0.2.7 playground/build-old: {} @@ -577,8 +577,8 @@ importers: specifier: ^4.0.1 version: 4.0.1(postcss@8.4.47) tinyglobby: - specifier: ^0.2.6 - version: 0.2.6 + specifier: ^0.2.7 + version: 0.2.7 playground/css-codesplit: {} @@ -4791,8 +4791,8 @@ packages: picomatch: optional: true - fdir@6.3.0: - resolution: {integrity: sha512-QOnuT+BOtivR77wYvCWHfGt9s4Pz1VIMbD463vegT5MLqNXy8rYFT/lPVEqf/bhYeT6qmqrNHhsX+rWwe3rOCQ==} + fdir@6.4.0: + resolution: {integrity: sha512-3oB133prH1o4j/L5lLW7uOCF1PlD+/It2L0eL/iAqWMB91RBbqTewABqxhj0ibBd90EEmWZq7ntIWzVaWcXTGQ==} peerDependencies: picomatch: ^3 || ^4 peerDependenciesMeta: @@ -6762,8 +6762,8 @@ packages: tinyexec@0.3.0: resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==} - tinyglobby@0.2.6: - resolution: {integrity: sha512-NbBoFBpqfcgd1tCiO8Lkfdk+xrA7mlLR9zgvZcZWQQwU63XAfUePyd6wZBaU93Hqw347lHnwFzttAkemHzzz4g==} + tinyglobby@0.2.7: + resolution: {integrity: sha512-qFWYeNxBQxrOTRHvGjlRdBamy8JFqu6c0bwRru9leE+q8J72tLtlT0L3v+2T7fbLXN7FGzDNBhXkWiJqHUHD9g==} engines: {node: '>=12.0.0'} tinypool@1.0.0: @@ -10541,7 +10541,7 @@ snapshots: optionalDependencies: picomatch: 2.3.1 - fdir@6.3.0(picomatch@4.0.2): + fdir@6.4.0(picomatch@4.0.2): optionalDependencies: picomatch: 4.0.2 @@ -12662,9 +12662,9 @@ snapshots: tinyexec@0.3.0: {} - tinyglobby@0.2.6: + tinyglobby@0.2.7: dependencies: - fdir: 6.3.0(picomatch@4.0.2) + fdir: 6.4.0(picomatch@4.0.2) picomatch: 4.0.2 tinypool@1.0.0: {} From 28a4b52b7cea65ff459daab8dd4268e2fd4bbddf Mon Sep 17 00:00:00 2001 From: ziebam Date: Mon, 30 Sep 2024 15:46:02 +0200 Subject: [PATCH 06/16] chore(deps): update the first glob argument --- packages/vite/src/node/optimizer/resolve.ts | 4 ++-- playground/backend-integration/vite.config.js | 2 +- playground/css/postcss.config.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/optimizer/resolve.ts b/packages/vite/src/node/optimizer/resolve.ts index 46c9df6370c779..3759d722e94b42 100644 --- a/packages/vite/src/node/optimizer/resolve.ts +++ b/packages/vite/src/node/optimizer/resolve.ts @@ -89,7 +89,7 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { ) possibleExportPaths.push( - ...globSync([exportValuePattern], { + ...globSync(exportValuePattern, { cwd: pkgData.dir, expandDirectories: false, ignore: ['node_modules'], @@ -146,7 +146,7 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { return matched } else { // for packages without exports, we can do a simple glob - const matched = globSync([pattern], { + const matched = globSync(pattern, { cwd: pkgData.dir, expandDirectories: false, ignore: ['node_modules'], diff --git a/playground/backend-integration/vite.config.js b/playground/backend-integration/vite.config.js index d9dba72adfc906..3ec36e7cfc1070 100644 --- a/playground/backend-integration/vite.config.js +++ b/playground/backend-integration/vite.config.js @@ -14,7 +14,7 @@ function BackendIntegrationExample() { const root = path.join(sourceCodeDir, 'entrypoints') const outDir = path.relative(root, path.join(projectRoot, 'dist/dev')) - const entrypoints = globSync([`${normalizePath(root)}/**/*`], { + const entrypoints = globSync(`${normalizePath(root)}/**/*`, { expandDirectories: false, onlyFiles: true, }).map((filename) => [path.relative(root, filename), filename]) diff --git a/playground/css/postcss.config.js b/playground/css/postcss.config.js index e0fea600e18818..54107e641abefb 100644 --- a/playground/css/postcss.config.js +++ b/playground/css/postcss.config.js @@ -19,7 +19,7 @@ function testDirDep() { const pattern = normalizePath( path.resolve(path.dirname(result.opts.from), './glob-dep/**/*.css'), ) - const files = globSync([pattern], { expandDirectories: false }) + const files = globSync(pattern, { expandDirectories: false }) const text = files.map((f) => fs.readFileSync(f, 'utf-8')).join('\n') atRule.parent.insertAfter(atRule, text) atRule.remove() From 70ffc047cd1a41744a4e9453b8e98393ab41dd2c Mon Sep 17 00:00:00 2001 From: ziebam Date: Mon, 30 Sep 2024 16:20:13 +0200 Subject: [PATCH 07/16] chore(deps): migrate remaining `fast-glob` usages --- packages/vite/package.json | 1 - packages/vite/src/node/optimizer/index.ts | 8 ++++---- packages/vite/src/node/optimizer/resolve.ts | 11 +---------- packages/vite/src/node/optimizer/scan.ts | 7 +++---- packages/vite/src/node/plugins/css.ts | 7 ++++--- packages/vite/src/node/plugins/importMetaGlob.ts | 10 +++++----- packages/vite/src/node/watch.ts | 6 +++--- pnpm-lock.yaml | 3 --- 8 files changed, 20 insertions(+), 33 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 9926b3bbdda7a8..dceead2cd578b9 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -120,7 +120,6 @@ "escape-html": "^1.0.3", "estree-walker": "^3.0.3", "etag": "^1.8.1", - "fast-glob": "^3.3.2", "http-proxy": "^1.18.1", "launch-editor-middleware": "^2.9.1", "lightningcss": "^1.27.0", diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index b156a38c6a6bc3..3de6a04367b3ab 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -7,7 +7,7 @@ import colors from 'picocolors' import type { BuildContext, BuildOptions as EsbuildBuildOptions } from 'esbuild' import esbuild, { build } from 'esbuild' import { init, parse } from 'es-module-lexer' -import glob from 'fast-glob' +import { isDynamicPattern } from 'tinyglobby' import type { ResolvedConfig } from '../config' import { createDebugger, @@ -151,8 +151,8 @@ export type DepOptimizationOptions = DepOptimizationConfig & { * will crawl those entry points instead. * * If neither of these fit your needs, you can specify custom entries using - * this option - the value should be a fast-glob pattern or array of patterns - * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from + * this option - the value should be a tinyglobby pattern or array of patterns + * (https://github.com/SuperchupuDev/tinyglobby) that are relative from * vite project root. This will overwrite default entries inference. */ entries?: string | string[] @@ -826,7 +826,7 @@ export async function addManuallyIncludedOptimizeDeps( const includes = [...optimizeDepsInclude] for (let i = 0; i < includes.length; i++) { const id = includes[i] - if (glob.isDynamicPattern(id)) { + if (isDynamicPattern(id)) { const globIds = expandGlobIds(id, environment.getTopLevelConfig()) includes.splice(i, 1, ...globIds) i += globIds.length - 1 diff --git a/packages/vite/src/node/optimizer/resolve.ts b/packages/vite/src/node/optimizer/resolve.ts index 3759d722e94b42..620b80b4cad9d6 100644 --- a/packages/vite/src/node/optimizer/resolve.ts +++ b/packages/vite/src/node/optimizer/resolve.ts @@ -79,6 +79,7 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { const exportsValue = getFirstExportStringValue(exports[key]) if (!exportsValue) continue + // TODO: Raise during the PR review. // "./dist/glob/*-browser/*.js" => "./dist/glob/**/*-browser/**/*.js" // NOTE: in some cases, this could expand to consecutive /**/*/**/* etc // but it's fine since fast-glob handles it the same. @@ -95,16 +96,6 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { ignore: ['node_modules'], }) .map((filePath) => { - // ensure "./" prefix for inconsistent fast-glob result - // glob.sync("./some-dir/**/*") -> "./some-dir/some-file" - // glob.sync("./**/*") -> "some-dir/some-file" - if ( - exportsValue.startsWith('./') && - !filePath.startsWith('./') - ) { - filePath = './' + filePath - } - // "./glob/*": "./dist/glob/*-browser/*.js" // `filePath`: "./dist/glob/foo-browser/foo.js" // we need to revert the file path back to the export key by diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 90298b8d21070a..4eb6dd883b891a 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -2,7 +2,6 @@ import fs from 'node:fs' import fsp from 'node:fs/promises' import path from 'node:path' import { performance } from 'node:perf_hooks' -import glob from 'fast-glob' import type { BuildContext, Loader, @@ -13,6 +12,7 @@ import type { import esbuild, { formatMessages, transform } from 'esbuild' import type { PartialResolvedId } from 'rollup' import colors from 'picocolors' +import { glob, isDynamicPattern } from 'tinyglobby' import { CSS_LANGS_RE, JS_TYPES_RE, @@ -332,12 +332,13 @@ function orderedDependencies(deps: Record) { function globEntries(pattern: string | string[], environment: ScanEnvironment) { const resolvedPatterns = arraify(pattern) - if (resolvedPatterns.every((str) => !glob.isDynamicPattern(str))) { + if (resolvedPatterns.every((str) => !isDynamicPattern(str))) { return resolvedPatterns.map((p) => normalizePath(path.resolve(environment.config.root, p)), ) } return glob(pattern, { + absolute: true, cwd: environment.config.root, ignore: [ '**/node_modules/**', @@ -347,8 +348,6 @@ function globEntries(pattern: string | string[], environment: ScanEnvironment) { ? [] : [`**/__tests__/**`, `**/coverage/**`]), ], - absolute: true, - suppressErrors: true, // suppress EACCES errors }) } diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index faa5f10e8146c1..dfdd5878e5504a 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -3,7 +3,6 @@ import fsp from 'node:fs/promises' import path from 'node:path' import { createRequire } from 'node:module' import { fileURLToPath, pathToFileURL } from 'node:url' -import glob from 'fast-glob' import postcssrc from 'postcss-load-config' import type { ExistingRawSourceMap, @@ -27,6 +26,7 @@ import type { TransformOptions } from 'esbuild' import { formatMessages, transform } from 'esbuild' import type { RawSourceMap } from '@ampproject/remapping' import { WorkerWithFallback } from 'artichokie' +import { escapePath, globSync } from 'tinyglobby' import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' import type { EnvironmentModuleNode } from '../server/moduleGraph' import { @@ -1406,10 +1406,11 @@ async function compileCSS( // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies const { dir, glob: globPattern = '**' } = message const pattern = - glob.escapePath(normalizePath(path.resolve(path.dirname(id), dir))) + + escapePath(normalizePath(path.resolve(path.dirname(id), dir))) + `/` + globPattern - const files = glob.sync(pattern, { + const files = globSync(pattern, { + expandDirectories: false, ignore: ['**/node_modules/**'], }) for (let i = 0; i < files.length; i++) { diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 991393f5aa6b54..6c50e44b4ded8d 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -12,10 +12,10 @@ import type { } from 'estree' import type { CustomPluginOptions, RollupAstNode, RollupError } from 'rollup' import MagicString from 'magic-string' -import fg from 'fast-glob' import { stringifyQuery } from 'ufo' import type { GeneralImportGlobOptions } from 'types/importGlob' import { parseAstAsync } from 'rollup/parseAst' +import { escapePath, glob } from 'tinyglobby' import type { Plugin } from '../plugin' import type { EnvironmentModuleNode } from '../server/moduleGraph' import type { ResolvedConfig } from '../config' @@ -396,10 +396,11 @@ export async function transformGlobImport( async ({ globsResolved, isRelative, options, index, start, end }) => { const cwd = getCommonBase(globsResolved) ?? root const files = ( - await fg(globsResolved, { - cwd, + await glob(globsResolved, { absolute: true, + cwd, dot: !!options.exhaustive, + expandDirectories: false, ignore: options.exhaustive ? [] : [join(cwd, '**/node_modules/**')], @@ -515,8 +516,7 @@ type IdResolver = ( function globSafePath(path: string) { // slash path to ensure \ is converted to / as \ could lead to a double escape scenario - // see https://github.com/mrmlnc/fast-glob#advanced-syntax - return fg.escapePath(normalizePath(path)) + return escapePath(normalizePath(path)) } function lastNthChar(str: string, n: number) { diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index cff92ce2f0f198..d47916d8874289 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -1,9 +1,9 @@ import { EventEmitter } from 'node:events' import path from 'node:path' -import glob from 'fast-glob' import type { FSWatcher, WatchOptions } from 'dep-types/chokidar' import type { OutputOptions } from 'rollup' import colors from 'picocolors' +import { escapePath } from 'tinyglobby' import { withTrailingSlash } from '../shared/utils' import { arraify, normalizePath } from './utils' import type { Logger } from './logger' @@ -59,12 +59,12 @@ export function resolveChokidarOptions( '**/.git/**', '**/node_modules/**', '**/test-results/**', // Playwright - glob.escapePath(cacheDir) + '/**', + escapePath(cacheDir) + '/**', ...arraify(ignoredList || []), ] if (emptyOutDir) { ignored.push( - ...[...resolvedOutDirs].map((outDir) => glob.escapePath(outDir) + '/**'), + ...[...resolvedOutDirs].map((outDir) => escapePath(outDir) + '/**'), ) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76cf63b3a04d6b..d175fb3aa81339 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -319,9 +319,6 @@ importers: etag: specifier: ^1.8.1 version: 1.8.1 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 http-proxy: specifier: ^1.18.1 version: 1.18.1(patch_hash=qqiqxx62zlcu62nljjmhlvexni)(debug@4.3.7) From 21e759e7ab26f472c191572c5ce7bfe815622ef5 Mon Sep 17 00:00:00 2001 From: ziebam Date: Mon, 30 Sep 2024 16:21:46 +0200 Subject: [PATCH 08/16] chore(deps): update `fast-glob` references in docs --- docs/config/dep-optimization-options.md | 2 +- docs/config/server-options.md | 2 +- docs/guide/features.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/config/dep-optimization-options.md b/docs/config/dep-optimization-options.md index 43152b738e483d..ba8bbbc027401b 100644 --- a/docs/config/dep-optimization-options.md +++ b/docs/config/dep-optimization-options.md @@ -8,7 +8,7 @@ By default, Vite will crawl all your `.html` files to detect dependencies that need to be pre-bundled (ignoring `node_modules`, `build.outDir`, `__tests__` and `coverage`). If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead. -If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. If you don't want to ignore `node_modules` and `build.outDir`, you can specify using literal string paths (without fast-glob patterns) instead. +If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://github.com/SuperchupuDev/tinyglobby) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. If you don't want to ignore `node_modules` and `build.outDir`, you can specify using literal string paths (without `tinyglobby` patterns) instead. ## optimizeDeps.exclude diff --git a/docs/config/server-options.md b/docs/config/server-options.md index eaf63a45a71443..817c5aa1367d80 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -184,7 +184,7 @@ The error that appears in the Browser when the fallback happens can be ignored. Warm up files to transform and cache the results in advance. This improves the initial page load during server starts and prevents transform waterfalls. -`clientFiles` are files that are used in the client only, while `ssrFiles` are files that are used in SSR only. They accept an array of file paths or [`fast-glob`](https://github.com/mrmlnc/fast-glob) patterns relative to the `root`. +`clientFiles` are files that are used in the client only, while `ssrFiles` are files that are used in SSR only. They accept an array of file paths or [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) patterns relative to the `root`. Make sure to only add files that are frequently used to not overload the Vite dev server on startup. diff --git a/docs/guide/features.md b/docs/guide/features.md index 2decd3b0b93eaf..c962f783c93522 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -542,7 +542,7 @@ Note that: - This is a Vite-only feature and is not a web or ES standard. - The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root) or an alias path (see [`resolve.alias` option](/config/shared-options.md#resolve-alias)). -- The glob matching is done via [`fast-glob`](https://github.com/mrmlnc/fast-glob) - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax). +- The glob matching is done via [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby). - You should also be aware that all the arguments in the `import.meta.glob` must be **passed as literals**. You can NOT use variables or expressions in them. ## Dynamic Import From 24a808afe4059e88d236e8614431301be4ce078e Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 1 Oct 2024 02:34:34 +0200 Subject: [PATCH 09/16] chore(deps): fix failing tests --- packages/vite/LICENSE.md | 44 +++++++++++++++++++++ packages/vite/package.json | 2 +- packages/vite/src/node/optimizer/resolve.ts | 7 ++++ packages/vite/src/node/plugins/css.ts | 1 + playground/backend-integration/package.json | 2 +- playground/css/package.json | 2 +- pnpm-lock.yaml | 18 ++++----- 7 files changed, 64 insertions(+), 12 deletions(-) diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 8bebd20a00e112..70bd797e83771b 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -1385,6 +1385,21 @@ Repository: git+https://github.com/mcollina/fastq.git --------------------------------------- +## fdir +License: MIT +By: thecodrr +Repository: git+https://github.com/thecodrr/fdir.git + +> Copyright 2023 Abdullah Atta +> +> 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. + +--------------------------------------- + ## fill-range License: MIT By: Jon Schlinkert, Edo Rivai, Paul Miller, Rouven Weßling @@ -3092,6 +3107,35 @@ Repository: git+https://github.com/antfu/strip-literal.git --------------------------------------- +## tinyglobby +License: MIT +By: Superchupu +Repository: git+https://github.com/SuperchupuDev/tinyglobby.git + +> MIT License +> +> Copyright (c) 2024 Madeline Gurriarán +> +> 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. + +--------------------------------------- + ## to-regex-range License: MIT By: Jon Schlinkert, Rouven Weßling diff --git a/packages/vite/package.json b/packages/vite/package.json index dceead2cd578b9..e1d3f4c92cc6d6 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -147,7 +147,7 @@ "source-map-support": "^0.5.21", "strip-ansi": "^7.1.0", "strip-literal": "^2.1.0", - "tinyglobby": "^0.2.7", + "tinyglobby": "^0.2.8", "tsconfck": "^3.1.3", "tslib": "^2.7.0", "types": "link:./types", diff --git a/packages/vite/src/node/optimizer/resolve.ts b/packages/vite/src/node/optimizer/resolve.ts index 620b80b4cad9d6..36723f56b738b2 100644 --- a/packages/vite/src/node/optimizer/resolve.ts +++ b/packages/vite/src/node/optimizer/resolve.ts @@ -96,6 +96,13 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { ignore: ['node_modules'], }) .map((filePath) => { + // `tinyglobby` returns paths as they are formatted by the underlying `fdir`. + // Both `globSync("./some-dir/**/*")` and `globSync("./**/*")` result in + // `"some-dir/somefile"` being returned, so we ensure the correct prefix manually. + if (exportsValue.startsWith('./')) { + filePath = './' + filePath + } + // "./glob/*": "./dist/glob/*-browser/*.js" // `filePath`: "./dist/glob/foo-browser/foo.js" // we need to revert the file path back to the export key by diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index dfdd5878e5504a..198cf1ecb9164c 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1410,6 +1410,7 @@ async function compileCSS( `/` + globPattern const files = globSync(pattern, { + absolute: true, expandDirectories: false, ignore: ['**/node_modules/**'], }) diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index f68cf8eb69591c..24634348c64670 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -12,6 +12,6 @@ "devDependencies": { "sass": "^1.79.4", "tailwindcss": "^3.4.13", - "tinyglobby": "^0.2.7" + "tinyglobby": "^0.2.8" } } diff --git a/playground/css/package.json b/playground/css/package.json index 29729bec9cafe8..d3e0b989e2e2b0 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -26,7 +26,7 @@ "sass": "^1.79.4", "stylus": "^0.63.0", "sugarss": "^4.0.1", - "tinyglobby": "^0.2.7" + "tinyglobby": "^0.2.8" }, "imports": { "#imports": "./imports-field.css" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d175fb3aa81339..314059728658c8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -401,8 +401,8 @@ importers: specifier: ^2.1.0 version: 2.1.0 tinyglobby: - specifier: ^0.2.7 - version: 0.2.7 + specifier: ^0.2.8 + version: 0.2.8 tsconfck: specifier: ^3.1.3 version: 3.1.3(typescript@5.5.3) @@ -509,8 +509,8 @@ importers: specifier: ^3.4.13 version: 3.4.13(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.5.3)) tinyglobby: - specifier: ^0.2.7 - version: 0.2.7 + specifier: ^0.2.8 + version: 0.2.8 playground/build-old: {} @@ -574,8 +574,8 @@ importers: specifier: ^4.0.1 version: 4.0.1(postcss@8.4.47) tinyglobby: - specifier: ^0.2.7 - version: 0.2.7 + specifier: ^0.2.8 + version: 0.2.8 playground/css-codesplit: {} @@ -6759,8 +6759,8 @@ packages: tinyexec@0.3.0: resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==} - tinyglobby@0.2.7: - resolution: {integrity: sha512-qFWYeNxBQxrOTRHvGjlRdBamy8JFqu6c0bwRru9leE+q8J72tLtlT0L3v+2T7fbLXN7FGzDNBhXkWiJqHUHD9g==} + tinyglobby@0.2.8: + resolution: {integrity: sha512-AMLZywN0vbhiZi2neFEaj9VIIxC+PjDMsp0nAK6tpR86LJavZgHqGz0S/FOONwBygC+mu7R0/TyAQw0gx0Mu9Q==} engines: {node: '>=12.0.0'} tinypool@1.0.0: @@ -12659,7 +12659,7 @@ snapshots: tinyexec@0.3.0: {} - tinyglobby@0.2.7: + tinyglobby@0.2.8: dependencies: fdir: 6.4.0(picomatch@4.0.2) picomatch: 4.0.2 From 4799f70aef3bec157d07a510c5a2470e6f8d3576 Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 1 Oct 2024 12:44:46 +0200 Subject: [PATCH 10/16] chore(deps): fix another test failure --- playground/backend-integration/vite.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/playground/backend-integration/vite.config.js b/playground/backend-integration/vite.config.js index 3ec36e7cfc1070..9e0a914234b7bf 100644 --- a/playground/backend-integration/vite.config.js +++ b/playground/backend-integration/vite.config.js @@ -15,6 +15,7 @@ function BackendIntegrationExample() { const outDir = path.relative(root, path.join(projectRoot, 'dist/dev')) const entrypoints = globSync(`${normalizePath(root)}/**/*`, { + absolute: true, expandDirectories: false, onlyFiles: true, }).map((filename) => [path.relative(root, filename), filename]) From e6e0ab0e53d09f4d52e423a521208a8204b26e5a Mon Sep 17 00:00:00 2001 From: ziebam Date: Tue, 1 Oct 2024 12:46:22 +0200 Subject: [PATCH 11/16] chore(deps): bump `tinyglobby` --- packages/vite/package.json | 2 +- playground/backend-integration/package.json | 2 +- playground/css/package.json | 2 +- pnpm-lock.yaml | 18 +++++++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index e1d3f4c92cc6d6..5f4642d3b85456 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -147,7 +147,7 @@ "source-map-support": "^0.5.21", "strip-ansi": "^7.1.0", "strip-literal": "^2.1.0", - "tinyglobby": "^0.2.8", + "tinyglobby": "^0.2.9", "tsconfck": "^3.1.3", "tslib": "^2.7.0", "types": "link:./types", diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index 24634348c64670..f5caaccf65c02b 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -12,6 +12,6 @@ "devDependencies": { "sass": "^1.79.4", "tailwindcss": "^3.4.13", - "tinyglobby": "^0.2.8" + "tinyglobby": "^0.2.9" } } diff --git a/playground/css/package.json b/playground/css/package.json index d3e0b989e2e2b0..b5d740079e8140 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -26,7 +26,7 @@ "sass": "^1.79.4", "stylus": "^0.63.0", "sugarss": "^4.0.1", - "tinyglobby": "^0.2.8" + "tinyglobby": "^0.2.9" }, "imports": { "#imports": "./imports-field.css" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 314059728658c8..9b71dd582591a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -401,8 +401,8 @@ importers: specifier: ^2.1.0 version: 2.1.0 tinyglobby: - specifier: ^0.2.8 - version: 0.2.8 + specifier: ^0.2.9 + version: 0.2.9 tsconfck: specifier: ^3.1.3 version: 3.1.3(typescript@5.5.3) @@ -509,8 +509,8 @@ importers: specifier: ^3.4.13 version: 3.4.13(ts-node@10.9.2(@types/node@20.16.10)(typescript@5.5.3)) tinyglobby: - specifier: ^0.2.8 - version: 0.2.8 + specifier: ^0.2.9 + version: 0.2.9 playground/build-old: {} @@ -574,8 +574,8 @@ importers: specifier: ^4.0.1 version: 4.0.1(postcss@8.4.47) tinyglobby: - specifier: ^0.2.8 - version: 0.2.8 + specifier: ^0.2.9 + version: 0.2.9 playground/css-codesplit: {} @@ -6759,8 +6759,8 @@ packages: tinyexec@0.3.0: resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==} - tinyglobby@0.2.8: - resolution: {integrity: sha512-AMLZywN0vbhiZi2neFEaj9VIIxC+PjDMsp0nAK6tpR86LJavZgHqGz0S/FOONwBygC+mu7R0/TyAQw0gx0Mu9Q==} + tinyglobby@0.2.9: + resolution: {integrity: sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==} engines: {node: '>=12.0.0'} tinypool@1.0.0: @@ -12659,7 +12659,7 @@ snapshots: tinyexec@0.3.0: {} - tinyglobby@0.2.8: + tinyglobby@0.2.9: dependencies: fdir: 6.4.0(picomatch@4.0.2) picomatch: 4.0.2 From a19b70a6b3c70b930374a467c964cc0bd41b9a7a Mon Sep 17 00:00:00 2001 From: ziebam Date: Wed, 2 Oct 2024 13:09:33 +0200 Subject: [PATCH 12/16] chore(deps): update the comment that mentions fast-glob --- packages/vite/src/node/optimizer/resolve.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vite/src/node/optimizer/resolve.ts b/packages/vite/src/node/optimizer/resolve.ts index 36723f56b738b2..af0ead43663301 100644 --- a/packages/vite/src/node/optimizer/resolve.ts +++ b/packages/vite/src/node/optimizer/resolve.ts @@ -79,10 +79,9 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] { const exportsValue = getFirstExportStringValue(exports[key]) if (!exportsValue) continue - // TODO: Raise during the PR review. // "./dist/glob/*-browser/*.js" => "./dist/glob/**/*-browser/**/*.js" // NOTE: in some cases, this could expand to consecutive /**/*/**/* etc - // but it's fine since fast-glob handles it the same. + // but it's fine since `tinyglobby` handles it the same. const exportValuePattern = exportsValue.replace(/\*/g, '**/*') // "./dist/glob/*-browser/*.js" => /dist\/glob\/(.*)-browser\/(.*)\.js/ const exportsValueGlobRe = new RegExp( From dbd3b0a2413457089a79c57c0df9f290275c8827 Mon Sep 17 00:00:00 2001 From: ziebam Date: Wed, 2 Oct 2024 13:19:48 +0200 Subject: [PATCH 13/16] chore(deps): improve globbing in css.ts --- packages/vite/src/node/plugins/css.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 198cf1ecb9164c..ea0a269fa42f04 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -26,7 +26,7 @@ import type { TransformOptions } from 'esbuild' import { formatMessages, transform } from 'esbuild' import type { RawSourceMap } from '@ampproject/remapping' import { WorkerWithFallback } from 'artichokie' -import { escapePath, globSync } from 'tinyglobby' +import { globSync } from 'tinyglobby' import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' import type { EnvironmentModuleNode } from '../server/moduleGraph' import { @@ -1405,12 +1405,9 @@ async function compileCSS( } else if (message.type === 'dir-dependency') { // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies const { dir, glob: globPattern = '**' } = message - const pattern = - escapePath(normalizePath(path.resolve(path.dirname(id), dir))) + - `/` + - globPattern - const files = globSync(pattern, { + const files = globSync(globPattern, { absolute: true, + cwd: path.resolve(path.dirname(id), dir), expandDirectories: false, ignore: ['**/node_modules/**'], }) From 905f3ee98407e37acaa0316139418ff44aee1eb2 Mon Sep 17 00:00:00 2001 From: ziebam Date: Thu, 3 Oct 2024 13:13:38 +0200 Subject: [PATCH 14/16] chore(deps): simplify ignored pattern --- packages/vite/src/node/plugins/importMetaGlob.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 6c50e44b4ded8d..4c0f841d5d8c31 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -354,7 +354,7 @@ function findCorrespondingCloseParenthesisPosition( const importPrefix = '__vite_glob_' -const { basename, dirname, relative, join } = posix +const { basename, dirname, relative } = posix export interface TransformGlobImportResult { s: MagicString @@ -401,9 +401,7 @@ export async function transformGlobImport( cwd, dot: !!options.exhaustive, expandDirectories: false, - ignore: options.exhaustive - ? [] - : [join(cwd, '**/node_modules/**')], + ignore: options.exhaustive ? [] : ['**/node_modules/**'], }) ) .filter((file) => file !== id) From 8a72feef08aa1da1a28059831e2bf9dd60a2be9d Mon Sep 17 00:00:00 2001 From: ziebam Date: Thu, 3 Oct 2024 13:19:41 +0200 Subject: [PATCH 15/16] chore(deps): revert the change --- packages/vite/src/node/plugins/importMetaGlob.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 4c0f841d5d8c31..6c50e44b4ded8d 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -354,7 +354,7 @@ function findCorrespondingCloseParenthesisPosition( const importPrefix = '__vite_glob_' -const { basename, dirname, relative } = posix +const { basename, dirname, relative, join } = posix export interface TransformGlobImportResult { s: MagicString @@ -401,7 +401,9 @@ export async function transformGlobImport( cwd, dot: !!options.exhaustive, expandDirectories: false, - ignore: options.exhaustive ? [] : ['**/node_modules/**'], + ignore: options.exhaustive + ? [] + : [join(cwd, '**/node_modules/**')], }) ) .filter((file) => file !== id) From 866a27c43815de456393f01de637e2cbd1eb0472 Mon Sep 17 00:00:00 2001 From: ziebam Date: Fri, 4 Oct 2024 12:52:27 +0200 Subject: [PATCH 16/16] chore(deps): simplify globbing (again) --- packages/vite/src/node/plugins/importMetaGlob.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 6c50e44b4ded8d..4c0f841d5d8c31 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -354,7 +354,7 @@ function findCorrespondingCloseParenthesisPosition( const importPrefix = '__vite_glob_' -const { basename, dirname, relative, join } = posix +const { basename, dirname, relative } = posix export interface TransformGlobImportResult { s: MagicString @@ -401,9 +401,7 @@ export async function transformGlobImport( cwd, dot: !!options.exhaustive, expandDirectories: false, - ignore: options.exhaustive - ? [] - : [join(cwd, '**/node_modules/**')], + ignore: options.exhaustive ? [] : ['**/node_modules/**'], }) ) .filter((file) => file !== id)