Skip to content

Commit

Permalink
Merge generate and write
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 21, 2020
1 parent 786909a commit 97f51ce
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions src/rollup/rollup.ts
Expand Up @@ -65,58 +65,24 @@ export async function rollupInternal(

const result: RollupBuild = {
cache: useCache ? graph.getCache() : undefined,
// TODO Lukas merge generate and write here
async generate(rawOutputOptions: OutputOptions) {
const {
options: outputOptions,
outputPluginDriver,
unsetOptions
} = getOutputOptionsAndPluginDriver(
rawOutputOptions as GenericConfigObject,
graph.pluginDriver,
inputOptions,
unsetInputOptions
);
const bundle = new Bundle(
outputOptions,
unsetOptions,
return handleGenerateWrite(
false,
inputOptions,
outputPluginDriver,
unsetInputOptions,
rawOutputOptions as GenericConfigObject,
graph
);
return createOutput(await bundle.generate(false));
},
watchFiles: Object.keys(graph.watchFiles),
async write(rawOutputOptions: OutputOptions) {
const {
options: outputOptions,
outputPluginDriver,
unsetOptions
} = getOutputOptionsAndPluginDriver(
rawOutputOptions as GenericConfigObject,
graph.pluginDriver,
return handleGenerateWrite(
true,
inputOptions,
unsetInputOptions
);
if (!outputOptions.dir && !outputOptions.file) {
return error({
code: 'MISSING_OPTION',
message: 'You must specify "output.file" or "output.dir" for the build.'
});
}
const bundle = new Bundle(
outputOptions,
unsetOptions,
inputOptions,
outputPluginDriver,
unsetInputOptions,
rawOutputOptions as GenericConfigObject,
graph
);
const generated = await bundle.generate(true);
await Promise.all(
Object.keys(generated).map(chunkId => writeOutputFile(generated[chunkId], outputOptions))
);
await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
return createOutput(generated);
}
};
if (inputOptions.perf) result.getTimings = getTimings;
Expand Down Expand Up @@ -161,6 +127,40 @@ function normalizePlugins(plugins: Plugin[], anonymousPrefix: string): void {
}
}

async function handleGenerateWrite(
isWrite: boolean,
inputOptions: NormalizedInputOptions,
unsetInputOptions: Set<string>,
rawOutputOptions: GenericConfigObject,
graph: Graph
): Promise<RollupOutput> {
const {
options: outputOptions,
outputPluginDriver,
unsetOptions
} = getOutputOptionsAndPluginDriver(
rawOutputOptions,
graph.pluginDriver,
inputOptions,
unsetInputOptions
);
const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
const generated = await bundle.generate(isWrite);
if (isWrite) {
if (!outputOptions.dir && !outputOptions.file) {
return error({
code: 'MISSING_OPTION',
message: 'You must specify "output.file" or "output.dir" for the build.'
});
}
await Promise.all(
Object.keys(generated).map(chunkId => writeOutputFile(generated[chunkId], outputOptions))
);
await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
}
return createOutput(generated);
}

function getOutputOptionsAndPluginDriver(
rawOutputOptions: GenericConfigObject,
inputPluginDriver: PluginDriver,
Expand Down

0 comments on commit 97f51ce

Please sign in to comment.