Skip to content

Commit

Permalink
provide bundle on output property
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 4, 2018
1 parent 994bd6e commit 2a634c7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/rollup/index.ts
Expand Up @@ -321,7 +321,9 @@ export default function rollup(
generate: <any>((rawOutputOptions: GenericConfigObject) => {
const promise = generate(rawOutputOptions, false).then(
result =>
inputOptions.experimentalCodeSplitting ? result : <OutputChunk>result[chunks[0].id]
inputOptions.experimentalCodeSplitting
? { output: result }
: <OutputChunk>result[chunks[0].id]
);
Object.defineProperty(promise, 'code', throwAsyncGenerateError);
Object.defineProperty(promise, 'map', throwAsyncGenerateError);
Expand Down Expand Up @@ -353,7 +355,7 @@ export default function rollup(
).then(
() =>
inputOptions.experimentalCodeSplitting
? result
? { output: result }
: <OutputChunk>result[chunks[0].id]
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/rollup/types.d.ts
Expand Up @@ -344,8 +344,8 @@ export interface OutputBundle {

export interface RollupBuild {
cache: RollupCache;
generate: (outputOptions: OutputOptions) => Promise<OutputBundle>;
write: (options: OutputOptions) => Promise<OutputBundle>;
generate: (outputOptions: OutputOptions) => Promise<{ output: OutputBundle }>;
write: (options: OutputOptions) => Promise<{ output: OutputBundle }>;
getTimings?: () => SerializedTimings;
}

Expand Down
42 changes: 21 additions & 21 deletions test/hooks/index.js
Expand Up @@ -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`);
});
});

Expand All @@ -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;
Expand Down Expand Up @@ -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');
});
});

Expand All @@ -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');
});
});

Expand Down Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -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`);
});
});

Expand Down

0 comments on commit 2a634c7

Please sign in to comment.