Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
feat: replace version with build-time variable.
Browse files Browse the repository at this point in the history
Version number will be replaced by webpack on build. Also remove version
unittest since it is redundant now.
  • Loading branch information
wdzeng committed Jul 11, 2023
1 parent 2494fba commit 90967ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
20 changes: 0 additions & 20 deletions src/__tests__/version.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export function isValidPassword(p: string | undefined): boolean {
return Boolean(p && p.length >= 8 && p.length <= 16)
}

export const version = '1.3.0'
export const version: string = process.env.VERSION || 'Development'
8 changes: 7 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import path from 'node:path'
import url from 'node:url'

import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
import webpack from 'webpack'

const projectRootPath = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)))
const packageJson = JSON.parse(fs.readFileSync(path.resolve(projectRootPath, 'package.json')))
const version = packageJson.version
const outputDir = path.resolve(projectRootPath, 'dist')

const versionPlugin = new webpack.DefinePlugin({ 'process.env.VERSION': JSON.stringify(version) })

export default {
mode: 'production',
entry: './src/index.ts',
Expand All @@ -32,5 +37,6 @@ export default {
experiments: {
topLevelAwait: true
},
externals: ['utf-8-validate', 'bufferutil']
externals: ['utf-8-validate', 'bufferutil'],
plugins: [versionPlugin]
}

0 comments on commit 90967ff

Please sign in to comment.