浏览代码

feat(build) make commit hash generation process generic

This way we can use it both in Webpack and TS builds.
dev0
Saúl Ibarra Corretgé 6 个月前
父节点
当前提交
73ff451f49
共有 6 个文件被更改,包括 30 次插入105 次删除
  1. 3
    0
      .gitignore
  2. 2
    1
      JitsiMeetJS.ts
  3. 0
    80
      package-lock.json
  4. 4
    4
      package.json
  5. 21
    0
      tools/gen-version.js
  6. 0
    20
      webpack-shared-config.js

+ 3
- 0
.gitignore 查看文件

@@ -20,3 +20,6 @@ types/auto
20 20
 types/types-comparer/auto.json
21 21
 types/types-comparer/hand-crafted.json
22 22
 *.tgz
23
+
24
+# Make sure we never commit a commit hash.
25
+version.ts

+ 2
- 1
JitsiMeetJS.ts 查看文件

@@ -36,6 +36,7 @@ import * as ConnectionQualityEvents
36 36
     from './service/connectivity/ConnectionQualityEvents';
37 37
 import * as E2ePingEvents from './service/e2eping/E2ePingEvents';
38 38
 import { createGetUserMediaEvent } from './service/statistics/AnalyticsEvents';
39
+import { COMMIT_HASH } from './version';
39 40
 
40 41
 const logger = Logger.getLogger('JitsiMeetJS');
41 42
 
@@ -109,7 +110,7 @@ interface ICreateLocalTrackFromMediaStreamOptions {
109 110
  */
110 111
 export default {
111 112
 
112
-    version: '{#COMMIT_HASH#}',
113
+    version: COMMIT_HASH,
113 114
 
114 115
     JitsiConnection,
115 116
 

+ 0
- 80
package-lock.json 查看文件

@@ -44,7 +44,6 @@
44 44
         "karma-sourcemap-loader": "0.3.8",
45 45
         "karma-webpack": "5.0.0",
46 46
         "process": "0.11.10",
47
-        "string-replace-loader": "3.0.3",
48 47
         "typedoc": "0.28.1",
49 48
         "typescript": "5.0.4",
50 49
         "webpack": "5.98.0",
@@ -7796,51 +7795,6 @@
7796 7795
         "node": ">=8.0"
7797 7796
       }
7798 7797
     },
7799
-    "node_modules/string-replace-loader": {
7800
-      "version": "3.0.3",
7801
-      "resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.3.tgz",
7802
-      "integrity": "sha512-8c26Dl6H9XmKNj3mFBvaUYR7ImOxQ4YRBFuUju78wXpa1cDpyDYvKmqGg8mfkxdYexQ/BBogB7PELlLnmR08nw==",
7803
-      "dev": true,
7804
-      "dependencies": {
7805
-        "loader-utils": "^2.0.0",
7806
-        "schema-utils": "^3.0.0"
7807
-      },
7808
-      "peerDependencies": {
7809
-        "webpack": "^5"
7810
-      }
7811
-    },
7812
-    "node_modules/string-replace-loader/node_modules/loader-utils": {
7813
-      "version": "2.0.4",
7814
-      "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
7815
-      "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
7816
-      "dev": true,
7817
-      "dependencies": {
7818
-        "big.js": "^5.2.2",
7819
-        "emojis-list": "^3.0.0",
7820
-        "json5": "^2.1.2"
7821
-      },
7822
-      "engines": {
7823
-        "node": ">=8.9.0"
7824
-      }
7825
-    },
7826
-    "node_modules/string-replace-loader/node_modules/schema-utils": {
7827
-      "version": "3.1.1",
7828
-      "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz",
7829
-      "integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==",
7830
-      "dev": true,
7831
-      "dependencies": {
7832
-        "@types/json-schema": "^7.0.8",
7833
-        "ajv": "^6.12.5",
7834
-        "ajv-keywords": "^3.5.2"
7835
-      },
7836
-      "engines": {
7837
-        "node": ">= 10.13.0"
7838
-      },
7839
-      "funding": {
7840
-        "type": "opencollective",
7841
-        "url": "https://opencollective.com/webpack"
7842
-      }
7843
-    },
7844 7798
     "node_modules/string-width": {
7845 7799
       "version": "4.2.3",
7846 7800
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@@ -14545,40 +14499,6 @@
14545 14499
         "fs-extra": "^10.0.0"
14546 14500
       }
14547 14501
     },
14548
-    "string-replace-loader": {
14549
-      "version": "3.0.3",
14550
-      "resolved": "https://registry.npmjs.org/string-replace-loader/-/string-replace-loader-3.0.3.tgz",
14551
-      "integrity": "sha512-8c26Dl6H9XmKNj3mFBvaUYR7ImOxQ4YRBFuUju78wXpa1cDpyDYvKmqGg8mfkxdYexQ/BBogB7PELlLnmR08nw==",
14552
-      "dev": true,
14553
-      "requires": {
14554
-        "loader-utils": "^2.0.0",
14555
-        "schema-utils": "^3.0.0"
14556
-      },
14557
-      "dependencies": {
14558
-        "loader-utils": {
14559
-          "version": "2.0.4",
14560
-          "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
14561
-          "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
14562
-          "dev": true,
14563
-          "requires": {
14564
-            "big.js": "^5.2.2",
14565
-            "emojis-list": "^3.0.0",
14566
-            "json5": "^2.1.2"
14567
-          }
14568
-        },
14569
-        "schema-utils": {
14570
-          "version": "3.1.1",
14571
-          "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz",
14572
-          "integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==",
14573
-          "dev": true,
14574
-          "requires": {
14575
-            "@types/json-schema": "^7.0.8",
14576
-            "ajv": "^6.12.5",
14577
-            "ajv-keywords": "^3.5.2"
14578
-          }
14579
-        }
14580
-      }
14581
-    },
14582 14502
     "string-width": {
14583 14503
       "version": "4.2.3",
14584 14504
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",

+ 4
- 4
package.json 查看文件

@@ -51,7 +51,6 @@
51 51
     "karma-sourcemap-loader": "0.3.8",
52 52
     "karma-webpack": "5.0.0",
53 53
     "process": "0.11.10",
54
-    "string-replace-loader": "3.0.3",
55 54
     "typedoc": "0.28.1",
56 55
     "typescript": "5.0.4",
57 56
     "webpack": "5.98.0",
@@ -59,11 +58,12 @@
59 58
     "webpack-cli": "4.9.0"
60 59
   },
61 60
   "scripts": {
62
-    "build": "npm run build:webpack && npm run build:tsc",
61
+    "build": "npm run gen-version && npm run build:webpack && npm run build:tsc",
63 62
     "build:webpack": "webpack",
64
-    "build:webpack-dev": "webpack --mode development",
63
+    "build:webpack-dev": "npm run gen-version && webpack --mode development",
65 64
     "build:tsc": "tsc --build --clean && tsc",
66 65
     "gen-types": "tsc --declaration --emitDeclarationOnly --outFile types/index.d.ts",
66
+    "gen-version": "node tools/gen-version.js",
67 67
     "lint": "eslint . --max-warnings 0",
68 68
     "lint-fix": "eslint . --max-warnings 0 --fix",
69 69
     "prepack": "npm run build && npm run gen-types",
@@ -71,7 +71,7 @@
71 71
     "test-watch": "karma start karma.conf.js --no-single-run",
72 72
     "typedoc": "typedoc",
73 73
     "validate": "npm ls",
74
-    "watch": "webpack --config webpack.config.js --watch --mode development"
74
+    "watch": "npm run gen-version && webpack --config webpack.config.js --watch --mode development"
75 75
   },
76 76
   "browser": "dist/umd/lib-jitsi-meet.min.js",
77 77
   "module": "dist/esm/JitsiMeetJS.js",

+ 21
- 0
tools/gen-version.js 查看文件

@@ -0,0 +1,21 @@
1
+/* global __dirname */
2
+
3
+const { execSync } = require('child_process');
4
+const { writeFileSync } = require('fs');
5
+const { join } = require('path');
6
+const process = require('process');
7
+
8
+const devNull = process.platform === 'win32' ? 'nul' : '/dev/null';
9
+const commitHash = process.env.LIB_JITSI_MEET_COMMIT_HASH
10
+    || execSync(`git rev-parse --short HEAD 2>${devNull} || echo development`)
11
+        .toString()
12
+        .trim();
13
+const outputPath = join(__dirname, '..', 'version.ts');
14
+
15
+writeFileSync(
16
+  outputPath,
17
+  `// This file is auto-generated during build
18
+export const COMMIT_HASH = '${commitHash}';\n`
19
+);
20
+
21
+console.log(`Generated commit hash: ${commitHash}`);

+ 0
- 20
webpack-shared-config.js 查看文件

@@ -1,16 +1,6 @@
1
-/* global __dirname */
2
-
3
-const { execSync } = require('child_process');
4
-const path = require('path');
5
-const process = require('process');
6 1
 const { IgnorePlugin, ProvidePlugin } = require('webpack');
7 2
 const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
8 3
 
9
-const devNull = process.platform === 'win32' ? 'nul' : '/dev/null';
10
-const commitHash = process.env.LIB_JITSI_MEET_COMMIT_HASH
11
-    || execSync(`git rev-parse --short HEAD 2>${devNull} || echo development`)
12
-        .toString()
13
-        .trim();
14 4
 
15 5
 module.exports = (minimize, analyzeBundle) => {
16 6
     return {
@@ -25,16 +15,6 @@ module.exports = (minimize, analyzeBundle) => {
25 15
         mode: minimize ? 'production' : 'development',
26 16
         module: {
27 17
             rules: [ {
28
-                // Version this build of the lib-jitsi-meet library.
29
-
30
-                loader: 'string-replace-loader',
31
-                options: {
32
-                    flags: 'g',
33
-                    replace: commitHash,
34
-                    search: '{#COMMIT_HASH#}'
35
-                },
36
-                test: path.join(__dirname, 'JitsiMeetJS.ts')
37
-            }, {
38 18
                 // Transpile ES2015 (aka ES6) to ES5.
39 19
 
40 20
                 loader: 'babel-loader',

正在加载...
取消
保存