Skip to content

Feature request [compiler API]: expose project build logic to public API #20265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jsamr opened this issue Nov 25, 2017 · 2 comments
Closed

Feature request [compiler API]: expose project build logic to public API #20265

jsamr opened this issue Nov 25, 2017 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@jsamr
Copy link

jsamr commented Nov 25, 2017

Scenario As a developer, I would like to use a very high level project compiler API for build purposes. It would be somehow symmetric to what tsc allows but in a programmatic way.
Although the compiler API is public, the project logic for file resolution isn't (i.e. : how the rootFileNames are resolved before passed to createProgram).
I would like something simpler that would allow me to intercept a serialized tsconfig and alter its properties (that would somehow provide a workaround for #20110). I could also chose to merge default excludes by importing a symbol (would fix #20108 )

Suggestion Perhaps abstracting the tsc logic would allow two interfaces to be implemented: API and CLI. This new layer could be labeled "build".

Speculative API sample

import { createProject, createProgramFromProject, Project, DEFAULT_EXCLUDE } from '@typescript/build'

function tsConfigInterceptor (tsconfig: any) {
  return {
    ...tsconfig,
    exclude: ['lib', DEFAULT_EXCLUDE].concat(tsconfig.exclude ? tsconfig.exclude : [])
  }
}

const project: Project = createProject(process.cwd(), tsConfigInterceptor)
const program = createProgramFromProject(project)
program.emit()

New definitions

export type TsConfigInterceptor = (tsconfig: any)  => any

export const DEFAULT_EXCLUDE = Symbol('DEFAULT_EXCLUDE')

/**
* @param tsconfigPath Root dir where tsconfig.json exists or tsconfig file name
* @param [interceptor] A callback that received the object deserialized from tsconfig 
* file and returns a new one
*/
export function createProject(tsconfigPath: string, interceptor?: TsConfigInterceptor): Project {
  // ...
}

/**
* @param project The project from which a program shall be created
*/
export function createProgramFromProject (project: Project): Program {
  // ...
}

@mhegazy
Copy link
Contributor

mhegazy commented Nov 27, 2017

Although the compiler API is public, the project logic for file resolution isn't (i.e. : how the rootFileNames are resolved before passed to createProgram).

All the tsconfig.json parsing function are public.. please see:

Here is the part of the compiler that use these functions for reference: https://github.com/Microsoft/TypeScript/blob/e934c305136ac3b8a980bfa089e18b301ce999e4/src/compiler/watch.ts#L65-L91

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Nov 27, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants