Fixes #21892: Do not read .d.ts files from disk when generating monaco.d.ts

This commit is contained in:
Alex Dima
2017-03-06 12:14:24 +01:00
parent 16b59a51d4
commit 1645d0d150
4 changed files with 88 additions and 105 deletions

View File

@@ -150,29 +150,36 @@ function reloadTypeScriptNodeModule(): NodeJS.ReadWriteStream {
}
function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream {
let timer: NodeJS.Timer = null;
const runSoon = function (howSoon: number) {
if (timer !== null) {
clearTimeout(timer);
timer = null;
const neededFiles: { [file: string]: boolean; } = {};
monacodts.getFilesToWatch(out).forEach(function (filePath) {
filePath = path.normalize(filePath);
neededFiles[filePath] = true;
});
const inputFiles: { [file: string]: string; } = {};
for (let filePath in neededFiles) {
if (/\bsrc(\/|\\)vs\b/.test(filePath)) {
// This file is needed from source => simply read it now
inputFiles[filePath] = fs.readFileSync(filePath).toString();
}
}
const setInputFile = (filePath: string, contents:string) => {
if (inputFiles[filePath] === contents) {
// no change
return;
}
inputFiles[filePath] = contents;
const neededInputFilesCount = Object.keys(neededFiles).length;
const availableInputFilesCount = Object.keys(inputFiles).length;
if (neededInputFilesCount === availableInputFilesCount) {
run();
}
timer = setTimeout(function () {
timer = null;
runNow();
}, howSoon);
};
const runNow = function () {
if (timer !== null) {
clearTimeout(timer);
timer = null;
}
// if (reporter.hasErrors()) {
// monacodts.complainErrors();
// return;
// }
const result = monacodts.run(out);
const run = () => {
const result = monacodts.run(out, inputFiles);
if (!result.isTheSame) {
if (isWatch) {
fs.writeFileSync(result.filePath, result.content);
@@ -185,32 +192,18 @@ function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream {
let resultStream: NodeJS.ReadWriteStream;
if (isWatch) {
const filesToWatchMap: { [file: string]: boolean; } = {};
monacodts.getFilesToWatch(out).forEach(function (filePath) {
filesToWatchMap[path.normalize(filePath)] = true;
});
watch('build/monaco/*').pipe(es.through(function () {
runSoon(5000);
run();
}));
resultStream = es.through(function (data) {
const filePath = path.normalize(data.path);
if (filesToWatchMap[filePath]) {
runSoon(5000);
}
this.emit('data', data);
});
} else {
resultStream = es.through(null, function () {
runNow();
this.emit('end');
});
}
resultStream = es.through(function (data) {
const filePath = path.normalize(data.path);
if (neededFiles[filePath]) {
setInputFile(filePath, data.contents.toString());
}
this.emit('data', data);
});
return resultStream;
}