diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index a61db117e81112..915c2c5392d526 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -182,9 +182,9 @@ describe('resolveBuildOutputs', () => { { format: 'es', }, - // { - // format: 'umd', - // }, + { + format: 'umd', + }, ]) }) @@ -223,7 +223,7 @@ describe('resolveBuildOutputs', () => { expect(resolveBuild).toThrowError(/Option "build\.lib\.name" is required/) }) - test.skip('throws an error when lib.name is missing on umd format', () => { + test('throws an error when lib.name is missing on umd format', () => { const logger = createLogger() const libOptions: LibraryOptions = { ...baseLibOptions, formats: ['umd'] } const resolveBuild = () => resolveBuildOutputs(void 0, libOptions, logger) @@ -242,7 +242,7 @@ describe('resolveBuildOutputs', () => { ) }) - test.skip('throws an error when output.name is missing on umd format', () => { + test('throws an error when output.name is missing on umd format', () => { const logger = createLogger() const libOptions: LibraryOptions = { ...baseLibOptions } const outputs: OutputOptions[] = [{ format: 'umd' }] @@ -346,7 +346,7 @@ describe('resolveLibFilename', () => { test('module package extensions', () => { const formatsToFilenames: FormatsToFileNames = [ ['es', 'my-lib.js'], - // ['umd', 'my-lib.umd.cjs'], + ['umd', 'my-lib.umd.cjs'], ['cjs', 'my-lib.cjs'], ['iife', 'my-lib.iife.js'], ] @@ -496,13 +496,13 @@ describe('resolveBuildOutputs', () => { expect(resolveBuildOutputs(undefined, libOptions, {} as Logger)).toEqual([ { format: 'es' }, - // { format: 'umd' }, + { format: 'umd' }, ]) expect( resolveBuildOutputs({ name: 'A' }, libOptions, {} as Logger), ).toEqual([ { format: 'es', name: 'A' }, - // { format: 'umd', name: 'A' }, + { format: 'umd', name: 'A' }, ]) expect( resolveBuildOutputs([{ name: 'A' }], libOptions, {} as Logger), @@ -529,7 +529,7 @@ describe('resolveBuildOutputs', () => { ).toEqual([{ name: 'A' }]) }) - test.skip('umd or iife: should not support multiple entries', () => { + test('umd or iife: should not support multiple entries', () => { ;['umd', 'iife'].forEach((format) => { expect(() => resolveBuildOutputs( @@ -546,7 +546,7 @@ describe('resolveBuildOutputs', () => { }) }) - test.skip('umd or iife: should define build.lib.name', () => { + test('umd or iife: should define build.lib.name', () => { ;['umd', 'iife'].forEach((format) => { expect(() => resolveBuildOutputs( diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index d6665884233256..f6a133bed15d3c 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -314,7 +314,7 @@ export interface LibraryOptions { cssFileName?: string } -export type LibraryFormats = 'es' | 'cjs' | 'iife' // | 'umd' | 'system' +export type LibraryFormats = 'es' | 'cjs' | 'iife' | 'umd' // | 'system' export interface ModulePreloadOptions { /** @@ -773,7 +773,7 @@ async function buildEnvironment( ? `[name].[ext]` : path.posix.join(options.assetsDir, `[name]-[hash].[ext]`), inlineDynamicImports: - /* output.format === 'umd' || */ output.format === 'iife', + output.format === 'umd' || output.format === 'iife', ...output, } } @@ -931,7 +931,7 @@ function resolveOutputJsExtension( type: string = 'commonjs', ): JsExt { if (type === 'module') { - return format === 'cjs' /* || format === 'umd' */ ? 'cjs' : 'js' + return format === 'cjs' || format === 'umd' ? 'cjs' : 'js' } else { return format === 'es' ? 'mjs' : 'js' } @@ -981,10 +981,10 @@ export function resolveBuildOutputs( Object.values(libOptions.entry).length > 1 const libFormats = libOptions.formats || - (libHasMultipleEntries ? ['es', 'cjs'] : ['es' /* , 'umd' */]) + (libHasMultipleEntries ? ['es', 'cjs'] : ['es', 'umd']) if (!Array.isArray(outputs)) { - if (/* libFormats.includes('umd') || */ libFormats.includes('iife')) { + if (libFormats.includes('umd') || libFormats.includes('iife')) { if (libHasMultipleEntries) { throw new Error( 'Multiple entry points are not supported when output formats include "umd" or "iife".', @@ -1012,7 +1012,7 @@ export function resolveBuildOutputs( outputs.forEach((output) => { if ( - /* output.format === 'umd' || */ output.format === 'iife' && + (output.format === 'umd' || output.format === 'iife') && !output.name ) { throw new Error( diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index 6af2f2cb4e55ce..468fc4cbb0595b 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -272,15 +272,14 @@ export function watchPackageDataPlugin(packageCache: PackageCache): Plugin { return { name: 'vite:watch-package-data', buildStart() { - // watchFile = this.addWatchFile.bind(this) + watchFile = this.addWatchFile.bind(this) watchQueue.forEach(watchFile) watchQueue.clear() }, buildEnd() { watchFile = watchFileStub }, - // TODO: use watchChange hook when implemented - handleHotUpdate({ file: id }) { + watchChange(id) { if (id.endsWith('/package.json')) { invalidatePackageData(packageCache, path.normalize(id)) } diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 9b8787c8fed4a8..f56a73fd9d745d 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -356,9 +356,9 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => { const contentIndex = opts.format === 'iife' ? Math.max(esbuildCode.search(IIFE_BEGIN_RE), 0) - : // : opts.format === 'umd' - // ? esbuildCode.indexOf(`(function(`) // same for minified or not - 0 + : opts.format === 'umd' + ? esbuildCode.indexOf(`(function(`) // same for minified or not + : 0 if (contentIndex > 0) { const esbuildHelpers = esbuildCode.slice(0, contentIndex) res.code = esbuildCode diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts index e7b087d24a1bdc..18685bf4f8d1c2 100644 --- a/vitest.config.e2e.ts +++ b/vitest.config.e2e.ts @@ -19,7 +19,6 @@ export default defineConfig({ ? [ './playground/environment-react-ssr/**/*.spec.[tj]s', // needs investigation './playground/external/**/*.spec.[tj]s', // https://github.com/rolldown/rolldown/issues/2041 - './playground/lib/**/*.spec.[tj]s', // umd format './playground/object-hooks/**/*.spec.[tj]s', // object hook sequential './playground/optimize-deps/**/*.spec.[tj]s', // https://github.com/rolldown/rolldown/issues/2031 './playground/tsconfig-json/__tests__/**/*.spec.[tj]s', // decorators is not supported by oxc