chore: use `tinyglobby` internally (#28686)

This commit is contained in:
Daniel Roe 2024-08-23 20:59:25 +01:00
parent 6ab3afc8bc
commit 8cb4bccc79
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
8 changed files with 26 additions and 27 deletions

View File

@ -72,7 +72,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": "1.12.0",
"happy-dom": "15.0.0",
"jiti": "1.21.6",
@ -88,6 +87,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 genericMessages from '../templates/messages.json'
@ -25,7 +25,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

@ -22,7 +22,6 @@
"@types/lodash-es": "4.17.12",
"@unocss/reset": "0.62.3",
"critters": "0.0.24",
"globby": "14.0.2",
"html-minifier": "4.0.0",
"html-validate": "8.21.0",
"jiti": "1.21.6",
@ -32,6 +31,7 @@
"prettier": "3.3.3",
"scule": "1.3.0",
"tinyexec": "0.2.0",
"tinyglobby": "0.2.2",
"unocss": "0.62.3",
"vite": "5.4.2"
}

View File

@ -96,9 +96,6 @@ importers:
eslint-typegen:
specifier: 0.3.1
version: 0.3.1(eslint@9.9.1(jiti@1.21.6))
globby:
specifier: 14.0.2
version: 14.0.2
h3:
specifier: 1.12.0
version: 1.12.0
@ -144,6 +141,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
@ -603,9 +603,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
@ -633,6 +630,9 @@ importers:
tinyexec:
specifier: 0.2.0
version: 0.2.0
tinyglobby:
specifier: 0.2.2
version: 0.2.2
unocss:
specifier: 0.62.3
version: 0.62.3(@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(`"211k"`)
const modules = await analyzeSizes('node_modules/**/*', serverDir)
const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"1351k"`)
const packages = modules.files
@ -74,7 +74,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(`"535k"`)
const modules = await analyzeSizes('node_modules/**/*', serverDir)
const modules = await analyzeSizes(['node_modules/**/*'], serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"82.1k"`)
const packages = modules.files
@ -94,8 +94,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,