diff --git a/src/rollup/index.ts b/src/rollup/index.ts index 7ece9ca63e8..611c209d085 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -1,4 +1,5 @@ import { EventEmitter } from 'events'; +import { Asset } from '../../node_modules/rollup'; import { optimizeChunks } from '../chunk-optimization'; import Graph from '../Graph'; import { createAddons } from '../utils/addons'; @@ -316,7 +317,14 @@ export default function rollup(rawInputOptions: GenericConfigObject): Promise { - if (Object.keys(bundle).length > 1) { + let chunkCnt = 0; + for (const fileName of Object.keys(bundle)) { + const file = bundle[fileName]; + if ((file).isAsset) continue; + chunkCnt++; + if (chunkCnt > 1) break; + } + if (chunkCnt > 1) { if (outputOptions.sourcemapFile) error({ code: 'INVALID_OPTION', diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 0b81f1c7a02..b4257309b7f 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -196,7 +196,6 @@ export interface Plugin { options: OutputOptions, chunk: OutputChunk ) => void | Promise; - /** @deprecated */ generateBundle?: ( this: PluginContext, options: OutputOptions, diff --git a/test/function/index.js b/test/function/index.js index 7d871ee21a3..0614c408aa2 100644 --- a/test/function/index.js +++ b/test/function/index.js @@ -41,7 +41,7 @@ runTestSuiteWithSamples('function', path.resolve(__dirname, 'samples'), (dir, co (config.options || {}).output || {} ) ) - .then(code => { + .then(({ output: [code] }) => { if (config.generateError) { unintendedError = new Error('Expected an error while generating output'); } diff --git a/test/hooks/index.js b/test/hooks/index.js index b1345e9689c..9649d4f635c 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -272,8 +272,9 @@ describe('hooks', () => { return bundle.generate({ format: 'es' }); }) .then(({ output }) => { - assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); - assert.equal(output['input.js'].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[0].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[1].fileName, 'assets/test-19916f7d.ext'); + assert.equal(output[1].source, 'hello world'); return rollup .rollup({ @@ -293,8 +294,9 @@ describe('hooks', () => { return bundle.generate({ format: 'es' }); }) .then(({ output }) => { - assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); - assert.equal(output['input.js'].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[0].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[1].fileName, 'assets/test-19916f7d.ext'); + assert.equal(output[1].source, 'hello world'); }); }); @@ -322,8 +324,9 @@ describe('hooks', () => { return bundle.generate({ format: 'es' }); }) .then(({ output }) => { - assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); - assert.equal(output['input.js'].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[0].code, `var input = new URL('../assets/test-19916f7d.ext', import.meta.url).href;\n\nexport default input;\n`); + assert.equal(output[1].fileName, 'assets/test-19916f7d.ext'); + assert.equal(output[1].source, 'hello world'); return rollup .rollup({ @@ -346,8 +349,8 @@ describe('hooks', () => { }) .then(({ output }) => { assert.equal(runs, 2); - assert.equal(output['assets/test-19916f7d.ext'], undefined); - assert.equal(output['input.js'].code.trim(), `alert('hello world');`); + assert.equal(output[0].code.trim(), `alert('hello world');`); + assert.equal(output.length, 1); }); }); @@ -483,7 +486,7 @@ module.exports = input; return bundle.generate({ format: 'es' }); }) .then(({ output: [,output] }) => { - assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); + assert.equal(output.source, 'hello world'); assert.equal(thrown, true); }); }); @@ -964,8 +967,8 @@ module.exports = input; format: 'es' }); }) - .then(bundle => { - assert.equal(bundle.code.trim(), `alert('hello');`); + .then(({ output }) => { + assert.equal(output[0].code.trim(), `alert('hello');`); }); }); }); \ No newline at end of file diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 678f34fc159..e1b48ffc82d 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,3 +1,3 @@ exports.input = 'acorn, acornInjectPlugins, cache, cacheExpiry, chunkGroupingSize, context, entry, experimentalTopLevelAwait, external, inlineDynamicImports, input, manualChunks, moduleContext, onwarn, optimizeChunks, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, treeshake, watch'; -exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, cacheExpirt, chunkFileNames, chunkGroupingSize, compact, config, context, dir, e, entry, entryFileNames, environment, esModule, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, optimizeChunks, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapFile, strict, treeshake, v, w, watch'; +exports.flags = 'acorn, acornInjectPlugins, amd, assetFileNames, banner, c, cache, cacheExpiry, chunkFileNames, chunkGroupingSize, compact, config, context, dir, e, entry, entryFileNames, environment, esModule, experimentalTopLevelAwait, exports, extend, external, f, file, footer, format, freeze, g, globals, h, i, indent, inlineDynamicImports, input, interop, intro, m, manualChunks, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, optimizeChunks, outro, paths, perf, plugins, preferConst, preserveModules, preserveSymlinks, shimMissingExports, silent, sourcemap, sourcemapFile, strict, treeshake, v, w, watch'; exports.output = 'amd, assetFileNames, banner, dir, chunkFileNames, compact, entryFileNames, esModule, exports, extend, file, footer, format, freeze, globals, indent, interop, intro, name, namespaceToStringTag, noConflict, outro, paths, sourcemap, sourcemapFile, strict'; diff --git a/test/sourcemaps/index.js b/test/sourcemaps/index.js index f091705619b..bc3dac1b6d5 100644 --- a/test/sourcemaps/index.js +++ b/test/sourcemaps/index.js @@ -59,7 +59,7 @@ function generateAndTestBundle(bundle, outputOptions, config, format, warnings) } return bundle.generate(outputOptions); }) - .then(({ code, map }) => { + .then(({ output: [{ code, map }] }) => { if (config.test) { return config.test(code, map, { format }); }