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

referenced source files, outside of the baseDir, cause a (silent!) change to the compiled file paths #201

Open
iislucas opened this issue Jan 21, 2015 · 11 comments

Comments

@iislucas
Copy link

When some referenced source lives outside of the baseDir, e.g. when compiling (with baseDir: 'src' and outDir: 'build'):

src/d1/foo.ts
src/d2/d2a/foo.ts
src/d2/d2b/foo.ts

and src/d1/foo.ts contains a require (or reference?) to pull in something from third_party/bar.ts then the generated output files end up within an extra subdirectory src, i.e. build/src/, even if baseDir was set to src. I think, in this case, it's probably best to give an error as otherwise typescript wouldn't know where to put third_party/bar.ts, so it's kind of forced to ignore the baseDir.

@basarat
Copy link
Member

basarat commented Jan 21, 2015

node_modules/grunt-ts/tasks/modules/amdLoader.ts(1,1)

think you need to exclude node_modules see example gruntfile: https://github.com/TypeStrong/grunt-ts#getting-started it is a bit unfortunate. I hope to come up with guidance around TypeScript project organization + templates at some point.

@basarat
Copy link
Member

basarat commented Jan 21, 2015

@iislucas baseDir is a target option, not a task option. Let me know if that doesn't work either :)

@TypeStrong/owners I feel like removing all target options and making everything a task option, just to remove this random ambiguity.

@iislucas
Copy link
Author

@basarat : I think I am specifying it as a target option above (the task options would be directly under ts) ... dev is the target. That not right?

@basarat
Copy link
Member

basarat commented Jan 22, 2015

@iislucas no a target option is directly under dev. options at the root or options under a target are called task options. I know its ugly but its grunt's design.

@iislucas
Copy link
Author

So options under the options value of a target are called task options. sigh... But thanks for clarifying!

So If I'm understanding correctly, you're saying this config should avoid generating the build/src, and directly put subdirectories into of src/* into build/*:

ts: {
  dev: {
        src: ['src/**/*.ts', '!src/**/*.d.ts'],
        outDir: 'build/',
        baseDir: 'src',
        options: {
          target: 'es5',
          comments: true,
          noImplicitAny: true,
          sourceMap: true,
          declaration: true,
          module: 'commonjs',
          fast: 'always'
        }
  }
}

However, trying this also does not work: I still end up with output in: build/src/d1/foo.ts instead of build/d1/foo.ts...

(I'm renaming this issue to clarify that the real issue is that baseDir doesn't stop tsc from generating too many subdirectories, and that what we'd really like is a cwd like behaviour as well as baseDir (baseDir just stops directories being flattened in their output if I understand correctly...)

@iislucas iislucas changed the title setting baseDir causes mysterious errors baseDir option doesn't avoid generating full paths, something like cwd would help Jan 22, 2015
@iislucas
Copy link
Author

OK, one more update... when I do the same thing but specify a single src file, I do get compilation output going into the expected directories. e.g. this works:

ts: {
  dev: {
        src: ['src/foo/main.ts'],
        outDir: 'build/',
        baseDir: 'src',
        options: {
          target: 'es5',
          comments: true,
          noImplicitAny: true,
          sourceMap: true,
          declaration: true,
          module: 'commonjs',
          fast: 'always'
        }
  }
}

It does indeed output files to 'build/foo/' and not 'build/src/foo/', but when I specify multiple src files, they annoyingly appear in 'build/src/foo/'... a bug?

@basarat
Copy link
Member

basarat commented Jan 22, 2015

but when I specify multiple src files,

Possibly a bug. can you tell me the src exactly so I can reproduce (.e.g is it src: ['src/foo/main.ts','src/foo/d1/second.ts'],)

@iislucas
Copy link
Author

It's a little unclear what causes this behavior to sometimes happen, e.g. in this project:
https://github.com/uProxy/uproxy-lib/blob/iislucas-gruntts-bugtest/Gruntfile.coffee#L165
It always happens for ts:dev, but not for ts:copypasteFreedomChatMain.
I created a new simple target with 3 files, but for that case grunt-ts operates fine w.r.t. baseDir. So I'm not sure what about the ts:dev target is causing the problem. Any ideas?

@iislucas
Copy link
Author

OK, I figured this out: the problem is when some referenced source lives outside of the baseDir, e.g. when compiling (with baseDir: 'src' and outDir: 'build'):

src/d1/foo.ts
src/d2/d2a/foo.ts
src/d2/d2b/foo.ts

and src/d1/foo.ts contains a require to pull in something from third_party/bar.ts then generated output lives within an extra subdirectory src, i.e. build/src/, even if baseDir was set to src. I think in this case, it's probably best to give an error as otherwise typescript wouldn't know where to put third_party/bar.ts, so it's kind of forced to ignore the baseDir.

@basarat
Copy link
Member

basarat commented Jan 29, 2015

it's probably best to give an error as otherwise typescript wouldn't know where to put third_party/bar.ts, so it's kind of forced to ignore the baseDir.

Awesome!

@iislucas
Copy link
Author

I've updated the description; we can probably now remove the confused comments :-)

@iislucas iislucas changed the title baseDir option doesn't avoid generating full paths, something like cwd would help referenced source files, outside of the baseDir, cause a (silent!) change to the compiled file paths Feb 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants