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

Strange file count increase when adding --outDir #41504

Closed
Minivera opened this issue Nov 11, 2020 · 5 comments
Closed

Strange file count increase when adding --outDir #41504

Minivera opened this issue Nov 11, 2020 · 5 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@Minivera
Copy link

TypeScript Version: 4.0.3

Search Terms: outDir, ourDir memory usage, outDir double files, outDir increase files

Code
This happens in multiple codebases. We're moving from compiling the JS files in-place to compiling into a dist directory, and we've seen a strange increase in memory usage of the tsc compiler. In particular, the number of picked up files seems to have jumped 3 times.

Here is our new ts-config.json

{
  "compilerOptions": {
    "outDir": "dist",
    "module": "commonjs",
    "target": "ES2017",
    "allowJs": true,
    "esModuleInterop": true
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Expected behavior:
I would expect this to not impact the number of compiled files by the tsc compiler. For reference, here are the diagnostics, before outDir:

npx tsc
Files:              142
Lines:            59867
Nodes:           247150
Identifiers:      88342
Symbols:          98523
Types:            39050
Instantiations:  118376
Memory used:    139533K
I/O read:         0.06s
I/O write:        0.00s
Parse time:       0.87s
Bind time:        0.33s
Check time:       1.90s
Emit time:        0.05s
Total time:       3.15s

Actual behavior:

Increase in easily 3x time the number of files picked up by tsc, double the amount of memory used by the compiler. Here are the diagnostics:

npx tsc
Files:              471
Lines:           146914
Nodes:           543555
Identifiers:     190086
Symbols:         272696
Types:           137235
Instantiations:  389976
Memory used:    363574K
I/O read:         0.16s
I/O write:        0.05s
Parse time:       1.65s
Bind time:        0.65s
Check time:       5.79s
Emit time:        0.71s
Total time:       8.80s

Related Issues: #30473

@RyanCavanaugh
Copy link
Member

Can you use --listFiles to show which other files are being included and characterize them?

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Nov 13, 2020
@Minivera
Copy link
Author

I cannot share the exact file name, but I noticed by comparing both that the previous 142 files only included ts files and packages. With outDir all js files from the import path in our codebase are getting included in those 400+ files, including packages a few more packages.

Is it possible that the combination of allowJs and outDir has led the compiler to process the JavaScript files so it can transpile and copy them? It seems TypeScript also transpiles some of our JavaScript files (Like converting the async/awaits to a generator for older targets). Would I be right to assume that this increase in file count is simply TypeScript transpiling JavaScript as part of the "compile to dist" process. Any known way to potentially disable that if it is the case?

@RyanCavanaugh
Copy link
Member

If you set allowJs then the default include pattern starts including *.js. You might try adding

  "include": ["./**/*.ts"],

to your tsconfig.

It sounds like this is more a configuration error than a bug, though.

@Minivera
Copy link
Author

I will try to improve the configuration in the coming weeks. It does sound like a configuration error, it would be great to be able to have TypeScript copy JS files without compiling them, but that's more of a feature requests than a bug report.

Thanks for pointing out the possible problem with our config. Should I close the issue?

@RyanCavanaugh
Copy link
Member

I can close; please open a new one if you find something odd. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants