Skip to content

Commit 845959a

Browse files
authored
Merge branch 'develop' into issue3459
2 parents 62bb93e + ed27170 commit 845959a

Some content is hidden

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

44 files changed

+601
-160
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,35 @@ npm run --silent build-all
168168
```
169169

170170
in order to compile the JavaScript files from the TypeScript source,
171-
and build the component files from the JavaScript files.
171+
and build the component files from the JavaScript files. Windows
172+
users will need to use the command
173+
174+
``` bash
175+
npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
176+
```
177+
178+
first in order to tell `pnpm` to use the `bash` shell for scripts that
179+
it runs, as that is required by the build scripts that MathJax defines
180+
in the `package.json` file. You may also need to use
181+
182+
``` bash
183+
Set-ExecutionPolicy Unrestricted
184+
```
185+
186+
to allow the scripts to run, if you receive errors about not being
187+
able to run the scripts.
188+
189+
The build process requires MathJax to set up a symbolic link, and in
190+
Windows, that requires permission, so you may receive an error message
191+
to that effect. If so, you may need to run
192+
193+
``` bash
194+
pnpm link:src
195+
```
196+
197+
from a shell with administrator privileges. Once that is done, you
198+
can run the build process from a non-administrator shell.
199+
172200

173201
## Code Contributions
174202

components/bin/build

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ process.chdir(path.dirname(json));
6161
const mjPath = path.relative(process.cwd(), path.resolve(__dirname, '..', '..', target));
6262
const mjGlobal = path.join('..', mjPath, 'components', 'global.js');
6363

64+
/**
65+
* Determine the module type
66+
*/
6467
function getType() {
6568
const component = config.component || 'part';
6669
if (component.match(/\/(svg|chtml|common)\/fonts\//)) return RegExp.$1 + '-font';
@@ -69,6 +72,13 @@ function getType() {
6972
return component;
7073
}
7174

75+
/**
76+
* Convert Windows paths to unix paths
77+
*/
78+
const normalize = process.platform === 'win32'
79+
? (file) => file.replace(/\\/g, '/')
80+
: (file) => file;
81+
7282
/**
7383
* Extract the configuration values
7484
*/
@@ -100,7 +110,7 @@ let PACKAGE = [];
100110
*/
101111
function processList(base, dir, list, top = true) {
102112
for (const item of list) {
103-
const file = path.join(dir, item);
113+
const file = normalize(path.join(dir, item));
104114
if (!EXCLUDE.has(file)) {
105115
const stat = fs.statSync(path.resolve(base, file));
106116
if (stat.isDirectory()) {
@@ -183,9 +193,9 @@ function processParts(parts) {
183193
function processLines(file, objects) {
184194
if (objects.length === 0) return [];
185195
const base = path.dirname(file).replace(/^\.$/, '');
186-
const dir = (PREFIX ? path.join(PREFIX, base) : base);
196+
const dir = (PREFIX ? normalize(path.join(PREFIX, base)) : base);
187197
const dots = dir.replace(/[^\/]+/g, '..') || '.';
188-
const relative = path.join(dots, '..', JS, dir, path.basename(file)).replace(/\.ts$/, '.js');
198+
const relative = normalize(path.join(dots, '..', JS, dir, path.basename(file))).replace(/\.ts$/, '.js');
189199
const name = path.parse(file).name;
190200
const lines = (target === 'mjs' ? [] : [
191201
'"use strict";',
@@ -254,7 +264,7 @@ function getExtraDirectories() {
254264
let prefix = '';
255265
let indent = INDENT;
256266
let postfix = '';
257-
for (let name of PREFIX.split(/\//)) {
267+
for (let name of PREFIX.split('/')) {
258268
if (name.match(/[^a-zA-Z0-9]/)) {
259269
name = `"${name}"`;
260270
}
@@ -271,19 +281,19 @@ function getExtraDirectories() {
271281
function processGlobal() {
272282
console.info(' ' + COMPONENT + '.ts');
273283
const lines = (target === 'cjs' ? [
274-
`const {combineWithMathJax} = require('${GLOBAL}')`,
275-
`const {VERSION} = require('${VERSION}');`,
284+
`const {combineWithMathJax} = require('${normalize(GLOBAL)}')`,
285+
`const {VERSION} = require('${normalize(VERSION)}');`,
276286
'',
277287
] : [
278-
`import {combineWithMathJax} from '${GLOBAL}';`,
279-
`import {VERSION} from '${VERSION}';`,
288+
`import {combineWithMathJax} from '${normalize(GLOBAL)}';`,
289+
`import {VERSION} from '${normalize(VERSION)}';`,
280290
'',
281291
]);
282292
const [prefix, indent, postfix] = getExtraDirectories();
283293
const packages = [];
284294
PACKAGE = PACKAGE.sort(sortDir);
285295
while (PACKAGE.length) {
286-
const dir = path.dirname(PACKAGE[0]).split(path.sep)[0];
296+
const dir = path.dirname(PACKAGE[0]).split('/')[0];
287297
packages.push(processPackage(lines, indent, dir));
288298
}
289299
const name = (ID.match(/[^a-zA-Z0-9_]/) ? `"${ID}"` : ID);
@@ -337,7 +347,7 @@ function processPackage(lines, space, dir) {
337347
if (path.dirname(PACKAGE[0]) === dir) {
338348
const file = PACKAGE.shift();
339349
const name = path.basename(file);
340-
let relativefile = path.join('..', JS, dir, name).replace(/\.ts$/, '.js')
350+
const relativefile = normalize(path.join('..', JS, dir, name).replace(/\.ts$/, '.js'));
341351
const component = 'module' + (++importCount);
342352
lines.push(
343353
target === 'cjs' ?

components/bin/makeAll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ function fileRegExp(name) {
124124
return new RegExp(name.replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
125125
}
126126

127+
/**
128+
* Options for the execSync() function
129+
*/
130+
const execOptions = process.platform === 'win32'
131+
? { shell: `${process.env.ProgramFiles}\\Git\\bin\\bash.exe` }
132+
: {};
133+
127134
/**
128135
* Get the current working directory
129136
*/
@@ -196,7 +203,7 @@ function processSubdirs(dir, action, config) {
196203
* Run a command on a given directory
197204
*/
198205
function run(cmd, dir) {
199-
return execSync(cmd + ` '${path.relative('.', dir).replace(/'/g, '\\\'')}'`);
206+
return execSync(cmd + ` '${path.relative('.', dir).replace(/'/g, '\\\'')}'`, execOptions);
200207
}
201208

202209
/**

components/bin/pack

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
const fs = require('fs');
2727
const path = require('path');
28-
const {spawn, execSync} = require('child_process');
28+
const {spawn} = require('child_process');
2929

3030
/**
3131
* The module type to use ('cjs' or 'mjs')
@@ -64,14 +64,7 @@ const rootRE = fileRegExp(path.dirname(jsPath));
6464
const nodeRE = /^.*\/node_modules/;
6565
const fontRE = new RegExp('^.*\\/(mathjax-[^\/-]*)(?:-font)?\/(build|[cm]js)');
6666

67-
/**
68-
* Find the directory where npx runs (so we know where "npx webpack" will run)
69-
* (We use npx rather than pnpm here as it seems that pnpm doesn't
70-
* find the executable from a node_modules directory higher than the
71-
* first package.json, and extensions and fonts can have their own
72-
* package.json.)
73-
*/
74-
const packDir = String(execSync('npx node -e "console.log(process.cwd())"'));
67+
const packDir = process.cwd();
7568

7669
/**
7770
* @param {string} dir The directory to pack
@@ -80,11 +73,20 @@ const packDir = String(execSync('npx node -e "console.log(process.cwd())"'));
8073
async function readJSON(dir) {
8174
return new Promise((ok, fail) => {
8275
const buffer = [];
83-
const child = spawn('npx', [
84-
'webpack', '--env', `dir=${path.relative(packDir, path.resolve(dir))}`,
85-
'--env', `bundle=${bundle}`, '--json',
86-
'-c', path.relative(packDir, path.join(compPath, 'webpack.config.' + target))
87-
]);
76+
const child = spawn(
77+
'npx',
78+
[
79+
'webpack',
80+
'--env', `dir=${path.relative(packDir, path.resolve(dir))}`,
81+
'--env', `bundle=${bundle}`,
82+
'--json',
83+
'-c', path.relative(packDir, path.join(compPath, 'webpack.config.' + target))
84+
],
85+
{
86+
cwd: packDir,
87+
shell: true,
88+
}
89+
);
8890
child.stdout.on('data', (data) => buffer.push(String(data)));
8991
child.stderr.on('data', (data) => console.error(String(data)));
9092
child.on('close', (code) => {

components/mjs/a11y/speech/speech.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import './lib/speech.js';
22

33
import {combineDefaults} from '#js/components/global.js';
44
import {Package} from '#js/components/package.js';
5-
import {hasWindow} from '#js/util/context.js';
5+
import {context} from '#js/util/context.js';
66
import {SpeechHandler} from '#js/a11y/speech.js';
77

88
if (MathJax.loader) {
99
let path = Package.resolvePath('[sre]', false);
1010
let maps = Package.resolvePath('[mathmaps]', false);
11-
if (hasWindow) {
11+
if (context.window) {
1212
path = new URL(path, location).href;
1313
maps = new URL(maps, location).href;
1414
} else {
1515
const REQUIRE = typeof require !== 'undefined' ? require : MathJax.config.loader.require;
1616
if (REQUIRE?.resolve) {
17-
path = REQUIRE.resolve(`${path}/require.mjs`).replace(/\/[^\/]*$/, '');
18-
maps = REQUIRE.resolve(`${maps}/base.json`).replace(/\/[^\/]*$/, '');
17+
path = context.path(REQUIRE.resolve(`${path}/require.mjs`)).replace(/\/[^\/]*$/, '');
18+
maps = context.path(REQUIRE.resolve(`${maps}/base.json`)).replace(/\/[^\/]*$/, '');
1919
} else {
2020
path = maps = '';
2121
}

components/mjs/a11y/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Loader.preLoaded(
99
'a11y/sre',
1010
'a11y/semantic-enrich',
1111
'a11y/speech',
12-
'a11y/explorer'
12+
'a11y/explorer',
13+
'input/mml',
1314
);

components/mjs/input/tex/extension.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {combineDefaults} from '#js/components/global.js';
2-
import {hasWindow} from '#js/util/context.js';
32

4-
export function fontExtension(id, name, pkg = `@mathjax/${name}`) {
3+
export function fontExtension(id, name, pkg = `[fonts]/${name}`) {
54
if (MathJax.loader) {
6-
const FONTPATH = hasWindow ? `https://cdn.jsdelivr.net/npm/${pkg}` : pkg;
75
const path = name.replace(/-font-extension$/, '-extension');
86
const jax = (MathJax.config?.startup?.output || 'chtml');
9-
combineDefaults(MathJax.config.loader, 'paths', {[path]: FONTPATH});
7+
combineDefaults(MathJax.config.loader, 'paths', {[path]: pkg});
108
if (!MathJax._.output?.[jax]) {
119
combineDefaults(MathJax.config.loader, 'dependencies', {[`[${path}]/${jax}`]: [`output/${jax}`]});
1210
}

components/mjs/node-main/node-main-setup.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ global.require = createRequire(import.meta.url);
44
const path = require("path");
55

66
if (!global.MathJax) global.MathJax = {};
7-
global.MathJax.__dirname = path.dirname(new URL(import.meta.url).pathname);
7+
global.MathJax.__dirname = path.dirname(new URL(import.meta.url).pathname);

components/mjs/node-main/node-main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ import '../startup/init.js';
2323
import {Loader, CONFIG} from '#js/components/loader.js';
2424
import {Package} from '#js/components/package.js';
2525
import {combineDefaults, combineConfig} from '#js/components/global.js';
26+
import {context} from '#js/util/context.js';
2627
import '../core/core.js';
2728
import '../adaptors/liteDOM/liteDOM.js';
2829
import {source} from '../source.js';
2930

3031
const MathJax = global.MathJax;
3132

3233
const path = eval('require("path")'); // get path from node, not webpack
33-
const dir = MathJax.config.__dirname; // set up by node-main.mjs or node-main.cjs
34+
const dir = context.path(MathJax.config.__dirname); // set up by node-main.mjs or node-main.cjs
3435

3536
/*
3637
* Set up the initial configuration

components/mjs/output/util.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import {combineDefaults, combineWithMathJax} from '#js/components/global.js';
22
import {Package} from '#js/components/package.js';
33
import {hasWindow} from '#js/util/context.js';
44

5-
export const FONTPATH = hasWindow
6-
? 'https://cdn.jsdelivr.net/npm/@mathjax/%%FONT%%-font'
7-
: '@mathjax/%%FONT%%-font';
8-
95
export function configFont(font, jax, config, extension = '') {
10-
const path = (config.fontPath || (FONTPATH + extension));
6+
const path = (config.fontPath || `[fonts]/%%FONT%%-font${extension}`);
117
const name = (font.match(/^[a-z]+:/) ? (font.match(/[^/:\\]*$/) || [jax])[0] : font);
128
combineDefaults(MathJax.config.loader, 'paths', {
139
[name+extension]: (name === font ? path.replace(/%%FONT%%/g, font) : font)

0 commit comments

Comments
 (0)