Skip to content

Commit

Permalink
Add build via esbuild
Browse files Browse the repository at this point in the history
This configures the existing build tasks to use esbuild by defualt. If
using the plain files is desired, passing `--bundle=false` will build
using plain files and still produce a runnable system.
  • Loading branch information
jakebailey committed Sep 19, 2022
1 parent fb8179c commit 99a9841
Show file tree
Hide file tree
Showing 31 changed files with 2,197 additions and 527 deletions.
364 changes: 196 additions & 168 deletions Gulpfile.js

Large diffs are not rendered by default.

1,974 changes: 1,895 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"!**/.gitattributes"
],
"devDependencies": {
"@babel/cli": "^7.18.10",
"@babel/core": "^7.19.1",
"@babel/plugin-transform-block-scoping": "^7.18.9",
"@microsoft/api-extractor": "^7.31.0",
"@octokit/rest": "latest",
"@types/async": "latest",
Expand Down Expand Up @@ -69,6 +72,7 @@
"chalk": "^4.1.2",
"del": "^6.1.1",
"diff": "^5.1.0",
"esbuild": "^0.15.7",
"eslint": "^8.22.0",
"eslint-formatter-autolinkable-stylish": "^1.2.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
11 changes: 7 additions & 4 deletions scripts/build/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ci = ["1", "true"].includes(process.env.CI);

/** @type {CommandLineOptions} */
module.exports = minimist(process.argv.slice(2), {
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci"],
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle"],
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
alias: {
/* eslint-disable quote-props */
Expand Down Expand Up @@ -41,6 +41,7 @@ module.exports = minimist(process.argv.slice(2), {
dirty: false,
built: false,
ci,
bundle: true
}
});

Expand All @@ -49,7 +50,7 @@ if (module.exports.built) {
}

/**
* @typedef TypedOptions
* @typedef CommandLineOptions
* @property {boolean} dirty
* @property {boolean} light
* @property {boolean} colors
Expand All @@ -69,7 +70,9 @@ if (module.exports.built) {
* @property {boolean} failed
* @property {boolean} keepFailed
* @property {boolean} ci
*
* @typedef {import("minimist").ParsedArgs & TypedOptions} CommandLineOptions
* @property {boolean} bundle
* @property {string} shards
* @property {string} shardId
* @property {string} break
*/
void 0;
64 changes: 0 additions & 64 deletions scripts/build/prepend.js

This file was deleted.

54 changes: 22 additions & 32 deletions scripts/build/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,57 @@
const { exec, Debouncer } = require("./utils");
const { resolve } = require("path");
const { findUpRoot } = require("./findUpDir");
const cmdLineOptions = require("./options");

class ProjectQueue {
/**
* @param {(projects: string[], lkg: boolean, force: boolean) => Promise<any>} action
* @param {(projects: string[]) => Promise<any>} action
*/
constructor(action) {
/** @type {{ lkg: boolean, force: boolean, projects?: string[], debouncer: Debouncer }[]} */
this._debouncers = [];
this._action = 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
* @param {object} options
*/
enqueue(project, { lkg = true, force = false } = {}) {
let entry = this._debouncers.find(entry => entry.lkg === lkg && entry.force === force);
if (!entry) {
const debouncer = new Debouncer(100, async () => {
const projects = entry.projects;
if (projects) {
entry.projects = undefined;
await this._action(projects, lkg, force);
}
});
this._debouncers.push(entry = { lkg, force, debouncer });
}
if (!entry.projects) entry.projects = [];
entry.projects.push(project);
return entry.debouncer.enqueue();
enqueue(project) {
if (!this._projects) this._projects = [];
this._projects.push(project);
return this._debouncer.enqueue();
}
}

const execTsc = (/** @type {boolean} */ lkg, /** @type {string[]} */ ...args) =>
const execTsc = (/** @type {string[]} */ ...args) =>
exec(process.execPath,
[resolve(findUpRoot(), lkg ? "./lib/tsc" : "./built/local/tsc"),
[resolve(findUpRoot(), cmdLineOptions.lkg ? "./lib/tsc" : "./built/local/tsc"),
"-b", ...args],
{ hidePrompt: true });

const projectBuilder = new ProjectQueue((projects, lkg, force) => execTsc(lkg, ...(force ? ["--force"] : []), ...projects));
const projectBuilder = new ProjectQueue((projects) => execTsc(...projects));

/**
* @param {string} project
* @param {object} options
* @param {boolean} [options.lkg=true]
* @param {boolean} [options.force=false]
*/
exports.buildProject = (project, { lkg, force } = {}) => projectBuilder.enqueue(project, { lkg, force });
exports.buildProject = (project) => projectBuilder.enqueue(project);

const projectCleaner = new ProjectQueue((projects, lkg) => execTsc(lkg, "--clean", ...projects));
const projectCleaner = new ProjectQueue((projects) => execTsc("--clean", ...projects));

/**
* @param {string} project
*/
exports.cleanProject = (project) => projectCleaner.enqueue(project);

const projectWatcher = new ProjectQueue((projects) => execTsc(/*lkg*/ true, "--watch", ...projects));
const projectWatcher = new ProjectQueue((projects) => execTsc("--watch", ...projects));

/**
* @param {string} project
* @param {object} options
* @param {boolean} [options.lkg=true]
*/
exports.watchProject = (project, { lkg } = {}) => projectWatcher.enqueue(project, { lkg });
exports.watchProject = (project) => projectWatcher.enqueue(project);
22 changes: 11 additions & 11 deletions scripts/build/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode)
errorStatus = exitCode;
error = new Error(`Process exited with status code ${errorStatus}.`);
}
else if (cmdLineOptions.ci) {
// finally, do a sanity check and build the compiler with the built version of itself
log.info("Starting sanity check build...");
// Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
if (exitCode !== 0) {
errorStatus = exitCode;
error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
}
}
// else if (cmdLineOptions.ci) {
// // finally, do a sanity check and build the compiler with the built version of itself
// log.info("Starting sanity check build...");
// // Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
// await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
// const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
// if (exitCode !== 0) {
// errorStatus = exitCode;
// error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
// }
// }
}
catch (e) {
errorStatus = undefined;
Expand Down
85 changes: 0 additions & 85 deletions scripts/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const fs = require("fs");
const path = require("path");
const log = require("fancy-log");
const mkdirp = require("mkdirp");
const del = require("del");
const File = require("vinyl");
const ts = require("../../lib/typescript");
Expand Down Expand Up @@ -225,90 +224,6 @@ function getDirSize(root) {
}
exports.getDirSize = getDirSize;

/**
* Flattens a project with project references into a single project.
* @param {string} projectSpec The path to a tsconfig.json file or its containing directory.
* @param {string} flattenedProjectSpec The output path for the flattened tsconfig.json file.
* @param {FlattenOptions} [options] Options used to flatten a project hierarchy.
*
* @typedef FlattenOptions
* @property {string} [cwd] The path to use for the current working directory. Defaults to `process.cwd()`.
* @property {import("../../lib/typescript").CompilerOptions} [compilerOptions] Compiler option overrides.
* @property {boolean} [force] Forces creation of the output project.
* @property {string[]} [exclude] Files to exclude (relative to `cwd`)
*/
function flatten(projectSpec, flattenedProjectSpec, options = {}) {
const cwd = normalizeSlashes(options.cwd ? path.resolve(options.cwd) : process.cwd());
const files = [];
const resolvedOutputSpec = path.resolve(cwd, flattenedProjectSpec);
const resolvedOutputDirectory = path.dirname(resolvedOutputSpec);
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, /*referrer*/ undefined);
const project = readJson(resolvedProjectSpec);
const skipProjects = /**@type {Set<string>}*/(new Set());
const skipFiles = new Set(options && options.exclude && options.exclude.map(file => normalizeSlashes(path.resolve(cwd, file))));
recur(resolvedProjectSpec, project);

if (options.force || needsUpdate(files, resolvedOutputSpec)) {
const config = {
extends: normalizeSlashes(path.relative(resolvedOutputDirectory, resolvedProjectSpec)),
compilerOptions: options.compilerOptions || {},
files: files.map(file => normalizeSlashes(path.relative(resolvedOutputDirectory, file)))
};
mkdirp.sync(resolvedOutputDirectory);
fs.writeFileSync(resolvedOutputSpec, JSON.stringify(config, undefined, 2), "utf8");
}

/**
* @param {string} projectSpec
* @param {object} project
*/
function recur(projectSpec, project) {
if (skipProjects.has(projectSpec)) return;
skipProjects.add(project);
if (project.references) {
for (const ref of project.references) {
const referencedSpec = resolveProjectSpec(ref.path, cwd, projectSpec);
const referencedProject = readJson(referencedSpec);
recur(referencedSpec, referencedProject);
}
}
if (project.include) {
throw new Error("Flattened project may not have an 'include' list.");
}
if (!project.files) {
throw new Error("Flattened project must have an explicit 'files' list.");
}
const projectDirectory = path.dirname(projectSpec);
for (let file of project.files) {
file = normalizeSlashes(path.resolve(projectDirectory, file));
if (skipFiles.has(file)) continue;
skipFiles.add(file);
files.push(file);
}
}
}
exports.flatten = flatten;

/**
* @param {string} file
*/
function normalizeSlashes(file) {
return file.replace(/\\/g, "/");
}

/**
* @param {string} projectSpec
* @param {string} cwd
* @param {string | undefined} referrer
* @returns {string}
*/
function resolveProjectSpec(projectSpec, cwd, referrer) {
const projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
const stats = fs.statSync(projectPath);
if (stats.isFile()) return normalizeSlashes(projectPath);
return normalizeSlashes(path.resolve(cwd, projectPath, "tsconfig.json"));
}

/**
* @param {string | ((file: File) => string) | { cwd?: string }} [dest]
* @param {{ cwd?: string }} [opts]
Expand Down
4 changes: 3 additions & 1 deletion src/cancellationToken/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "../tsconfig-base",
"compilerOptions": {
"outDir": "../../built/local/cancellationToken",
"outDir": "../../built/local",
"tsBuildInfoFile": "../../built/local/cancellationToken.tsbuildinfo",
"rootDir": ".",
"module": "commonjs",
"types": [
"node"
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ export namespace Debug {
try {
if (sys && sys.require) {
const basePath = getDirectoryPath(resolvePath(sys.getExecutingFilePath()));
const result = sys.require(basePath, "./compiler-debug") as RequireResult<ExtendedDebugModule>;
const result = sys.require(basePath, "./compilerDebug") as RequireResult<ExtendedDebugModule>;
if (!result.error) {
result.module.init(ts);
extendedDebugModule = result.module;
Expand Down
Loading

0 comments on commit 99a9841

Please sign in to comment.