Skip to content

Commit

Permalink
[generated] Run dprint and update baselines
Browse files Browse the repository at this point in the history
[git-generate]
set -x
npm ci
npx dprint fmt
npx hereby clean
npx hereby dts
npx hereby runtests -t 'Public APIs|goToTypeDefinition_' &> /dev/null || npx hereby baseline-accept
  • Loading branch information
jakebailey committed Aug 11, 2023
1 parent 4ee08a7 commit ed78891
Show file tree
Hide file tree
Showing 439 changed files with 87,581 additions and 23,222 deletions.
88 changes: 74 additions & 14 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ const localize = task({
dependencies: [generateDiagnostics],
run: async () => {
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
await exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
await exec(process.execPath, [
"scripts/generateLocalizedDiagnosticMessages.mjs",
"src/loc/lcl",
"built/local",
diagnosticMessagesGeneratedJson,
], { ignoreExitCode: true });
}
},
});
Expand Down Expand Up @@ -312,7 +317,10 @@ function entrypointBuildTask(options) {
const outDir = path.dirname(options.output);
await fs.promises.mkdir(outDir, { recursive: true });
const moduleSpecifier = path.relative(outDir, options.builtEntrypoint);
await fs.promises.writeFile(options.output, `module.exports = require("./${moduleSpecifier.replace(/[\\/]/g, "/")}")`);
await fs.promises.writeFile(
options.output,
`module.exports = require("./${moduleSpecifier.replace(/[\\/]/g, "/")}")`,
);
},
});

