microsoft / microsoft/TypeScript

Support using --module and --outDir flags in conjunction with --build

Open
#26,763 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Search Terms

--build --module --outDir

Suggestion

I would like to be able to pass --module and --outDir, in --build mode so that I can have multiple npm scripts for different build outputs without needing multiple tsconfig files.

Use Cases

In Aurelia vNext we've fully adopted the new 3.0 build system and are starting to prepare for publishing. We want to publish the build outputs for all different module systems (for all packages) so that consumers can easily point to the one that's compatible with their project.

We have been able to do this pre-3.0 like so:

    "build:commonjs": "tsc -m commonjs --outDir dist/commonjs",
    "build:amd": "tsc -m amd --outDir dist/amd",
    "build:system": "tsc -m system --outDir dist/system",
    "build:umd": "tsc -m umd --outDir dist/umd",
    "build:es2015": "tsc -m es2015 --outDir dist/es2015",

Now when trying to do this, it doesn't work:

    "build:commonjs": "tsc -b -m commonjs --outDir dist/commonjs",
    "build:amd": "tsc -b -m amd --outDir dist/amd",
    "build:system": "tsc -b -m system --outDir dist/system",
    "build:umd": "tsc -b -m umd --outDir dist/umd",
    "build:es2015": "tsc -b -m es2015 --outDir dist/es2015",
    "build:esnext": "tsc -b -m esnext --outDir dist/esnext",

Results in:

message TS6096: File (...)/packages/runtime/-m' does not exist
message TS6096: File (...)/packages/runtime/commonjs' does not exist

And nothing else happening. I read in the docs that only 4 particular flags are supported in conjunction with --build so it seems this is simply not implemented.

Examples

We'd like to have something like this in the packages package.json:

    "build:commonjs": "tsc -b -m commonjs --outDir dist/commonjs",
    "build:amd": "tsc -b -m amd --outDir dist/amd",
    "build:system": "tsc -b -m system --outDir dist/system",
    "build:umd": "tsc -b -m umd --outDir dist/umd",
    "build:es2015": "tsc -b -m es2015 --outDir dist/es2015",
    "build:esnext": "tsc -b -m esnext --outDir dist/esnext",
    "build": "run-p build:*",

And when calling npm run build from the top-level package (using lerna...), that would produce build outputs in all module formats for all packages

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. new expression-level syntax)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the documented flags supported with --build and reproduce the reported TS6096 behavior using the example commands. Done means --module and --outDir work with --build and produce the requested module-format outputs without requiring multiple tsconfig files.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.