duojs / duo

A next-generation package manager for the front-end
3.42k stars 118 forks source link

feat(transpilation-plugins): default extension of required files to exte... #418

Closed frankwallis closed 9 years ago

frankwallis commented 9 years ago

...nsion of entry file

I'm working on a typescript compiler for duo but I have run into this problem, currently duo will default the extension of required files to the type of the entry file (entry.type). The problem is that I have transpiled the entry file and changed its type from 'ts' to 'js' as shown in the coffeescript example. This means that the dependent files are not found as duo is looking for dep.js instead of dep.ts

import dep = require("./dep"); // should go to dep.ts

I cannot specify the extension in the require because the typescript compiler does not expect require paths to have extensions. I believe that coffeescript also lets you omit the .coffee extension but I'm not certain about that.

This fix is to use the extension of the entry file as the default instead of entry.type (which can change). A better solution might be to try both extensions.

It will have no impact on existing javascript libraries. (when extension(entry.path) == entry.type).

I welcome your feedback, thanks

stephenmathieson commented 9 years ago

will this allow ts/coffee files to require() non-ts/coffee files?

e.g.

index.coffee

foo = require('./foo')

foo.js

module.exports = 'foo'
frankwallis commented 9 years ago

no that will try to resolve './foo.coffee' and fail.

foo = require('/.foo.js');

would work however.

it could be made to work by trying various extensions

frankwallis commented 9 years ago

I have worked around this by rewriting the requires in the compiled output and adding the '.ts' extension