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-perfectionist": "3.2.0",
"eslint-typegen": "0.3.1",
"globby": "14.0.2",
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
"happy-dom": "15.0.0",
"jiti": "2.0.0-beta.3",
@ -94,6 +93,7 @@
"semver": "7.6.3",
"std-env": "3.7.0",
"tinyexec": "0.2.0",
"tinyglobby": "0.2.2",
"typescript": "5.5.4",
"ufo": "1.5.4",
"vitest": "2.0.5",

View File

@ -1,14 +1,11 @@
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { promises as fsp } from 'node:fs'
import { globby } from 'globby'
import { glob } from 'tinyglobby'
const templatesRoot = fileURLToPath(new URL('..', import.meta.url))
const r = (...path: string[]) => resolve(join(templatesRoot, ...path))
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) {
const { template } = await import(file)
const updated = template({

View File

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

View File

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

View File

@ -107,9 +107,6 @@ importers:
eslint-typegen:
specifier: 0.3.1
version: 0.3.1(eslint@9.9.0(jiti@2.0.0-beta.3))
globby:
specifier: 14.0.2
version: 14.0.2
h3:
specifier: npm:h3-nightly@2.0.0-1718872656.6765a6e
version: h3-nightly@2.0.0-1718872656.6765a6e
@ -155,6 +152,9 @@ importers:
tinyexec:
specifier: 0.2.0
version: 0.2.0
tinyglobby:
specifier: 0.2.2
version: 0.2.2
typescript:
specifier: 5.5.4
version: 5.5.4
@ -605,9 +605,6 @@ importers:
critters:
specifier: 0.0.24
version: 0.0.24
globby:
specifier: 14.0.2
version: 14.0.2
html-minifier:
specifier: 4.0.0
version: 4.0.0
@ -632,6 +629,9 @@ importers:
tinyexec:
specifier: 0.2.0
version: 0.2.0
tinyglobby:
specifier: 0.2.2
version: 0.2.2
unocss:
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))

View File

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

View File

@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url'
import fsp from 'node:fs/promises'
import { beforeAll, describe, expect, it } from 'vitest'
import { exec } from 'tinyexec'
import { globby } from 'globby'
import { glob } from 'tinyglobby'
import { join } from 'pathe'
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
for (const outputDir of ['.output', '.output-inline']) {
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(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)
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"`)
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)
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"`)
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) {
const files: string[] = await globby(pattern, { cwd: rootDir })
async function analyzeSizes (pattern: string[], rootDir: string) {
const files: string[] = await glob(pattern, { cwd: rootDir })
let totalBytes = 0
for (const file of files) {
const path = join(rootDir, file)

View File

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