From eca1b6ad4edbbdffa408430db3c39b28447a7ac3 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Thu, 19 Nov 2026 01:50:35 +0900 Subject: [PATCH 1/2] fix(benchmark): fit a last array of exactly 80 columns on one line formatJson counted a trailing comma after every array, so an array that ends its object and fills exactly 80 columns was split over lines while Prettier keeps it on one. main's refresh wrote such a row (devup-ui-large-turbo-wasm), and `bun run lint` rejects history.json again. The comma now counts only when one follows, and history.json is rewritten. Co-Authored-By: Claude Opus 5.5 --- benchmark-record.js | 5 +++-- benchmark/history.json | 4 +--- .../src/__tests__/benchmark-record.test.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/benchmark-record.js b/benchmark-record.js index 2a25c9309..7e5f1e776 100644 --- a/benchmark-record.js +++ b/benchmark-record.js @@ -188,10 +188,11 @@ export function formatJson(value) { return ( JSON.stringify(value, null, 2).replace( /^( *)(.*)\[\n((?:\1 {2}(?:-?[\d.e+-]+|"[^"\n]*"|null),?\n)+)\1\]/gm, - (whole, indent, key, items) => { + (whole, indent, key, items, offset, json) => { const values = items.trim().split(/,\n */) const line = `${indent}${key}[${values.join(', ')}]` - if (line.length + 1 <= PRINT_WIDTH) return line + const comma = json[offset + whole.length] === ',' ? 1 : 0 + if (line.length + comma <= PRINT_WIDTH) return line return values.every((item) => /^-?[\d.e+-]+$/.test(item)) ? fillNumbers(indent, key, values) : whole diff --git a/benchmark/history.json b/benchmark/history.json index db1fcffce..79cc5f333 100644 --- a/benchmark/history.json +++ b/benchmark/history.json @@ -292,9 +292,7 @@ "devup-ui-large": [15.099, 15.029, 15.117, 88882994, 1388, 934329], "devup-ui-large-wasm": [16.233, 16.017, 16.28, 89000421, 1388, 934329], "devup-ui-large-turbo": [6.037, 5.938, 6.244, 38676786, 1512, 571629], - "devup-ui-large-turbo-wasm": [ - 6.5, 6.483, 6.542, 38662174, 1512, 571629 - ] + "devup-ui-large-turbo-wasm": [6.5, 6.483, 6.542, 38662174, 1512, 571629] } }, { diff --git a/packages/plugin-utils/src/__tests__/benchmark-record.test.ts b/packages/plugin-utils/src/__tests__/benchmark-record.test.ts index e7075a0e5..42d011ee8 100644 --- a/packages/plugin-utils/src/__tests__/benchmark-record.test.ts +++ b/packages/plugin-utils/src/__tests__/benchmark-record.test.ts @@ -411,6 +411,18 @@ describe('benchmark JSON', () => { ) }) + it('fits a last array of 80 columns on one line, as it takes no comma', () => { + // Exactly 80 columns, 81 when a comma follows + const values = [1.5, 2.25, 3.125, 38662174, 1512, 571629, 12345678, 1234] + const fits = { aaaaaaaaaaaaaaaa: values } + const split = { aaaaaaaaaaaaaaaa: values, b: 1 } + const line = ` "aaaaaaaaaaaaaaaa": [${values.join(', ')}]` + + expect(line).toHaveLength(80) + expect(formatJson(fits)).toBe(`{\n${line}\n}\n`) + expect(formatJson(split).split('\n')[1]).toBe(' "aaaaaaaaaaaaaaaa": [') + }) + it('formats the checked files exactly as it writes them', () => { for (const file of ['benchmark-results.json', 'benchmark/history.json']) { const text = readFileSync(join(ROOT, file), 'utf8').replaceAll( From d1ee2fa1c2118110b16d2eed15d5f5a0527662c8 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Thu, 19 Nov 2026 06:24:57 +0900 Subject: [PATCH 2/2] perf(plugins): leave the runtime package out of the prepasses The shared class-slot reservation and the Next production prewarm followed every import of @devup-ui/react into its own modules (23 on the benchmark app), read and resolved them, and extracted them before the bundler started, although extracting them yields no style. Both now skip the runtime package, from the app and from other Devup UI packages; a test pins that its modules add nothing to a sheet. The webpack reservation seeded file numbers for those modules ahead of the project's own files, so per-file class prefixes now start at `a-` on the benchmark app instead of `x-`; the styles are the same. Co-Authored-By: Claude Opus 5.5 --- ...hangepack_log_prepass_runtime_package.json | 8 +++ .../next-plugin/src/__tests__/prewarm.test.ts | 30 +++++++++++ packages/next-plugin/src/prewarm.ts | 2 + .../src/__tests__/reservation-entries.test.ts | 32 ++++++++++++ .../src/__tests__/runtime-package.test.ts | 52 +++++++++++++++++++ packages/plugin-utils/src/index.ts | 1 + .../plugin-utils/src/reservation-discovery.ts | 2 + packages/plugin-utils/src/runtime-package.ts | 13 +++++ 8 files changed, 140 insertions(+) create mode 100644 .changepacks/changepack_log_prepass_runtime_package.json create mode 100644 packages/plugin-utils/src/__tests__/runtime-package.test.ts create mode 100644 packages/plugin-utils/src/runtime-package.ts diff --git a/.changepacks/changepack_log_prepass_runtime_package.json b/.changepacks/changepack_log_prepass_runtime_package.json new file mode 100644 index 000000000..05f38d7c2 --- /dev/null +++ b/.changepacks/changepack_log_prepass_runtime_package.json @@ -0,0 +1,8 @@ +{ + "changes": { + "packages/plugin-utils/package.json": "Patch", + "packages/next-plugin/package.json": "Patch" + }, + "note": "Skip `@devup-ui/react` in the passes that run before the bundler: the shared class-slot reservation and the Next production prewarm no longer read, resolve or extract the runtime package's own modules, which hold no styles. Next's Turbopack setup drops from about 40 ms to 15 ms on the benchmark app and each webpack compiler does less work. Webpack per-file builds now number a project's files without the runtime package's modules in front of them, so per-file class prefixes and stylesheet names can be shorter (`devup-ui-0.css` and `a-` instead of `devup-ui-23.css` and `x-`); the styles are unchanged.", + "date": "2026-11-19T00:00:00.000Z" +} diff --git a/packages/next-plugin/src/__tests__/prewarm.test.ts b/packages/next-plugin/src/__tests__/prewarm.test.ts index 0d4d2b9cb..b1f43dfa5 100644 --- a/packages/next-plugin/src/__tests__/prewarm.test.ts +++ b/packages/next-plugin/src/__tests__/prewarm.test.ts @@ -151,6 +151,36 @@ describe('collectProductionPrewarmFiles', () => { ]) }) + it('neither reads nor lists the runtime package, from the app or from another Devup UI package', () => { + // Given the runtime package and a component package importing it. + writePackage('@devup-ui/react', './index.js', { + 'index.js': 'export { Box } from "./Box.js"', + 'Box.js': 'export const Box = 1', + 'stylex.js': 'export const props = 1', + }) + writePackage('@devup-ui/components', './index.js', { + 'index.js': + 'import { Box } from "@devup-ui/react"; import "@devup-ui/react/stylex.js"; export const Button = Box', + }) + // When collecting the extraction set of an app importing both. + const files = collectProductionPrewarmFiles({ + cwd, + graph: makeGraph( + [], + [ + '@devup-ui/react', + '@devup-ui/react/stylex.js', + '@devup-ui/components', + ], + ), + expectedBaseFiles: [], + libPackage: '@devup-ui/react', + include: [], + }) + // Then only the component package is extracted ahead of the bundler. + expect(files).toEqual(['node_modules/@devup-ui/components/index.js']) + }) + it('propagates a genuine accepted-package collection error', () => { // Given a malformed accepted package manifest. writePackage('design-system', './index.js', { 'index.js': '' }) diff --git a/packages/next-plugin/src/prewarm.ts b/packages/next-plugin/src/prewarm.ts index 8564ed492..c78877de1 100644 --- a/packages/next-plugin/src/prewarm.ts +++ b/packages/next-plugin/src/prewarm.ts @@ -3,6 +3,7 @@ import { extname, isAbsolute, relative, resolve } from 'node:path' import { createModuleResolver, + isRuntimePackage, parseImports, SOURCE_FILE_REGEX, type StaticImportGraph, @@ -88,6 +89,7 @@ export function collectProductionPrewarmFiles({ [...specifiers].sort().map((specifier) => ({ importer, specifier })), ) for (const { importer, specifier } of queue) { + if (isRuntimePackage(specifier)) continue const local = specifier.startsWith('.') || isAbsolute(specifier) if (!local) { const packageName = packageNameFromSpecifier(specifier) diff --git a/packages/plugin-utils/src/__tests__/reservation-entries.test.ts b/packages/plugin-utils/src/__tests__/reservation-entries.test.ts index 0bd758cb5..d3335edd7 100644 --- a/packages/plugin-utils/src/__tests__/reservation-entries.test.ts +++ b/packages/plugin-utils/src/__tests__/reservation-entries.test.ts @@ -133,3 +133,35 @@ it('retains prepared compiled overlays for an exact physical entry and never fee ) expect(result.dependencies).toHaveLength(2) }) + +it('never reads the runtime package, from the app or from another Devup UI package', () => { + // Given + using fs = fixture() + fs.write( + 'src/A.tsx', + `${STYLE}\nimport '@devup-ui/components'; import '@devup-ui/react/stylex'`, + ) + fs.write('node_modules/@devup-ui/react/package.json', '{"main":"index.js"}') + fs.write('node_modules/@devup-ui/react/index.js', STYLE) + fs.write('node_modules/@devup-ui/react/stylex.js', STYLE) + fs.write( + 'node_modules/@devup-ui/components/package.json', + '{"main":"index.js"}', + ) + fs.write('node_modules/@devup-ui/components/index.js', STYLE) + // When + const { inputs, dependencies, packageManifests } = collectReservationInputs({ + roots: ['src'], + cwd: fs.root, + package: '@devup-ui/react', + importAliases: {}, + toId: (path: string) => relative(fs.root, path), + }) + // Then + expect(inputs.map(({ filename }) => filename.replaceAll('\\', '/'))).toEqual([ + 'node_modules/@devup-ui/components/index.js', + 'src/A.tsx', + ]) + expect(dependencies).toHaveLength(2) + expect(packageManifests).toHaveLength(1) +}) diff --git a/packages/plugin-utils/src/__tests__/runtime-package.test.ts b/packages/plugin-utils/src/__tests__/runtime-package.test.ts new file mode 100644 index 000000000..5eb24cab5 --- /dev/null +++ b/packages/plugin-utils/src/__tests__/runtime-package.test.ts @@ -0,0 +1,52 @@ +import { readdirSync, readFileSync } from 'node:fs' +import { join, relative } from 'node:path' + +import { expect, it } from 'bun:test' + +import { RUNTIME_PACKAGE } from '../runtime-package' +import { mergeImportAliases } from '../types' + +const wasm = await import('../../../../bindings/devup-ui-wasm/pkg/index.js') + +const ROOT = join(import.meta.dir, '../../../..') + +function modules(directory: string): string[] { + return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { + const path = join(directory, entry.name) + if (entry.isDirectory()) + return entry.name === '__tests__' ? [] : modules(path) + return /\.tsx?$/.test(entry.name) && + !/\.(?:test(?:-d)?\.tsx?|d\.ts)$/.test(entry.name) + ? [path] + : [] + }) +} + +it('gets no styles from the modules of the runtime package, which the prepasses skip', () => { + // The prepasses that complete the sheet before the bundler runs neither read + // nor extract the runtime package: that is only right while it has no styles + wasm.resetBuildState() + const files = modules(join(ROOT, 'packages/react/src')) + expect(files.length).toBeGreaterThan(10) + const styled = files.filter((path) => { + const output = wasm.codeExtractWithoutSourceMap( + relative(ROOT, path).replaceAll('\\', '/'), + readFileSync(path, 'utf-8'), + RUNTIME_PACKAGE, + './df', + // One sheet: every style any module adds shows in it + true, + false, + true, + mergeImportAliases(undefined, undefined), + ) + try { + return output.updatedBaseStyle + } finally { + output.free() + } + }) + expect(styled).toEqual([]) + expect(wasm.getCss(null, false)).toBe('') + wasm.resetBuildState() +}) diff --git a/packages/plugin-utils/src/index.ts b/packages/plugin-utils/src/index.ts index 66487196f..300d0c853 100644 --- a/packages/plugin-utils/src/index.ts +++ b/packages/plugin-utils/src/index.ts @@ -58,6 +58,7 @@ export { type ReservationInventory, } from './reservation-discovery' export { reservationGraph } from './reservation-graph' +export { isRuntimePackage, RUNTIME_PACKAGE } from './runtime-package' export { createNodeModulesExcludeRegex, createThemeInterfaceArgs, diff --git a/packages/plugin-utils/src/reservation-discovery.ts b/packages/plugin-utils/src/reservation-discovery.ts index 9f65f4d21..3b8731de4 100644 --- a/packages/plugin-utils/src/reservation-discovery.ts +++ b/packages/plugin-utils/src/reservation-discovery.ts @@ -12,6 +12,7 @@ import { isReservationReadFailure, reservationSource, } from './reservation-source' +import { isRuntimePackage } from './runtime-package' import type { WasmImportAliases } from './types' export type ReservationInput = { @@ -169,6 +170,7 @@ export function collectReservationInputs( overlay?.filename ?? physicalPath, code, )) { + if (isRuntimePackage(specifier)) continue const allowed = allowedPackage(specifier, include) const module = reservationSource( () => resolver(specifier, physicalPath), diff --git a/packages/plugin-utils/src/runtime-package.ts b/packages/plugin-utils/src/runtime-package.ts new file mode 100644 index 000000000..c4e04dcac --- /dev/null +++ b/packages/plugin-utils/src/runtime-package.ts @@ -0,0 +1,13 @@ +/** + * The package whose API the extraction compiles away. Its own modules hold no + * styles (extracting any of them changes nothing), so the passes that complete + * the sheet before the bundler runs neither read nor extract them. + */ +export const RUNTIME_PACKAGE = '@devup-ui/react' + +/** Whether an import specifier names the runtime package or one of its subpaths */ +export function isRuntimePackage(specifier: string): boolean { + return ( + specifier === RUNTIME_PACKAGE || specifier.startsWith(`${RUNTIME_PACKAGE}/`) + ) +}