@1adybug/prettier-plugin-sort-imports 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,7 @@ A powerful Prettier plugin for intelligently grouping and sorting import stateme
13
13
  - ✅ **Side Effect Handling**: Configurable sorting behavior for side effect imports
14
14
  - ✅ **Unused Import Removal**: Optional automatic removal of unused imports
15
15
  - ✅ **Factory Function Pattern**: Support for custom functions in configuration files
16
+ - ✅ **Tailwind CSS Integration**: Compatible with `prettier-plugin-tailwindcss`
16
17
 
17
18
  ## Quick Start
18
19
 
@@ -288,6 +289,7 @@ export default {
288
289
  ```
289
290
 
290
291
  **Benefits of this approach**:
292
+
291
293
  - ✅ **Reusable**: Share the same configuration across multiple projects
292
294
  - ✅ **Version Control**: Track your import sorting rules in git
293
295
  - ✅ **Maintainable**: Keep complex logic separate from prettier config
@@ -556,6 +558,30 @@ export default {
556
558
 
557
559
  This maintains configuration flexibility while not violating Prettier's configuration system limitations.
558
560
 
561
+ ## Integration with Other Plugins
562
+
563
+ ### Tailwind CSS
564
+
565
+ This plugin works seamlessly with `prettier-plugin-tailwindcss`. For detailed setup instructions, see [TAILWINDCSS_INTEGRATION.md](./TAILWINDCSS_INTEGRATION.md).
566
+
567
+ **Quick Setup:**
568
+
569
+ ```javascript
570
+ // prettier.config.mjs
571
+ export default {
572
+ plugins: [
573
+ "@1adybug/prettier-plugin-sort-imports",
574
+ "prettier-plugin-tailwindcss", // Must come last
575
+ ],
576
+ tailwindFunctions: ["clsx", "cn", "cva", "tw"],
577
+ }
578
+ ```
579
+
580
+ This will:
581
+
582
+ - ✅ Sort and merge your imports
583
+ - ✅ Sort your Tailwind CSS classes according to the recommended order
584
+
559
585
  ## Notes
560
586
 
561
587
  1. **Only processes consecutive import/export statement blocks at the beginning of files**
package/README.zh-CN.md CHANGED
@@ -282,6 +282,7 @@ export default {
282
282
  ```
283
283
 
284
284
  **此方法的优点**:
285
+
285
286
  - ✅ **可复用**:在多个项目间共享相同配置
286
287
  - ✅ **版本控制**:在 git 中跟踪你的导入排序规则
287
288
  - ✅ **易维护**:将复杂逻辑从 prettier 配置中分离
package/dist/index.js CHANGED
@@ -581,11 +581,11 @@ function createCombinedPreprocess(parserName, config) {
581
581
  ...prettierOptions
582
582
  };
583
583
  const preprocessFunctions = [];
584
+ preprocessFunctions.push((text, options)=>preprocessImports(text, options, config));
584
585
  for (const plugin of otherPlugins){
585
586
  const parser = plugin?.parsers?.[parserName];
586
587
  if (parser?.preprocess && "function" == typeof parser.preprocess) preprocessFunctions.push(parser.preprocess);
587
588
  }
588
- preprocessFunctions.push((text, options)=>preprocessImports(text, options, config));
589
589
  let processedText = text;
590
590
  for (const preprocess of preprocessFunctions)try {
591
591
  processedText = preprocess(processedText, mergedOptions);
@@ -620,23 +620,43 @@ function createPluginInstance(config = {}) {
620
620
  ...baseOptions
621
621
  };
622
622
  for (const plugin of otherPlugins)if (plugin?.options) Object.assign(mergedOptions, plugin.options);
623
- return {
624
- parsers: {
625
- babel: {
626
- ...babel,
627
- preprocess: createCombinedPreprocess("babel", config)
628
- },
629
- typescript: {
630
- ...typescript,
631
- preprocess: createCombinedPreprocess("typescript", config)
632
- },
633
- "babel-ts": {
634
- ...babelTs,
635
- preprocess: createCombinedPreprocess("babel-ts", config)
623
+ const mergedPrinters = {};
624
+ for (const plugin of otherPlugins)if (plugin?.printers) Object.assign(mergedPrinters, plugin.printers);
625
+ const mergedParsers = {};
626
+ const parserNames = [
627
+ "babel",
628
+ "typescript",
629
+ "babel-ts"
630
+ ];
631
+ const baseParsers = {
632
+ babel,
633
+ typescript,
634
+ "babel-ts": babelTs
635
+ };
636
+ for (const parserName of parserNames){
637
+ const baseParser = baseParsers[parserName];
638
+ let merged = {
639
+ ...baseParser
640
+ };
641
+ for (const plugin of otherPlugins){
642
+ const otherParser = plugin?.parsers?.[parserName];
643
+ if (otherParser) {
644
+ const { preprocess, ...otherAttrs } = otherParser;
645
+ merged = {
646
+ ...merged,
647
+ ...otherAttrs
648
+ };
636
649
  }
637
- },
650
+ }
651
+ merged.preprocess = createCombinedPreprocess(parserName, config);
652
+ mergedParsers[parserName] = merged;
653
+ }
654
+ const result = {
655
+ parsers: mergedParsers,
638
656
  options: mergedOptions
639
657
  };
658
+ if (Object.keys(mergedPrinters).length > 0) result.printers = mergedPrinters;
659
+ return result;
640
660
  }
641
661
  function createPlugin(config = {}) {
642
662
  return createPluginInstance(config);
package/dist/sorter.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Group, ImportContent, ImportStatement, PluginConfig } from "./types"; /** 导入类型 */
1
+ import { Group, ImportContent, ImportStatement, PluginConfig } from "./types";
2
2
  /** 合并后的配置 */
3
3
  export interface MergedConfig extends Omit<Required<PluginConfig>, "separator" | "removeUnusedImports" | "otherPlugins" | "prettierOptions"> {
4
4
  separator: PluginConfig["separator"];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1adybug/prettier-plugin-sort-imports",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "一个 Prettier 插件,用于对 JavaScript/TypeScript 文件的导入语句进行分组和排序",
6
6
  "keywords": [
7
7
  "prettier",
@@ -54,6 +54,7 @@
54
54
  "@types/bun": "latest",
55
55
  "@types/node": "^22.18.6",
56
56
  "prettier": "^3.6.2",
57
+ "prettier-plugin-tailwindcss": "^0.7.0",
57
58
  "supports-color": "^10.2.2",
58
59
  "typescript": "^5.9.2"
59
60
  },