Skip to content

Commit 2f5f6a0

Browse files
committed
Make version.ts use a constant and create the file during the build process. (#818)
1 parent 3e6df37 commit 2f5f6a0

File tree

4 files changed

+64
-24
lines changed

4 files changed

+64
-24
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_js:
33
- 17
44
sudo: false
55
script:
6+
- components/bin/version
67
- npm install
78
- npm run compile
89
- npm run make-components

Diff for: components/bin/version

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#! /usr/bin/env node
2+
3+
/*************************************************************
4+
*
5+
* Copyright (c) 2022 The MathJax Consortium
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/**
21+
* @fileoverview Creates the version.ts file from the package version number
22+
*
23+
* @author [email protected] (Davide Cervone)
24+
*/
25+
26+
27+
const fs = require('fs');
28+
const path = require('path');
29+
30+
const package = path.resolve(__dirname, '..', '..', 'package.json');
31+
const version = require(package).version;
32+
33+
const lines = `/*************************************************************
34+
*
35+
* Copyright (c) 2022 The MathJax Consortium
36+
*
37+
* Licensed under the Apache License, Version 2.0 (the "License");
38+
* you may not use this file except in compliance with the License.
39+
* You may obtain a copy of the License at
40+
*
41+
* http://www.apache.org/licenses/LICENSE-2.0
42+
*
43+
* Unless required by applicable law or agreed to in writing, software
44+
* distributed under the License is distributed on an "AS IS" BASIS,
45+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46+
* See the License for the specific language governing permissions and
47+
* limitations under the License.
48+
*/
49+
50+
/**
51+
* @fileoverview The version of MathJax (used to tell what version a component
52+
* was compiled against).
53+
*
54+
* @author [email protected] (Davide Cervone)
55+
*/
56+
57+
export const VERSION = '${version}';
58+
`;
59+
60+
fs.writeFileSync(path.resolve(__dirname, '..', '..', 'ts', 'components', 'version.ts'), lines);

Diff for: components/webpack.common.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ function quoteRE(string) {
4646
const PLUGINS = function (js, dir) {
4747
const mjdir = path.resolve(__dirname, '..', 'js');
4848
const jsdir = path.resolve(dir, js);
49-
const package = path.resolve(__dirname, '..', 'package.json');
5049

5150
//
5251
// Record the js directory for the pack command
5352
//
5453
return [new webpack.DefinePlugin({
55-
__JSDIR__: jsdir,
56-
PACKAGE_VERSION: `'${require(package).version}'`
54+
__JSDIR__: jsdir
5755
})];
5856
};
5957

Diff for: ts/components/version.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*************************************************************
22
*
3-
* Copyright (c) 2018-2022 The MathJax Consortium
3+
* Copyright (c) 2022 The MathJax Consortium
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -22,23 +22,4 @@
2222
* @author [email protected] (Davide Cervone)
2323
*/
2424

25-
declare const PACKAGE_VERSION: string; // provided by webpack via DefinePlugin
26-
27-
export const VERSION = (
28-
typeof PACKAGE_VERSION === 'undefined' ?
29-
//
30-
// This will not be included in the webpack version, so only runs in node
31-
//
32-
(function () {
33-
//
34-
// Look up the version from the package.json file
35-
//
36-
/* tslint:disable-next-line:no-eval */
37-
const load = eval('require');
38-
/* tslint:disable-next-line:no-eval */
39-
const dirname = eval('__dirname');
40-
const path = load('path');
41-
return load(path.resolve(dirname, '..', '..', 'package.json')).version;
42-
})() :
43-
PACKAGE_VERSION
44-
);
25+
export const VERSION = '3.2.1';

0 commit comments

Comments
 (0)