4

When running tsc how do we exclude the src folder (Root containing folder) from output? I have the outDir set to target and instead of target/src/file.ts I would like target/file.ts?

Ole
  • 41,793
  • 59
  • 191
  • 359
  • Do you have all your code in the src folder? – Simeon Smith Jul 12 '18 at 22:37
  • I'm assuming this question is related to your [last one](https://stackoverflow.com/q/51313753/1541563)? – Patrick Roberts Jul 12 '18 at 22:37
  • @PatrickRoberts it's related in the sense that I'm pursuing creating a clean `dist or target` directory to publish from...Would be a lot easier if there was a `base` package.json property though ... :) – Ole Jul 12 '18 at 22:39
  • @SimeonSmith yes currently the code is in the `src` folder. I'm planning on building it all into a `target` folder and then copying package.json into that folder so that I can run npm publish from the target folder and have all the typescript modules be importable from there. – Ole Jul 12 '18 at 22:40
  • So in other words I would like to avoid compiling and then having to do additional moving of resources in order to create a clean `dist` folder to run `npm publish` from. – Ole Jul 12 '18 at 22:42
  • You should just be able to use tsc src to select everything in that folder and not output the src folder. What does your compile command look like right now? – Simeon Smith Jul 12 '18 at 22:43
  • It could be `tsc src/*` – Simeon Smith Jul 12 '18 at 22:45
  • Getting error TS6053: on the different attempts ... – Ole Jul 12 '18 at 22:48
  • I though perhaps I could use the `rootDir` options in tsconfig.json, but when I use that typescript complains that it does not contain the `test` directory ... – Ole Jul 12 '18 at 22:50
  • This is the target repository: https://github.com/fireflysemantics/validator – Ole Jul 12 '18 at 23:00
  • 1
    How about using the `"include"` option in your tsconfig? So something like `{"compilerOptions": { ... }, "include": [ "./src/" ]}`? – CRice Jul 12 '18 at 23:01
  • 1
    You're going to want a different tsc command to compile your tests. You can't do both at the same time and have the src not compile to the same folder. You can chain the commands though. – Simeon Smith Jul 13 '18 at 02:53
  • Yeah I'm using ts-node to both run nyc code coverage and mocha tests at the same time. I have a follow up question about running the build using a separate tsconfig file here: https://stackoverflow.com/questions/51316731/compiler-option-for-specifying-the-name-of-the-tsconfig-json-file – Ole Jul 13 '18 at 16:06

1 Answers1

2

Your probably looking for the rootDir tsconfig option. Specifically, in your case: rootDir: 'src/', supposing your keeping all source files under ./src/ and your tsconfig.json at the level above src/.

Note however, tsc may silently ignore this setting if your actually importing files that aren't under src/, say for example you import your package.json from top level.

spinkus
  • 7,694
  • 4
  • 38
  • 62