-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support jsconfig.json
#87
Comments
This is the most prominent documentation of jsconfig i could find: https://code.visualstudio.com/docs/languages/jsconfig, but it remains vague about
As for implementation, you'd have to check for existing use of hardcoded "tsconfig.json" values and refactor them to allow using "jsconfig.json". And last but not least there would have to be additional test fixtures that ensure it's working correctly. |
Here's what the source code says: https://github.com/microsoft/TypeScript/blob/bdcf8abb0c280cd0e41a2bc1f9c5f806b05ae424/src/compiler/commandLineParser.ts#L3394-L3399 function getDefaultCompilerOptions(configFileName?: string) {
const options: CompilerOptions = configFileName && getBaseFileName(configFileName) === "jsconfig.json"
? { allowJs: true, maxNodeModuleJsDepth: 2, allowSyntheticDefaultImports: true, skipLibCheck: true, noEmit: true }
: {};
return options;
} |
i've made a fork at https://github.com/duanwilliam/tsconfck/tree/jsconfig-support to try to work on it.
seems it can in fact override the default options (e.g. the jsconfig can set
(i'm assuming you're referring to |
Thanks for looking into this!
this is a bit silly. jsconfig.json with
is this regardless of
import bar from '$somewhere/bar.js' jsconfig.json {
"compilerOptions": {
"paths": {"$somewhere":"path/to/somewhere"}
}
} If i understand you correctly you're saying that bundlers are aware of jsconfig.json compilerOptions.paths and resolve them even without tsc? My understanding is that you would have to run tsc first to resolve these, bundlers don't do it on their own (otherwise they'd had have a way to resolve these correctly already) |
as far as i'm aware the work on my fork is doing so at the moment.
i can't seem to observe this, are there any specific tests demonstrating it?
(wip)
so (as far as i'm aware) handling jsconfig.json |
@MichaelDeBoey tsconfk@3 is currently in pre-release and will be released soon (to be included in vite5) are you still interested in this? |
I did look into this a bit more and it seems like tsc itself does not look for https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#using-tsconfigjson-or-jsconfigjson findConfigFile also has an explicit argument that defaults to So to line up with typescript the best way to implement this in tsconfck is to add a new option In addition the extensions handling needs to be updated to include js/cjs/mjs/jsx extensions in case But this won't help vite-tsconfig-paths on it's own as that would have to detect use of jsconfig.json and call tsconfck accordingly. In general i think vite-tsconfig-paths maybe has it backwards. Instead of making tsconfig/jsconfig the source of truth for aliases, vite config should remain that source and vite-tsconfig-paths can generate a some features of ts path mapping like fallbacks would not be easily replicated by this, but i don't think they are supported by vite-tsconfig-paths or vite today (unless you implement a custom plugin with resolveId that runs this.resolve multiple times) cc @aleclarson |
@dominikg Since we moved away from converting Remix stacks to JS in v2, we're just going to update to latest |
see #132 |
released in tsconfck@3.0.0-next.9 import {find,parse} from 'tsconfck'
const jsconfigPath = await find('some/path/to/a/file.js',{configName:'jsconfig.json'})
// '/abs/some/path/jsconfig.json'
const parsed = await parse('some/path/to/a/file.js',{configName:'jsconfig.json'})
// parsed = {
// tsconfigFile: '/abs/some/path/jsconfig.json'
// tsconfig: {...}
// } cli also has a npx tsconfck@next find some/path/to/a/file.js -js |
I'd say that |
In that case vite-tsconfig-paths would have to reimplement whatever logic vscode uses internally, with the new Note: you can use a single cache instance for both tsconfig and jsconfig via const cache = new TSConfckCache();
const jsconfig = await find(file,{cache, configName:'jsconfig.json'});
const tsconfig = await find(file,{cache});
// or
const [jsconfig,tsconfig] = await Promise.all(['jsconfig.json','tsconfig.json'].map(configName => find(file,{cache,configName}));
// see which one is closer and act accordingly |
IMO is enough to vite-tsconfig-paths expose configName option |
I plan for |
you can do that with vite providing vite-tsconfig-paths tsconfig.json, but bring your own cache (and watcher) for jsconfig.json. Neither tsc nor esbuild take jsconfig.json into account by default, so it would be really strange for tsconfck to do so |
I trust @dominikg's call on this one, I don't have a particular perspective to add here. |
The difference is that tsc/esbuild are for compiling TypeScript files, while tsconfck is for tsconfig loading and, as a consequence, bundling, which is not solely TypeScript focused (a situation similar to VS Code). |
I'm not keen on adding custom find modes that implement what various other tools are doing. tsconfck is already more complex than i'd like it to be, thanks to the myriad of extras typescript added to it's config handling over the years. What exactly would you expect tsconfck to return if not the config that tsc itself would use? The new configName option is exactly what they do in their own findConfigFile function. |
tbh their config system is too complex in general and i hope they revise it, maybe in a similar way eslint now offers a flat config, making tsconfck obsolete. |
Given that the new async implementation is very fast and the code required in userland to implement resolving either jsconfig or tsconfig is pretty small and working for astro, i'm calling this implemented. @aleclarson if this still isn't enough for vite-tsconfig-paths please raise a new feature request for mixed configName support, including links to typescript and vscode documentation describing in detail how it's supposed to work correctly. |
jsconfig.json
is the same file astsconfig.json
, it just says you're using JS instead of TS@aleclarson's
vite-tsconfig-paths
used to usetsconfig-paths
to resolve thejsconfig.json
/tsconfig.json
, but switched to this package for doing so.This however had the breaking change of not supporting
jsconfig.json
anymore (see aleclarson/vite-tsconfig-paths#22 (comment)).@dominikg I would love to get support for
jsconfig.json
again, as we're convertingtsconfig.json
tojsconfig.json
if people choose to have JS templates in @remix-run.This means our stacks (see
indie-stack
,blues-stack
&grunge-stack
) needs to keep usingvite-tsconfig-paths
v3 in order to keep supporting this behavior, but of course we'd love to have all our dependencies to latest version.I'm always happy to help implement this as well if you could point me into the right direction.
The text was updated successfully, but these errors were encountered: