Skip to content

Commit

Permalink
feat: Add in debug option, and log out short sha for commit being upl…
Browse files Browse the repository at this point in the history
…oaded (#117)

Add in bundler plugin config option to enable debug level logs.
  • Loading branch information
nicholas-codecov committed Apr 9, 2024
1 parent ff552dc commit 153f684
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/popular-chicken-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@codecov/bundler-plugin-core": patch
"@codecov/webpack-plugin": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
---

Add in debug option that will enable more in-depth logs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("bundleAnalysisPluginFactory", () => {
enableBundleAnalysis: true,
retryCount: 3,
uploadToken: "test-token",
debug: false,
},
bundleAnalysisUploadPlugin: () => ({
version: "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getPreSignedURL } from "../utils/getPreSignedURL.ts";
import { type NormalizedOptions } from "../utils/normalizeOptions.ts";
import { detectProvider } from "../utils/provider.ts";
import { uploadStats } from "../utils/uploadStats.ts";
import { debug } from "../utils/logging.ts";

interface BundleAnalysisUploadPluginArgs {
options: NormalizedOptions;
Expand Down Expand Up @@ -55,6 +56,10 @@ export const bundleAnalysisPluginFactory = ({
const inputs: ProviderUtilInputs = { envs, args };
const provider = await detectProvider(inputs);

if (options.debug) {
debug(`Uploading stats for commit: ${provider.commit.slice(0, 7)}`);
}

let url = "";
try {
url = await getPreSignedURL({
Expand Down
3 changes: 3 additions & 0 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export interface Options {

/** Override values for passing custom information to API. */
uploadOverrides?: UploadOverrides;

/** Option to enable debug logs for the plugin. */
debug?: boolean;
}

export type BundleAnalysisUploadPlugin = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const tests: Test[] = [
dryRun: false,
retryCount: 3,
enableBundleAnalysis: false,
debug: false,
},
},
},
Expand All @@ -48,6 +49,7 @@ const tests: Test[] = [
slug: "test-slug",
pr: "1234",
},
debug: true,
},
},
expected: {
Expand All @@ -66,6 +68,7 @@ const tests: Test[] = [
slug: "test-slug",
pr: "1234",
},
debug: true,
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions packages/bundler-plugin-core/src/utils/normalizeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ const optionsSchemaFactory = (options: Options) =>
.string({ invalid_type_error: "`uploadToken` must be a string." })
.optional(),
uploadOverrides: UploadOverridesSchema.optional(),
debug: z
.boolean({
invalid_type_error: "`debug` must be a boolean.",
})
.default(false),
});

interface NormalizedOptionsFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function _getSHA(inputs: ProviderUtilInputs): string {
const mergeCommit = mergeCommitMessage.split(" ")[1];

commit = mergeCommit;
} else if (mergeCommitMessage === "") {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("rollupBundleAnalysisPlugin", () => {
dryRun: true,
enableBundleAnalysis: true,
retryCount: 1,
debug: false,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("viteBundleAnalysisPlugin", () => {
dryRun: true,
enableBundleAnalysis: true,
retryCount: 1,
debug: false,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("webpackBundleAnalysisPlugin", () => {
dryRun: true,
enableBundleAnalysis: true,
retryCount: 1,
debug: false,
},
});

Expand Down

0 comments on commit 153f684

Please sign in to comment.