-
Notifications
You must be signed in to change notification settings - Fork 130
WIP: enable typescript@next path mapping #283
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
Conversation
This is a hack to make it possible to use the `baseUrl` property in typescript@next. The `paths` object property may also work, too. Less confident about the `rootDirs` array property. I believe that baseUrl is to be interpreted as from the directory where tsconfig.json lives, and this isn't generally avaialable in gulp-typescript's API, so one reason (among many) that this is a hack and not a solution is that it assumes the directory found to be the 'commonBasePath' is assumed to be the tsconfig file's directory, which may not always be the case.
I'm not sure how this fixes these issues. If the only problem is that |
I'm slightly suspicious of the shortcut I put in to interpret non-absolute paths so blithely. I don't even know the spec for these properties down to the bone, so it's hard for me to know exactly what I'm looking for. I'm using I had tried the I haven't tested the logic for I think Sure -- there's a million ways to get the tsconfig path -- if there is one. I don't know what the compiler does or will do if someone uses these as flags without a project.... So, to make a long story short, I think this will probably be a WIP until those issues are worked out. I have limited time to follow through, but I will poke at this as time permits if nobody else does. Oh, and the code style of my hack should not stand. I think I wrote it as I did to make extra clear that I didn't think it was anywhere near ready for merging. :) |
Heck -- I suspect this wouldn't even work in windows!
|
I just realized I didn't address your first sentence: "I'm not sure how this fixes these issues." What this does is check whether Typescript is asking for a rooted/absolute path vs. non-rooted path. If tsc wants the traditional rooted/absolute path, it proceeds as it's always done. If it wants a relative path, the relative path it gives will be based on the resolution of the tsconfig dir and baseUrl (if present). tsc handles that resolution, so the path it asks for needs to be interpreted as from the tsconfig dir. So, we resolve that (using an inaccurate proxy for tsconfig dir) and check if the full path is in the dictionary.
The issue I have with tsconfigdir is that (a) it's only available way up at the project level, and would need to be passed down deeply into this code and (b) it's not always going to be available, and I don't know what's right to do then... |
|
I've taken a look at this and it appeared that setting the |
This isn't really a pull request, in that I know my "solution" is far from ready for prime time, but I thought I'd throw this up here in case anyone wants to take the ball and run with it toward a real implementation.
See Path mappings based module resolution.
This is a hack to make it possible to use the
baseUrl
propertyin typescript@next. The
paths
object property probably also works, too.Less confident about the
rootDirs
array property.I believe that baseUrl is to be interpreted as from the directory
where tsconfig.json lives, and this isn't generally avaialable in
gulp-typescript's API, so one reason (among many) that this is a
hack and not a solution is that it assumes the directory found to
be the 'commonBasePath' is assumed to be the tsconfig file's
directory, which may not always be the case.