Avoid hard-wired build-tree paths
Instead, search for stuff up the directory tree, with the main functionality being to look for `Gulpfile.js` and assume the resulting directory is the root. (Unfortunatley, this is implemented twice, one in `scripts` and another in `src`. It's not possible to use a single implementation for both since that would require assuming a directory structure which this is intended to avoid.) Also, in `scripts/build/projects.js`, abstracdt common exec functionality into a local helper, and use full paths based on the above search instead of assuming relative paths assuming CWD being in the project root.
This commit is contained in:
parent
7c3f607032
commit
556098ed50
21
scripts/build/findUpDir.js
Normal file
21
scripts/build/findUpDir.js
Normal file
|
@ -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;
|
|
@ -1,5 +1,7 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
const { exec, Debouncer } = require("./utils");
|
const { exec, Debouncer } = require("./utils");
|
||||||
|
const { resolve } = require("path");
|
||||||
|
const { findUpRoot } = require("./findUpDir");
|
||||||
|
|
||||||
class ProjectQueue {
|
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
|
* @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 });
|
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
|
* @param {string} project
|
||||||
*/
|
*/
|
||||||
exports.cleanProject = (project) => projectCleaner.enqueue(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
|
* @param {string} project
|
||||||
|
|
|
@ -9,6 +9,7 @@ const log = require("fancy-log");
|
||||||
const cmdLineOptions = require("./options");
|
const cmdLineOptions = require("./options");
|
||||||
const { CancellationToken } = require("prex");
|
const { CancellationToken } = require("prex");
|
||||||
const { exec } = require("./utils");
|
const { exec } = require("./utils");
|
||||||
|
const { findUpFile } = require("./findUpDir");
|
||||||
|
|
||||||
const mochaJs = require.resolve("mocha/bin/_mocha");
|
const mochaJs = require.resolve("mocha/bin/_mocha");
|
||||||
exports.localBaseline = "tests/baselines/local/";
|
exports.localBaseline = "tests/baselines/local/";
|
||||||
|
@ -73,11 +74,11 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
let args = [];
|
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
|
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
|
||||||
if (!runInParallel) {
|
if (!runInParallel) {
|
||||||
args.push(mochaJs);
|
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" : "") + '"');
|
args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"');
|
||||||
if (tests) {
|
if (tests) {
|
||||||
args.push("-g", `"${tests}"`);
|
args.push("-g", `"${tests}"`);
|
||||||
|
|
21
src/harness/findUpDir.ts
Normal file
21
src/harness/findUpDir.ts
Normal file
|
@ -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"));
|
||||||
|
}
|
Loading…
Reference in a new issue