Skip to content

Commit 2345793

Browse files
authored
ref(core): Add missing and change unused options (#101)
Revisit our options after checking them for completeness against the webpack plugin and Sentry CLI: * Add the missing `debug` options to the plugin and make the `logger.debug` output depend on it * Pass the previously unused `dist` option to the CLI constructor * Move the previously top-level `validate` option to `IncludeEntry`
1 parent b6e9f34 commit 2345793

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
8686
hub: sentryHub,
8787
prefix: `[sentry-${unpluginMetaContext.framework}-plugin]`,
8888
silent: internalOptions.silent,
89+
debug: internalOptions.debug,
8990
});
9091

9192
const cli = getSentryCli(internalOptions, logger);

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type RequiredInternalOptions = Required<
99
| "url"
1010
| "release"
1111
| "finalize"
12-
| "validate"
1312
| "vcsRemote"
1413
| "dryRun"
1514
| "debug"
@@ -36,7 +35,10 @@ export type InternalOptions = RequiredInternalOptions &
3635
NormalizedInternalOptions;
3736

3837
type RequiredInternalIncludeEntry = Required<
39-
Pick<UserIncludeEntry, "paths" | "ext" | "stripCommonPrefix" | "sourceMapReference" | "rewrite">
38+
Pick<
39+
UserIncludeEntry,
40+
"paths" | "ext" | "stripCommonPrefix" | "sourceMapReference" | "rewrite" | "validate"
41+
>
4042
>;
4143

4244
type OptionalInternalIncludeEntry = Partial<
@@ -84,7 +86,6 @@ export function normalizeUserOptions(userOptions: UserOptions): InternalOptions
8486
url: userOptions.url ?? "https://sentry.io/",
8587
release: userOptions.release ?? "",
8688
finalize: userOptions.finalize ?? true,
87-
validate: userOptions.validate ?? false,
8889
vcsRemote: userOptions.vcsRemote ?? "origin",
8990
customHeader: userOptions.customHeader,
9091
dryRun: userOptions.dryRun ?? false,
@@ -134,5 +135,6 @@ function normalizeIncludeEntry(
134135
stripCommonPrefix: includeEntry.stripCommonPrefix ?? userOptions.stripCommonPrefix ?? false,
135136
sourceMapReference: includeEntry.sourceMapReference ?? userOptions.sourceMapReference ?? true,
136137
rewrite: includeEntry.rewrite ?? userOptions.rewrite ?? true,
138+
validate: includeEntry.validate ?? userOptions.validate ?? false,
137139
};
138140
}

packages/bundler-plugin-core/src/sentry/cli.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ export type SentryCLILike = SentryCli | SentryDryRunCLI;
1212
* that makes no-ops out of most CLI operations
1313
*/
1414
export function getSentryCli(internalOptions: InternalOptions, logger: Logger): SentryCLILike {
15-
const { silent, org, project, authToken, url, vcsRemote, customHeader } = internalOptions;
15+
const { silent, org, project, authToken, url, vcsRemote, customHeader, dist } = internalOptions;
1616
const cli = new SentryCli(internalOptions.configFile, {
17-
silent,
17+
url,
18+
authToken,
1819
org,
1920
project,
20-
authToken,
21-
url,
2221
vcsRemote,
22+
dist,
23+
silent,
2324
customHeader,
2425
});
2526

packages/bundler-plugin-core/src/sentry/logger.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { SeverityLevel, Hub } from "@sentry/node";
22

33
interface LoggerOptions {
4-
silent?: boolean;
4+
silent: boolean;
5+
debug: boolean;
56
hub: Hub;
67
prefix: string;
78
}
@@ -24,23 +25,23 @@ export function createLogger(options: LoggerOptions): Logger {
2425

2526
return {
2627
info(message: string, ...params: unknown[]) {
27-
if (!options?.silent) {
28+
if (!options.silent) {
2829
// eslint-disable-next-line no-console
2930
console.log(`${options.prefix} Info: ${message}`, ...params);
3031
}
3132

3233
addBreadcrumb("info", message);
3334
},
3435
warn(message: string, ...params: unknown[]) {
35-
if (!options?.silent) {
36+
if (!options.silent) {
3637
// eslint-disable-next-line no-console
3738
console.log(`${options.prefix} Warning: ${message}`, ...params);
3839
}
3940

4041
addBreadcrumb("warning", message);
4142
},
4243
error(message: string, ...params: unknown[]) {
43-
if (!options?.silent) {
44+
if (!options.silent) {
4445
// eslint-disable-next-line no-console
4546
console.log(`${options.prefix} Error: ${message}`, ...params);
4647
}
@@ -49,7 +50,7 @@ export function createLogger(options: LoggerOptions): Logger {
4950
},
5051

5152
debug(message: string, ...params: unknown[]) {
52-
if (!options?.silent) {
53+
if (!options.silent && options.debug) {
5354
// eslint-disable-next-line no-console
5455
console.log(`${options.prefix} Debug: ${message}`, ...params);
5556
}

packages/bundler-plugin-core/src/sentry/releasePipeline.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export async function uploadSourceMaps(options: InternalOptions, ctx: BuildConte
5555

5656
ctx.logger.info("Uploading Sourcemaps.");
5757

58+
// Since our internal include entries contain all top-level sourcemaps options,
59+
// we only need to pass the include option here.
5860
await ctx.cli.releases.uploadSourceMaps(options.release, { include: options.include });
5961

6062
ctx.logger.info("Successfully uploaded Sourcemaps.");

packages/bundler-plugin-core/src/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ export type Options = Omit<IncludeEntry, "paths"> & {
8888
*/
8989
include: string | IncludeEntry | Array<string | IncludeEntry>;
9090

91-
/**
92-
* When `true`, attempts source map validation before upload if rewriting is not enabled.
93-
* It will spot a variety of issues with source maps and cancel the upload if any are found.
94-
*
95-
* Defaults to `false` as this can cause false positives.
96-
*/
97-
validate?: boolean;
98-
9991
/* --- other unimportant (for now) stuff- properties: */
10092

10193
/**
@@ -261,6 +253,14 @@ export type IncludeEntry = {
261253
* Defaults to true
262254
*/
263255
rewrite?: boolean;
256+
257+
/**
258+
* When `true`, attempts source map validation before upload if rewriting is not enabled.
259+
* It will spot a variety of issues with source maps and cancel the upload if any are found.
260+
*
261+
* Defaults to `false` as this can cause false positives.
262+
*/
263+
validate?: boolean;
264264
};
265265

266266
type SetCommitsOptions = {

packages/bundler-plugin-core/test/logger.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Logger", () => {
2626
["debug", "Debug"],
2727
] as const)(".%s() should log correctly", (loggerMethod, logLevel) => {
2828
const prefix = "[some-prefix]";
29-
const logger = createLogger({ hub, prefix });
29+
const logger = createLogger({ hub, prefix, silent: false, debug: true });
3030

3131
logger[loggerMethod]("Hey!");
3232

@@ -45,7 +45,7 @@ describe("Logger", () => {
4545
["debug", "Debug"],
4646
] as const)(".%s() should log multiple params correctly", (loggerMethod, logLevel) => {
4747
const prefix = "[some-prefix]";
48-
const logger = createLogger({ hub, prefix });
48+
const logger = createLogger({ hub, prefix, silent: false, debug: true });
4949

5050
logger[loggerMethod]("Hey!", "this", "is", "a test with", 5, "params");
5151

@@ -65,9 +65,9 @@ describe("Logger", () => {
6565
});
6666

6767
describe("doesn't log when `silent` option is `true`", () => {
68-
it.each(["info", "warn", "error"] as const)(".%s()", (loggerMethod) => {
68+
it.each(["info", "warn", "error", "debug"] as const)(".%s()", (loggerMethod) => {
6969
const prefix = "[some-prefix]";
70-
const logger = createLogger({ silent: true, hub, prefix });
70+
const logger = createLogger({ hub, prefix, silent: true, debug: true });
7171

7272
logger[loggerMethod]("Hey!");
7373

packages/bundler-plugin-core/test/option-mappings.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("normalizeUserOptions()", () => {
2525
rewrite: true,
2626
sourceMapReference: true,
2727
stripCommonPrefix: false,
28+
validate: false,
2829
},
2930
],
3031
org: "my-org",
@@ -33,7 +34,6 @@ describe("normalizeUserOptions()", () => {
3334
silent: false,
3435
telemetry: true,
3536
url: "https://sentry.io/",
36-
validate: false,
3737
vcsRemote: "origin",
3838
});
3939
});
@@ -68,6 +68,7 @@ describe("normalizeUserOptions()", () => {
6868
rewrite: true,
6969
sourceMapReference: false,
7070
stripCommonPrefix: true,
71+
validate: false,
7172
},
7273
],
7374
org: "my-org",
@@ -76,7 +77,6 @@ describe("normalizeUserOptions()", () => {
7677
silent: false,
7778
telemetry: true,
7879
url: "https://sentry.io/",
79-
validate: false,
8080
vcsRemote: "origin",
8181
});
8282
});

0 commit comments

Comments
 (0)