-
Notifications
You must be signed in to change notification settings - Fork 262
Remapping Module Alias Names #558
Comments
There isn't currently any way to achieve this. I'd be open to a proposal, but I'm also hoping more of this would work at the TypeScript level. If TypeScript is remapping module paths, why wouldn't it automatically remap the global module paths to match? |
For < TS 2.0, TypeScript does no remapping. We have used For example, if we had a module declare module 'package/foo' {
export foo;
} And we would configure in our AMD loader: {
packages: [
{ name: 'package', location: 'node_modules/package/dist/umd' }
]
} As mentioned above though, typings will always emit declare module '~package/dist/umd/foo' {
export foo;
}
declare module 'package/dist/umd/foo' {
import alias = require('~package/dist/umd/foo');
export = alias;
} Although I haven't tried it, for TypeScript 2, in the {
"paths": {
"package/*": [ "node_modules/package/dist/umd/*" ]
}
} And that would essentially allow TypeScript to resolve a reference to I am not sure how TypeScript will be manifesting that in the TypeScript services, but even then it would only inform of a possible way of resolving the reference, versus actually giving a definitive name for a module. So as far as a proposal, what would work for our use case (though I don't know if it would work for everyone) is to allow something like this in {
"dependencies": {
"package": {
"typings": "npm:package",
"rootDir": "dist/umd"
}
}
} Where the |
Just to follow up on module resolution in TypeScript 2.0. The following configuration in the {
"compilerOptions": {
"baseUrl": ".",
"paths": {
"package/*": [ "./node_modules/package/dist/umd/*" ]
}
}
} |
Prerequisites
0.x
to1.0
Description
Ability to remap module names. In cases where other loaders are being used and TypeScripts
moduleResolution
is set toclassic
(and with TypeScript 2.0, where paths will be able to be supplied), there can be a disconnect between the module ID managed by typings and the location of the corresponding emitted code.For example, if I have a
./node_modules/my-package/dist/amd/foo.js
and a./node_modules/my-package/dist/amd/foo.d.ts
I would configure my package loader so thatmy-package/foo
would resolve tonode_modules/my-package/dist/amd/foo.js
and therefore in my TypeScript code, I would want toimport foo from 'my-package/foo';
to resolve to the typings in./node_modules/my-package/dist/amd/foo.d.ts
.As far as I can tell though, typings will always create the "real" module as
~my-package/dist/amd/foo
and alias the module tomy-package/dist/amd/foo
, neither of which will represent the run-time configuration.I have read the documentation and open and closed tickets... While I found a couple things that sort of maybe would have helped, I have been unable to find a way of configuring a
typings.json
to be able to import a package and remap the module names.As I mention above, in TypeScript 2.0 (which is unreleased as of this writing) there will be an ability to explicitly remap paths (see: Microsoft/TypeScript#5039) and this should allow TypeScript to resolve
.ts
files in other locations and sort of accomplish the above, but it would not provide the additional management of dependencies, etc. that typings/typings brings.Currently we use dts-generator to general ambient/global definitions that are mapped, but then that of course causes other challenges of trying to manage ambient/global definitions.
Steps to Reproduce
Expected behavior: [What did you expect to happen?]
Find a way to remap/alias/use a different root when using typings/typings.
Actual behavior: [What actually happened?]
Unable to find a way.
Versions
1.0.4
The text was updated successfully, but these errors were encountered: