2121
2222import '../startup/init.js' ;
2323import { Loader , CONFIG } from '#js/components/loader.js' ;
24- import { Package } from '#js/components/package .js' ;
25- import { combineDefaults , combineConfig } from '#js/components/global .js' ;
24+ import { MathJax , combineDefaults , combineConfig } from '#js/components/global .js' ;
25+ import { resolvePath } from '#js/util/AsyncLoad .js' ;
2626import { context } from '#js/util/context.js' ;
2727import '../core/core.js' ;
2828import '../adaptors/liteDOM/liteDOM.js' ;
2929import { source } from '../source.js' ;
3030
31- const MathJax = global . MathJax ;
32-
33- const path = eval ( 'require("path")' ) ; // get path from node, not webpack
31+ const REQUIRE = eval ( 'require' ) ; // get require from node, not webpack
32+ const path = REQUIRE ( "path" ) ;
33+ const fs = REQUIRE ( "fs" ) . promises ;
3434const dir = context . path ( MathJax . config . __dirname ) ; // set up by node-main.mjs or node-main.cjs
3535
3636/*
@@ -48,23 +48,26 @@ combineDefaults(MathJax.config, 'output', {font: 'mathjax-newcm'});
4848 */
4949Loader . preLoaded ( 'loader' , 'startup' , 'core' , 'adaptors/liteDOM' ) ;
5050
51+ /*
52+ * Set the paths.
53+ */
5154if ( path . basename ( dir ) === 'node-main' ) {
5255 CONFIG . paths . esm = CONFIG . paths . mathjax ;
5356 CONFIG . paths . sre = '[esm]/sre' ;
54- CONFIG . paths . mathjax = path . dirname ( dir ) ;
57+ CONFIG . paths . mathjax = path . resolve ( dir , '..' , '..' , '..' , 'bundle' ) ;
5558 combineDefaults ( CONFIG , 'source' , source ) ;
5659} else {
5760 CONFIG . paths . mathjax = dir ;
5861}
59- //
60- // Set the asynchronous loader to use the js directory, so we can load
61- // other files like entity definitions
62- //
63- const ROOT = path . resolve ( dir , '..' , '..' , '..' , path . basename ( path . dirname ( dir ) ) ) ;
64- const REQUIRE = MathJax . config . loader . require ;
62+
63+ /*
64+ * Set the asynchronous loader to handle json files
65+ */
6566MathJax . _ . mathjax . mathjax . asyncLoad = function ( name ) {
66- return REQUIRE ( name . charAt ( 0 ) === '.' ? path . resolve ( ROOT , name ) :
67- name . charAt ( 0 ) === '[' ? Package . resolvePath ( name ) : name ) ;
67+ const file = resolvePath ( name , ( name ) => path . resolve ( CONFIG . paths . mathjax , name ) ) ;
68+ return file . match ( / \. j s o n $ / )
69+ ? fs . readFile ( REQUIRE . resolve ( file ) ) . then ( ( json ) => JSON . parse ( json ) )
70+ : REQUIRE ( file ) ;
6871} ;
6972
7073/*
0 commit comments