Closed shawnsparks closed 8 years ago
I solved most of the problem using this configuration. I had to add fast: 'never'
because otherwise files in subdirectories like src/services/example.ts
would get compiled to dist/example.ts
. This would break imports. Is there a way to use outDir, modules, and fast compiling?
ts: {
default: {
src: [ 'src/**/*.ts' ],
outDir: 'dist',
options: {
module: 'commonjs',
fast: 'never'
}
}
}
Hi, Fast shouldn't affect outDir so this sounds like a bug. Thanks for the report.
Here appear to be a couple related issues: https://github.com/TypeStrong/grunt-ts/issues/77 and https://github.com/TypeStrong/grunt-ts/issues/139
.baseDir.ts
file gets created in src/services
and not src
.tasks/modules/compile.js
references options.baseDir
, but tasks/modules/optionsResolver.js
has nothing about baseDir. It's like the baseDir option was removed at some point in time. I did a rewrite of the options resolver last summer and it's likely I broke baseDir
because it wasn't documented. #300 is related too. It's on the list of things I need to get to as well as fast
being broken at least in certain situations. Thank you for the report and certainly PRs accepted. I'll try to spend some time on grunt-ts soon.
So I believe the problem from #139 is how baseDir is calculated when not explicitly set. My repo is very similar to what's described in that issue. I have my code in a src
folder. I also have type_definitions/node.d.ts
outside of src
directory. This results in utils.findCommonPath(...) to return an empty string so options.baseDir
is never defined. A .baseDir.ts
file is never created. Ultimately, fast compilation creates an incorrect folder structure in dist
(value of outDir
). The code for this is in compile.ts lines 114-116 currently.
baseDir
option can't be explicitly set because it's missing from optionsResolver.ts line 13.
So the really simple fix seems to be to add baseDir
to optionsResolver.ts, and explicitly set it in gruntfile. It will still result in problems for people who include type definitions outside of src folder or otherwise have source code from two different paths in their repo and who don't explicitly set baseDir.
My thoughts are below. Let me know what you think and I can try to help with PRs.
I merged in the PR for number one. Thank you so much for your contribution.
I like your idea 2.
I think that idea 3 would be useful, but honestly I would prefer to just eliminate .baseDir.ts altogether. There is a rootDir
feature natively supported by new TypeScript versions. #300 has some discussion on that topic.
Thanks again.
Ok, I did not understand rootDir
and that it replaces baseDir
when using newer versions of TypeScript. I submitted #344. If you're happy with that, we can close this ticket as I'm assuming most people are using a new enough version of TypeScript for rootDir
.
Your fixes should be available in v5.4.0 - just deployed to npm. Please let me know if you experience further issues.
I am going to close this ticket and open a new one to investigate fast
interfering with outDir
.
Thanks so much!!!
How can I have the generated files output to a different directory than source files when using modules? I have tried both
out
andoutDir
, but neither work with modules. I simply don't want generated files sitting next to source files and must break source into multiple files. New to TypeScript so let me know if I'm missing something obvious.