Skip to content

Commit d39f50e

Browse files
authored
fix(core): Check for dev mode via process.env.NODE_ENV (#666)
1 parent 071fd5c commit d39f50e

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export function sentryUnpluginFactory({
8484
debug: userOptions.debug ?? false,
8585
});
8686

87+
// Not a bulletproof check but should be good enough to at least sometimes determine
88+
// if the plugin is called in dev/watch mode or for a prod build. The important part
89+
// here is to avoid a false positive. False negatives are okay.
90+
const isDevMode = process.env["NODE_ENV"] === "development";
91+
8792
try {
8893
const dotenvFile = fs.readFileSync(
8994
path.join(process.cwd(), ".env.sentry-build-plugin"),
@@ -106,7 +111,7 @@ export function sentryUnpluginFactory({
106111

107112
const options = normalizeUserOptions(userOptions);
108113

109-
if (unpluginMetaContext.watchMode || options.disable) {
114+
if (options.disable) {
110115
return [
111116
{
112117
name: "sentry-noop-plugin",
@@ -274,7 +279,7 @@ export function sentryUnpluginFactory({
274279
"Release injection disabled via `release.inject` option. Will not inject release."
275280
);
276281
} else if (!options.release.name) {
277-
logger.warn(
282+
logger.debug(
278283
"No release name provided. Will not inject release. Please set the `release.name` option to identify your release."
279284
);
280285
} else {
@@ -316,9 +321,11 @@ export function sentryUnpluginFactory({
316321
}
317322

318323
if (!options.release.name) {
319-
logger.warn(
324+
logger.debug(
320325
"No release name provided. Will not create release. Please set the `release.name` option to identify your release."
321326
);
327+
} else if (isDevMode) {
328+
logger.debug("Running in development mode. Will not create release.");
322329
} else if (!options.authToken) {
323330
logger.warn(
324331
"No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/"
@@ -367,6 +374,8 @@ export function sentryUnpluginFactory({
367374
logger.debug(
368375
"Source map upload was disabled. Will not upload sourcemaps using debug ID process."
369376
);
377+
} else if (isDevMode) {
378+
logger.debug("Running in development mode. Will not upload sourcemaps.");
370379
} else if (!options.authToken) {
371380
logger.warn(
372381
"No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/"

packages/rollup-plugin/test/public-api.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test("Rollup plugin should exist", () => {
77
});
88

99
describe("sentryRollupPlugin", () => {
10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
1014
it("returns an array of rollup plugins", () => {
1115
const plugins = sentryRollupPlugin({
1216
authToken: "test-token",
@@ -27,4 +31,41 @@ describe("sentryRollupPlugin", () => {
2731
"sentry-file-deletion-plugin",
2832
]);
2933
});
34+
35+
it("doesn't include release management and debug id upload plugins if NODE_ENV is 'development'", () => {
36+
const originalNodeEnv = process.env["NODE_ENV"];
37+
process.env["NODE_ENV"] = "development";
38+
39+
const consoleSpy = jest.spyOn(console, "debug").mockImplementation(() => {
40+
/* avoid test output pollution */
41+
});
42+
43+
const plugins = sentryRollupPlugin({
44+
authToken: "test-token",
45+
org: "test-org",
46+
project: "test-project",
47+
debug: true,
48+
}) as Plugin[];
49+
50+
expect(Array.isArray(plugins)).toBe(true);
51+
52+
const pluginNames = plugins.map((plugin) => plugin.name);
53+
54+
expect(pluginNames).toEqual([
55+
"sentry-telemetry-plugin",
56+
"sentry-rollup-release-injection-plugin",
57+
"sentry-rollup-debug-id-injection-plugin",
58+
"sentry-file-deletion-plugin",
59+
]);
60+
61+
expect(consoleSpy).toHaveBeenCalledWith(
62+
expect.stringContaining("Running in development mode. Will not create release.")
63+
);
64+
65+
expect(consoleSpy).toHaveBeenCalledWith(
66+
expect.stringContaining("Running in development mode. Will not upload sourcemaps.")
67+
);
68+
69+
process.env["NODE_ENV"] = originalNodeEnv;
70+
});
3071
});

packages/vite-plugin/test/public-api.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test("Vite plugin should exist", () => {
77
});
88

99
describe("sentryVitePlugin", () => {
10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
1014
it("returns an array of Vite plugins", () => {
1115
const plugins = sentryVitePlugin({
1216
authToken: "test-token",
@@ -27,4 +31,41 @@ describe("sentryVitePlugin", () => {
2731
"sentry-file-deletion-plugin",
2832
]);
2933
});
34+
35+
it("doesn't include release management and debug id upload plugins if NODE_ENV is 'development'", () => {
36+
const originalNodeEnv = process.env["NODE_ENV"];
37+
process.env["NODE_ENV"] = "development";
38+
39+
const consoleSpy = jest.spyOn(console, "debug").mockImplementation(() => {
40+
/* avoid test output pollution */
41+
});
42+
43+
const plugins = sentryVitePlugin({
44+
authToken: "test-token",
45+
org: "test-org",
46+
project: "test-project",
47+
debug: true,
48+
}) as VitePlugin[];
49+
50+
expect(Array.isArray(plugins)).toBe(true);
51+
52+
const pluginNames = plugins.map((plugin) => plugin.name);
53+
54+
expect(pluginNames).toEqual([
55+
"sentry-telemetry-plugin",
56+
"sentry-vite-release-injection-plugin",
57+
"sentry-vite-debug-id-injection-plugin",
58+
"sentry-file-deletion-plugin",
59+
]);
60+
61+
expect(consoleSpy).toHaveBeenCalledWith(
62+
expect.stringContaining("Running in development mode. Will not create release.")
63+
);
64+
65+
expect(consoleSpy).toHaveBeenCalledWith(
66+
expect.stringContaining("Running in development mode. Will not upload sourcemaps.")
67+
);
68+
69+
process.env["NODE_ENV"] = originalNodeEnv;
70+
});
3071
});

0 commit comments

Comments
 (0)