Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): display app version again #14844

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-shell-odd/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
Expand Down
5 changes: 3 additions & 2 deletions app-shell/electron-builder.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'
const path = require('path')
const { versionForProject } = require('../scripts/git-version')

const {
OT_APP_DEPLOY_BUCKET,
Expand Down Expand Up @@ -45,7 +44,9 @@ module.exports = async () => ({
},
],
extraMetadata: {
version: await versionForProject(project),
version: await (
await import('../scripts/git-version.mjs')
).versionForProject(project),
productName: project === 'robot-stack' ? 'Opentrons' : 'Opentrons-OT3',
},
extraResources: USE_PYTHON ? ['python'] : [],
Expand Down
2 changes: 1 addition & 1 deletion app-shell/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
Expand Down
110 changes: 59 additions & 51 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
import path from 'path'
import { defineConfig } from 'vite'
import { UserConfig, defineConfig } from 'vite'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { UserConfig, defineConfig } from 'vite'
import {defineConfig } from 'vite'
import type { UserConfig } from 'vite'

import react from '@vitejs/plugin-react'
import postCssImport from 'postcss-import'
import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import { versionForProject } from '../scripts/git-version.mjs'

export default defineConfig({
// this makes imports relative rather than absolute
base: '',
build: {
// Relative to the root
outDir: 'dist',
},
plugins: [
react({
include: '**/*.tsx',
babel: {
// Use babel.config.js files
configFile: true,
export default defineConfig(
async(): Promise<UserConfig> => {
const project = process.env.OPENTRONS_PROJECT ?? 'robot-stack'
const version = await versionForProject(project)
return {
// this makes imports relative rather than absolute
base: '',
build: {
// Relative to the root
outDir: 'dist',
},
}),
],
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
},
css: {
postcss: {
plugins: [
postCssImport({ root: 'src/' }),
postCssApply(),
postColorModFunction(),
postCssPresetEnv({ stage: 0 }),
lostCss(),
react({
include: '**/*.tsx',
babel: {
// Use babel.config.js files
configFile: true,
},
}),
],
},
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
'@opentrons/components/styles': path.resolve(
'../components/src/index.module.css'
),
'@opentrons/components': path.resolve('../components/src/index.ts'),
'@opentrons/shared-data': path.resolve('../shared-data/js/index.ts'),
'@opentrons/step-generation': path.resolve(
'../step-generation/src/index.ts'
),
'@opentrons/api-client': path.resolve('../api-client/src/index.ts'),
'@opentrons/react-api-client': path.resolve(
'../react-api-client/src/index.ts'
),
},
},
})
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
},
css: {
postcss: {
plugins: [
postCssImport({ root: 'src/' }),
postCssApply(),
postColorModFunction(),
postCssPresetEnv({ stage: 0 }),
lostCss(),
],
},
},
define: {
'process.env': process.env,
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_OPENTRONS_PROJECT_: JSON.stringify(project),
},
resolve: {
alias: {
'@opentrons/components/styles': path.resolve(
'../components/src/index.module.css'
),
'@opentrons/components': path.resolve('../components/src/index.ts'),
'@opentrons/shared-data': path.resolve('../shared-data/js/index.ts'),
'@opentrons/step-generation': path.resolve(
'../step-generation/src/index.ts'
),
'@opentrons/api-client': path.resolve('../api-client/src/index.ts'),
'@opentrons/react-api-client': path.resolve(
'../react-api-client/src/index.ts'
),
},
},
}
})
2 changes: 1 addition & 1 deletion discovery-client/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'
import pkg from './package.json'
import path from 'path'
import { UserConfig, defineConfig } from 'vite'
Expand Down
2 changes: 1 addition & 1 deletion discovery-client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const webpackMerge = require('webpack-merge')
const { DefinePlugin } = require('webpack')
const { nodeBaseConfig } = require('@opentrons/webpack-config')
const { versionForProject } = require('../scripts/git-version')
const { versionForProject } = require('../scripts/git-version.mjs')

