简体   繁体   中英

Loading dependencies other than by relative path?

I'm working in a build system which is... different.

  • It runs tools like compilers in parallel on remote machines.
  • We keep dependencies in a common place for all users, rather than copying a lib/ directory or similar under each project's source root.
  • We check out only a subset of the repository to each developers machine, which means some files are on local disk and some are accessed in a FUSE filesystem.
  • Some inputs (eg. .d.ts files) are generated by the build system and these are in a different path or loaded from yet another FUSE filesystem.

So I end up with things like

// hmm, is this the right number of ..'s to 
// get up to the shared DefinitelyTyped repo?
/// <reference path='../../../../../typings/angularjs/angular.d.ts' />

and a lot of code shuffling files around inside the build system to lay out a file structure mimicking what tsc expects.

These problems are due to relying exclusively on the tsc behavior of resolving /// <reference/> tags relative to the path of the file in which it appears. What I would really like is to give a stack of absolute paths which should be resolved by checking in order:

  1. Root path in the developers working space
  2. Root path where build system puts generated files
  3. Root path of the readonly snapshot of the entire repository

Does anyone have a workaround for loading files a different way (like a custom compiler frontend on top of the language services API?) Has the core TS team considered a feature like this?

Does anyone have a workaround for loading files a different way

You can use grunt-ts transforms to resolve the relative path issues for you : https://github.com/TypeStrong/grunt-ts#transforms

(like a custom compiler frontend on top of the language services API?)

Atom-TypeScript has a compilation context determined from tsconfig.json : https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md so you don't need to reference files. But you will still need to import them for external modules. I am working on making it easier to generate these for you (one of the reasons I created atomts).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM