Skip to content

Commit

Permalink
Hack something together to test various builds
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Sep 14, 2022
1 parent cf0ff15 commit e9c4c4c
Show file tree
Hide file tree
Showing 11 changed files with 661 additions and 38 deletions.
86 changes: 71 additions & 15 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const cmdLineOptions = require("./scripts/build/options");
const copyright = "CopyrightNotice.txt";
const cleanTasks = [];

const testRunner = "./built/local/testRunner/runner.js";
const testRunner = "./built/local/testRunner.js";

const buildScripts = () => buildProject("scripts");
task("scripts", buildScripts);
Expand Down Expand Up @@ -57,9 +57,7 @@ const diagnosticInformationMapTs = "src/compiler/diagnosticInformationMap.genera
const diagnosticMessagesJson = "src/compiler/diagnosticMessages.json";
const diagnosticMessagesGeneratedJson = "src/compiler/diagnosticMessages.generated.json";
const generateDiagnostics = async () => {
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
await exec(process.execPath, ["scripts/processDiagnosticMessages.js", diagnosticMessagesJson]);
}
await exec(process.execPath, ["scripts/processDiagnosticMessages.js", diagnosticMessagesJson]);
};
task("generate-diagnostics", series(buildScripts, generateDiagnostics));
task("generate-diagnostics").description = "Generates a diagnostic file in TypeScript based on an input JSON file";
Expand Down Expand Up @@ -89,14 +87,65 @@ const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt
.concat(generatedLCGFile);

const localize = async () => {
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.js", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
}
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.js", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
};

/**
* @param {string} entrypoint
* @param {string} outfile
*/
async function esbuild(entrypoint, outfile) {
await exec("node_modules/esbuild/bin/esbuild", [
entrypoint,
"--bundle",
`--outfile=${outfile}`,
"--platform=node",
"--target=node10", // Node 10; oldest benchmarker.
"--sourcemap",
"--external:./node_modules/*",
"--conditions=require",
// "--supported:const-and-let=false", // Unfortunately, no: https://github.com/evanw/esbuild/issues/297
"--supported:object-rest-spread=false", // See: https://github.com/evanw/esbuild/releases/tag/v0.14.46
]);
}

const buildSrc = () => buildProject("src");

const writeHackyShim = (project) => {
return (done) => {
fs.writeFileSync(`./built/local/${project}.js`, `module.exports = require("./${project}/${project}.js")`);
done();
};
};

const buildAll = () => buildProject("src");
const preBundleFromSrc = parallel(generateLibs, series(buildScripts, generateDiagnostics, localize));
const preBuildSrc = preBundleFromSrc;
const preBundleFromEmit = series(preBundleFromSrc, buildSrc);

const bundleTscFromEmit = () => esbuild("./built/local/tsc/tsc.js", "./built/local/tsc.js");
const bundleTypescriptFromEmit = () => esbuild("./built/local/typescript/typescript.js", "./built/local/typescript.js");
const bundleServerFromEmit = () => esbuild("./built/local/tsserver/server.js", "./built/local/tsserver.js");
const bundleServerLibraryFromEmit = () => esbuild("./built/local/tsserverlibrary/tsserverlibrary.js", "./built/local/tsserverlibrary.js");
const bundleTestsFromEmit = () => esbuild("./built/local/testRunner/_namespaces/Harness.js", testRunner);


const bundleTscFromSrc = () => esbuild("./built/local/tsc/tsc.js", "./built/local/tsc.js");
const bundleTypescriptFromSrc = () => esbuild("./built/local/typescript/typescript.js", "./built/local/typescript.js");
const bundleServerFromSrc = () => esbuild("./built/local/tsserver/server.js", "./built/local/tsserver.js");
const bundleServerLibraryFromSrc = () => esbuild("./built/local/tsserverlibrary/tsserverlibrary.js", "./built/local/tsserverlibrary.js");
const bundleTestsFromSrc = () => esbuild("./built/local/testRunner/_namespaces/Harness.js", testRunner);

