diff --git a/scripts/build/findUpDir.js b/scripts/build/findUpDir.js new file mode 100644 index 00000000000..fab301c6dcd --- /dev/null +++ b/scripts/build/findUpDir.js @@ -0,0 +1,21 @@ +const { join, resolve, dirname } = require("path"); +const { existsSync } = require("fs"); + +// search directories upward to avoid hard-wired paths based on the +// build tree (same as src/harness/findUpDir.ts) + +function findUpFile(name) { + let dir = __dirname; + while (true) { + const fullPath = join(dir, name); + if (existsSync(fullPath)) return fullPath; + const up = resolve(dir, ".."); + if (up === dir) return name; // it'll fail anyway + dir = up; + } +} +exports.findUpFile = findUpFile; + +const findUpRoot = () => + findUpRoot.cached || (findUpRoot.cached = dirname(findUpFile("Gulpfile.js"))); +exports.findUpRoot = findUpRoot; diff --git a/scripts/build/projects.js b/scripts/build/projects.js index 954f37af84e..38db816e23b 100644 --- a/scripts/build/projects.js +++ b/scripts/build/projects.js @@ -1,5 +1,7 @@ // @ts-check const { exec, Debouncer } = require("./utils"); +const { resolve } = require("path"); +const { findUpRoot } = require("./findUpDir"); class ProjectQueue { /** @@ -33,7 +35,13 @@ class ProjectQueue { } } -const projectBuilder = new ProjectQueue((projects, lkg, force) => exec(process.execPath, [lkg ? "./lib/tsc" : "./built/local/tsc", "-b", ...(force ? ["--force"] : []), ...projects], { hidePrompt: true })); +const execTsc = (lkg, ...args) => + exec(process.execPath, + [resolve(findUpRoot(), lkg ? "./lib/tsc" : "./built/local/tsc"), + "-b", ...args], + { hidePrompt: true }) + +const projectBuilder = new ProjectQueue((projects, lkg, force) => execTsc(lkg, ...(force ? ["--force"] : []), ...projects)); /** * @param {string} project @@ -43,14 +51,14 @@ const projectBuilder = new ProjectQueue((projects, lkg, force) => exec(process.e */ exports.buildProject = (project, { lkg, force } = {}) => projectBuilder.enqueue(project, { lkg, force }); -const projectCleaner = new ProjectQueue((projects, lkg) => exec(process.execPath, [lkg ? "./lib/tsc" : "./built/local/tsc", "-b", "--clean", ...projects], { hidePrompt: true })); +const projectCleaner = new ProjectQueue((projects, lkg) => execTsc(lkg, "--clean", ...projects)); /** * @param {string} project */ exports.cleanProject = (project) => projectCleaner.enqueue(project); -const projectWatcher = new ProjectQueue((projects) => exec(process.execPath, ["./lib/tsc", "-b", "--watch", ...projects], { hidePrompt: true })); +const projectWatcher = new ProjectQueue((projects) => execTsc(true, "--watch", ...projects)); /** * @param {string} project diff --git a/scripts/build/tests.js b/scripts/build/tests.js index 7fee32566dd..10c6db79cf1 100644 --- a/scripts/build/tests.js +++ b/scripts/build/tests.js @@ -9,6 +9,7 @@ const log = require("fancy-log"); const cmdLineOptions = require("./options"); const { CancellationToken } = require("prex"); const { exec } = require("./utils"); +const { findUpFile } = require("./findUpDir"); const mochaJs = require.resolve("mocha/bin/_mocha"); exports.localBaseline = "tests/baselines/local/"; @@ -73,11 +74,11 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, /** @type {string[]} */ let args = []; - // timeout normally isn"t necessary but Travis-CI has been timing out on compiler baselines occasionally + // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer if (!runInParallel) { args.push(mochaJs); - args.push("-R", "scripts/failed-tests"); + args.push("-R", findUpFile("scripts/failed-tests.js")); args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"'); if (tests) { args.push("-g", `"${tests}"`); diff --git a/src/harness/findUpDir.ts b/src/harness/findUpDir.ts new file mode 100644 index 00000000000..03b5ebdf285 --- /dev/null +++ b/src/harness/findUpDir.ts @@ -0,0 +1,21 @@ +namespace findUpDir { + import { join, resolve, dirname } from "path"; + import { existsSync } from "fs"; + + // search directories upward to avoid hard-wired paths based on the + // build tree (same as scripts/build/findUpDir.js) + + export function findUpFile(name: string) { + let dir = __dirname; + while (true) { + const fullPath = join(dir, name); + if (existsSync(fullPath)) return fullPath; + const up = resolve(dir, ".."); + if (up === dir) return name; // it'll fail anyway + dir = up; + } + } + + export const findUpRoot: { (): string; cached?: string; } = () => + findUpRoot.cached ||= dirname(findUpFile("Gulpfile.js")); +}