@1adybug/prettier 0.0.1 → 0.0.2
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/dist/index.d.ts +2 -1
- package/dist/index.js +24 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,8 +5,21 @@ import prettier_plugin_block_padding from "prettier-plugin-block-padding";
|
|
|
5
5
|
import prettier_plugin_remove_braces from "@1adybug/prettier-plugin-remove-braces";
|
|
6
6
|
import { createPlugin } from "@1adybug/prettier-plugin-sort-imports";
|
|
7
7
|
import * as __rspack_external_prettier_plugin_tailwindcss_a3404f7e from "prettier-plugin-tailwindcss";
|
|
8
|
+
const packageJson = json5.parse(readFileSync("package.json", "utf-8"));
|
|
9
|
+
function hasDependency(dependency) {
|
|
10
|
+
const dependencies = packageJson.dependencies ?? {};
|
|
11
|
+
const devDependencies = packageJson.devDependencies ?? {};
|
|
12
|
+
const peerDependencies = packageJson.peerDependencies ?? {};
|
|
13
|
+
const total = Object.keys({
|
|
14
|
+
...dependencies,
|
|
15
|
+
...devDependencies,
|
|
16
|
+
...peerDependencies
|
|
17
|
+
});
|
|
18
|
+
return total.some((item)=>"string" == typeof dependency ? item === dependency : dependency.test(item));
|
|
19
|
+
}
|
|
20
|
+
const hasReact = hasDependency("react");
|
|
8
21
|
function isReact(path) {
|
|
9
|
-
return /^@?react\b/.test(path);
|
|
22
|
+
return hasReact && /^@?react\b/.test(path);
|
|
10
23
|
}
|
|
11
24
|
function isBuiltin(path) {
|
|
12
25
|
return path.startsWith("node:") || builtinModules.includes(path);
|
|
@@ -44,6 +57,15 @@ function getModuleType(path) {
|
|
|
44
57
|
if (isRelative(path)) return "relative";
|
|
45
58
|
return "third-party";
|
|
46
59
|
}
|
|
60
|
+
const hasTailwindcss = hasDependency("tailwindcss");
|
|
61
|
+
const otherPlugins = hasTailwindcss ? [
|
|
62
|
+
prettier_plugin_block_padding,
|
|
63
|
+
__rspack_external_prettier_plugin_tailwindcss_a3404f7e,
|
|
64
|
+
prettier_plugin_remove_braces
|
|
65
|
+
] : [
|
|
66
|
+
prettier_plugin_block_padding,
|
|
67
|
+
prettier_plugin_remove_braces
|
|
68
|
+
];
|
|
47
69
|
const src_plugin = createPlugin({
|
|
48
70
|
getGroup ({ path }) {
|
|
49
71
|
const info = {
|
|
@@ -58,11 +80,7 @@ const src_plugin = createPlugin({
|
|
|
58
80
|
separator: "",
|
|
59
81
|
sortSideEffect: true,
|
|
60
82
|
removeUnusedImports: true,
|
|
61
|
-
otherPlugins
|
|
62
|
-
prettier_plugin_block_padding,
|
|
63
|
-
__rspack_external_prettier_plugin_tailwindcss_a3404f7e,
|
|
64
|
-
prettier_plugin_remove_braces
|
|
65
|
-
]
|
|
83
|
+
otherPlugins
|
|
66
84
|
});
|
|
67
85
|
const src = src_plugin;
|
|
68
86
|
export { src as default, src_plugin as plugin };
|