Skip to content

Commit f588ed7

Browse files
committed
Add build via esbuild
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.
1 parent eb15662 commit f588ed7

33 files changed

+943
-485
lines changed

Gulpfile.js

+241-173
Large diffs are not rendered by default.

package-lock.json

+574
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"chalk": "^4.1.2",
6767
"del": "^6.1.1",
6868
"diff": "^5.1.0",
69+
"esbuild": "^0.15.9",
6970
"eslint": "^8.22.0",
7071
"eslint-formatter-autolinkable-stylish": "^1.2.0",
7172
"eslint-plugin-import": "^2.26.0",

scripts/build/options.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ci = ["1", "true"].includes(process.env.CI);
66

77
/** @type {CommandLineOptions} */
88
module.exports = minimist(process.argv.slice(2), {
9-
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci"],
9+
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle"],
1010
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
1111
alias: {
1212
/* eslint-disable quote-props */
@@ -41,6 +41,7 @@ module.exports = minimist(process.argv.slice(2), {
4141
dirty: false,
4242
built: false,
4343
ci,
44+
bundle: true
4445
}
4546
});
4647

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

5152
/**
52-
* @typedef TypedOptions
53+
* @typedef CommandLineOptions
5354
* @property {boolean} dirty
5455
* @property {boolean} light
5556
* @property {boolean} colors
@@ -69,7 +70,9 @@ if (module.exports.built) {
6970
* @property {boolean} failed
7071
* @property {boolean} keepFailed
7172
* @property {boolean} ci
72-
*
73-
* @typedef {import("minimist").ParsedArgs & TypedOptions} CommandLineOptions
73+
* @property {boolean} bundle
74+
* @property {string} shards
75+
* @property {string} shardId
76+
* @property {string} break
7477
*/
7578
void 0;

scripts/build/prepend.js

-64
This file was deleted.

scripts/build/projects.js

+22-32
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,57 @@
22
const { exec, Debouncer } = require("./utils");
33
const { resolve } = require("path");
44
const { findUpRoot } = require("./findUpDir");
5+
const cmdLineOptions = require("./options");
56

67
class ProjectQueue {
78
/**
8-
* @param {(projects: string[], lkg: boolean, force: boolean) => Promise<any>} action
9+
* @param {(projects: string[]) => Promise<any>} action
910
*/
1011
constructor(action) {
11-
/** @type {{ lkg: boolean, force: boolean, projects?: string[], debouncer: Debouncer }[]} */
12-
this._debouncers = [];
13-
this._action = action;
12+
/** @type {string[] | undefined} */
13+
this._projects = undefined;
14+
this._debouncer = new Debouncer(100, async () => {
15+
const projects = this._projects;
16+
if (projects) {
17+
this._projects = undefined;
18+
await action(projects);
19+
}
20+
});
1421
}
1522

1623
/**
1724
* @param {string} project
18-
* @param {object} options
1925
*/
20-
enqueue(project, { lkg = true, force = false } = {}) {
21-
let entry = this._debouncers.find(entry => entry.lkg === lkg && entry.force === force);
22-
if (!entry) {
23-
const debouncer = new Debouncer(100, async () => {
24-
const projects = entry.projects;
25-
if (projects) {
26-
entry.projects = undefined;
27-
await this._action(projects, lkg, force);
28-
}
29-
});
30-
this._debouncers.push(entry = { lkg, force, debouncer });
31-
}
32-
if (!entry.projects) entry.projects = [];
33-
entry.projects.push(project);
34-
return entry.debouncer.enqueue();
26+
enqueue(project) {
27+
if (!this._projects) this._projects = [];
28+
this._projects.push(project);
29+
return this._debouncer.enqueue();
3530
}
3631
}
3732

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

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

4641
/**
4742
* @param {string} project
48-
* @param {object} options
49-
* @param {boolean} [options.lkg=true]
50-
* @param {boolean} [options.force=false]
5143
*/
52-
exports.buildProject = (project, { lkg, force } = {}) => projectBuilder.enqueue(project, { lkg, force });
44+
exports.buildProject = (project) => projectBuilder.enqueue(project);
5345

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

5648
/**
5749
* @param {string} project
5850
*/
5951
exports.cleanProject = (project) => projectCleaner.enqueue(project);
6052

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

6355
/**
6456
* @param {string} project
65-
* @param {object} options
66-
* @param {boolean} [options.lkg=true]
6757
*/
68-
exports.watchProject = (project, { lkg } = {}) => projectWatcher.enqueue(project, { lkg });
58+
exports.watchProject = (project) => projectWatcher.enqueue(project);

scripts/build/tests.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode)
123123
errorStatus = exitCode;
124124
error = new Error(`Process exited with status code ${errorStatus}.`);
125125
}
126-
else if (cmdLineOptions.ci) {
127-
// finally, do a sanity check and build the compiler with the built version of itself
128-
log.info("Starting sanity check build...");
129-
// Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
130-
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
131-
const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
132-
if (exitCode !== 0) {
133-
errorStatus = exitCode;
134-
error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
135-
}
136-
}
126+
// else if (cmdLineOptions.ci) {
127+
// // finally, do a sanity check and build the compiler with the built version of itself
128+
// log.info("Starting sanity check build...");
129+
// // Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
130+
// await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
131+
// const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
132+
// if (exitCode !== 0) {
133+
// errorStatus = exitCode;
134+
// error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
135+
// }
136+
// }
137137
}
138138
catch (e) {
139139
errorStatus = undefined;

scripts/build/utils.js

-85
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
const fs = require("fs");
88
const path = require("path");
99
const log = require("fancy-log");
10-
const mkdirp = require("mkdirp");
1110
const del = require("del");
1211
const File = require("vinyl");
1312
const ts = require("../../lib/typescript");
@@ -225,90 +224,6 @@ function getDirSize(root) {
225224
}
226225
exports.getDirSize = getDirSize;
227226

228-
/**
229-
* Flattens a project with project references into a single project.
230-
* @param {string} projectSpec The path to a tsconfig.json file or its containing directory.
231-
* @param {string} flattenedProjectSpec The output path for the flattened tsconfig.json file.
232-
* @param {FlattenOptions} [options] Options used to flatten a project hierarchy.
233-
*
234-
* @typedef FlattenOptions
235-
* @property {string} [cwd] The path to use for the current working directory. Defaults to `process.cwd()`.
236-
* @property {import("../../lib/typescript").CompilerOptions} [compilerOptions] Compiler option overrides.
237-
* @property {boolean} [force] Forces creation of the output project.
238-
* @property {string[]} [exclude] Files to exclude (relative to `cwd`)
239-
*/
240-
function flatten(projectSpec, flattenedProjectSpec, options = {}) {
241-
const cwd = normalizeSlashes(options.cwd ? path.resolve(options.cwd) : process.cwd());
242-
const files = [];
243-
const resolvedOutputSpec = path.resolve(cwd, flattenedProjectSpec);
244-
const resolvedOutputDirectory = path.dirname(resolvedOutputSpec);
245-
const resolvedProjectSpec = resolveProjectSpec(projectSpec, cwd, /*referrer*/ undefined);
246-
const project = readJson(resolvedProjectSpec);
247-
const skipProjects = /**@type {Set<string>}*/(new Set());
248-
const skipFiles = new Set(options && options.exclude && options.exclude.map(file => normalizeSlashes(path.resolve(cwd, file))));
249-
recur(resolvedProjectSpec, project);
250-
251-
if (options.force || needsUpdate(files, resolvedOutputSpec)) {
252-
const config = {
253-
extends: normalizeSlashes(path.relative(resolvedOutputDirectory, resolvedProjectSpec)),
254-
compilerOptions: options.compilerOptions || {},
255-
files: files.map(file => normalizeSlashes(path.relative(resolvedOutputDirectory, file)))
256-
};
257-
mkdirp.sync(resolvedOutputDirectory);
258-
fs.writeFileSync(resolvedOutputSpec, JSON.stringify(config, undefined, 2), "utf8");
259-
}
260-
261-
/**
262-
* @param {string} projectSpec
263-
* @param {object} project
264-
*/
265-
function recur(projectSpec, project) {
266-
if (skipProjects.has(projectSpec)) return;
267-
skipProjects.add(project);
268-
if (project.references) {
269-
for (const ref of project.references) {
270-
const referencedSpec = resolveProjectSpec(ref.path, cwd, projectSpec);
271-
const referencedProject = readJson(referencedSpec);
272-
recur(referencedSpec, referencedProject);
273-
}
274-
}
275-
if (project.include) {
276-
throw new Error("Flattened project may not have an 'include' list.");
277-
}
278-
if (!project.files) {
279-
throw new Error("Flattened project must have an explicit 'files' list.");
280-
}
281-
const projectDirectory = path.dirname(projectSpec);
282-
for (let file of project.files) {
283-
file = normalizeSlashes(path.resolve(projectDirectory, file));
284-
if (skipFiles.has(file)) continue;
285-
skipFiles.add(file);
286-
files.push(file);
287-
}
288-
}
289-
}
290-
exports.flatten = flatten;
291-
292-
/**
293-
* @param {string} file
294-
*/
295-
function normalizeSlashes(file) {
296-
return file.replace(/\\/g, "/");
297-
}
298-
299-
/**
300-
* @param {string} projectSpec
301-
* @param {string} cwd
302-
* @param {string | undefined} referrer
303-
* @returns {string}
304-
*/
305-
function resolveProjectSpec(projectSpec, cwd, referrer) {
306-
const projectPath = normalizeSlashes(path.resolve(cwd, referrer ? path.dirname(referrer) : "", projectSpec));
307-
const stats = fs.statSync(projectPath);
308-
if (stats.isFile()) return normalizeSlashes(projectPath);
309-
return normalizeSlashes(path.resolve(cwd, projectPath, "tsconfig.json"));
310-
}
311-
312227
/**
313228
* @param {string | ((file: File) => string) | { cwd?: string }} [dest]
314229
* @param {{ cwd?: string }} [opts]

0 commit comments

Comments
 (0)