Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make version.ts use a constant and create the file during the build process. (#818) #824

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_js:
- 17
sudo: false
script:
- components/bin/version
- npm install
- npm run compile
- npm run make-components
Expand Down
60 changes: 60 additions & 0 deletions components/bin/version
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#! /usr/bin/env node

/*************************************************************
*
* Copyright (c) 2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Creates the version.ts file from the package version number
*
* @author dpvc@mathjax.org (Davide Cervone)
*/


const fs = require('fs');
const path = require('path');

const package = path.resolve(__dirname, '..', '..', 'package.json');
const version = require(package).version;

const lines = `/*************************************************************
*
* Copyright (c) 2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview The version of MathJax (used to tell what version a component
* was compiled against).
*
* @author dpvc@mathjax.org (Davide Cervone)
*/

export const VERSION = '${version}';
`;

fs.writeFileSync(path.resolve(__dirname, '..', '..', 'ts', 'components', 'version.ts'), lines);
4 changes: 1 addition & 3 deletions components/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ function quoteRE(string) {
const PLUGINS = function (js, dir) {
const mjdir = path.resolve(__dirname, '..', 'js');
const jsdir = path.resolve(dir, js);
const package = path.resolve(__dirname, '..', 'package.json');

//
// Record the js directory for the pack command
//
return [new webpack.DefinePlugin({
__JSDIR__: jsdir,
PACKAGE_VERSION: `'${require(package).version}'`
__JSDIR__: jsdir
})];
};

Expand Down
23 changes: 2 additions & 21 deletions ts/components/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*************************************************************
*
* Copyright (c) 2018-2022 The MathJax Consortium
* Copyright (c) 2022 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,23 +22,4 @@
* @author dpvc@mathjax.org (Davide Cervone)
*/

declare const PACKAGE_VERSION: string; // provided by webpack via DefinePlugin

export const VERSION = (
typeof PACKAGE_VERSION === 'undefined' ?
//
// This will not be included in the webpack version, so only runs in node
//
(function () {
//
// Look up the version from the package.json file
//
/* tslint:disable-next-line:no-eval */
const load = eval('require');
/* tslint:disable-next-line:no-eval */
const dirname = eval('__dirname');
const path = load('path');
return load(path.resolve(dirname, '..', '..', 'package.json')).version;
})() :
PACKAGE_VERSION
);
export const VERSION = '3.2.1';