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 path alias for webpack and babel #9205

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ruanyl
Copy link
Member

@ruanyl ruanyl commented Jan 17, 2025

Description

This PR add path alias support for webpack and babel. Previously, path alias only works for importing typescript types.

  1. webpack now supports opensearch-dashboards/public path alias
  2. Refactor the current in-house path resolution in BundleRefsPlugin to use webpack internal compiler.resolverFactory to work with webpack path alias
  3. Introduced babel-plugin-module-resolver to enable path alias support for babel so that we can use path alias in server side code and jest tests.

Examples:

For public code

// before
import { formatUrlWithWorkspaceId } from '../../../../../src/core/public/utils';
// after
import { formatUrlWithWorkspaceId } from 'opensearch-dashboards/public/utils';

For server code

// before
import { fromRoot } from '../../../core/server/utils';
// after
import { fromRoot } from 'opensearch-dashboards/server/utils';

For jest tests:

// before
import { applicationServiceMock } from '../../../src/core/public/mocks';
// after
import { applicationServiceMock } from 'opensearch-dashboards/public/mocks'

Issues Resolved

#9184

Screenshot

Testing the changes

Changelog

  • infra: add path alias support for webpack and babel

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.05%. Comparing base (15a19fa) to head (f3fc1df).
Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9205      +/-   ##
==========================================
+ Coverage   60.93%   61.05%   +0.11%     
==========================================
  Files        3809     3816       +7     
  Lines       91270    91493     +223     
  Branches    14414    14459      +45     
==========================================
+ Hits        55618    55858     +240     
+ Misses      32097    32070      -27     
- Partials     3555     3565      +10     
Flag Coverage Δ
Linux_1 29.12% <100.00%> (+0.15%) ⬆️
Linux_2 56.45% <ø> (+<0.01%) ⬆️
Linux_3 38.03% <ø> (?)
Linux_4 29.08% <ø> (+0.04%) ⬆️
Windows_1 29.14% <100.00%> (+0.15%) ⬆️
Windows_2 56.40% <ø> (+<0.01%) ⬆️
Windows_3 38.03% <ø> (+0.06%) ⬆️
Windows_4 29.08% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hailong-am
Copy link
Collaborator

can we have some existing code updated to new format? so that we can verify it works during build and also take it as example.

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