Skip to content

Commit d73a2a1

Browse files
committed
Update build tools to work in Windows
1 parent f98da55 commit d73a2a1

4 files changed

Lines changed: 43 additions & 24 deletions

File tree

components/bin/build

Lines changed: 16 additions & 6 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()) {
@@ -271,12 +281,12 @@ 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();
@@ -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) => {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@
8686
"copy:mml3": "copy() { pnpm -s log:single 'Copying legacy code MathML3'; pnpm copyfiles -u 1 ts/input/mathml/mml3/mml3.sef.json $1; }; copy",
8787
"copy:pkg": "copy() { pnpm -s log:single \"Copying package.json to $1\"; pnpm copyfiles -u 2 components/bin/package.json $1; }; copy",
8888
"=============================================================================== log": "",
89-
"log:comp": "log() { echo \\\\033[32m$1\\\\033[0m; }; log",
90-
"log:header": "log() { echo '============='; echo $1; echo '============='; }; log",
91-
"log:single": "log() { echo \\\\033[34m--$1\\\\033[0m; }; log",
89+
"log:comp": "log() { echo \u001B[32m$1\u001B[0m; }; log",
90+
"log:header": "log() { echo '\u001B[1m============='; echo $1; echo '=============\u001B[0m'; }; log",
91+
"log:single": "log() { echo \u001B[94m--$1\u001B[0m; }; log",
9292
"=============================================================================== cjs": "",
9393
"cjs:build": "pnpm -s log:header 'Building cjs'; pnpm -s cjs:src:build && pnpm -s cjs:components:build",
9494
"cjs:bundle:clean": "pnpm clean:dir bundle-cjs",

0 commit comments

Comments
 (0)