Skip to content

Commit

Permalink
chore: use tinyglobby internally (nuxt#28686)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Aug 23, 2024
1 parent f9752fe commit 0d74264
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]",
"happy-dom": "15.0.0",
"jiti": "2.0.0-beta.3",
Expand All @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions packages/ui-templates/lib/prerender.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
9 changes: 6 additions & 3 deletions packages/ui-templates/lib/render.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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[] = []

Expand Down
12 changes: 6 additions & 6 deletions test/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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(`
[
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions test/prepare.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 0d74264

Please sign in to comment.