Skip to content

Commit 8c0c0cb

Browse files
authored
Merge pull request #738 from mathjax/extension-versions
Add versions to component files and check them when loaded
2 parents 0fa9bfc + eaded1b commit 8c0c0cb

File tree

47 files changed

+185
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+185
-10
lines changed

components/bin/build

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const path = require('path');
3030
/**
3131
* The amount of space for each level of indentation
3232
*/
33-
const INDENT = ' ';
33+
const INDENT = ' ';
3434

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

54+
function getType() {
55+
const component = config.component || 'part';
56+
if (component.match(/\/(svg|chtml|common)\/fonts\//)) return RegExp.$1 + '-font';
57+
if (component.match(/\/(mathml|tex)\/.+\//)) return RegExp.$1 + '-extension';
58+
if (component.match(/^(.+)\//)) return RegExp.$1;
59+
return component;
60+
}
61+
5462
/**
5563
* Extract the configuration values
5664
*/
5765
const COMPONENT = path.basename(config.component || 'part'); // name of the component
66+
const ID = config.id || config.component || 'part'; // the ID of the component
5867
const TARGETS = config.targets || []; // the files to include in the component
5968
const EXCLUDE = new Map((config.exclude || []).map(name => [name, true])); // files to exclude from the component
6069
const EXCLUDESUBDIRS = config.excludeSubdirs === 'true'; // exclude subdirectories or not
6170
const JS = config.js || config.mathjax || mjPath; // path to the compiled .js files
6271
const LIB = config.lib || './lib'; // path to the lib directory to create
63-
const GLOBAL = config.global || mjGlobal; // path to the global.js file
6472
const TS = config.ts || JS.replace(/js$/, 'ts'); // path to the .ts files
73+
const GLOBAL = config.global || mjGlobal; // path to the global.js file
74+
const VERSION = config.version || mjGlobal.replace(/global/, 'version'); // path to the version.js file
75+
const TYPE = config.type || getType(); // the module type
6576

6677
/**
6778
* The list of files that need to be added to the lib directory
@@ -222,6 +233,7 @@ function processGlobal() {
222233
console.info(' ' + COMPONENT + '.ts');
223234
const lines = [
224235
`import {combineWithMathJax} from '${GLOBAL}';`,
236+
`import {VERSION} from '${VERSION}';`,
225237
'',
226238
];
227239
const packages = [];
@@ -230,9 +242,17 @@ function processGlobal() {
230242
const dir = path.dirname(PACKAGE[0]).split(path.sep)[0];
231243
packages.push(processPackage(lines, INDENT, dir));
232244
}
233-
lines.push('', `combineWithMathJax({_: {`);
234-
lines.push(INDENT + packages.join(',\n' + INDENT));
235-
lines.push('}});');
245+
const name = (ID.match(/[^a-zA-Z0-9_]/) ? `"${ID}"` : ID);
246+
lines.push(
247+
'',
248+
'if (MathJax.loader) {',
249+
INDENT + `MathJax.loader.checkVersion('${ID}', VERSION, '${TYPE}');`,
250+
'}',
251+
'',
252+
`combineWithMathJax({_: {`,
253+
INDENT + packages.join(',\n' + INDENT),
254+
'}});'
255+
);
236256
fs.writeFileSync(path.join(LIB, COMPONENT + '.js'), lines.join('\n') + '\n');
237257
}
238258

components/src/input/mml/build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"component": "inpu/mml",
2+
"component": "input/mml",
33
"targets": [
44
"input/mathml.ts",
55
"input/mathml"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[mml]/mml3",
23
"component": "input/mml/extensions/mml3",
34
"targets": ["input/mathml/mml3"]
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/action",
23
"component": "input/tex/extensions/action",
34
"targets": ["input/tex/action"]
45
}

components/src/input/tex/extensions/all-packages/build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/all-packages",
23
"component": "input/tex/extensions/all-packages",
34
"targets": [
45
"input/tex/AllPackages.ts",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/ams",
23
"component": "input/tex/extensions/ams",
34
"targets": ["input/tex/ams"]
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/amscd",
23
"component": "input/tex/extensions/amscd",
34
"targets": ["input/tex/amscd"]
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/autoload",
23
"component": "input/tex/extensions/autoload",
34
"targets": ["input/tex/autoload"]
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/bbox",
23
"component": "input/tex/extensions/bbox",
34
"targets": ["input/tex/bbox"]
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"id": "[tex]/boldsymbol",
23
"component": "input/tex/extensions/boldsymbol",
34
"targets": ["input/tex/boldsymbol"]
45
}

0 commit comments

Comments
 (0)