Skip to content

Commit

Permalink
chore: use package.json version field as compatibility key
Browse files Browse the repository at this point in the history
  • Loading branch information
shhdgit committed May 28, 2021
1 parent 98e2e8b commit 565209d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions ui/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
REACT_APP_SENTRY_DSN=https://[email protected]/5721090
REACT_APP_SENTRY_ENABLED=false
RELEASE_VERSION=$set_by_config_overrides
1 change: 1 addition & 0 deletions ui/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ REACT_APP_VERSION=$npm_package_version
REACT_APP_NAME=$npm_package_name
REACT_APP_SENTRY_DSN=https://[email protected]/5721090
REACT_APP_SENTRY_ENABLED=true
RELEASE_VERSION=$set_by_config_overrides
18 changes: 10 additions & 8 deletions ui/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ const supportDynamicPublicPathPrefix = () => (config) => {
return config
}

const overrideProcessEnv = value => config => {
const plugin = config.plugins.find(plugin => plugin.constructor.name === 'DefinePlugin');
const processEnv = plugin.definitions['process.env'] || {};
const overrideProcessEnv = (value) => (config) => {
const plugin = config.plugins.find(
(plugin) => plugin.constructor.name === 'DefinePlugin'
)
const processEnv = plugin.definitions['process.env'] || {}

plugin.definitions['process.env'] = {
...processEnv,
...value,
};
}

return config;
};
return config
}

const getInternalVersion = () => {
const out = execSync(`grep -v '^\#' ../release-version`)
Expand Down Expand Up @@ -171,6 +173,6 @@ module.exports = override(
addExtraEntries(),
supportDynamicPublicPathPrefix(),
overrideProcessEnv({
INTERNAL_VERSION: JSON.stringify(getInternalVersion())
}),
RELEASE_VERSION: JSON.stringify(getInternalVersion()),
})
)
3 changes: 2 additions & 1 deletion ui/lib/utils/useCompatibilityLocalstorage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useLocalStorageState } from 'ahooks'

// we can **update version field in package.json** to upgrade local storage version key
export function useCompatibilityLocalstorage<T>(
key: string,
defaultValue: T | (() => T)
) {
return useLocalStorageState(
`${key}_${process.env.INTERNAL_VERSION}`,
`${key}.v${process.env.REACT_APP_VERSION}`,
defaultValue
)
}
2 changes: 1 addition & 1 deletion ui/src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Integrations } from '@sentry/tracing'
import { sentryEnabled } from '@lib/utils/sentryHelpers'

if (sentryEnabled) {
const version = process.env.REACT_APP_VERSION
const version = process.env.RELEASE_VERSION
const name = process.env.REACT_APP_NAME
const hash = process.env.REACT_APP_COMMIT_HASH
const release = `${name}@${version}+${hash}`
Expand Down

0 comments on commit 565209d

Please sign in to comment.