diff --git a/src/rollup/index.ts b/src/rollup/index.ts index a2e1a8ae119..b69c1f135e7 100644 --- a/src/rollup/index.ts +++ b/src/rollup/index.ts @@ -321,7 +321,9 @@ export default function rollup( generate: ((rawOutputOptions: GenericConfigObject) => { const promise = generate(rawOutputOptions, false).then( result => - inputOptions.experimentalCodeSplitting ? result : result[chunks[0].id] + inputOptions.experimentalCodeSplitting + ? { output: result } + : result[chunks[0].id] ); Object.defineProperty(promise, 'code', throwAsyncGenerateError); Object.defineProperty(promise, 'map', throwAsyncGenerateError); @@ -353,7 +355,7 @@ export default function rollup( ).then( () => inputOptions.experimentalCodeSplitting - ? result + ? { output: result } : result[chunks[0].id] ) ); diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 4055a6c3551..26fe43558b8 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -344,8 +344,8 @@ export interface OutputBundle { export interface RollupBuild { cache: RollupCache; - generate: (outputOptions: OutputOptions) => Promise; - write: (options: OutputOptions) => Promise; + generate: (outputOptions: OutputOptions) => Promise<{ output: OutputBundle }>; + write: (options: OutputOptions) => Promise<{ output: OutputBundle }>; getTimings?: () => SerializedTimings; } diff --git a/test/hooks/index.js b/test/hooks/index.js index 716d2ad54a3..d88b85463b9 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -267,9 +267,9 @@ describe('hooks', () => { .then(bundle => { return bundle.generate({ format: 'es' }); }) - .then(outputBundle => { - assert.equal(outputBundle['assets/test-19916f7d.ext'], 'hello world'); - assert.equal(outputBundle['input.js'].code, `var input = new URL(\'../assets/test-19916f7d.ext\', import.meta.url).href;\n\nexport default input;\n`); + .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`); }); }); @@ -291,8 +291,8 @@ describe('hooks', () => { .then(bundle => { return bundle.generate({ format: 'cjs' }); }) - .then(outputBundle => { - assert.equal(outputBundle['input.js'].code, `'use strict'; + .then(({ output }) => { + assert.equal(output['input.js'].code, `'use strict'; var input = new (typeof URL !== 'undefined' ? URL : require('ur'+'l').URL)((process.browser ? '' : 'file:') + __dirname + '/assets/test-19916f7d.ext', process.browser && document.baseURI).href; @@ -322,8 +322,8 @@ module.exports = input; assetFileNames: '[name][extname]' }); }) - .then(outputBundle => { - assert.equal(outputBundle['test.ext'], 'hello world'); + .then(({ output }) => { + assert.equal(output['test.ext'], 'hello world'); }); }); @@ -349,8 +349,8 @@ module.exports = input; .then(bundle => { return bundle.generate({ format: 'es' }); }) - .then(outputBundle => { - assert.equal(outputBundle['assets/test-19916f7d.ext'], 'hello world'); + .then(({ output }) => { + assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); }); }); @@ -380,8 +380,8 @@ module.exports = input; .then(bundle => { return bundle.generate({ format: 'es' }); }) - .then(outputBundle => { - assert.equal(outputBundle['assets/test-19916f7d.ext'], 'hello world'); + .then(({ output }) => { + assert.equal(output['assets/test-19916f7d.ext'], 'hello world'); }); }); @@ -503,16 +503,16 @@ module.exports = input; .then(outputBundle2 => [outputBundle1, outputBundle2]) ) ) - .then(([outputBundle1, outputBundle2]) => { - assert.equal(outputBundle1['input.js'].code, `alert('hello');\n`); - assert.equal(outputBundle1['assets/lateDepAsset-671f747d'], `custom source`); - assert.equal(outputBundle1['assets/lateMainAsset-863ea4b5'], `references assets/lateDepAsset-671f747d`); - - assert.equal(outputBundle2['input.js'].code, `'use strict';\n\nalert('hello');\n`); - assert.equal(outputBundle2['assets/lateDepAsset-671f747d'], undefined); - assert.equal(outputBundle2['assets/lateMainAsset-863ea4b5'], undefined); - assert.equal(outputBundle2['assets/lateDepAsset-c107f5fc'], `different source`); - assert.equal(outputBundle2['assets/lateMainAsset-6dc2262b'], `references assets/lateDepAsset-c107f5fc`); + .then(([{ output: output1 }, { output: output2 }]) => { + assert.equal(output1['input.js'].code, `alert('hello');\n`); + assert.equal(output1['assets/lateDepAsset-671f747d'], `custom source`); + assert.equal(output1['assets/lateMainAsset-863ea4b5'], `references assets/lateDepAsset-671f747d`); + + assert.equal(output2['input.js'].code, `'use strict';\n\nalert('hello');\n`); + assert.equal(output2['assets/lateDepAsset-671f747d'], undefined); + assert.equal(output2['assets/lateMainAsset-863ea4b5'], undefined); + assert.equal(output2['assets/lateDepAsset-c107f5fc'], `different source`); + assert.equal(output2['assets/lateMainAsset-6dc2262b'], `references assets/lateDepAsset-c107f5fc`); }); });