From 657d0119cc09dff820b4dc80ab502cf183cdf358 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 15 Jun 2018 15:53:03 -0700 Subject: [PATCH] Dont use unreliable inodes for checking file identity (#25008) * Dont use unreliable inode as unique identifier * Just concat with `\n * Introduce path-overriding code to allow local executables ot be found --- Jakefile.js | 9 +++++++++ scripts/build/getDirSize.js | 13 +++---------- scripts/produceLKG.ts | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 9b3876ea13..0a758cc453 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -10,6 +10,15 @@ const ts = require("./lib/typescript"); const del = require("del"); const getDirSize = require("./scripts/build/getDirSize"); +// add node_modules to path so we don't need global modules, prefer the modules by adding them first +var nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter; +if (process.env.path !== undefined) { + process.env.path = nodeModulesPathPrefix + process.env.path; +} +else if (process.env.PATH !== undefined) { + process.env.PATH = nodeModulesPathPrefix + process.env.PATH; +} + const host = process.env.TYPESCRIPT_HOST || process.env.host || "node"; const locales = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-br", "ru", "tr", "zh-cn", "zh-tw"]; diff --git a/scripts/build/getDirSize.js b/scripts/build/getDirSize.js index 278c4e7f00..58a65907e4 100644 --- a/scripts/build/getDirSize.js +++ b/scripts/build/getDirSize.js @@ -4,26 +4,19 @@ const { join } = require("path"); /** * Find the size of a directory recursively. - * Symbolic links are counted once (same inode). + * Symbolic links can cause a loop. * @param {string} root - * @param {Set} seen * @returns {number} bytes */ -function getDirSize(root, seen = new Set()) { +function getDirSize(root) { const stats = lstatSync(root); - if (seen.has(stats.ino)) { - return 0; - } - - seen.add(stats.ino); - if (!stats.isDirectory()) { return stats.size; } return readdirSync(root) - .map(file => getDirSize(join(root, file), seen)) + .map(file => getDirSize(join(root, file))) .reduce((acc, num) => acc + num, 0); } diff --git a/scripts/produceLKG.ts b/scripts/produceLKG.ts index 800234e688..f7e5d0ceec 100644 --- a/scripts/produceLKG.ts +++ b/scripts/produceLKG.ts @@ -75,7 +75,7 @@ async function writeGitAttributes() { async function copyWithCopyright(fileName: string) { const content = await fs.readFile(path.join(source, fileName), "utf-8"); - await fs.writeFile(path.join(dest, fileName), copyright + "\r\n" + content); + await fs.writeFile(path.join(dest, fileName), copyright + "\n" + content); } async function copyFromBuiltLocal(fileName: string) {