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

feat: generate relative imports #538

Merged
merged 2 commits into from
Jun 9, 2024
Merged

feat: generate relative imports #538

merged 2 commits into from
Jun 9, 2024

Conversation

huozhi
Copy link
Owner

@huozhi huozhi commented Jun 9, 2024

This will PR generates the relative paths relationship for the JS bundles.

For instance, for the 2 exports which one is relying on the other one, and ./foo is dependent on ./, project name is "my-lib":

- src/
  |- index.ts
  |- foo.ts

Bunchee will output the below structure and use "<project name>/<export path>" as dependency for each bundle to import the other export bundles. e.g. foo.js will import from "my-lib" as it's the ./ export.

- dist/
  |- index.js
  |- foo.js

This output is not ideal cause it might resolve the 2nd module resolving. And some bundler might error (e.g. vite).

After this PR, the output the relative path for all imports and there's no extra module resolving. And we did some smart resolution which also based on the output format, to make sure CJS is only requiring other CJS bundles and ESM can resolve other ESM bundles.

e.g.

  1. default ESM case
// ./dist/foo.js

import core from './index.js'
  1. dual package case
// ./dist/foo.cjs

const code = require('./index.cjs')
// ./dist/foo.mjs

import core from './index.mjs'
  1. types

Types will also be smartly resolved like above, but since we could have import.types or require.types conditions, or simply types conditions, so we'll resolve twice to make sure it's able to be resolved properly matching with the format.

Resolves #511

@huozhi huozhi marked this pull request as ready for review June 9, 2024 16:37
@huozhi huozhi merged commit a974e46 into main Jun 9, 2024
4 checks passed
@huozhi huozhi deleted the feat/relative-paths branch June 9, 2024 16:51
@huozhi huozhi mentioned this pull request Jun 9, 2024
renovate bot added a commit to GSTJ/react-native-magic-modal that referenced this pull request Jul 17, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [bunchee](https://togithub.com/huozhi/bunchee) | [`5.1.6` ->
`5.2.2`](https://renovatebot.com/diffs/npm/bunchee/5.1.6/5.2.2) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/bunchee/5.2.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/bunchee/5.2.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/bunchee/5.1.6/5.2.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/bunchee/5.1.6/5.2.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>huozhi/bunchee (bunchee)</summary>

### [`v5.2.2`](https://togithub.com/huozhi/bunchee/releases/tag/v5.2.2)

[Compare
Source](https://togithub.com/huozhi/bunchee/compare/v5.2.1...v5.2.2)

#### Fixes

- Perf: Update `@swc/core` by [@&#8203;kdy1](https://togithub.com/kdy1)
in
[huozhi/bunchee#552
- Fix: conditional export bundle mapping by
[@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#553

#### Misc

- Update to ts 5.5 by [@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#554

**Full Changelog**:
huozhi/bunchee@v5.2.1...v5.2.2

### [`v5.2.1`](https://togithub.com/huozhi/bunchee/releases/tag/v5.2.1)

[Compare
Source](https://togithub.com/huozhi/bunchee/compare/v5.2.0...v5.2.1)

#### Patches

- fix: dev spinner by [@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#549
- Fix special cond alias by
[@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#550

**Full Changelog**:
huozhi/bunchee@v5.2.0...v5.2.1

### [`v5.2.0`](https://togithub.com/huozhi/bunchee/releases/tag/v5.2.0)

[Compare
Source](https://togithub.com/huozhi/bunchee/compare/v5.1.6...v5.2.0)

#### Feature

We improved the module path generation when there're multi-entries and
dependent on each others, which using relative paths that will benefit
module resolving speed. Also we introduced a spinner during build to
help large project to visually notice the build change

- feat: generate relative imports by
[@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#538
- feat: loading spinner by [@&#8203;huozhi](https://togithub.com/huozhi)
in
[huozhi/bunchee#539

#### Patches

- fix: special shouldnt override default condition by
[@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#543
- Fix watch mode spinner by
[@&#8203;huozhi](https://togithub.com/huozhi) in
[huozhi/bunchee#545

**Full Changelog**:
huozhi/bunchee@v5.1.6...v5.2.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/GSTJ/react-native-magic-modal).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate the js with relative imports
1 participant