|
2 | 2 | /* eslint-disable import/no-dynamic-require */ |
3 | 3 | const path = require('path'); |
4 | 4 | const fs = require('fs'); |
| 5 | +const { execSync } = require('child_process'); |
5 | 6 | const { defineConfig } = require('@rspack/cli'); |
6 | 7 | const { TsCheckerRspackPlugin } = require('ts-checker-rspack-plugin'); |
7 | 8 | const dotenv = require('dotenv'); |
@@ -30,6 +31,20 @@ module.exports = (webpackEnv, argv) => { |
30 | 31 | throw Error(`Invalid mode passed: ${mode}`); |
31 | 32 | } |
32 | 33 |
|
| 34 | + // Extract the git branch and commit from environment variables or git commands |
| 35 | + let gitBranch = env.GIT_BRANCH; |
| 36 | + let gitCommitHash = env.GIT_COMMIT_HASH; |
| 37 | + try { |
| 38 | + if (!gitBranch) { |
| 39 | + gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); |
| 40 | + } |
| 41 | + if (!gitCommitHash) { |
| 42 | + gitCommitHash = execSync('git rev-parse --short HEAD').toString().trim(); |
| 43 | + } |
| 44 | + } catch (e) { |
| 45 | + console.warn('Could not determine git branch/commit hash via git command, falling back to environment variables or undefined.'); |
| 46 | + } |
| 47 | + |
33 | 48 | const isDevServerOnly = env.dev_server_only?.toLowerCase() === 'true'; |
34 | 49 | const devtool = env.devtool?.toLowerCase() === 'false' ? false : (env.devtool || (isEnvDevelopment ? 'eval-source-map' : 'source-map')); |
35 | 50 | const isReactRefresh = isDevServer && isEnvDevelopment; |
@@ -388,6 +403,8 @@ module.exports = (webpackEnv, argv) => { |
388 | 403 | 'process.env.__APP_NAME__': JSON.stringify(appPkg.name), |
389 | 404 | 'process.env.__APP_DISPLAY_NAME__': JSON.stringify(appPkg.displayName || appPkg.name), |
390 | 405 | 'process.env.__VERSION__': JSON.stringify(appPkg.version), |
| 406 | + 'process.env.__GIT_BRANCH__': JSON.stringify(gitBranch), |
| 407 | + 'process.env.__GIT_COMMIT_HASH__': JSON.stringify(gitCommitHash), |
391 | 408 | 'process.env.__LICENSE__': JSON.stringify(appPkg.license), |
392 | 409 | 'process.env.__BUILD_ID__': JSON.stringify(buildId), |
393 | 410 | 'process.env.__APP_CONTEXT__': JSON.stringify('/'), |
|
0 commit comments