Skip to content

Commit

Permalink
feat: Add option to customize the analysis output filename (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 authored Feb 6, 2024
1 parent bba8cda commit 3edb66d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/core/utils/building/internal-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export async function internalBuild(): Promise<BuildOutput> {

if (wxt.config.analysis.enabled) {
await combineAnalysisStats();
const statsPath = relative(wxt.config.root, wxt.config.analysis.outputFile);
wxt.logger.info(
`Analysis complete:\n ${pc.gray('└─')} ${pc.yellow('stats.html')}`,
`Analysis complete:\n ${pc.gray('└─')} ${pc.yellow(statsPath)}`,
);
}

Expand All @@ -94,7 +95,13 @@ async function combineAnalysisStats(): Promise<void> {

await exec(
'rollup-plugin-visualizer',
[...absolutePaths, '--template', wxt.config.analysis.template],
[
...absolutePaths,
'--template',
wxt.config.analysis.template,
'--filename',
wxt.config.analysis.outputFile,
],
{ cwd: wxt.config.root, stdio: 'inherit' },
);
await Promise.all(absolutePaths.map((statsFile) => fs.remove(statsFile)));
Expand Down
9 changes: 6 additions & 3 deletions src/core/utils/building/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export async function resolveConfig(
analysis: {
enabled: mergedConfig.analysis?.enabled ?? false,
template: mergedConfig.analysis?.template ?? 'treemap',
outputFile: path.resolve(
root,
mergedConfig.analysis?.outputFile ?? 'stats.html',
),
},
userConfigMetadata: userConfigMetadata ?? {},
alias,
Expand Down Expand Up @@ -216,9 +220,8 @@ function mergeInlineConfig(
outDir: inlineConfig.outDir ?? userConfig.outDir,
zip,
analysis: {
enabled: inlineConfig.analysis?.enabled ?? userConfig.analysis?.enabled,
template:
inlineConfig.analysis?.template ?? userConfig.analysis?.template,
...userConfig.analysis,
...inlineConfig.analysis,
},
alias: {
...userConfig.alias,
Expand Down
1 change: 1 addition & 0 deletions src/core/utils/testing/fake-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const fakeResolvedConfig = fakeObjectCreator<ResolvedConfig>(() => {
analysis: {
enabled: false,
template: 'treemap',
outputFile: 'stats.html',
},
zip: {
artifactTemplate: '{{name}}-{{version}}.zip',
Expand Down
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ export interface InlineConfig {
* @default "treemap"
*/
template?: PluginVisualizerOptions['template'];
/**
* Name of the output HTML file. Relative to the project's root directory.
*
* @default "stats.html"
*/
outputFile?: string;
};
/**
* Add additional paths to the `.wxt/tsconfig.json`. Use this instead of overwriting the `paths`
Expand Down Expand Up @@ -895,6 +901,8 @@ export interface ResolvedConfig {
analysis: {
enabled: boolean;
template: NonNullable<PluginVisualizerOptions['template']>;
/** Absolute file path */
outputFile: string;
};
userConfigMetadata: Omit<C12ResolvedConfig<UserConfig>, 'config'>;
/**
Expand Down

0 comments on commit 3edb66d

Please sign in to comment.