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

Fix unresolved dependencies #823

Merged
merged 4 commits into from
Jan 15, 2025
Merged

Fix unresolved dependencies #823

merged 4 commits into from
Jan 15, 2025

Conversation

emersion
Copy link
Member

@emersion emersion commented Jan 14, 2025

See individual commits.

We don't want to include our dependencies (react, maplibre, and so
on) in the osrd-ui library bundle: because library users download these as
transitive deps we want to leave it up to them to resolve the
imports and include them in the final app bundle. For instance,
OSRD is responsible for inlining maplibre imports in ui-warped-map's
bundle.

On the other hand, relative imports local to the package should be
bundled.

By default, rollup only resolves relative imports, and doesn't
resolve global imports. rollup prints an error when it encounters
a global import that it can't resolve. We don't want to just
ignore unresolved global imports, because that would silently
allow broken non-existing imports.

The @rollup/plugin-node-resolve plugin allows rollup to resolve
global imports like node does. However, by default it includes
all global imports in the bundle. This isn't what we want: we
want to exclude dependencies from the bundle.

To fix this, follow the recommendations in the rollup docs
and use the "external" option to check whether an import points
to the "node_modules" directory or a "dist" directory of any
osrd-ui package. In that case, ask rollup to not bundle the
import.

We don't need to manually specify a list of external imports
from each package anymore.

We don't want to include our dependencies (react, maplibre, and so
on) in the final bundle: because library users download these as
transitive deps we want to leave it up to them to resolve the
imports and include them in the final app bundle. For instance,
OSRD is responsible for inlining maplibre imports in ui-warped-map's
bundle.

On the other hand, relative imports local to the package should be
bundled.

By default, rollup only resolves relative imports, and doesn't
resolve global imports. rollup prints an error when it encounters
a global import that it can't resolve. We don't want to just
ignore unresolved global imports, because that would silently
allow broken non-existing imports.

The @rollup/plugin-node-resolve plugin allows rollup to resolve
global imports like node does. However, by default it includes
all global imports in the bundle. This isn't what we want: we
want to exclude dependencies from the bundle.

To fix this, follow the recommendations in the rollup docs [1]
and use the "external" option to check whether an import points
to the "node_modules" directory or a "dist" directory of any
osrd-ui package. In that case, ask rollup to not bundle the
import.

We don't need to manually specify a list of external imports
from each package anymore.

[1]: https://rollupjs.org/configuration-options/#external

Signed-off-by: Simon Ser <[email protected]>
Use the directory name to figure out the current project name.

This fixes a bunch of incorrect project names: "osrdcore" was used
for packages other than ui-core.

Signed-off-by: Simon Ser <[email protected]>
Instead of hand-rolling our own rollup configuration, use the
defaults. Fixes unresolved import errors.

Signed-off-by: Simon Ser <[email protected]>
@emersion emersion requested a review from a team as a code owner January 14, 2025 12:02
@emersion emersion requested a review from Yohh January 14, 2025 12:02
@emersion emersion assigned SharglutDev and unassigned SharglutDev Jan 14, 2025
@emersion emersion requested a review from SharglutDev January 14, 2025 12:02
@emersion emersion self-assigned this Jan 14, 2025
Copy link
Contributor

@Yohh Yohh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks

Copy link
Contributor

@SharglutDev SharglutDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@emersion emersion added this pull request to the merge queue Jan 15, 2025
Merged via the queue into dev with commit b779ece Jan 15, 2025
6 checks passed
@emersion emersion deleted the emr/unresolved-imports branch January 15, 2025 09:12
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.

3 participants