Skip to content
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

jsconfig ignored? #304

Open
texastoland opened this issue Mar 13, 2022 · 1 comment
Open

jsconfig ignored? #304

texastoland opened this issue Mar 13, 2022 · 1 comment
Labels
kind: feature New feature or request scope: upstream Issue in upstream dependency solution: workaround available There is a workaround available for this issue

Comments

@texastoland
Copy link

texastoland commented Mar 13, 2022

What happens and why it is wrong

I was struggling with generating JSDoc typings for a library using Microdundle. It generated index.d.ts but none of the imported files. The root issue was missing "include" : ["src"] (inspired by #211). I tried adding it to jsconfig.json after scouring issues here as well as in Microbundle and TSDX. I finally tried renaming to tsconfig.json and resolved my issue.

Suggested fix

Arguably this might belong in Microbundle if JSDoc typings aren't an intended use case for this plugin? Or just manually pass "jsconfig.json".

const fileName = tsModule.findConfigFile(pluginOptions.cwd, tsModule.sys.fileExists, pluginOptions.tsconfig);
// if the value was provided, but no file, fail hard
if (pluginOptions.tsconfig !== undefined && !fileName)
throw new Error(`failed to open '${fileName}'`);

	const getConfig = (name) => tsModule.findConfigFile(pluginOptions.cwd, tsModule.sys.fileExists, name);
	const fileName =
		getConfig(pluginOptions.tsconfig) ||
		// if the value was provided, but no file, fail hard (previously `failed to open undefined`)
		(pluginOptions.tsconfig && throw new Error(`failed to open '${pluginOptions.tsconfig}'`)) ||
		getConfig("jsconfig.json");

Environment

Versions

From package-lock.json (envinfo doesn't list nested dependencies):

  npmPackages:
    typescript: 4.5.5
    rollup: 2.67.2
    rollup-plugin-typescript2: 0.29.0

rollup.config.js

`rollup.config.js`:

https://github.com/developit/microbundle/blob/v0.14.2/src/index.js#L523-L556

tsconfig.json

`tsconfig.json`:

include (described above) is the only key in tsconfig.json.

package.json

`package.json`:
  npmPackages:
    microbundle: ^0.14.2 => 0.14.2

plugin output with verbosity 3

plugin output with verbosity 3:
@agilgur5
Copy link
Collaborator

agilgur5 commented Apr 20, 2022

Good find! I wrote TSDX's tsconfig parsing in jaredpalmer/tsdx#489 , which borrowed some code from here actually (I was the solo maintainer of and only active contributor to TSDX for over a year). I've contributed some fixes etc here too. And I was looking to extract some of this similar code into a tiny package for parsing tsconfigs actually, mainly because the TS API is really non-trivial and opaque to use (see that PR for some details of how I had to figure out how to parse with it).

Or just manually pass "jsconfig.json".

The tsconfig option could probably just be set to ./jsconfig.json for this to work here.

I'm not a maintainer here, but your proposal sounds more or less reasonable to me. I would probably make several stylistic changes, throw an error if neither exists, and use a default value if it's currently undefined so that the error is readable.

That being said, since this plugin doesn't set defaults for tsconfig, it may indeed make more sense for downstream packages to implement support for this.

I also wonder if just using a tsconfig with allowJs: true is enough for most users and jsconfig support should otherwise be built into the TS API. I'm actually a little surprised it's not reading a jsconfig when pluginOptions.tsconfig is undefined

@agilgur5 agilgur5 added kind: feature New feature or request solution: workaround available There is a workaround available for this issue labels Apr 24, 2022
@agilgur5 agilgur5 added the scope: upstream Issue in upstream dependency label Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request scope: upstream Issue in upstream dependency solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

No branches or pull requests

2 participants