Przeglądaj źródła

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 miesięcy temu
rodzic
commit
73ff451f49
6 zmienionych plików z 30 dodań i 105 usunięć
  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 Wyświetl plik

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

+ 2
- 1
JitsiMeetJS.ts Wyświetl plik

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

+ 0
- 80
package-lock.json Wyświetl plik

44
         "karma-sourcemap-loader": "0.3.8",
44
         "karma-sourcemap-loader": "0.3.8",
45
         "karma-webpack": "5.0.0",
45
         "karma-webpack": "5.0.0",
46
         "process": "0.11.10",
46
         "process": "0.11.10",
47
-        "string-replace-loader": "3.0.3",
48
         "typedoc": "0.28.1",
47
         "typedoc": "0.28.1",
49
         "typescript": "5.0.4",
48
         "typescript": "5.0.4",
50
         "webpack": "5.98.0",
49
         "webpack": "5.98.0",
7796
         "node": ">=8.0"
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
     "node_modules/string-width": {
7798
     "node_modules/string-width": {
7845
       "version": "4.2.3",
7799
       "version": "4.2.3",
7846
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
7800
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
14545
         "fs-extra": "^10.0.0"
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
     "string-width": {
14502
     "string-width": {
14583
       "version": "4.2.3",
14503
       "version": "4.2.3",
14584
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
14504
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",

+ 4
- 4
package.json Wyświetl plik

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

+ 21
- 0
tools/gen-version.js Wyświetl plik

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 Wyświetl plik

1
-/* global __dirname */
2
-
3
-const { execSync } = require('child_process');
4
-const path = require('path');
5
-const process = require('process');
6
 const { IgnorePlugin, ProvidePlugin } = require('webpack');
1
 const { IgnorePlugin, ProvidePlugin } = require('webpack');
7
 const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
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
 module.exports = (minimize, analyzeBundle) => {
5
 module.exports = (minimize, analyzeBundle) => {
16
     return {
6
     return {
25
         mode: minimize ? 'production' : 'development',
15
         mode: minimize ? 'production' : 'development',
26
         module: {
16
         module: {
27
             rules: [ {
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
                 // Transpile ES2015 (aka ES6) to ES5.
18
                 // Transpile ES2015 (aka ES6) to ES5.
39
 
19
 
40
                 loader: 'babel-loader',
20
                 loader: 'babel-loader',

Ładowanie…
Anuluj
Zapisz