MCPcopy Create free account
hub / github.com/cevek/ttypescript / createProgram

Function createProgram

packages/ttypescript/src/patchCreateProgram.ts:43–110  ·  view source on GitHub ↗
(
        rootNamesOrOptions: ReadonlyArray<string> | ts.CreateProgramOptions,
        options?: ts.CompilerOptions,
        host?: ts.CompilerHost,
        oldProgram?: ts.Program,
        configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>
    )

Source from the content-addressed store, hash-verified

41 configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>
42 ): ts.Program;
43 function createProgram(
44 rootNamesOrOptions: ReadonlyArray<string> | ts.CreateProgramOptions,
45 options?: ts.CompilerOptions,
46 host?: ts.CompilerHost,
47 oldProgram?: ts.Program,
48 configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>
49 ): ts.Program {
50 let rootNames;
51 let createOpts: ts.CreateProgramOptions | undefined;
52 if (!Array.isArray(rootNamesOrOptions)) {
53 createOpts = rootNamesOrOptions as ts.CreateProgramOptions;
54 }
55 if (createOpts) {
56 rootNames = createOpts.rootNames;
57 options = createOpts.options;
58 host = createOpts.host;
59 oldProgram = createOpts.oldProgram;
60 configFileParsingDiagnostics = createOpts.configFileParsingDiagnostics;
61 } else {
62 options = options!;
63 rootNames = rootNamesOrOptions as ReadonlyArray<string>;
64 }
65
66 if (forceReadConfig) {
67 const info = getConfig(tsm, options, rootNames, projectDir);
68 options = info.compilerOptions;
69 if (createOpts) {
70 createOpts.options = options;
71 }
72 projectDir = info.projectDir;
73 }
74 const program: ts.Program = createOpts
75 ? originCreateProgram(createOpts)
76 : originCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics);
77
78 const plugins = preparePluginsFromCompilerOptions(options.plugins);
79 const pluginCreator = new PluginCreator(tsm, plugins, projectDir);
80
81 const originEmit = program.emit;
82
83 /**
84 * The emit method has the following declaration:
85 * https://github.com/microsoft/TypeScript/blob/bfc55b5762443c37ecdef08a3b5a4e057b4d1e85/src/compiler/builderPublic.ts#L101
86 * The declaration specifies 5 arguments, but it's not true. Sometimes the emit method takes 6 arguments.
87 */
88 program.emit = function newEmit(
89 targetSourceFile?: ts.SourceFile,
90 writeFile?: ts.WriteFileCallback,
91 cancellationToken?: ts.CancellationToken,
92 emitOnlyDtsFiles?: boolean,
93 customTransformers?: ts.CustomTransformers,
94 arg?: boolean
95 ): ts.EmitResult {
96 const mergedTransformers = pluginCreator.createTransformers({ program }, customTransformers);
97 const result: ts.EmitResult = (originEmit as any)(
98 targetSourceFile,
99 writeFile,
100 cancellationToken,

Callers

nothing calls this directly

Calls 3

createTransformersMethod · 0.95
getConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…