chore: use tinyglobby internally (#28686)

This commit is contained in:
Daniel Roe 2024-08-23 20:59:25 +01:00 committed by GitHub
parent f9752fe7af
commit 0d742647a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 26 additions and 27 deletions

View File

@ -78,7 +78,6 @@
"eslint-plugin-no-only-tests": "3.3.0", "eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-perfectionist": "3.2.0", "eslint-plugin-perfectionist": "3.2.0",
"eslint-typegen": "0.3.1", "eslint-typegen": "0.3.1",
"globby": "14.0.2",
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e", "h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
"happy-dom": "15.0.0", "happy-dom": "15.0.0",
"jiti": "2.0.0-beta.3", "jiti": "2.0.0-beta.3",
@ -94,6 +93,7 @@
"semver": "7.6.3", "semver": "7.6.3",
"std-env": "3.7.0", "std-env": "3.7.0",
"tinyexec": "0.2.0", "tinyexec": "0.2.0",
"tinyglobby": "0.2.2",
"typescript": "5.5.4", "typescript": "5.5.4",
"ufo": "1.5.4", "ufo": "1.5.4",
"vitest": "2.0.5", "vitest": "2.0.5",

View File

@ -1,14 +1,11 @@
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { promises as fsp } from 'node:fs' import { promises as fsp } from 'node:fs'
import { globby } from 'globby' import { glob } from 'tinyglobby'
const templatesRoot = fileURLToPath(new URL('..', import.meta.url)) const templatesRoot = fileURLToPath(new URL('..', import.meta.url))
const r = (...path: string[]) => resolve(join(templatesRoot, ...path))
async function main () { async function main () {
const templates = await globby(r('dist/templates/*.js')) const templates = await glob(['dist/templates/*.js'], { cwd: templatesRoot })
for (const file of templates) { for (const file of templates) {
const { template } = await import(file) const { template } = await import(file)
const updated = template({ const updated = template({

View File

@ -1,13 +1,13 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { readFileSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs' import { readFileSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs'
import { copyFile } from 'node:fs/promises' import { copyFile } from 'node:fs/promises'
import { basename, dirname, join, resolve } from 'pathe' import { basename, dirname, join } from 'pathe'
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
// @ts-expect-error https://github.com/GoogleChromeLabs/critters/pull/151 // @ts-expect-error https://github.com/GoogleChromeLabs/critters/pull/151
import Critters from 'critters' import Critters from 'critters'
import { genObjectFromRawEntries } from 'knitwork' import { genObjectFromRawEntries } from 'knitwork'
import htmlMinifier from 'html-minifier' import htmlMinifier from 'html-minifier'
import { globby } from 'globby' import { glob } from 'tinyglobby'
import { camelCase } from 'scule' import { camelCase } from 'scule'
import { version } from '../../nuxt/package.json' import { version } from '../../nuxt/package.json'
@ -26,7 +26,10 @@ export const RenderPlugin = () => {
enforce: 'post', enforce: 'post',
async writeBundle () { async writeBundle () {
const critters = new Critters({ path: outputDir }) const critters = new Critters({ path: outputDir })
const htmlFiles = await globby(resolve(outputDir, 'templates/**/*.html'), { absolute: true }) const htmlFiles = await glob(['templates/**/*.html'], {
cwd: outputDir,
absolute: true,
})
const templateExports: Array<{ const templateExports: Array<{
exportName: string exportName: string

View File

@ -21,7 +21,6 @@
"@types/html-minifier": "4.0.5", "@types/html-minifier": "4.0.5",
"@unocss/reset": "0.62.2", "@unocss/reset": "0.62.2",
"critters": "0.0.24", "critters": "0.0.24",
"globby": "14.0.2",
"html-minifier": "4.0.0", "html-minifier": "4.0.0",
"html-validate": "8.21.0", "html-validate": "8.21.0",
"jiti": "2.0.0-beta.3", "jiti": "2.0.0-beta.3",
@ -30,6 +29,7 @@
"prettier": "3.3.3", "prettier": "3.3.3",
"scule": "1.3.0", "scule": "1.3.0",
"tinyexec": "0.2.0", "tinyexec": "0.2.0",
"tinyglobby": "0.2.2",
"unocss": "0.62.2", "unocss": "0.62.2",
"vite": "5.4.2" "vite": "5.4.2"
} }

View File

@ -107,9 +107,6 @@ importers:
eslint-typegen: eslint-typegen:
specifier: 0.3.1 specifier: 0.3.1
version: 0.3.1(eslint@9.9.0(jiti@2.0.0-beta.3)) version: 0.3.1(eslint@9.9.0(jiti@2.0.0-beta.3))
globby:
specifier: 14.0.2
version: 14.0.2
h3: h3:
specifier: npm:h3-nightly@2.0.0-1718872656.6765a6e specifier: npm:h3-nightly@2.0.0-1718872656.6765a6e
version: h3-nightly@2.0.0-1718872656.6765a6e version: h3-nightly@2.0.0-1718872656.6765a6e
@ -155,6 +152,9 @@ importers:
tinyexec: tinyexec:
specifier: 0.2.0 specifier: 0.2.0
version: 0.2.0 version: 0.2.0
tinyglobby:
specifier: 0.2.2
version: 0.2.2
typescript: typescript:
specifier: 5.5.4 specifier: 5.5.4
version: 5.5.4 version: 5.5.4
@ -605,9 +605,6 @@ importers:
critters: critters:
specifier: 0.0.24 specifier: 0.0.24
version: 0.0.24 version: 0.0.24
globby:
specifier: 14.0.2
version: 14.0.2
html-minifier: html-minifier:
specifier: 4.0.0 specifier: 4.0.0
version: 4.0.0 version: 4.0.0
@ -632,6 +629,9 @@ importers:
tinyexec: tinyexec:
specifier: 0.2.0 specifier: 0.2.0
version: 0.2.0 version: 0.2.0
tinyglobby:
specifier: 0.2.2
version: 0.2.2
unocss: unocss:
specifier: 0.62.2 specifier: 0.62.2
version: 0.62.2(@unocss/webpack@0.62.2(rollup@4.21.0)(webpack@5.94.0(esbuild@0.23.1)))(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.69.4)(terser@5.27.0)) version: 0.62.2(@unocss/webpack@0.62.2(rollup@4.21.0)(webpack@5.94.0(esbuild@0.23.1)))(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.2(@types/node@20.16.1)(sass@1.69.4)(terser@5.27.0))

View File

@ -2,7 +2,7 @@ import { execSync } from 'node:child_process'
import { promises as fsp } from 'node:fs' import { promises as fsp } from 'node:fs'
import { $fetch } from 'ofetch' import { $fetch } from 'ofetch'
import { resolve } from 'pathe' import { resolve } from 'pathe'
import { globby } from 'globby' import { glob } from 'tinyglobby'
import { exec } from 'tinyexec' import { exec } from 'tinyexec'
import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen' import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen'
@ -43,7 +43,7 @@ export async function loadPackage (dir: string) {
export async function loadWorkspace (dir: string) { export async function loadWorkspace (dir: string) {
const workspacePkg = await loadPackage(dir) const workspacePkg = await loadPackage(dir)
const pkgDirs = (await globby(['packages/*'], { onlyDirectories: true })).sort() const pkgDirs = (await glob(['packages/*'], { onlyDirectories: true })).sort()
const packages: Package[] = [] const packages: Package[] = []

View File

@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url'
import fsp from 'node:fs/promises' import fsp from 'node:fs/promises'
import { beforeAll, describe, expect, it } from 'vitest' import { beforeAll, describe, expect, it } from 'vitest'
import { exec } from 'tinyexec' import { exec } from 'tinyexec'
import { globby } from 'globby' import { glob } from 'tinyglobby'
import { join } from 'pathe' import { join } from 'pathe'
describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM_CI)('minimal nuxt application', () => { describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM_CI)('minimal nuxt application', () => {
@ -18,7 +18,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
// Identical behaviour between inline/external vue options as this should only affect the server build // Identical behaviour between inline/external vue options as this should only affect the server build
for (const outputDir of ['.output', '.output-inline']) { for (const outputDir of ['.output', '.output-inline']) {
it('default client bundle size', async () => { it('default client bundle size', async () => {
const clientStats = await analyzeSizes('**/*.js', join(rootDir, outputDir, 'public')) const clientStats = await analyzeSizes(['**/*.js'], join(rootDir, outputDir, 'public'))
expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot(`"108k"`) expect.soft(roundToKilobytes(clientStats.totalBytes)).toMatchInlineSnapshot(`"108k"`)
expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` expect(clientStats.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
[ [
@ -34,7 +34,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"205k"`) expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"205k"`)
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1355k"`) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1355k"`)
const packages = modules.files const packages = modules.files
@ -75,7 +75,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"529k"`) expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"529k"`)
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"86.1k"`) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"86.1k"`)
const packages = modules.files const packages = modules.files
@ -96,8 +96,8 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
}) })
}) })
async function analyzeSizes (pattern: string | string[], rootDir: string) { async function analyzeSizes (pattern: string[], rootDir: string) {
const files: string[] = await globby(pattern, { cwd: rootDir }) const files: string[] = await glob(pattern, { cwd: rootDir })
let totalBytes = 0 let totalBytes = 0
for (const file of files) { for (const file of files) {
const path = join(rootDir, file) const path = join(rootDir, file)

View File

@ -1,12 +1,11 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { rm } from 'node:fs/promises' import { rm } from 'node:fs/promises'
import { globby } from 'globby' import { glob } from 'tinyglobby'
import { exec } from 'tinyexec' import { exec } from 'tinyexec'
async function initTesting () { async function initTesting () {
const dirs = await globby('*', { const dirs = await glob(['*'], {
onlyDirectories: true, onlyDirectories: true,
cwd: fileURLToPath(new URL('./fixtures', import.meta.url)), cwd: fileURLToPath(new URL('./fixtures', import.meta.url)),
absolute: true, absolute: true,