mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
This eliminates a significant number of dependencies, eliminating all npm audit issues, speeding up `npm ci` by 20%, and overall making the build faster (faster startup, direct code is faster than streams, etc) and clearer to understand. I'm finding it much easier to make build changes for the module transform with this; I can more clearly indicate task dependencies and prevent running tasks that don't need to be run. Given we're changing our build process entirely (new deps, new steps), it seems like this is a good time to change things up.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
import { exec, Debouncer } from "./utils.mjs";
|
|
import { resolve } from "path";
|
|
import { findUpRoot } from "./findUpDir.mjs";
|
|
import cmdLineOptions from "./options.mjs";
|
|
|
|
class ProjectQueue {
|
|
/**
|
|
* @param {(projects: string[]) => Promise<any>} action
|
|
*/
|
|
constructor(action) {
|
|
/** @type {string[] | undefined} */
|
|
this._projects = undefined;
|
|
this._debouncer = new Debouncer(100, async () => {
|
|
const projects = this._projects;
|
|
if (projects) {
|
|
this._projects = undefined;
|
|
await action(projects);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} project
|
|
*/
|
|
enqueue(project) {
|
|
if (!this._projects) this._projects = [];
|
|
this._projects.push(project);
|
|
return this._debouncer.enqueue();
|
|
}
|
|
}
|
|
|
|
const execTsc = (/** @type {string[]} */ ...args) =>
|
|
exec(process.execPath,
|
|
[resolve(findUpRoot(), cmdLineOptions.lkg ? "./lib/tsc.js" : "./built/local/tsc.js"),
|
|
"-b", ...args],
|
|
{ hidePrompt: true });
|
|
|
|
const projectBuilder = new ProjectQueue((projects) => execTsc(...projects));
|
|
|
|
/**
|
|
* @param {string} project
|
|
*/
|
|
export const buildProject = (project) => projectBuilder.enqueue(project);
|
|
|
|
const projectCleaner = new ProjectQueue((projects) => execTsc("--clean", ...projects));
|
|
|
|
/**
|
|
* @param {string} project
|
|
*/
|
|
export const cleanProject = (project) => projectCleaner.enqueue(project);
|
|
|
|
const projectWatcher = new ProjectQueue((projects) => execTsc("--watch", "--preserveWatchOutput", ...projects));
|
|
|
|
/**
|
|
* @param {string} project
|
|
*/
|
|
export const watchProject = (project) => projectWatcher.enqueue(project);
|