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

Please consider adding a command to generate jsconfig.json #13096

Closed
razonyang opened this issue Nov 28, 2024 · 7 comments
Closed

Please consider adding a command to generate jsconfig.json #13096

razonyang opened this issue Nov 28, 2024 · 7 comments
Labels
Milestone

Comments

@razonyang
Copy link
Contributor

Hi, the jsconfig.json is really useful for development, however it won't be created without using js.Build (correct me if I'm wrong).

Take nested modules development as an use case, which does not invoke js.Build directly.

// example.org/a/assets/modules/a/index.ts
export const a = () => {}

I'd like to generate a jsconfig.json inside b module's assets via a Hugo command (e.g. hugo mod jsconfig gen), to enable the intellisense feature.

// example.org/b/assets/modules/b/index.ts
import { a } from 'modules/a'

console.log(a())
@bep
Copy link
Member

bep commented Nov 28, 2024

js.Build (correct me if I'm wrong).

That is correct.

hugo mod jsconfig gen

How would this work? What should it include?

@razonyang
Copy link
Contributor Author

How would this work? What should it include?

I tested it on VS code with the same form of jsconfig.json generated by js.Build (put it under the /assets folder of current module/project), and it works.

image

@razonyang
Copy link
Contributor Author

I tried different configurations again, but autocomplete was not working until I imported the package once.

It's more complex than I initially thought. I'll post a working format if I find it.

@bep
Copy link
Member

bep commented Nov 29, 2024

I'll post a working format if I find it.

So, I think I understand the format (I fiddled with this back when I implemented the js.Build setup), but ...

  • With js.Build I know what JS source folder are in use and where.
  • With hugo mod jsconfig gen, that is not obvious.
  • Also, with js.Build, the config is always up-to-date, which is important when the source moves (e.g. by using module workspaces or replacements in go.mod)

Also, I suspect in most situations it's practical to do module JS dev with something that runs, e.g. a test project that pulls in one or modules and ... build it with js.Build, which gives you what you want.

@razonyang
Copy link
Contributor Author

With hugo mod jsconfig gen, that is not obvious.

Yes, it's not obvious, I have a simple implementation that maps paths by looping through dependency mounts even they are not being imported.

Also, I suspect in most situations it's practical to do module JS dev with something that runs, e.g. a test project that pulls in one or modules and ... build it with js.Build, which gives you what you want.

Thank you, I will give this approach a try.

@bep
Copy link
Member

bep commented Nov 29, 2024

Thank you, I will give this approach a try.

I assume you have seen this, but workspaces can be really useful for "these" kinds of things:

https://gohugo.io/hugo-modules/use-modules/#module-workspaces

Also, to get a jsconfig.json file, you don't need to use the bundles you build with it, it should be enough if you do:

js.Build (resources.Get "my.js")
js.Build (resources.Get "myother.js")

Hugo collects source folders built, and creates a jsconfig.json at the end.

@razonyang
Copy link
Contributor Author

Thank you for providing a comprehensive solution.

I think of a solution that publish the types only to NPM, it's static mapping rather than dymanic, which maybe much useful and easier to set up.

This request doesn't make much sense, so I'm closing it.

Thank you for taking time on this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants