Fix babel worker special cases check on windows
This commit is contained in:
parent
7c201f5d59
commit
64234d2bb4
2 changed files with 17 additions and 10 deletions
|
@ -7,6 +7,7 @@ const babel = require('@babel/core');
|
||||||
const multimatch = require('multimatch');
|
const multimatch = require('multimatch');
|
||||||
const options = JSON.parse(fs.readFileSync('.babelrc'));
|
const options = JSON.parse(fs.readFileSync('.babelrc'));
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
|
const { comparePaths } = require('./utils');
|
||||||
|
|
||||||
/* exported onmessage */
|
/* exported onmessage */
|
||||||
async function babelWorker(ev) {
|
async function babelWorker(ev) {
|
||||||
|
@ -30,18 +31,18 @@ async function babelWorker(ev) {
|
||||||
try {
|
try {
|
||||||
let contents = await fs.readFile(sourcefile, 'utf8');
|
let contents = await fs.readFile(sourcefile, 'utf8');
|
||||||
// Patch react
|
// Patch react
|
||||||
if (sourcefile === 'resource/react.js') {
|
if (comparePaths(sourcefile, 'resource/react.js')) {
|
||||||
transformed = contents.replace('instanceof Error', '.constructor.name == "Error"')
|
transformed = contents.replace('instanceof Error', '.constructor.name == "Error"')
|
||||||
}
|
}
|
||||||
// Patch react-dom
|
// Patch react-dom
|
||||||
else if (sourcefile === 'resource/react-dom.js') {
|
else if (comparePaths(sourcefile, 'resource/react-dom.js')) {
|
||||||
transformed = contents.replace(/ ownerDocument\.createElement\((.*?)\)/gi, 'ownerDocument.createElementNS(HTML_NAMESPACE, $1)')
|
transformed = contents.replace(/ ownerDocument\.createElement\((.*?)\)/gi, 'ownerDocument.createElementNS(HTML_NAMESPACE, $1)')
|
||||||
.replace('element instanceof win.HTMLIFrameElement',
|
.replace('element instanceof win.HTMLIFrameElement',
|
||||||
'typeof element != "undefined" && element.tagName.toLowerCase() == "iframe"')
|
'typeof element != "undefined" && element.tagName.toLowerCase() == "iframe"')
|
||||||
.replace("isInputEventSupported = false", 'isInputEventSupported = true');
|
.replace("isInputEventSupported = false", 'isInputEventSupported = true');
|
||||||
}
|
}
|
||||||
// Patch react-virtualized
|
// Patch react-virtualized
|
||||||
else if (sourcefile === 'resource/react-virtualized.js') {
|
else if (comparePaths(sourcefile, 'resource/react-virtualized.js')) {
|
||||||
transformed = contents.replace('scrollDiv = document.createElement("div")', 'scrollDiv = document.createElementNS("http://www.w3.org/1999/xhtml", "div")')
|
transformed = contents.replace('scrollDiv = document.createElement("div")', 'scrollDiv = document.createElementNS("http://www.w3.org/1999/xhtml", "div")')
|
||||||
.replace('document.body.appendChild(scrollDiv)', 'document.documentElement.appendChild(scrollDiv)')
|
.replace('document.body.appendChild(scrollDiv)', 'document.documentElement.appendChild(scrollDiv)')
|
||||||
.replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)');
|
.replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)');
|
||||||
|
|
|
@ -111,16 +111,22 @@ const formatDirsForMatcher = dirs => {
|
||||||
return dirs.length > 1 ? `{${dirs.join(',')}}` : dirs[0];
|
return dirs.length > 1 ? `{${dirs.join(',')}}` : dirs[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function comparePaths(actualPath, testedPath) {
|
||||||
|
// compare paths after normalizing os-specific path separator
|
||||||
|
return path.normalize(actualPath) === path.normalize(testedPath);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
cleanUp,
|
||||||
|
comparePaths,
|
||||||
|
compareSignatures,
|
||||||
|
formatDirsForMatcher,
|
||||||
|
getFileSignature,
|
||||||
|
getPathRelativeTo,
|
||||||
|
getSignatures,
|
||||||
isWindows,
|
isWindows,
|
||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
cleanUp,
|
|
||||||
getSignatures,
|
|
||||||
getFileSignature,
|
|
||||||
compareSignatures,
|
|
||||||
writeSignatures,
|
writeSignatures,
|
||||||
getPathRelativeTo,
|
};
|
||||||
formatDirsForMatcher
|
|
||||||
};
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue