Merge pull request #1857 from tnajdek/fix-windows-build

Fix babel worker file-specific fixes check on Windows
This commit is contained in:
Dan Stillman 2020-07-29 09:57:20 -04:00 committed by GitHub
commit 83cdbd8e5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -7,6 +7,7 @@ const babel = require('@babel/core');
const multimatch = require('multimatch');
const options = JSON.parse(fs.readFileSync('.babelrc'));
const cluster = require('cluster');
const { comparePaths } = require('./utils');
/* exported onmessage */
async function babelWorker(ev) {
@ -30,18 +31,18 @@ async function babelWorker(ev) {
try {
let contents = await fs.readFile(sourcefile, 'utf8');
// Patch react
if (sourcefile === 'resource/react.js') {
if (comparePaths(sourcefile, 'resource/react.js')) {
transformed = contents.replace('instanceof Error', '.constructor.name == "Error"')
}
// 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)')
.replace('element instanceof win.HTMLIFrameElement',
'typeof element != "undefined" && element.tagName.toLowerCase() == "iframe"')
.replace("isInputEventSupported = false", 'isInputEventSupported = true');
}
// 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")')
.replace('document.body.appendChild(scrollDiv)', 'document.documentElement.appendChild(scrollDiv)')
.replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)');

View file

@ -111,16 +111,22 @@ const formatDirsForMatcher = dirs => {
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 = {
cleanUp,
comparePaths,
compareSignatures,
formatDirsForMatcher,
getFileSignature,
getPathRelativeTo,
getSignatures,
isWindows,
onError,
onProgress,
onSuccess,
cleanUp,
getSignatures,
getFileSignature,
compareSignatures,
writeSignatures,
getPathRelativeTo,
formatDirsForMatcher
};
};