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(extract): makes support for subpath imports explicit #855

Merged
merged 3 commits into from
Oct 21, 2023

Conversation

sverweij
Copy link
Owner

@sverweij sverweij commented Oct 21, 2023

Description

  • ensures that subpath imports are recognized as 'aliased', just like the webpack and tsconfig aliases & import paths.
  • splits out the 'aliased' dependency type into three (while leaving the 'aliased' one in place both for convenience and backwards compatibility): aliased-subpath-import, aliased-webpack, aliased-tsconfig
  • modifies the moreThanOneDependencyType rule/ matcher so ...
    • it doesn't count aliases as separate dependency types (see documentation for rationale)
    • it doesn't count type-only as separate dependency types (also: see documentation)

TODO: subpath imports can resolve to local modules ("#*": "./src/*"), but also to 3rd party modules ("#aliasdash/*": "lodash/*") or even core modules (which should be considered a criminal offence and is currently not even recognized in enhanced-resolve: "#path-but-aliased": "path"). These should be added to the dependencyTypes array as well - will probably be in a separate PR, though.

Motivation and Context

subpath imports work since node 12.9 (!) and are a vastly superior alternative to tsconfig paths other alias systems (in webpack, babel, ...):

  • there's native support for it in nodejs, typescript (recent versions) and most other bundler/ packager under the sun.
  • This means it doesn't require third party shims/ polyfills, which is good for site reliability.

Dependency-cruiser already correctly resolved subpath imports - this PR ensures they're explicitly named as such.

How Has This Been Tested?

  • green ci
  • additional automated non-regression tests
  • updated automated non-regression tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation only change
  • Refactor (non-breaking change which fixes an issue without changing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • 📖

    • My change doesn't require a documentation update, or ...
    • it does and I have updated it
  • ⚖️

    • The contribution will be subject to The MIT license, and I'm OK with that.
    • The contribution is my own original work.
    • I am ok with the stuff in CONTRIBUTING.md.

@codeclimate
Copy link

codeclimate bot commented Oct 21, 2023

Code Climate has analyzed commit 6d1ec8d and detected 0 issues on this pull request.

View more on Code Climate.

@sverweij sverweij merged commit 36c3dde into main Oct 21, 2023
7 checks passed
@sverweij sverweij deleted the feature/make-support-for-subpath-imports-explicit branch October 21, 2023 14:10
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.

None yet

1 participant