Skip to content

Commit

Permalink
Merge pull request #738 from mathjax/extension-versions
Browse files Browse the repository at this point in the history
Add versions to component files and check them when loaded
  • Loading branch information
dpvc authored Feb 25, 2022
2 parents 0fa9bfc + eaded1b commit 8c0c0cb
Show file tree
Hide file tree
Showing 47 changed files with 185 additions and 10 deletions.
30 changes: 25 additions & 5 deletions components/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const path = require('path');
/**
* The amount of space for each level of indentation
*/
const INDENT = ' ';
const INDENT = ' ';

/**
* The pattern to use when looking for explort commands to process
Expand All @@ -51,17 +51,28 @@ const mjGlobal = path.join('..', mjPath, 'components', 'global.js');
*/
const config = JSON.parse(fs.readFileSync(process.argv[2] || 'build.json'));

function getType() {
const component = config.component || 'part';
if (component.match(/\/(svg|chtml|common)\/fonts\//)) return RegExp.$1 + '-font';
if (component.match(/\/(mathml|tex)\/.+\//)) return RegExp.$1 + '-extension';
if (component.match(/^(.+)\//)) return RegExp.$1;
return component;
}

/**
* Extract the configuration values
*/
const COMPONENT = path.basename(config.component || 'part'); // name of the component
const ID = config.id || config.component || 'part'; // the ID of the component
const TARGETS = config.targets || []; // the files to include in the component
const EXCLUDE = new Map((config.exclude || []).map(name => [name, true])); // files to exclude from the component
const EXCLUDESUBDIRS = config.excludeSubdirs === 'true'; // exclude subdirectories or not
const JS = config.js || config.mathjax || mjPath; // path to the compiled .js files
const LIB = config.lib || './lib'; // path to the lib directory to create
const GLOBAL = config.global || mjGlobal; // path to the global.js file
const TS = config.ts || JS.replace(/js$/, 'ts'); // path to the .ts files
const GLOBAL = config.global || mjGlobal; // path to the global.js file
const VERSION = config.version || mjGlobal.replace(/global/, 'version'); // path to the version.js file
const TYPE = config.type || getType(); // the module type

/**
* The list of files that need to be added to the lib directory
Expand Down Expand Up @@ -222,6 +233,7 @@ function processGlobal() {
console.info(' ' + COMPONENT + '.ts');
const lines = [
`import {combineWithMathJax} from '${GLOBAL}';`,
`import {VERSION} from '${VERSION}';`,
'',
];
const packages = [];
Expand All @@ -230,9 +242,17 @@ function processGlobal() {
const dir = path.dirname(PACKAGE[0]).split(path.sep)[0];
packages.push(processPackage(lines, INDENT, dir));
}
lines.push('', `combineWithMathJax({_: {`);
lines.push(INDENT + packages.join(',\n' + INDENT));
lines.push('}});');
const name = (ID.match(/[^a-zA-Z0-9_]/) ? `"${ID}"` : ID);
lines.push(
'',
'if (MathJax.loader) {',
INDENT + `MathJax.loader.checkVersion('${ID}', VERSION, '${TYPE}');`,
'}',
'',
`combineWithMathJax({_: {`,
INDENT + packages.join(',\n' + INDENT),
'}});'
);
fs.writeFileSync(path.join(LIB, COMPONENT + '.js'), lines.join('\n') + '\n');
}

Expand Down
2 changes: 1 addition & 1 deletion components/src/input/mml/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"component": "inpu/mml",
"component": "input/mml",
"targets": [
"input/mathml.ts",
"input/mathml"
Expand Down
1 change: 1 addition & 0 deletions components/src/input/mml/extensions/mml3/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[mml]/mml3",
"component": "input/mml/extensions/mml3",
"targets": ["input/mathml/mml3"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/action/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/action",
"component": "input/tex/extensions/action",
"targets": ["input/tex/action"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/all-packages",
"component": "input/tex/extensions/all-packages",
"targets": [
"input/tex/AllPackages.ts",
Expand Down
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/ams/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/ams",
"component": "input/tex/extensions/ams",
"targets": ["input/tex/ams"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/amscd/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/amscd",
"component": "input/tex/extensions/amscd",
"targets": ["input/tex/amscd"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/autoload/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/autoload",
"component": "input/tex/extensions/autoload",
"targets": ["input/tex/autoload"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/bbox/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/bbox",
"component": "input/tex/extensions/bbox",
"targets": ["input/tex/bbox"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/boldsymbol/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/boldsymbol",
"component": "input/tex/extensions/boldsymbol",
"targets": ["input/tex/boldsymbol"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/braket/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/braket",
"component": "input/tex/extensions/braket",
"targets": ["input/tex/braket"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/bussproofs/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/bussproofs",
"component": "input/tex/extensions/bussproofs",
"targets": ["input/tex/bussproofs"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/cancel/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/cancel",
"component": "input/tex/extensions/cancel",
"targets": ["input/tex/cancel"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/cases/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/cases",
"component": "input/tex/extensions/cases",
"targets": ["input/tex/cases"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/centernot/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/centernot",
"component": "input/tex/extensions/centernot",
"targets": ["input/tex/centernot"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/color/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/color",
"component": "input/tex/extensions/color",
"targets": ["input/tex/color"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/colortbl/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/colortbl",
"component": "input/tex/extensions/colortbl",
"targets": ["input/tex/colortbl"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/colorv2/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/colorv2",
"component": "input/tex/extensions/colorv2",
"targets": ["input/tex/colorv2"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/configmacros",
"component": "input/tex/extensions/configmacros",
"targets": ["input/tex/configmacros"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/empheq/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/empheq",
"component": "input/tex/extensions/empheq",
"targets": ["input/tex/empheq"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/enclose/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/enclose",
"component": "input/tex/extensions/enclose",
"targets": ["input/tex/enclose"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/extpfeil/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/extpfeil",
"component": "input/tex/extensions/extpfeil",
"targets": ["input/tex/extpfeil"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/gensymb/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/gensymb",
"component": "input/tex/extensions/gensymb",
"targets": ["input/tex/gensymb"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/html/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/html",
"component": "input/tex/extensions/html",
"targets": ["input/tex/html"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/mathtools/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/mathtools",
"component": "input/tex/extensions/mathtools",
"targets": ["input/tex/mathtools"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/mhchem/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/mhchem",
"component": "input/tex/extensions/mhchem",
"targets": ["input/tex/mhchem"],
"exclude": ["input/tex/mhchem/mhchem_parser.d.ts"]
Expand Down
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/newcommand/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/newcommand",
"component": "input/tex/extensions/newcommand",
"targets": ["input/tex/newcommand"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/noerrors/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/noerrors",
"component": "input/tex/extensions/noerrors",
"targets": ["input/tex/noerrors"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/noundefined/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/noundefined",
"component": "input/tex/extensions/noundefined",
"targets": ["input/tex/noundefined"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/physics/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/physics",
"component": "input/tex/extensions/physics",
"targets": ["input/tex/physics"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/require/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/require",
"component": "input/tex/extensions/require",
"targets": ["input/tex/require"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/setoptions/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/setoptions",
"component": "input/tex/extensions/setoptions",
"targets": ["input/tex/setoptions"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/tagformat/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/tagformat",
"component": "input/tex/extensions/tagformat",
"targets": ["input/tex/tagformat"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/textcomp/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/textcomp",
"component": "input/tex/extensions/textcomp",
"targets": ["input/tex/textcomp"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/textmacros/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/textmacros",
"component": "input/tex/extensions/textmacros",
"targets": ["input/tex/textmacros"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/unicode/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/unicode",
"component": "input/tex/extensions/unicode",
"targets": ["input/tex/unicode"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/upgreek/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/upgreek",
"component": "input/tex/extensions/upgreek",
"targets": ["input/tex/upgreek"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/verb/build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "[tex]/verb",
"component": "input/tex/extensions/verb",
"targets": ["input/tex/verb"]
}
6 changes: 5 additions & 1 deletion components/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ 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})];
return [new webpack.DefinePlugin({
__JSDIR__: jsdir,
PACKAGE_VERSION: `'${require(package).version}'`
})];
};

/**
Expand Down
4 changes: 3 additions & 1 deletion ts/components/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @author dpvc@mathjax.org (Davide Cervone)
*/

import {VERSION} from './version.js';

/**
* The MathJax variable as a configuration object
*/
Expand Down Expand Up @@ -127,7 +129,7 @@ if (typeof global.MathJax === 'undefined') {
*/
if (!(global.MathJax as MathJaxObject).version) {
global.MathJax = {
version: '3.2.0',
version: VERSION,
_: {},
config: global.MathJax
};
Expand Down
Loading

0 comments on commit 8c0c0cb

Please sign in to comment.