Skip to content

Support prioritizeNamedImports option#187

Merged
mizdra merged 3 commits into
mainfrom
support-prioritize-named-imports
Jun 7, 2025
Merged

Support prioritizeNamedImports option#187
mizdra merged 3 commits into
mainfrom
support-prioritize-named-imports

Conversation

@mizdra
Copy link
Copy Markdown
Owner

@mizdra mizdra commented Jun 7, 2025

ref: #181
parent: #182

Many users who use named exports prefer to import CSS Modules using namespace imports (e.g., import * as styles from ...) (ref: https://x.com/mizdra/status/1927324264853639254). Therefore, we will prioritize namespace imports in autocompletion.

Additionally, for users who prefer to import CSS Modules using named imports (e.g., import { foo } from ...), we have added the prioritizeNamedImports option.

2025-06-08.1.18.34.mov

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 7, 2025

🦋 Changeset detected

Latest commit: aa53448

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@css-modules-kit/ts-plugin Minor
@css-modules-kit/core Minor
css-modules-kit-vscode Patch
@css-modules-kit/codegen Patch
@css-modules-kit/stylelint-plugin Patch
@css-modules-kit/eslint-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mizdra mizdra force-pushed the support-prioritize-named-imports branch from c6accbc to b24e719 Compare June 7, 2025 16:27
@mizdra mizdra requested a review from Copilot June 7, 2025 16:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new prioritizeNamedImports option that controls whether named imports are preferred over namespace imports for CSS modules when namedExports is enabled.

  • Introduces prioritizeNamedImports in core config and applies it in TS plugin completion and code-fix logic
  • Updates language service proxy to wire through resolver and completion/details handlers
  • Adds README docs, tests, and a changeset for the new option

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/ts-plugin/src/util.ts Added import conversion helper to namespace imports
packages/ts-plugin/src/language-service/... Wired prioritizeNamedImports through completions and fixes
packages/core/src/config.ts Extended CMKConfig with new option and parsing logic
packages/core/src/config.test.ts Added test for reading new option
packages/ts-plugin/e2e/named-exports.test.ts Expanded E2E tests for both namespace and named-import modes
README.md Documented prioritizeNamedImports option
.changeset/moody-hornets-hammer.md Bumped package versions for the feature
Comments suppressed due to low confidence (2)

packages/core/src/config.ts:19

  • This new config property lacks a JSDoc comment. Please add a description, e.g. /** Whether to prefer named imports over namespace imports when namedExports is true. */.
prioritizeNamedImports: boolean;

README.md:174

  • The example for false is misleading. It should illustrate a namespace import (e.g. import * as styles from '...') to match the actual behavior.
When this option is `true`, `import { button } from '...'` will be added. When this option is `false`, `import button from '...'` will be added.

Comment thread packages/ts-plugin/src/util.ts
Comment thread packages/ts-plugin/src/language-service/feature/code-fix.ts
Comment thread README.md Outdated
@mizdra mizdra force-pushed the support-prioritize-named-imports branch from b24e719 to aa53448 Compare June 7, 2025 16:34
@mizdra mizdra merged commit fb0563d into main Jun 7, 2025
6 checks passed
@mizdra mizdra deleted the support-prioritize-named-imports branch June 7, 2025 16:39
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.

2 participants