Improve getWorkerSrcFiles (builder.js)
It took a while to figure out why adding comments in worker_loader.js caused the build to fail, because getWorkerSrcFiles did not print an error message when it failed to parse the file. These issues have been resolved as follows: - Leading comments are stripped. - The trailing comma is removed from the array. - Errors are detected and useful error messages are printed.
This commit is contained in:
parent
1416a1b521
commit
8ba73cb4de
36
external/builder/builder.js
vendored
36
external/builder/builder.js
vendored
@ -235,21 +235,29 @@ function getWorkerSrcFiles(filePath) {
|
|||||||
var src = fs.readFileSync(filePath).toString();
|
var src = fs.readFileSync(filePath).toString();
|
||||||
var reSrcFiles = /var\s+otherFiles\s*=\s*(\[[^\]]*\])/;
|
var reSrcFiles = /var\s+otherFiles\s*=\s*(\[[^\]]*\])/;
|
||||||
var match = reSrcFiles.exec(src);
|
var match = reSrcFiles.exec(src);
|
||||||
try {
|
if (!match) {
|
||||||
var files = JSON.parse(match[1].replace(/'/g, '"'));
|
throw new Error('Cannot find otherFiles array in ' + filePath);
|
||||||
var srcFiles = files.filter(function(name) {
|
|
||||||
return name.indexOf('external') === -1;
|
|
||||||
});
|
|
||||||
var externalSrcFiles = files.filter(function(name) {
|
|
||||||
return name.indexOf('external') > -1;
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
srcFiles: srcFiles,
|
|
||||||
externalSrcFiles: externalSrcFiles
|
|
||||||
};
|
|
||||||
} catch(e) {
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var files = match[1].replace(/'/g, '"').replace(/^\s*\/\/.*/gm, '')
|
||||||
|
.replace(/,\s*]$/, ']');
|
||||||
|
try {
|
||||||
|
files = JSON.parse(files);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error('Failed to parse otherFiles in ' + filePath + ' as JSON, ' +
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
var srcFiles = files.filter(function(name) {
|
||||||
|
return name.indexOf('external') === -1;
|
||||||
|
});
|
||||||
|
var externalSrcFiles = files.filter(function(name) {
|
||||||
|
return name.indexOf('external') > -1;
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
srcFiles: srcFiles,
|
||||||
|
externalSrcFiles: externalSrcFiles
|
||||||
|
};
|
||||||
}
|
}
|
||||||
exports.getWorkerSrcFiles = getWorkerSrcFiles;
|
exports.getWorkerSrcFiles = getWorkerSrcFiles;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user