Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix make-cjs-components script to work without mjs files being built first #1013

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/bin/link-full
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');

const dir = path.join(__dirname, '..', '..');

if (fs.existsSync(path.join(dir, 'node_modules'))) {
if (fs.existsSync(path.join(dir, 'node_modules')) &&
!fs.existsSync(path.join(dir, 'node_modules', 'mathjax-full'))) {
fs.symlinkSync(dir, path.join(dir, 'node_modules', 'mathjax-full'));
}
41 changes: 41 additions & 0 deletions components/mjs/fullpath.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*************************************************************
*
* Copyright (c) 2023 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Gets the fully resolved path from a webpack request object using the
* correct package.json file to map pseudo-packages to the mjs/cjs directories.
* When this file is in the components/cjs directory, it will use the
* package.json in that directory, which maps them to the mathjax-full/cjs files.
* When in the components/mjs directory, the main package.json file will be used.
*/

let path = require('path');

/**
* @param {object} resource The module resource object from webpack
* @return {string} The full path to the module
*/
function fullPath(resource) {
const file = resource.request ?
(resource.request.charAt(0) === '.' ?
path.resolve(resource.path, resource.request) :
resource.request) :
resource.path;
return file.charAt(0) === '/' ? file : require.resolve(file);
}

module.exports.fullPath = fullPath;
19 changes: 6 additions & 13 deletions components/webpack.common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ function quoteRE(string) {
return string.replace(/([\\.{}[\]()?*^$])/g, '\\$1');
}

/**
* @param {object} resource The module resource object from webpack
* Wreturn {string} The full path to the module
*/
function fullPath(resource) {
const file = resource.request ?
(resource.request.charAt(0) === '.' ?
path.resolve(resource.path, resource.request) :
resource.request) :
resource.path;
return file.charAt(0) === '/' ? file : require.resolve(file);
}

/****************************************************************/

/**
Expand Down Expand Up @@ -150,6 +137,12 @@ const RESOLVE = function (js, dir, target, libs) {
[jsRE, path.join(dir, lib) + path.sep] :
[mjRE, path.join(root, lib) + path.sep]));

//
// Function to get full paths using the proper package.json file get the
// pseudo-package includes to be correct.
//
const {fullPath} = require(`./${target}/fullpath.cjs`);

//
// Function to replace imported files by ones in the specified component lib directories.
//
Expand Down