Skip to content

Commit

Permalink
[experiment] make tsc use the public API
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Apr 2, 2024
1 parent 8e11448 commit 30b0ee2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
25 changes: 13 additions & 12 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
validateLocaleAndSetLanguage,
version,
WatchCompilerHost,
WatchOfConfigFile,
WatchOptions,
} from "./_namespaces/ts";

Expand All @@ -94,6 +95,7 @@ interface Statistic {
type: StatisticType;
}

/** @internal */
export enum StatisticType {
time,
count,
Expand Down Expand Up @@ -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();
Expand All @@ -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<EmitAndSemanticDiagnosticsBuilderProgram> | WatchOfConfigFile<EmitAndSemanticDiagnosticsBuilderProgram> {
if (isBuild(commandLineArgs)) {
const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(commandLineArgs.slice(1));
if (buildOptions.generateCpuProfile && system.enableCPUProfiler) {
Expand Down
5 changes: 1 addition & 4 deletions src/tsc/_namespaces/ts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/* Generated file to emulate the ts namespace. */

export * from "../../compiler/_namespaces/ts";
export * from "../../executeCommandLine/_namespaces/ts";
export * from "../../typescript/typescript";
3 changes: 1 addition & 2 deletions src/tsc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
},
"references": [
{ "path": "../compiler" },
{ "path": "../executeCommandLine" }
{ "path": "../typescript" }
],
"include": ["**/*"]
}
1 change: 1 addition & 0 deletions src/typescript/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
3 changes: 2 additions & 1 deletion src/typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
{ "path": "../compiler" },
{ "path": "../jsTyping" },
{ "path": "../services" },
{ "path": "../server" }
{ "path": "../server" },
{ "path": "../executeCommandLine" }
],
"include": ["**/*"]
}

0 comments on commit 30b0ee2

Please sign in to comment.