diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72d572c01e5c..cd358158b2ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,6 @@ env: ${{ github.workspace }}/packages/*/build ${{ github.workspace }}/packages/ember/*.d.ts ${{ github.workspace }}/packages/gatsby/*.d.ts - ${{ github.workspace }}/packages/core/src/version.ts ${{ github.workspace }}/packages/utils/cjs ${{ github.workspace }}/packages/utils/esm diff --git a/packages/core/test/lib/carrier.test.ts b/packages/core/test/lib/carrier.test.ts index 3c94c96b98c1..6e846d496ea5 100644 --- a/packages/core/test/lib/carrier.test.ts +++ b/packages/core/test/lib/carrier.test.ts @@ -42,14 +42,13 @@ describe('getSentryCarrier', () => { describe('multiple (older) SDKs', () => { it("returns the version of the sentry carrier object of the SDK's version rather than the one set in .version", () => { const sentryCarrier = getSentryCarrier({ + // @ts-expect-error - this is just a test object __SENTRY__: { - version: '8.0.0' as const, // another SDK set this + version: '8.0.0', // another SDK set this '8.0.0': { - // @ts-expect-error - this is just a test object, not passing a full stack stack: {}, }, [SDK_VERSION]: { - // @ts-expect-error - this is just a test object, not passing a full ACS acs: {}, }, hub: {}, diff --git a/packages/utils/.eslintrc.js b/packages/utils/.eslintrc.js index 35c6aab563f5..604db95b9dbe 100644 --- a/packages/utils/.eslintrc.js +++ b/packages/utils/.eslintrc.js @@ -15,5 +15,5 @@ module.exports = { }, ], // symlinks to the folders inside of `build`, created to simulate what's in the npm package - ignorePatterns: ['cjs/**', 'esm/**'], + ignorePatterns: ['cjs/**', 'esm/**', 'rollup.npm.config.mjs'], }; diff --git a/packages/utils/package.json b/packages/utils/package.json index ed4493a2a98b..3ef330009ccc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -63,7 +63,6 @@ "lint": "eslint . --format stylish", "test": "jest", "test:watch": "jest --watch", - "version": "node ../../scripts/versionbump.js src/version.ts", "yalc:publish": "yalc publish --push --sig" }, "volta": { diff --git a/packages/utils/rollup.npm.config.mjs b/packages/utils/rollup.npm.config.mjs index d28a7a6f54a0..8e219b3c2d9b 100644 --- a/packages/utils/rollup.npm.config.mjs +++ b/packages/utils/rollup.npm.config.mjs @@ -1,4 +1,6 @@ +import replace from '@rollup/plugin-replace'; import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; +import packageJson from './package.json' with { type: 'json' }; export default makeNPMConfigVariants( makeBaseNPMConfig({ @@ -12,6 +14,14 @@ export default makeNPMConfigVariants( ? true : Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES), }, + plugins: [ + replace({ + preventAssignment: true, + values: { + __SENTRY_SDK_VERSION__: JSON.stringify(packageJson.version), + }, + }), + ], }, }), ); diff --git a/packages/utils/src/version.ts b/packages/utils/src/version.ts index 79596a866885..c4f3fcfb8363 100644 --- a/packages/utils/src/version.ts +++ b/packages/utils/src/version.ts @@ -1 +1,4 @@ -export const SDK_VERSION = '8.38.0'; +// This is a magic string replaced by rollup +declare const __SENTRY_SDK_VERSION__: string; + +export const SDK_VERSION = typeof __SENTRY_SDK_VERSION__ === 'string' ? __SENTRY_SDK_VERSION__ : '0.0.0-unknown.0'; diff --git a/scripts/versionbump.js b/scripts/versionbump.js deleted file mode 100644 index 931df2a7829c..000000000000 --- a/scripts/versionbump.js +++ /dev/null @@ -1,31 +0,0 @@ -const { readFile, writeFile } = require('node:fs').promises; -const pjson = require(`${process.cwd()}/package.json`); - -const REPLACE_REGEX = /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g; - -async function run() { - const files = process.argv.slice(2); - if (files.length === 0) { - // eslint-disable-next-line no-console - console.error('[versionbump] Please provide files to bump'); - process.exit(1); - } - - try { - await Promise.all( - files.map(async file => { - const data = String(await readFile(file, 'utf8')); - await writeFile(file, data.replace(REPLACE_REGEX, pjson.version)); - }), - ); - - // eslint-disable-next-line no-console - console.log(`[versionbump] Bumped version for ${files.join(', ')}`); - } catch (error) { - // eslint-disable-next-line no-console - console.error('[versionbump] Error occurred:', error); - process.exit(1); - } -} - -run();