@1adybug/prettier 0.0.13 → 0.0.14

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,13 +6,21 @@ import prettier_plugin_remove_braces from "@1adybug/prettier-plugin-remove-brace
6
6
  import { createPlugin } from "@1adybug/prettier-plugin-sort-imports";
7
7
  import { createMatchPath, loadConfig } from "tsconfig-paths";
8
8
  import * as __rspack_external_prettier_plugin_tailwindcss_a3404f7e from "prettier-plugin-tailwindcss";
9
- createRequire(import.meta.url);
9
+ const src_require = createRequire(import.meta.url);
10
+ function isPossibleFile(base, item) {
11
+ if (!item.startsWith(`${base}.`)) return false;
12
+ const left = item.slice(base.length + 1);
13
+ if (!left) return false;
14
+ if ("d.ts" === left) return true;
15
+ if (left.includes(".")) return false;
16
+ return true;
17
+ }
10
18
  function fileExistsWithAnyExtension(path) {
11
19
  if (existsSync(path)) return true;
12
20
  const { dir, base } = parse(path);
13
21
  if (!existsSync(dir)) return false;
14
22
  const list = readdirSync(dir);
15
- return list.some((item)=>item.startsWith(`${base}.`));
23
+ return list.some((item)=>isPossibleFile(base, item));
16
24
  }
17
25
  function getResolveAlias(filepath) {
18
26
  try {
@@ -37,6 +45,14 @@ function getResolveAlias(filepath) {
37
45
  return;
38
46
  }
39
47
  }
48
+ function hasDependency(dependency) {
49
+ try {
50
+ src_require.resolve(dependency);
51
+ return true;
52
+ } catch (error) {
53
+ return false;
54
+ }
55
+ }
40
56
  function isReact(path) {
41
57
  return /^(npm:)?react(-dom|-native)?(\/|$)/.test(path);
42
58
  }
@@ -68,17 +84,21 @@ function getModuleType(path) {
68
84
  if (isRelative(path)) return "relative";
69
85
  return "third-party";
70
86
  }
71
- const otherPlugins = [
87
+ const hasTailwindcss = hasDependency("tailwindcss");
88
+ const otherPlugins = hasTailwindcss ? [
72
89
  prettier_plugin_block_padding,
73
90
  __rspack_external_prettier_plugin_tailwindcss_a3404f7e,
74
91
  prettier_plugin_remove_braces
92
+ ] : [
93
+ prettier_plugin_block_padding,
94
+ prettier_plugin_remove_braces
75
95
  ];
76
96
  let src_resolveAlias;
77
97
  function getResolvedPathDir(resolvedPath) {
78
98
  if (existsSync(resolvedPath) && statSync(resolvedPath).isFile()) return parse(resolvedPath).dir;
79
99
  const { dir, base } = parse(resolvedPath);
80
100
  const list = readdirSync(dir);
81
- for (const item of list)if (item.startsWith(`${base}.`) && statSync(join(dir, item)).isFile()) return dir;
101
+ for (const item of list)if (isPossibleFile(base, item) && statSync(join(dir, item)).isFile()) return dir;
82
102
  return resolvedPath;
83
103
  }
84
104
  const config = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1adybug/prettier",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "推荐的 Prettier 配置",
5
5
  "keywords": [
6
6
  "prettier",