@1adybug/prettier 0.0.1
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 +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rslib project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get started
|
|
12
|
+
|
|
13
|
+
Build the library:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun run build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the library in watch mode:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun run dev
|
|
23
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { builtinModules } from "module";
|
|
3
|
+
import json5 from "json5";
|
|
4
|
+
import prettier_plugin_block_padding from "prettier-plugin-block-padding";
|
|
5
|
+
import prettier_plugin_remove_braces from "@1adybug/prettier-plugin-remove-braces";
|
|
6
|
+
import { createPlugin } from "@1adybug/prettier-plugin-sort-imports";
|
|
7
|
+
import * as __rspack_external_prettier_plugin_tailwindcss_a3404f7e from "prettier-plugin-tailwindcss";
|
|
8
|
+
function isReact(path) {
|
|
9
|
+
return /^@?react\b/.test(path);
|
|
10
|
+
}
|
|
11
|
+
function isBuiltin(path) {
|
|
12
|
+
return path.startsWith("node:") || builtinModules.includes(path);
|
|
13
|
+
}
|
|
14
|
+
let pathAlias = [];
|
|
15
|
+
try {
|
|
16
|
+
const tsConfig = json5.parse(readFileSync("tsconfig.json", "utf-8"));
|
|
17
|
+
pathAlias = Object.keys(tsConfig.compilerOptions?.paths ?? {}).map((item)=>item.match(/^((@|~).*\/)\*/)).filter(Boolean).map((item)=>item?.[1]);
|
|
18
|
+
} catch {}
|
|
19
|
+
function isAbsolute(path) {
|
|
20
|
+
return pathAlias.some((item)=>path.startsWith(item));
|
|
21
|
+
}
|
|
22
|
+
function isRelative(path) {
|
|
23
|
+
return path.startsWith("./") || path.startsWith("../");
|
|
24
|
+
}
|
|
25
|
+
function compareGroupName(a, b) {
|
|
26
|
+
const orders = [
|
|
27
|
+
"react",
|
|
28
|
+
"builtin",
|
|
29
|
+
"third-party",
|
|
30
|
+
"absolute",
|
|
31
|
+
"relative"
|
|
32
|
+
];
|
|
33
|
+
const aInfo = JSON.parse(a);
|
|
34
|
+
const bInfo = JSON.parse(b);
|
|
35
|
+
return orders.indexOf(aInfo.type) - orders.indexOf(bInfo.type) || aInfo.dir.localeCompare(bInfo.dir);
|
|
36
|
+
}
|
|
37
|
+
function getDir(path) {
|
|
38
|
+
return path.match(/^(((@|~)\/?|\.{1,2}\/)([^./]+))(\/|$)/)?.[1] ?? "";
|
|
39
|
+
}
|
|
40
|
+
function getModuleType(path) {
|
|
41
|
+
if (isReact(path)) return "react";
|
|
42
|
+
if (isBuiltin(path)) return "builtin";
|
|
43
|
+
if (isAbsolute(path)) return "absolute";
|
|
44
|
+
if (isRelative(path)) return "relative";
|
|
45
|
+
return "third-party";
|
|
46
|
+
}
|
|
47
|
+
const src_plugin = createPlugin({
|
|
48
|
+
getGroup ({ path }) {
|
|
49
|
+
const info = {
|
|
50
|
+
type: getModuleType(path),
|
|
51
|
+
dir: getDir(path)
|
|
52
|
+
};
|
|
53
|
+
return JSON.stringify(info);
|
|
54
|
+
},
|
|
55
|
+
sortGroup (a, b) {
|
|
56
|
+
return Number(a.isSideEffect) - Number(b.isSideEffect) || compareGroupName(a.name, b.name);
|
|
57
|
+
},
|
|
58
|
+
separator: "",
|
|
59
|
+
sortSideEffect: true,
|
|
60
|
+
removeUnusedImports: true,
|
|
61
|
+
otherPlugins: [
|
|
62
|
+
prettier_plugin_block_padding,
|
|
63
|
+
__rspack_external_prettier_plugin_tailwindcss_a3404f7e,
|
|
64
|
+
prettier_plugin_remove_braces
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
const src = src_plugin;
|
|
68
|
+
export { src as default, src_plugin as plugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1adybug/prettier",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "自用的 Prettier 配置",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"prettier",
|
|
7
|
+
"plugin"
|
|
8
|
+
],
|
|
9
|
+
"author": "1adybug <lurongv@qq.com>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/1adybug/prettier.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/1adybug/prettier#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/1adybug/prettier/issues"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "rslib build",
|
|
33
|
+
"dev": "rslib build --watch",
|
|
34
|
+
"format": "prettier --write .",
|
|
35
|
+
"fg": "npm run format && git add . && git commit -m \"✨feature: format\"",
|
|
36
|
+
"prepare": "husky"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@1adybug/prettier-plugin-remove-braces": "^0.0.3",
|
|
40
|
+
"@1adybug/prettier-plugin-sort-imports": "^0.0.16",
|
|
41
|
+
"json5": "^2.2.3",
|
|
42
|
+
"prettier-plugin-block-padding": "^0.0.10",
|
|
43
|
+
"prettier-plugin-tailwindcss": "^0.7.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@rslib/core": "^0.18.2",
|
|
47
|
+
"@types/node": "^24.10.1",
|
|
48
|
+
"husky": "^9.1.7",
|
|
49
|
+
"lint-staged": "^16.2.7",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"prettier": "^3.0.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.com/"
|
|
58
|
+
},
|
|
59
|
+
"lint-staged": {
|
|
60
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
61
|
+
}
|
|
62
|
+
}
|