Expand All @@ -336,13 +344,19 @@ function entrypointBuildTask(options) {
const watch = task({
name: `watch-${options.name}`,
hiddenFromTaskList: true, // This is best effort.
dependencies: (options.buildDeps ?? []).concat(options.mainDeps ?? []).concat(cmdLineOptions.bundle ? [] : [shim]),
dependencies: (options.buildDeps ?? []).concat(options.mainDeps ?? []).concat(
cmdLineOptions.bundle ? [] : [shim],
),
run: () => {
// These watch functions return promises that resolve once watch mode has started,
// allowing them to operate as regular tasks, while creating unresolved promises
// in the background that keep the process running after all tasks have exited.
if (!printedWatchWarning) {
console.error(chalk.yellowBright("Warning: watch mode is incomplete and may not work as expected. Use at your own risk."));
console.error(
chalk.yellowBright(
"Warning: watch mode is incomplete and may not work as expected. Use at your own risk.",
),
);
printedWatchWarning = true;
}

Expand Down Expand Up @@ -386,7 +400,12 @@ export const dtsServices = task({
description: "Bundles typescript.d.ts",
dependencies: [buildServices],
run: async () => {
if (needsUpdate("./built/local/typescript/tsconfig.tsbuildinfo", ["./built/local/typescript.d.ts", "./built/local/typescript.internal.d.ts"])) {
if (
needsUpdate("./built/local/typescript/tsconfig.tsbuildinfo", [
"./built/local/typescript.d.ts",
"./built/local/typescript.internal.d.ts",
])
) {
await runDtsBundler("./built/local/typescript/typescript.d.ts", "./built/local/typescript.d.ts");
}
},
Expand Down Expand Up @@ -435,8 +454,16 @@ export const dtsLssl = task({
description: "Bundles tsserverlibrary.d.ts",
dependencies: [buildLssl],
run: async () => {
if (needsUpdate("./built/local/tsserverlibrary/tsconfig.tsbuildinfo", ["./built/local/tsserverlibrary.d.ts", "./built/local/tsserverlibrary.internal.d.ts"])) {
await runDtsBundler("./built/local/tsserverlibrary/tsserverlibrary.d.ts", "./built/local/tsserverlibrary.d.ts");
if (
needsUpdate("./built/local/tsserverlibrary/tsconfig.tsbuildinfo", [
"./built/local/tsserverlibrary.d.ts",
"./built/local/tsserverlibrary.internal.d.ts",
])
) {
await runDtsBundler(
"./built/local/tsserverlibrary/tsserverlibrary.d.ts",
"./built/local/tsserverlibrary.d.ts",
);
}
},
});
Expand Down Expand Up @@ -572,7 +599,13 @@ export const watchOtherOutputs = task({
name: "watch-other-outputs",
description: "Builds miscelaneous scripts and documents distributed with the LKG",
hiddenFromTaskList: true,
dependencies: [watchCancellationToken, watchTypingsInstaller, watchWatchGuard, generateTypesMap, copyBuiltLocalDiagnosticMessages],
dependencies: [
watchCancellationToken,
watchTypingsInstaller,
watchWatchGuard,
generateTypesMap,
copyBuiltLocalDiagnosticMessages,
],
});

export const local = task({
Expand Down Expand Up @@ -650,7 +683,10 @@ export const runTestsAndWatch = task({
if (!token.signaled) {
running = true;
try {
await runConsoleTests(testRunner, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, { token, watching: true });
await runConsoleTests(testRunner, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, {
token,
watching: true,
});
}
catch {
// ignore
Expand Down Expand Up @@ -805,7 +841,10 @@ export const updateSublime = task({
dependencies: [tsserver],
run: async () => {
for (const file of ["built/local/tsserver.js", "built/local/tsserver.js.map"]) {
await fs.promises.copyFile(file, path.resolve("../TypeScript-Sublime-Plugin/tsserver/", path.basename(file)));
await fs.promises.copyFile(
file,
path.resolve("../TypeScript-Sublime-Plugin/tsserver/", path.basename(file)),
);
}
},
});
Expand Down Expand Up @@ -834,7 +873,10 @@ export const produceLKG = task({
.concat(localizationTargets)
.filter(f => !fs.existsSync(f));
if (missingFiles.length > 0) {
throw new Error("Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n" + missingFiles.join("\n"));
throw new Error(
"Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n"
+ missingFiles.join("\n"),
);
}

await exec(process.execPath, ["scripts/produceLKG.mjs"]);
Expand Down Expand Up @@ -862,19 +904,37 @@ export const clean = task({
export const configureNightly = task({
name: "configure-nightly",
description: "Runs scripts/configurePrerelease.mjs to prepare a build for nightly publishing",
run: () => exec(process.execPath, ["scripts/configurePrerelease.mjs", "dev", "package.json", "src/compiler/corePublic.ts"]),
run: () =>
exec(process.execPath, [
"scripts/configurePrerelease.mjs",
"dev",
"package.json",
"src/compiler/corePublic.ts",
]),
});

export const configureInsiders = task({
name: "configure-insiders",
description: "Runs scripts/configurePrerelease.mjs to prepare a build for insiders publishing",
run: () => exec(process.execPath, ["scripts/configurePrerelease.mjs", "insiders", "package.json", "src/compiler/corePublic.ts"]),
run: () =>
exec(process.execPath, [
"scripts/configurePrerelease.mjs",
"insiders",
"package.json",
"src/compiler/corePublic.ts",
]),
});

export const configureExperimental = task({
name: "configure-experimental",
description: "Runs scripts/configurePrerelease.mjs to prepare a build for experimental publishing",
run: () => exec(process.execPath, ["scripts/configurePrerelease.mjs", "experimental", "package.json", "src/compiler/corePublic.ts"]),
run: () =>
exec(process.execPath, [
"scripts/configurePrerelease.mjs",
"experimental",
"package.json",
"src/compiler/corePublic.ts",
]),
});

export const help = task({
Expand Down
16 changes: 15 additions & 1 deletion scripts/build/localization.mjs
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
export const localizationDirectories = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-br", "ru", "tr", "zh-cn", "zh-tw"].map(f => f.toLowerCase());
export const localizationDirectories = [
"cs",
"de",
"es",
"fr",
"it",
"ja",
"ko",
"pl",
"pt-br",
"ru",
"tr",
"zh-cn",
"zh-tw",
].map(f => f.toLowerCase());
18 changes: 17 additions & 1 deletion scripts/build/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ import os from "os";
const ci = ["1", "true"].includes(process.env.CI ?? "");

const parsed = minimist(process.argv.slice(2), {
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle", "typecheck", "lint", "coverage"],
boolean: [
"dirty",
"light",
"colors",
"lkg",
"soft",
"fix",
"failed",
"keepFailed",
"force",
"built",
"ci",
"bundle",
"typecheck",
"lint",
"coverage",
],
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
alias: {
/* eslint-disable quote-props */
Expand Down
13 changes: 8 additions & 5 deletions scripts/build/projects.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ class ProjectQueue {

const tscPath = resolve(
findUpRoot(),
cmdLineOptions.lkg ? "./lib/tsc.js" :
cmdLineOptions.built ? "./built/local/tsc.js" :
"./node_modules/typescript/lib/tsc.js",
cmdLineOptions.lkg ? "./lib/tsc.js"
: cmdLineOptions.built ? "./built/local/tsc.js"
: "./node_modules/typescript/lib/tsc.js",
);

const execTsc = (/** @type {string[]} */ ...args) => exec(process.execPath, [tscPath, "-b", ...args], { hidePrompt: true });
const execTsc = (/** @type {string[]} */ ...args) =>
exec(process.execPath, [tscPath, "-b", ...args], { hidePrompt: true });

const projectBuilder = new ProjectQueue(projects => execTsc(...(cmdLineOptions.bundle ? [] : ["--emitDeclarationOnly", "false"]), ...projects));
const projectBuilder = new ProjectQueue(projects =>
execTsc(...(cmdLineOptions.bundle ? [] : ["--emitDeclarationOnly", "false"]), ...projects)
);

/**
* @param {string} project
Expand Down
26 changes: 24 additions & 2 deletions scripts/build/tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt
}

if (tests || runners || light || testTimeout || taskConfigsFolder || keepFailed || shards || shardId) {
writeTestConfigFile(tests, runners, light, taskConfigsFolder, workerCount, stackTraceLimit, testTimeout, keepFailed, shards, shardId);
writeTestConfigFile(
tests,
runners,
light,
taskConfigsFolder,
workerCount,
stackTraceLimit,
testTimeout,
keepFailed,
shards,
shardId,
);
}

const colors = cmdLineOptions.colors;
Expand Down Expand Up @@ -198,7 +209,18 @@ async function cleanCoverageDir() {
* @param {number | undefined} [shards]
* @param {number | undefined} [shardId]
*/
export function writeTestConfigFile(tests, runners, light, taskConfigsFolder, workerCount, stackTraceLimit, timeout, keepFailed, shards, shardId) {
export function writeTestConfigFile(
tests,
runners,
light,
taskConfigsFolder,
workerCount,
stackTraceLimit,
timeout,
keepFailed,
shards,
shardId,
) {
const testConfigContents = JSON.stringify({
test: tests ? [tests] : undefined,
runners: runners ? runners.split(",") : undefined,
Expand Down
8 changes: 5 additions & 3 deletions scripts/build/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export async function exec(cmd, args, options = {}) {
const { ignoreExitCode, waitForExit = true, ignoreStdout } = options;

if (!options.hidePrompt) console.log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
const proc = spawn(which.sync(cmd), args, { stdio: waitForExit ? ignoreStdout ? ["inherit", "ignore", "inherit"] : "inherit" : "ignore" });
const proc = spawn(which.sync(cmd), args, {
stdio: waitForExit ? ignoreStdout ? ["inherit", "ignore", "inherit"] : "inherit" : "ignore",
});
if (waitForExit) {
const onCanceled = () => {
proc.kill();
Expand All @@ -39,8 +41,8 @@ export async function exec(cmd, args, options = {}) {
resolve({ exitCode: exitCode ?? undefined });
}
else {
const reason = options.token?.signaled ? options.token.reason ?? new CancelError() :
new ExecError(exitCode);
const reason = options.token?.signaled ? options.token.reason ?? new CancelError()
: new ExecError(exitCode);
reject(reason);
}
subscription?.unsubscribe();
Expand Down
4 changes: 3 additions & 1 deletion scripts/checkPackageSize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const baseRepo = process.argv[2];
const headRepo = process.argv[3];

/** @type {Array<{ size: number, unpackedSize: number; files: Array<{ path: string; size: number; }>; }>} */
const [before, after] = JSON.parse(cp.execFileSync("npm", ["pack", "--dry-run", "--json", baseRepo, headRepo], { encoding: "utf8" }));
const [before, after] = JSON.parse(
cp.execFileSync("npm", ["pack", "--dry-run", "--json", baseRepo, headRepo], { encoding: "utf8" }),
);

/** @param {{ path: string; size: number; }[]} files */
function filesToMap(files) {
Expand Down
23 changes: 18 additions & 5 deletions scripts/configurePrerelease.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function main() {
// Ensure we are actually changing something - the user probably wants to know that the update failed.
if (tsFileContents === modifiedTsFileContents) {
let err = `\n '${tsFilePath}' was not updated while configuring for a prerelease publish for '${tag}'.\n `;
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
err +=
`Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
throw new Error(err + "\n");
}

Expand All @@ -78,19 +79,31 @@ function main() {
function updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatch) {
const majorMinorRgx = /export const versionMajorMinor = "(\d+\.\d+)"/;
const majorMinorMatch = majorMinorRgx.exec(tsFileContents);
assert(majorMinorMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${majorMinorRgx}'.`);
assert(
majorMinorMatch !== null,
`The file '${tsFilePath}' seems to no longer have a string matching '${majorMinorRgx}'.`,
);
const parsedMajorMinor = majorMinorMatch[1];
assert(parsedMajorMinor === majorMinor, `versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`);
assert(
parsedMajorMinor === majorMinor,
`versionMajorMinor does not match. ${tsFilePath}: '${parsedMajorMinor}'; package.json: '${majorMinor}'`,
);

const versionRgx = /export const version(?:: string)? = `\$\{versionMajorMinor\}\.(\d)(-\w+)?`;/;
const patchMatch = versionRgx.exec(tsFileContents);
assert(patchMatch !== null, `The file '${tsFilePath}' seems to no longer have a string matching '${versionRgx.toString()}'.`);
assert(
patchMatch !== null,
`The file '${tsFilePath}' seems to no longer have a string matching '${versionRgx.toString()}'.`,
);
const parsedPatch = patchMatch[1];
if (parsedPatch !== patch) {
throw new Error(`patch does not match. ${tsFilePath}: '${parsedPatch}; package.json: '${patch}'`);
}

return tsFileContents.replace(versionRgx, `export const version: string = \`\${versionMajorMinor}.${nightlyPatch}\`;`);
return tsFileContents.replace(
versionRgx,
`export const version: string = \`\${versionMajorMinor}.${nightlyPatch}\`;`,
);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions scripts/dtsBundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ function isInternalDeclaration(node) {
*/
function getParentVariableStatement(node) {
const declarationList = node.parent;
assert(ts.isVariableDeclarationList(declarationList), `expected VariableDeclarationList at ${nodeToLocation(node)}`);
assert(declarationList.declarations.length === 1, `expected VariableDeclarationList of length 1 at ${nodeToLocation(node)}`);
assert(
ts.isVariableDeclarationList(declarationList),
`expected VariableDeclarationList at ${nodeToLocation(node)}`,
);
assert(
declarationList.declarations.length === 1,
`expected VariableDeclarationList of length 1 at ${nodeToLocation(node)}`,
);
const variableStatement = declarationList.parent;
assert(ts.isVariableStatement(variableStatement), `expected VariableStatement at ${nodeToLocation(node)}`);
return variableStatement;
Expand Down Expand Up @@ -235,7 +241,8 @@ function findInScope(name) {
/** @type {(symbol: ts.Symbol | undefined, excludes?: ts.SymbolFlags) => boolean} */
function isNonLocalAlias(symbol, excludes = ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace) {
if (!symbol) return false;
return (symbol.flags & (ts.SymbolFlags.Alias | excludes)) === ts.SymbolFlags.Alias || !!(symbol.flags & ts.SymbolFlags.Alias && symbol.flags & ts.SymbolFlags.Assignment);
return (symbol.flags & (ts.SymbolFlags.Alias | excludes)) === ts.SymbolFlags.Alias
|| !!(symbol.flags & ts.SymbolFlags.Alias && symbol.flags & ts.SymbolFlags.Assignment);
}

/**
Expand Down Expand Up @@ -319,7 +326,13 @@ function verifyMatchingSymbols(decl) {
}

if (symbolsConflict(symbolOfNode, symbolInScope)) {
fail(`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])},\n but containing scope contains a symbol with the same name declared at ${symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])}`);
fail(
`Declaration at ${nodeToLocation(decl)}\n references ${symbolOfNode.name} at ${
symbolOfNode.declarations && nodeToLocation(symbolOfNode.declarations[0])
},\n but containing scope contains a symbol with the same name declared at ${
symbolInScope.declarations && nodeToLocation(symbolInScope.declarations[0])
}`,
);
}
}

Expand Down
Loading

0 comments on commit ed78891

Please sign in to comment.