Skip to content

Commit 8cfbd35

Browse files
author
Luca Forstner
authored
feat: Add sentryCliBinaryExists function (#171)
1 parent d967ae6 commit 8cfbd35

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

MIGRATION.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ The purpose of this option is to support module-federated projects or micro fron
4343
The `customHeader` was used to attach an additional header to outgoing requests to Sentry when uploading source maps.
4444
This option has been removed in favor of the `headers` option which allows for attaching multiple headers.
4545

46+
### Renaming of `cliBinaryExists` to `sentryCliBinaryExists`
47+
48+
The `cliBinaryExists` function was renamed to `sentryCliBinaryExists`.
49+
4650
## Upgrading from 0.3.x to 0.4.x
4751

4852
### Replacing default exports with named exports

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
uploadSourceMaps,
1111
} from "./sentry/releasePipeline";
1212
import "@sentry/tracing";
13+
import SentryCli from "@sentry/cli";
1314
import {
1415
addPluginOptionInformationToHub,
1516
addSpanToTransaction,
@@ -22,6 +23,7 @@ import { InternalOptions, normalizeUserOptions, validateOptions } from "./option
2223
import { getSentryCli } from "./sentry/cli";
2324
import { makeMain } from "@sentry/node";
2425
import path from "path";
26+
import fs from "fs";
2527

2628
const ALLOWED_TRANSFORMATION_FILE_ENDINGS = [".js", ".ts", ".jsx", ".tsx", ".mjs"];
2729

@@ -364,6 +366,15 @@ function generateGlobalInjectorCode({
364366
return code;
365367
}
366368

369+
/**
370+
* Determines whether the Sentry CLI binary is in its expected location.
371+
* This function is useful since `@sentry/cli` installs the binary via a post-install
372+
* script and post-install scripts may not always run. E.g. with `npm i --ignore-scripts`.
373+
*/
374+
export function sentryCliBinaryExists(): boolean {
375+
return fs.existsSync(SentryCli.getPath());
376+
}
377+
367378
// eslint-disable-next-line @typescript-eslint/no-explicit-any
368379
export const sentryVitePlugin: (options: Options) => any = unplugin.vite;
369380
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { sentryEsbuildPlugin } from "@sentry/bundler-plugin-core";
1+
export { sentryEsbuildPlugin, sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
22
export type { Options as SentryEsbuildPluginOptions } from "@sentry/bundler-plugin-core";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { sentryRollupPlugin } from "@sentry/bundler-plugin-core";
1+
export { sentryRollupPlugin, sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
22
export type { Options as SentryRollupPluginOptions } from "@sentry/bundler-plugin-core";

packages/vite-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { sentryVitePlugin } from "@sentry/bundler-plugin-core";
1+
export { sentryVitePlugin, sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
22
export type { Options as SentryVitePluginOptions } from "@sentry/bundler-plugin-core";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { sentryWebpackPlugin } from "@sentry/bundler-plugin-core";
1+
export { sentryWebpackPlugin, sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
22
export type { Options as SentryWebpackPluginOptions } from "@sentry/bundler-plugin-core";

0 commit comments

Comments
 (0)