Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

tsconfig.json suggestions #45

Closed
kdmadej opened this issue Dec 27, 2016 · 4 comments
Closed

tsconfig.json suggestions #45

kdmadej opened this issue Dec 27, 2016 · 4 comments

Comments

@kdmadej
Copy link

kdmadej commented Dec 27, 2016

A couple of ideas that popped into my mind when trying to get FuseBox to work with TS and React (all in reference to getTypeScriptConfig())

  • documenting the existance of the tsConfig option (I don't think I've seen it anywhere in the docs or the site)
  • letting users specify the location of the tsconfig.json file (by default it looks in homeDir, but I think I'm not the only one that prefers to keep his tsconfig.json in project's root and not in src dir together with the sources, nor do I find it clean to add symlinks); one can work around the lack of this feature by reading the contents of tsconfig.json from a different location and feeding it to FuseBox through the tsConfig option, but I believe this to be a common enough use-case to consider adding it as a separate option
  • finding some less strict way of parsing the JSON contents of the tsconfig.json than using require (afaik TS lets you keep comments in your config, require is too strict about the JSON structure for that and it would be nice to reuse the same ts config across all tools)
  • (this one is more a question than an idea or an issue, mostly because I haven't had the time to dug deeper into FuseBox's code); just wanted to point out that .tsx files do not to trigger switching to typescript mode and yet my project bundles without problems (probably because of things like this and this) also I don't know the significance of ensureFolderAndExtensions but it seems to depend on tsMode and assume a .ts extension
@nchanged
Copy link
Contributor

Thank you very much for the ideas.
Good thinking. I was expecting someone to raise that topic sooner or later =)

  • tsconfig.json will be configurable (it was on my list)
  • Can be done (any suggestions how?)
  • I guess it's a bug. .tsx should trigger typescript mode.

When you are in typescript mode and do an import that looks like import foo from "./foo" FuseBox has to know that you are referring to a .ts extension not .js

Let me know what you think

Cheers

@kdmadej
Copy link
Author

kdmadej commented Dec 28, 2016

Regarding the strictness: I think this suggestion is a plausible approach (read the contents, minify, feed into JSON.parse).
Another way to do this would be to mimic the behaviour of ts itself, as depicted in the pr that introduced comments to tsconfig.

Although the best solution in my opinion would be for ts to expose a parseConfigFile method to help developers maintain a consistent way of parsing the config file across projects that depend on it. I guess I'll post a suggestion on their issue tracker.

EDIT: apparently the aforementioned parseConfigFileTextToJson() is already exposed. Example usage:

const fs = require('fs');
const ts = require('typescript');

const configPath = './tsconfig.json';
const tsconfig = fs.readFileSync(configPath).toString();
const parsedConfig = ts.parseConfigFileTextToJson(configPath, tsconfig); // the first argument seems to be used only for diagnostics
// parsedConfig.config contains the configuration object that can be passed to fuse-box

@devmondo
Copy link
Member

the way i see it is really simple, just provide option to take the path relative to project dir, and feed it to TS and that is all. Fuse is now and should always be transparent about plugins, in essence it should only receive content wither it is compiled or not and do the bundling.

@devmondo
Copy link
Member

devmondo commented Mar 6, 2017

this is now supported, please reopen if otherwise :)

@devmondo devmondo closed this as completed Mar 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants