From 30b0ee2b9994c36d7a432844b6b0e3907103c556 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:26:32 -0800 Subject: [PATCH] [experiment] make tsc use the public API --- Herebyfile.mjs | 25 ++++++++++---------- src/executeCommandLine/executeCommandLine.ts | 7 +++++- src/tsc/_namespaces/ts.ts | 5 +--- src/tsc/tsconfig.json | 3 +-- src/typescript/_namespaces/ts.ts | 1 + src/typescript/tsconfig.json | 3 ++- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Herebyfile.mjs b/Herebyfile.mjs index 10598bd1e65ab..09dabb94a79c9 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -383,18 +383,6 @@ function entrypointBuildTask(options) { return { build, bundle, shim, main, watch }; } -const { main: tsc, watch: watchTsc } = entrypointBuildTask({ - name: "tsc", - description: "Builds the command-line compiler", - buildDeps: [generateDiagnostics], - project: "src/tsc", - srcEntrypoint: "./src/tsc/tsc.ts", - builtEntrypoint: "./built/local/tsc/tsc.js", - output: "./built/local/tsc.js", - mainDeps: [generateLibs], -}); -export { tsc, watchTsc }; - const { main: services, build: buildServices, watch: watchServices } = entrypointBuildTask({ name: "services", description: "Builds the typescript.js library", @@ -408,6 +396,19 @@ const { main: services, build: buildServices, watch: watchServices } = entrypoin }); export { services, watchServices }; +const { main: tsc, watch: watchTsc } = entrypointBuildTask({ + name: "tsc", + description: "Builds the command-line compiler", + buildDeps: [generateDiagnostics], + project: "src/tsc", + srcEntrypoint: "./src/tsc/tsc.ts", + builtEntrypoint: "./built/local/tsc/tsc.js", + output: "./built/local/tsc.js", + mainDeps: [generateLibs, services], + bundlerOptions: { usePublicAPI: true }, +}); +export { tsc, watchTsc }; + export const dtsServices = task({ name: "dts-services", description: "Bundles typescript.d.ts", diff --git a/src/executeCommandLine/executeCommandLine.ts b/src/executeCommandLine/executeCommandLine.ts index 16d02310b5eb7..8de28c6aa2d3f 100644 --- a/src/executeCommandLine/executeCommandLine.ts +++ b/src/executeCommandLine/executeCommandLine.ts @@ -85,6 +85,7 @@ import { validateLocaleAndSetLanguage, version, WatchCompilerHost, + WatchOfConfigFile, WatchOptions, } from "./_namespaces/ts"; @@ -94,6 +95,7 @@ interface Statistic { type: StatisticType; } +/** @internal */ export enum StatisticType { time, count, @@ -730,6 +732,7 @@ function executeCommandLineWorker( } } +/** @internal */ export function isBuild(commandLineArgs: readonly string[]) { if (commandLineArgs.length > 0 && commandLineArgs[0].charCodeAt(0) === CharacterCodes.minus) { const firstOption = commandLineArgs[0].slice(commandLineArgs[0].charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase(); @@ -738,12 +741,14 @@ export function isBuild(commandLineArgs: readonly string[]) { return false; } +/** @internal */ export type ExecuteCommandLineCallbacks = (program: Program | BuilderProgram | ParsedCommandLine) => void; +/** @internal */ export function executeCommandLine( system: System, cb: ExecuteCommandLineCallbacks, commandLineArgs: readonly string[], -) { +): void | SolutionBuilder | WatchOfConfigFile { if (isBuild(commandLineArgs)) { const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(commandLineArgs.slice(1)); if (buildOptions.generateCpuProfile && system.enableCPUProfiler) { diff --git a/src/tsc/_namespaces/ts.ts b/src/tsc/_namespaces/ts.ts index 8e361ae718461..205e6849694b0 100644 --- a/src/tsc/_namespaces/ts.ts +++ b/src/tsc/_namespaces/ts.ts @@ -1,4 +1 @@ -/* Generated file to emulate the ts namespace. */ - -export * from "../../compiler/_namespaces/ts"; -export * from "../../executeCommandLine/_namespaces/ts"; +export * from "../../typescript/typescript"; diff --git a/src/tsc/tsconfig.json b/src/tsc/tsconfig.json index 21e193ad5d70c..7d54c64c1dc78 100644 --- a/src/tsc/tsconfig.json +++ b/src/tsc/tsconfig.json @@ -3,8 +3,7 @@ "compilerOptions": { }, "references": [ - { "path": "../compiler" }, - { "path": "../executeCommandLine" } + { "path": "../typescript" } ], "include": ["**/*"] } diff --git a/src/typescript/_namespaces/ts.ts b/src/typescript/_namespaces/ts.ts index 3060a64378787..f105a6c4098db 100644 --- a/src/typescript/_namespaces/ts.ts +++ b/src/typescript/_namespaces/ts.ts @@ -4,5 +4,6 @@ export * from "../../compiler/_namespaces/ts"; export * from "../../jsTyping/_namespaces/ts"; export * from "../../services/_namespaces/ts"; export * from "../../server/_namespaces/ts"; +export * from "../../executeCommandLine/_namespaces/ts"; import * as server from "./ts.server"; export { server }; diff --git a/src/typescript/tsconfig.json b/src/typescript/tsconfig.json index 20b8306af53eb..8aa4380d6d726 100644 --- a/src/typescript/tsconfig.json +++ b/src/typescript/tsconfig.json @@ -6,7 +6,8 @@ { "path": "../compiler" }, { "path": "../jsTyping" }, { "path": "../services" }, - { "path": "../server" } + { "path": "../server" }, + { "path": "../executeCommandLine" } ], "include": ["**/*"] }