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

Rewrite exports parser #465

Merged
merged 32 commits into from
Mar 3, 2024
Merged

Rewrite exports parser #465

merged 32 commits into from
Mar 3, 2024

Conversation

huozhi
Copy link
Owner

@huozhi huozhi commented Feb 25, 2024

This PR changes the way of how bunchee parsing package exports and matching with entries.

While making the lint feature, I realize we could collect the source files first instead of do a matching for possible entry file when we create a job each time.

The approach now is to have a export path to output files and conditions mapping

'.' -> [
   ['./dist/index.js', 'require'],
   ['./dist/index.mjs', 'import'],
]

If you have more special conditions, the export type will become a composed type connected by '.'

'.' -> [
   ['./dist/index.js', 'require'],
   ['./dist/index.mjs', 'import'],
   ['./dist/index.react-server.mjs', 'import.react-server'],
]

Then we'll collect all the entry files, including executable binaries, they'll be

'./index' -> {
   'import': '<>/src/index.mjs',
   'default': '<>/src/index.js',
},
'./index.development' -> {
   'development': <>/src/index.js,
},

As you can see, the entry ./index will have 2 outputs: one is ESM format (import), another is default format, the default is based evaluated based on the package type.

We'll normalize the keys of the collected entries key, and do a overlapping with the collected output files. So that each entry file with its corresponding output files can become the building jobs later.

Previous approah of parsing export paths is too complex especially composing with development and production conditions.

Fixes #469
Fixes #407

@huozhi huozhi changed the title [wip] Rewrite exports parser Rewrite exports parser Mar 3, 2024
@huozhi huozhi marked this pull request as ready for review March 3, 2024 20:02
@huozhi huozhi merged commit b01509d into main Mar 3, 2024
3 checks passed
@huozhi huozhi deleted the fix/nested-dev-prod-exports branch March 3, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant