Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_best_effort_warnings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"packages/plugin-utils/package.json":"Patch","packages/vite-plugin/package.json":"Patch","packages/webpack-plugin/package.json":"Patch","packages/rsbuild-plugin/package.json":"Patch","packages/bun-plugin/package.json":"Patch"},"note":"When an optional setup step fails and the build goes on without it (Vite, webpack and Bun file numbering, the webpack and Rsbuild import graphs, the webpack stylesheet warm-up), print one warning naming the step, the cause and what the build loses instead of continuing silently. A project without a src directory stays quiet. No new build errors.","date":"2026-11-15T00:00:00.000Z"}
27 changes: 27 additions & 0 deletions packages/bun-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ describe('registered Bun hooks', () => {
expect(loads.length).toBe(2)
})

it('warns when runtime file numbering fails, and stays quiet without src', async () => {
const collect = spyOn(pluginUtils, 'collectNumberedFiles')
const warn = spyOn(console, 'warn').mockImplementation(() => {})
try {
collect.mockImplementation(() => {
throw new Error('scan boom')
})
await register({ engine: 'wasm' })
expect(warn).toHaveBeenCalledWith(
'[devup-ui] Bun file numbering failed: scan boom. Stylesheet file numbers follow the order Bun loads files in, so they can differ between runs of the same source.',
)

warn.mockClear()
collect.mockImplementation(() => {
throw Object.assign(new Error('ENOENT'), {
code: 'ENOENT',
path: nodePath.resolve('src'),
})
})
await register({ engine: 'wasm' })
expect(warn).not.toHaveBeenCalled()
} finally {
warn.mockRestore()
collect.mockRestore()
}
})

it('leaves invalid JavaScript to the native loader after scanning fails', async () => {
const path = join(root, 'malformed.ts')
const source = 'import {'
Expand Down
10 changes: 10 additions & 0 deletions packages/bun-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
type CustomShorthands,
type DevupCompiler,
type DevupEngine,
isMissingDirectory,
isProjectJsx,
loadCompiler,
loadDevupConfig,
mergeImportAliases,
normalizeShorthands,
readJsxImportSource,
seedFileNumbers,
setupWarning,
tailwindCssFiles,
withTailwindCss,
} from '@devup-ui/plugin-utils'
Expand Down Expand Up @@ -236,6 +238,14 @@ function DevupUI(options: DevupUIBunPluginOptions = {}) {
)
} catch (error) {
if (!(error instanceof Error)) throw error
if (!isMissingDirectory(error, resolve('src')))
console.warn(
setupWarning(
'Bun file numbering',
error,
'Stylesheet file numbers follow the order Bun loads files in, so they can differ between runs of the same source.',
),
)
}
}

Expand Down
39 changes: 39 additions & 0 deletions packages/plugin-utils/src/__tests__/shared.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,47 @@ import {
DEFAULT_THEME_INTERFACE_NAMES,
type DevupUIBasePluginOptions,
getFileNumByFilename,
isMissingDirectory,
setupWarning,
} from '../shared'

describe('isMissingDirectory', () => {
const missing = (path?: unknown, code = 'ENOENT') =>
Object.assign(new Error('missing'), { code, path })

it('recognizes the directory itself not existing', () => {
expect(isMissingDirectory(missing('/project/src/'), '/project/src')).toBe(
true,
)
})

it('rejects another path, another code and other thrown values', () => {
expect(
isMissingDirectory(missing('/project/src/a.ts'), '/project/src'),
).toBe(false)
expect(
isMissingDirectory(missing('/project/src', 'EACCES'), '/project/src'),
).toBe(false)
expect(isMissingDirectory(missing(), '/project/src')).toBe(false)
expect(isMissingDirectory(new Error('boom'), '/project/src')).toBe(false)
expect(isMissingDirectory('ENOENT', '/project/src')).toBe(false)
})
})

describe('setupWarning', () => {
it('names the step, the cause and what the build loses', () => {
expect(
setupWarning('Vite file numbering', new Error('EACCES'), 'Numbers vary.'),
).toBe('[devup-ui] Vite file numbering failed: EACCES. Numbers vary.')
})

it('reads a thrown value that is not an Error', () => {
expect(setupWarning('Step', 'gone', 'Impact.')).toBe(
'[devup-ui] Step failed: gone. Impact.',
)
})
})

describe('getFileNumByFilename', () => {
it('should return null for devup-ui.css', () => {
expect(getFileNumByFilename('devup-ui.css')).toBeNull()
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export {
type DevupThemeInterfaceNames,
type DevupUIBasePluginOptions,
getFileNumByFilename,
isMissingDirectory,
setupWarning,
} from './shared'
export {
createSharedSlotReservation,
Expand Down
30 changes: 30 additions & 0 deletions packages/plugin-utils/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'node:path'

import type { DevupEngine } from './compiler-types'
import type { CustomShorthands, ImportAliases } from './types'

Expand Down Expand Up @@ -108,3 +110,31 @@ export interface DevupUIBasePluginOptions {
/** Build-time aliases that expand one style prop into multiple CSS properties. */
shorthands?: CustomShorthands
}

/**
* The warning a plugin prints when an optional setup step fails and the build
* goes on without it: the step, the root cause and what the build loses.
*/
export function setupWarning(
step: string,
error: unknown,
impact: string,
): string {
const cause = error instanceof Error ? error.message : String(error)
return `[devup-ui] ${step} failed: ${cause}. ${impact}`
}

/**
* Whether `error` reports that `dir` itself does not exist. A project without
* that source root has nothing there to scan, so the step loses nothing.
*/
export function isMissingDirectory(error: unknown, dir: string): boolean {
return (
error instanceof Error &&
'code' in error &&
error.code === 'ENOENT' &&
'path' in error &&
typeof error.path === 'string' &&
resolve(error.path) === resolve(dir)
)
}
12 changes: 11 additions & 1 deletion packages/rsbuild-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import {
type DevupUIBasePluginOptions,
getFileNumByFilename,
type ImportAliases,
isMissingDirectory,
loadCompiler,
loadDevupConfig,
mergeImportAliases,
normalizeShorthands,
planAtomHoist,
readJsxImportSource,
setupWarning,
tailwindCssFiles,
withTailwindCss,
} from '@devup-ui/plugin-utils'
Expand Down Expand Up @@ -265,8 +267,16 @@ export const DevupUI = ({
'[devup-ui] fewer than 2 routes were detected; atom hoisting is a no-op (single-entry/SPA).',
)
}
} catch {
} catch (error) {
// Best-effort; on failure atom hoisting stays off (identity).
if (!isMissingDirectory(error, resolve(process.cwd(), 'src')))
console.warn(
setupWarning(
'Rsbuild import graph',
error,
'Atom hoisting is off, so atoms several routes share are not moved into the shared stylesheet.',
),
)
}
}

Expand Down
14 changes: 11 additions & 3 deletions packages/vite-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,23 @@ describe('devupUIVitePlugin', () => {
expect(seedFileMapSpy).not.toHaveBeenCalled()
})

it('keeps building when the scan fails', async () => {
it('keeps building when the scan fails, and says what numbering loses', async () => {
onlyDirs('src')
collectSpy.mockImplementation(() => {
throw new Error('scan boom')
})
const warn = spyOn(console, 'warn').mockImplementation(() => {})

await createPlugin({}).configResolved({ root: '/p' })
try {
await createPlugin({}).configResolved({ root: '/p' })

expect(seedFileMapSpy).not.toHaveBeenCalled()
expect(seedFileMapSpy).not.toHaveBeenCalled()
expect(warn).toHaveBeenCalledWith(
'[devup-ui] Vite file numbering failed: scan boom. Stylesheet file numbers follow the order Vite transforms files in, so they can differ between builds of the same source.',
)
} finally {
warn.mockRestore()
}
})

describe('source collection before seeding', () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
normalizeShorthands,
readJsxImportSource,
seedFileNumbers,
setupWarning,
tailwindCssFiles,
withTailwindCss,
} from '@devup-ui/plugin-utils'
Expand Down Expand Up @@ -529,8 +530,15 @@ export function DevupUI({
importAliases,
}),
)
} catch {
} catch (error) {
// Best-effort; on failure numbering falls back to arrival order.
console.warn(
setupWarning(
'Vite file numbering',
error,
'Stylesheet file numbers follow the order Vite transforms files in, so they can differ between builds of the same source.',
),
)
}
reservation.configure(config)
if (extractionSession === session) session.ready = true
Expand Down
63 changes: 57 additions & 6 deletions packages/webpack-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,17 @@ describe('devupUIWebpackPlugin', () => {
collectSpy.mockImplementation(() => {
throw new Error('scan boom')
})
new DevupUIWebpackPlugin({ engine: 'wasm', debug: true }).apply(
asCompiler(createCompiler()),
)
const warn = spyOn(console, 'warn').mockImplementation(() => {})
try {
new DevupUIWebpackPlugin({ engine: 'wasm', debug: true }).apply(
asCompiler(createCompiler()),
)
expect(warn).toHaveBeenCalledWith(
'[devup-ui] webpack file numbering failed: scan boom. Stylesheet file numbers follow the order webpack compiles files in, so they can differ between builds of the same source.',
)
} finally {
warn.mockRestore()
}
} finally {
collectSpy.mockRestore()
seedSpy.mockRestore()
Expand Down Expand Up @@ -1288,9 +1296,52 @@ describe('devupUIWebpackPlugin', () => {
throw new Error('boom')
})
const plugin = new DevupUIWebpackPlugin({ engine: 'wasm', atomHoist: 2 })
// apply must still complete without throwing
plugin.apply(asCompiler(createCompiler()))
expect(setAtomHoistSpy).not.toHaveBeenCalled()
const warn = spyOn(console, 'warn').mockImplementation(() => {})
try {
// apply must still complete without throwing
plugin.apply(asCompiler(createCompiler()))
expect(setAtomHoistSpy).not.toHaveBeenCalled()
expect(warn).toHaveBeenCalledWith(
'[devup-ui] webpack import graph failed: boom. Classes are not merged across files only one module imports, and atom hoisting is off.',
)
} finally {
warn.mockRestore()
}
})

it('warns without atom hoisting when a pre-pass outside atom mode fails', () => {
buildCanonicalMapSpy.mockImplementation(() => {
throw new Error('boom')
})
const warn = spyOn(console, 'warn').mockImplementation(() => {})
try {
new DevupUIWebpackPlugin({ engine: 'wasm', atomHoist: 0 }).apply(
asCompiler(createCompiler()),
)
expect(warn).toHaveBeenCalledWith(
'[devup-ui] webpack import graph failed: boom. Classes are not merged across files only one module imports.',
)
} finally {
warn.mockRestore()
}
})

it('stays quiet when the project has no src directory to scan', () => {
buildCanonicalMapSpy.mockImplementation(() => {
throw Object.assign(new Error('ENOENT'), {
code: 'ENOENT',
path: resolve(process.cwd(), 'src'),
})
})
const warn = spyOn(console, 'warn').mockImplementation(() => {})
try {
new DevupUIWebpackPlugin({ engine: 'wasm', atomHoist: 2 }).apply(
asCompiler(createCompiler()),
)
expect(warn).not.toHaveBeenCalled()
} finally {
warn.mockRestore()
}
})

it('configures atom hoisting BEFORE registering loader rules', () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import {
extractedNeedles,
getFileNumByFilename,
type ImportAliases,
isMissingDirectory,
loadCompiler,
loadDevupConfigSync,
mergeImportAliases,
normalizeShorthands,
planAtomHoist,
readJsxImportSource,
seedFileNumbers,
setupWarning,
tailwindCssFiles,
type WasmImportAliases,
withTailwindCss,
Expand Down Expand Up @@ -225,6 +227,13 @@ export class DevupUIWebpackPlugin {
if (this.options.productionPrewarmFiles !== undefined) throw error
// Best-effort warm-up; on failure the css-loader still serves whatever
// atoms were extracted, matching pre-fix behavior.
console.warn(
setupWarning(
'webpack stylesheet warm-up',
error,
'A stylesheet webpack builds before every file it holds is extracted can miss their styles.',
),
)
}
}

Expand Down Expand Up @@ -335,6 +344,16 @@ export class DevupUIWebpackPlugin {
throw error
// Best-effort; on failure canonical() is the identity (no merge) and atom
// hoisting stays off.
if (!isMissingDirectory(error, resolve(process.cwd(), 'src')))
console.warn(
setupWarning(
'webpack import graph',
error,
atomMode
? 'Classes are not merged across files only one module imports, and atom hoisting is off.'
: 'Classes are not merged across files only one module imports.',
),
)
}

// Number every file the build can extract in path order, so class
Expand All @@ -361,6 +380,13 @@ export class DevupUIWebpackPlugin {
)
throw error
// Best-effort; numbering falls back to arrival order.
console.warn(
setupWarning(
'webpack file numbering',
error,
'Stylesheet file numbers follow the order webpack compiles files in, so they can differ between builds of the same source.',
),
)
}
// Pre-warm the extractor so the css-loader serves COMPLETE CSS.
//
Expand Down
Loading