Inform tsc of project-to-project dependencies (#495)

Fixes issues with watch build when a change impacts dependent
projects.

Also fix issues preventing a watch build in VS Code from being
successful due to dist/ or dist-dev/ not being created yet.

With both of these, it is now actually possible to do only rush
update on pristine enlistment, then Ctrl+Shift+B in VS Code as
CONTRIBUTING.md claims.
This commit is contained in:
Nick Guerrera 2021-04-26 14:33:08 -07:00 коммит произвёл GitHub
Родитель fa575e515e
Коммит 9bda6a8fc9
5 изменённых файлов: 50 добавлений и 17 удалений

Просмотреть файл

@ -1,5 +1,5 @@
import { spawn, spawnSync } from "child_process";
import { readFileSync } from "fs";
import { statSync, readFileSync } from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
@ -108,24 +108,51 @@ export function runWatch(watch, dir, build, options) {
let lastStartTime;
dir = resolve(dir);
// build once up-front.
runBuild();
// We might need to wait for another watcher to create the directory.
try {
statSync(dir);
} catch (err) {
if (err.code === "ENOENT") {
waitForDirectoryCreation();
return;
}
throw err;
}
watch.createMonitor(dir, { interval: 0.2, ...options }, (monitor) => {
let handler = function (file) {
if (lastStartTime && monitor?.files[file]?.mtime < lastStartTime) {
// File was changed before last build started so we can ignore it. This
// avoids running the build unnecessarily when a series of input files
// change at the same time.
return;
}
runBuild(file);
};
start();
monitor.on("created", handler);
monitor.on("changed", handler);
monitor.on("removed", handler);
});
function waitForDirectoryCreation() {
logWithTime(`${dir} doesn't exist yet: waiting for it to be created.`);
watch.createMonitor(dirname(dir), "created", (monitor) => {
monitor.on("created", (file) => {
if (file === dir) {
logWithTime(`${dir} created.`);
start();
}
});
});
}
function start() {
// build once up-front.
runBuild();
watch.createMonitor(dir, { interval: 0.2, ...options }, (monitor) => {
let handler = function (file) {
if (lastStartTime && monitor?.files[file]?.mtime < lastStartTime) {
// File was changed before last build started so we can ignore it. This
// avoids running the build unnecessarily when a series of input files
// change at the same time.
return;
}
runBuild(file);
};
monitor.on("created", handler);
monitor.on("changed", handler);
monitor.on("removed", handler);
});
}
function runBuild(file) {
runBuildAsync(file).catch((err) => {

Просмотреть файл

@ -1,5 +1,6 @@
{
"extends": "../tsconfig.json",
"references": [{ "path": "../adl/tsconfig.json" }],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"

Просмотреть файл

@ -84,8 +84,10 @@
"@azure-tools/tmlanguage-generator": "0.1.4",
"@rollup/plugin-commonjs": "~17.1.0",
"@rollup/plugin-node-resolve": "~11.2.0",
"@types/mkdirp": "~1.0.1",
"@types/node": "~14.0.27",
"@types/vscode": "~1.53.0",
"mkdirp": "~1.0.4",
"rollup": "~2.41.4",
"typescript": "~4.2.4",
"vsce": "~1.85.1",

Просмотреть файл

@ -3,6 +3,7 @@
import * as tm from "@azure-tools/tmlanguage-generator";
import fs from "fs/promises";
import mkdirp from "mkdirp";
import { resolve } from "path";
type IncludeRule = tm.IncludeRule<ADLScope>;
@ -333,5 +334,6 @@ export async function main() {
const plist = await tm.emitPList(grammar, {
errorSourceFilePath: resolve("./src/tmlanguage.ts"),
});
await mkdirp("./dist");
await fs.writeFile("./dist/adl.tmLanguage", plist);
}

Просмотреть файл

@ -1,5 +1,6 @@
{
"extends": "../tsconfig.json",
"references": [{ "path": "../tmlanguage-generator/tsconfig.json" }],
"compilerOptions": {
"outDir": "dist-dev",
"rootDir": "src",