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

Support main module configuration in package.json #342

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

hendrikvanantwerpen
Copy link
Collaborator

Similar to tree-sitter-stack-graphs-javascript, this PR add support for the main attribute in package.json files.

If a main module is specified, the exports of that module are accessible directly from the package name. If it is unspecified, we default to index as Node does.

@BekaValentine
Copy link
Contributor

What are the TSG-side components that make this work?

@hendrikvanantwerpen
Copy link
Collaborator Author

What are the TSG-side components that make this work?

Good question! It works because of the following pre-existing behavior:

  • In TSG we introduce module definitions prefixed by %M guards. For example a module src/api.ts becomes %M -> src -> api.

  • In npm_package.rs the package name becomes a definition prefixed by a %NonRelM guard (because non-relative imports can resolve to it). For example, package @acme/foo becomes %NonRelM -> @acme -> foo`.

What is added is the following:

  • The main property introduces a reference from the package definition to the main module. If main is ./src/api.ts, it becomes a reference api -> src -> %M.

The whole chain that works like a rewrite: a reference to @acme/foo becomes src/api via:

%NonRelM` -> @acme -> foo -> api -> src -> %M

I'd add a picture, but the graphs for these examples are already quite large. Does this clarify things?

@BekaValentine
Copy link
Contributor

It does not clarify things. In package.json, the programmer can specify different choices for main files. They can say that the main file, say, index.ts or that its foo.ts or whatever.

How does this information make it's way into the TSG file such that the graphs can be built differently depending on what that value is?

@hendrikvanantwerpen hendrikvanantwerpen merged commit fa506ac into main Nov 13, 2023
6 checks passed
@hendrikvanantwerpen hendrikvanantwerpen deleted the ts-support-package-main branch November 13, 2023 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants