Skip to content

Commit e18ec72

Browse files
committed
Use new approach for setting source
1 parent 9f584bd commit e18ec72

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

packages/utils/src/env.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
1717

18-
declare const __SENTRY_CDN_BUNDLE__: boolean | undefined;
18+
type SdkSource = 'npm' | 'cdn' | 'loader';
19+
20+
declare const __SENTRY_SDK_SOURCE__: SdkSource | undefined;
1921

2022
/**
2123
* Figures out if we're building a browser bundle.
@@ -27,8 +29,8 @@ export function isBrowserBundle(): boolean {
2729
}
2830

2931
/**
30-
* Figures out if we're a CDN or npm bundle.
32+
* Get source of SDK.
3133
*/
32-
export function isCDNBundle(): 'cdn' | 'npm' {
33-
return typeof __SENTRY_CDN_BUNDLE__ !== 'undefined' && !!__SENTRY_CDN_BUNDLE__ ? 'npm' : 'cdn';
34+
export function getSDKSource(): SdkSource {
35+
return typeof __SENTRY_SDK_SOURCE__ !== 'undefined' ? __SENTRY_SDK_SOURCE__ : 'npm';
3436
}

rollup/bundleHelpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
makeTerserPlugin,
1818
makeTSPlugin,
1919
makeExcludeReplayPlugin,
20-
makeIsCDNBundlePlugin,
20+
makeSetSDKSourcePlugin,
2121
} from './plugins/index.js';
2222
import { mergePlugins } from './utils';
2323

@@ -142,29 +142,29 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
142142
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
143143
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
144144
const terserPlugin = makeTerserPlugin();
145-
const isCDNBundlePlugin = makeIsCDNBundlePlugin(true);
145+
const setSdkSourcePlugin = makeSetSDKSourcePlugin('cdn');
146146

147147
// The additional options to use for each variant we're going to create.
148148
const variantSpecificConfigMap = {
149149
'.js': {
150150
output: {
151151
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
152152
},
153-
plugins: [includeDebuggingPlugin, isCDNBundlePlugin],
153+
plugins: [includeDebuggingPlugin, setSdkSourcePlugin],
154154
},
155155

156156
'.min.js': {
157157
output: {
158158
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
159159
},
160-
plugins: [stripDebuggingPlugin, terserPlugin, isCDNBundlePlugin],
160+
plugins: [stripDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
161161
},
162162

163163
'.debug.min.js': {
164164
output: {
165165
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
166166
},
167-
plugins: [includeDebuggingPlugin, terserPlugin, isCDNBundlePlugin],
167+
plugins: [includeDebuggingPlugin, setSdkSourcePlugin, terserPlugin],
168168
},
169169
};
170170

rollup/npmHelpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
makeCleanupPlugin,
1414
makeSucrasePlugin,
1515
makeDebugBuildStatementReplacePlugin,
16-
makeIsCDNBundlePlugin,
16+
makeSetSDKSourcePlugin,
1717
} from './plugins/index.js';
1818
import { mergePlugins } from './utils';
1919

@@ -32,7 +32,7 @@ export function makeBaseNPMConfig(options = {}) {
3232
const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin();
3333
const cleanupPlugin = makeCleanupPlugin();
3434
const extractPolyfillsPlugin = makeExtractPolyfillsPlugin();
35-
const isNPMBundlePlugin = makeIsCDNBundlePlugin(false);
35+
const setSdkSourcePlugin = makeSetSDKSourcePlugin('npm');
3636

3737
const defaultBaseConfig = {
3838
input: entrypoints,
@@ -85,11 +85,11 @@ export function makeBaseNPMConfig(options = {}) {
8585

8686
plugins: [
8787
nodeResolvePlugin,
88+
setSdkSourcePlugin,
8889
sucrasePlugin,
8990
debugBuildStatementReplacePlugin,
9091
cleanupPlugin,
9192
extractPolyfillsPlugin,
92-
isNPMBundlePlugin,
9393
],
9494

9595
// don't include imported modules from outside the package in the final output

rollup/plugins/bundlePlugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export function makeIsDebugBuildPlugin(includeDebugging) {
6363
});
6464
}
6565

66-
export function makeIsCDNBundlePlugin(isCDNBundle) {
66+
export function makeSetSDKSourcePlugin(sdkSource) {
6767
return replace({
6868
values: {
69-
__SENTRY_CDN_BUNDLE__: isCDNBundle,
69+
__SENTRY_SDK_SOURCE__: sdkSource,
7070
},
7171
});
7272
}

0 commit comments

Comments
 (0)