const ENTRY_INDEX = path.join(__dirname, 'src/index.ts')
const ENTRY_CLI = path.join(__dirname, 'src/cli.ts')
Expand Down
2 changes: 1 addition & 1 deletion labware-library/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { baseConfig } = require('@opentrons/webpack-config')
// const {baseConfig, DEV_MODE} = require('@opentrons/webpack-config')
const pkg = require('./package.json')

const { versionForProject } = require('../scripts/git-version')
const { versionForProject } = require('../scripts/git-version.mjs')

const JS_ENTRY = path.join(__dirname, 'src/index.tsx')
const HTML_ENTRY = path.join(__dirname, 'src/index.hbs')
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssPresetEnv from 'postcss-preset-env'
import lostCss from 'lost'
import { versionForProject } from '../scripts/git-version'
import { versionForProject } from '../scripts/git-version.mjs'

const testAliases: {} | { 'file-saver': string } =
process.env.CYPRESS === '1'
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy/create-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {
tagFromDetails,
prefixForProject,
monorepoGit,
} = require('../git-version')
} = require('../git-version.mjs')

const USAGE =
'\nUsage:\n node ./scripts/deploy/create-release <token> <tag> [--deploy] [--allow-old]'
Expand Down
26 changes: 9 additions & 17 deletions scripts/git-version.js → scripts/git-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@
// What that all boils down to is that we need, and this module provides, an interface to get the version of a
// given project that currently exists in the monorepo.

const git = require('simple-git')
const { dirname } = require('path')
const REPO_BASE = dirname(__dirname)
import git from 'simple-git'
import { dirname } from 'path'
import { fileURLToPath } from 'url'
const REPO_BASE = dirname(dirname(fileURLToPath(import.meta.url)))

function monorepoGit() {
return git({ baseDir: REPO_BASE })
}

const detailsFromTag = tag =>
export const detailsFromTag = tag =>
tag.includes('@') ? tag.split('@') : ['robot-stack', tag.substring(1)]

function tagFromDetails(project, version) {
export function tagFromDetails(project, version) {
const prefix = prefixForProject(project)
return `${prefix}${version}`
}

function prefixForProject(project) {
export function prefixForProject(project) {
if (project === 'robot-stack') {
return 'v'
} else {
return `${project}@`
}
}

async function latestTagForProject(project) {
export async function latestTagForProject(project) {
return (
await monorepoGit().raw([
'describe',
Expand All @@ -50,7 +51,7 @@ async function latestTagForProject(project) {
).trim()
}

async function versionForProject(project) {
export async function versionForProject(project) {
return latestTagForProject(project)
.then(tag => detailsFromTag(tag)[1])
.catch(error => {
Expand All @@ -60,12 +61,3 @@ async function versionForProject(project) {
return '0.0.0-dev'
})
}

module.exports = {
detailsFromTag,
tagFromDetails,
prefixForProject,
latestTagForProject,
versionForProject,
monorepoGit,
}
2 changes: 1 addition & 1 deletion scripts/update-releases-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs/promises')

// Updates a releases historical manifest with a release's version.

const versionFinder = require('./git-version')
const versionFinder = require('./git-version.mjs')

const parseArgs = require('./deploy/lib/parseArgs')
const USAGE =
Expand Down
2 changes: 1 addition & 1 deletion usb-bridge/node-client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path')
const webpackMerge = require('webpack-merge')
const { DefinePlugin } = require('webpack')
const { nodeBaseConfig } = require('@opentrons/webpack-config')
const { versionForProject } = require('../../scripts/git-version')
const { versionForProject } = require('../../scripts/git-version.mjs')

const ENTRY_INDEX = path.join(__dirname, 'src/index.ts')
const ENTRY_CLI = path.join(__dirname, 'src/cli.ts')
Expand Down
Loading