const bundleAllFromSrc = series([
bundleTscFromSrc,
bundleTypescriptFromSrc,
bundleServerFromSrc,
bundleServerLibraryFromSrc,
bundleTestsFromSrc,
]);
task("bundle-src", series(preBundleFromSrc, bundleAllFromSrc));

task("moduleBuild", parallel(generateLibs, series(buildScripts, localize, buildAll)));

task("buildSrc", preBundleFromEmit);

const apiExtractor = async () => {
async function runApiExtractor(configPath) {
Expand All @@ -114,17 +163,20 @@ const apiExtractor = async () => {
await runApiExtractor("./src/tsserverlibrary/api-extractor.json");
};

task("api-extractor", series(task("moduleBuild"), apiExtractor));
task("api-extractor", series(buildSrc, apiExtractor));

const buildDebugTools = () => buildProject("src/debug");
const cleanDebugTools = () => cleanProject("src/debug");
cleanTasks.push(cleanDebugTools);

// Pre-build steps when targeting the LKG compiler
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools));
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics /** , buildDebugTools */));

const buildTsc = () => buildProject("src/tsc");
task("tsc", series(lkgPreBuild, buildTsc));

// task("tsc", series(preBundleFromSrc, bundleTscFromSrc)); // esbuild on ./src
// task("tsc", series(preBundleFromEmit, bundleTscFromEmit)); // esbuild on emitted ./built/local
task("tsc", series(preBuildSrc, buildSrc, writeHackyShim("tsc"))); // CJS
task("tsc").description = "Builds the command-line compiler";

const cleanTsc = () => cleanProject("src/tsc");
Expand Down Expand Up @@ -244,7 +296,11 @@ task("dynamicImportCompat", buildDynamicImportCompat);
const buildServerMain = () => buildProject("src/tsserver", cmdLineOptions);
const buildServer = series(buildDynamicImportCompat, buildServerMain);
buildServer.displayName = "buildServer";
task("tsserver", series(preBuild, buildServer));

// task("tsserver", series(preBundleFromSrc, bundleServerFromSrc)); // esbuild on ./src
// task("tsserver", series(preBundleFromEmit, bundleServerFromEmit)); // esbuild on emitted ./built/local

task("tsserver", series(preBuildSrc, buildSrc, writeHackyShim("tsserver"))); // CJS
task("tsserver").description = "Builds the language server";
task("tsserver").flags = {
" --built": "Compile using the built version of the compiler."
Expand Down Expand Up @@ -461,7 +517,7 @@ const preTest = parallel(buildTsc, buildTests, buildServices, buildLssl);
preTest.displayName = "preTest";

const runTests = () => runConsoleTests(testRunner, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
task("runtests", series(/*preBuild, preTest,*/ task("moduleBuild"), runTests)); // TODO(jakebailey): fix this for modules
task("runtests", series(/*preBuild, preTest,*/ preBundleFromSrc, bundleTestsFromSrc, runTests)); // TODO(jakebailey): fix this for modules
task("runtests").description = "Runs the tests using the built run.js file.";
task("runtests").flags = {
"-t --tests=<regex>": "Pattern for tests to run.",
Expand All @@ -480,7 +536,7 @@ task("runtests").flags = {
};

const runTestsParallel = () => runConsoleTests(testRunner, "min", /*runInParallel*/ cmdLineOptions.workers > 1, /*watchMode*/ false);
task("runtests-parallel", series(/*preBuild, preTest,*/ task("moduleBuild"), runTestsParallel)); // TODO(jakebailey): fix this for modules
task("runtests-parallel", series(/*preBuild, preTest,*/ preBundleFromSrc, bundleTestsFromSrc, runTestsParallel)); // TODO(jakebailey): fix this for modules
task("runtests-parallel").description = "Runs all the tests in parallel using the built run.js file.";
task("runtests-parallel").flags = {
" --light": "Run tests in light mode (fewer verifications, but tests run faster).",
Expand Down
Loading

0 comments on commit e9c4c4c

Please sign in to comment.