Skip to content
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

Add the build command-line option to compilerOptions map #32329

Closed
5 tasks done
lucas-rudd opened this issue Jul 10, 2019 · 2 comments
Closed
5 tasks done

Add the build command-line option to compilerOptions map #32329

lucas-rudd opened this issue Jul 10, 2019 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@lucas-rudd
Copy link

lucas-rudd commented Jul 10, 2019

Search Terms

build compilerOptions
build typescript SDK
build yarn workspaces dependencies with typescript
build option typescript sdk

Suggestion

I'd like to see the build command line argument added to the compilerOptions map in tsconfig.json to allow for services to basically run tsc -b when the compiler is run.

Use Cases

For building services with project references without passing in the --build or -b flag to the cli command.

This will be useful for developing plugins which can support the new project references functionality and also for codifying the intended compiler functionality in tsconfig.json so people working on the project don't need to know that -b needs to be passed when attempting to compile.

This would be most useful in monorepos which need to have their dependencies compiled before deployment.

Examples

For example, a Typescript project built and deployed utilizing serverless framework, the serverless-plugin-typescript package, and yarn workspaces may have a project structure which looks like this.

typescript-serverless-api-project/
├── packages/
│   └── base-handler/
|       ├── src/
|        |   ├── index.ts
|       ├── tsconfig.json
|      └── package.json
└── services/
   └── admin-service/
      ├── src/
       |   ├── index.ts
      ├── serverless.yml
      ├── tsconfig.json
      └── package.json

The admin-service depends on the base-handler; as such, the base-handler should be compiled when the admin-service is compiles. The tsconfig for the service may look like this

{
    "extends": "../../configs/tsconfig.json",
    "compilerOptions": {
        "outDir": ".build",
        "composite": true
    },
    "references": [{
        "path": "../../packages/base-handler"
    }]
}

When sls deploy is run in the admin-service directory, the serverless-plugin-typescript will use the configuration in tsconfig.json and compile the project.

I can run tsc -b in the service to build the references. However, I cannot create a programmatic plugin for this behavior.

It would be ideal to have the tsconfig for the services in this monorepo to look like this

{
    "extends": "../../configs/tsconfig.json",
    "compilerOptions": {
       "build": true,
        "outDir": ".build"
    },
    "references": [{
        "path": "../../packages/base-handler"
    }]
}

and use the build key to basically run tsc -build simply when I run tsc. Programmatically, this compilerOption would be ideal to pass into the createProgram method.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh
Copy link
Member

You should think of tsc --build as a separate tool from tsc without --build; in fact we nearly shipped it this way. It's intentionally not part of the tsconfig file because it represents an "outer" operation that occurs over multiple config files and has other associated behaviors (like up-to-date checking). It'd be a conceptual confusion to include this in the config file.

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript labels Jul 10, 2019
@lucas-rudd
Copy link
Author

lucas-rudd commented Jul 10, 2019

I understand the desire to keep that logical separation.

What about in regards to including a method in the SDK to allow for the invocation of this command programmatically.

Is that currently possible, or desirable?

That would allow for a similar result. A plugin could allow for the 'build' option to be specified elsewhere from tsconfig, and then run the appropriate method in the typescript SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants