@1adybug/prettier-plugin-sort-imports 0.0.28 → 0.0.29
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 +7 -7
- package/README.zh-CN.md +7 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/sorter.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,7 +153,7 @@ interface PluginConfig {
|
|
|
153
153
|
/** Whether to remove unused imports, defaults to false */
|
|
154
154
|
removeUnusedImports?: boolean
|
|
155
155
|
/** Whether to add/remove the node: prefix for Node.js builtin modules */
|
|
156
|
-
nodeProtocol?:
|
|
156
|
+
nodeProtocol?: "add" | "remove"
|
|
157
157
|
}
|
|
158
158
|
```
|
|
159
159
|
|
|
@@ -169,7 +169,7 @@ export default {
|
|
|
169
169
|
sortSideEffect: false, // Whether to sort side effect imports
|
|
170
170
|
groupSeparator: "", // Group separator
|
|
171
171
|
removeUnusedImports: false, // Whether to remove unused imports
|
|
172
|
-
nodeProtocol:
|
|
172
|
+
nodeProtocol: "add", // "add" to add node: prefix ("remove" to remove)
|
|
173
173
|
}
|
|
174
174
|
```
|
|
175
175
|
|
|
@@ -201,7 +201,7 @@ export default {
|
|
|
201
201
|
groupSeparator: "\n",
|
|
202
202
|
sortSideEffect: true,
|
|
203
203
|
removeUnusedImports: false,
|
|
204
|
-
nodeProtocol:
|
|
204
|
+
nodeProtocol: "add",
|
|
205
205
|
}),
|
|
206
206
|
],
|
|
207
207
|
}
|
|
@@ -378,14 +378,14 @@ function MyComponent() {
|
|
|
378
378
|
|
|
379
379
|
Whether to add/remove the `node:` prefix for Node.js builtin modules. Defaults to `undefined` (no change).
|
|
380
380
|
|
|
381
|
-
- `
|
|
382
|
-
- `
|
|
381
|
+
- `"add"`: add `node:` prefix
|
|
382
|
+
- `"remove"`: remove `node:` prefix
|
|
383
383
|
|
|
384
384
|
```ts
|
|
385
385
|
// Before
|
|
386
|
-
// nodeProtocol:
|
|
386
|
+
// nodeProtocol: "remove"
|
|
387
387
|
import fs from "fs"
|
|
388
|
-
// nodeProtocol:
|
|
388
|
+
// nodeProtocol: "add"
|
|
389
389
|
import fs from "node:fs"
|
|
390
390
|
import path from "node:path"
|
|
391
391
|
import path from "path"
|
package/README.zh-CN.md
CHANGED
|
@@ -152,7 +152,7 @@ interface PluginConfig {
|
|
|
152
152
|
/** 是否删除未使用的导入,默认为 false */
|
|
153
153
|
removeUnusedImports?: boolean
|
|
154
154
|
/** 是否为 Node.js 内置模块自动添加/移除 node: 前缀 */
|
|
155
|
-
nodeProtocol?:
|
|
155
|
+
nodeProtocol?: "add" | "remove"
|
|
156
156
|
}
|
|
157
157
|
```
|
|
158
158
|
|
|
@@ -168,7 +168,7 @@ export default {
|
|
|
168
168
|
sortSideEffect: false, // 是否对副作用导入排序
|
|
169
169
|
groupSeparator: "", // 分组分隔符
|
|
170
170
|
removeUnusedImports: false, // 是否删除未使用的导入
|
|
171
|
-
nodeProtocol:
|
|
171
|
+
nodeProtocol: "add", // "add" 为添加 node: 前缀("remove" 为移除)
|
|
172
172
|
}
|
|
173
173
|
```
|
|
174
174
|
|
|
@@ -197,7 +197,7 @@ export default {
|
|
|
197
197
|
groupSeparator: "",
|
|
198
198
|
sortSideEffect: true,
|
|
199
199
|
removeUnusedImports: false,
|
|
200
|
-
nodeProtocol:
|
|
200
|
+
nodeProtocol: "add",
|
|
201
201
|
}),
|
|
202
202
|
],
|
|
203
203
|
}
|
|
@@ -374,14 +374,14 @@ function MyComponent() {
|
|
|
374
374
|
|
|
375
375
|
是否为 Node.js 内置模块自动添加/移除 `node:` 前缀,默认为 `undefined`(不处理)。
|
|
376
376
|
|
|
377
|
-
- `
|
|
378
|
-
- `
|
|
377
|
+
- `"add"`:自动添加 `node:` 前缀
|
|
378
|
+
- `"remove"`:自动移除 `node:` 前缀
|
|
379
379
|
|
|
380
380
|
```ts
|
|
381
381
|
// 排序前
|
|
382
|
-
// nodeProtocol:
|
|
382
|
+
// nodeProtocol: "remove"
|
|
383
383
|
import fs from "fs"
|
|
384
|
-
// nodeProtocol:
|
|
384
|
+
// nodeProtocol: "add"
|
|
385
385
|
import fs from "node:fs"
|
|
386
386
|
import path from "node:path"
|
|
387
387
|
import path from "path"
|
package/dist/index.d.ts
CHANGED
|
@@ -19,10 +19,10 @@ export interface Options extends PrettierOptions {
|
|
|
19
19
|
removeUnusedImports?: boolean;
|
|
20
20
|
/**
|
|
21
21
|
* Whether to add/remove the node: prefix for Node.js builtin modules.
|
|
22
|
-
*
|
|
22
|
+
* "add": add, "remove": remove, undefined: no change.
|
|
23
23
|
* @default undefined
|
|
24
24
|
*/
|
|
25
|
-
nodeProtocol?:
|
|
25
|
+
nodeProtocol?: "add" | "remove";
|
|
26
26
|
/**
|
|
27
27
|
* 自定义获取分组名称。
|
|
28
28
|
*/
|
package/dist/index.js
CHANGED
|
@@ -597,8 +597,9 @@ function applyNodeProtocol(modulePath, nodeProtocol) {
|
|
|
597
597
|
const hasNodePrefix = modulePath.startsWith("node:");
|
|
598
598
|
const normalizedPath = hasNodePrefix ? modulePath.slice(5) : modulePath;
|
|
599
599
|
if (!isNodeBuiltinModule(normalizedPath)) return modulePath;
|
|
600
|
-
if (nodeProtocol) return hasNodePrefix ? modulePath : `node:${modulePath}`;
|
|
601
|
-
return hasNodePrefix ? normalizedPath : modulePath;
|
|
600
|
+
if ("add" === nodeProtocol) return hasNodePrefix ? modulePath : `node:${modulePath}`;
|
|
601
|
+
if ("remove" === nodeProtocol) return hasNodePrefix ? normalizedPath : modulePath;
|
|
602
|
+
return modulePath;
|
|
602
603
|
}
|
|
603
604
|
function getImportRanges(imports) {
|
|
604
605
|
const ranges = imports.map((statement)=>({
|
|
@@ -726,9 +727,9 @@ function createPluginInstance(config = {}) {
|
|
|
726
727
|
default: false
|
|
727
728
|
},
|
|
728
729
|
nodeProtocol: {
|
|
729
|
-
type: "
|
|
730
|
+
type: "string",
|
|
730
731
|
category: "Import Sort",
|
|
731
|
-
description: "
|
|
732
|
+
description: "Add/remove node: prefix for Node.js builtin modules"
|
|
732
733
|
}
|
|
733
734
|
};
|
|
734
735
|
const otherPlugins = config.otherPlugins || [];
|
package/dist/sorter.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Group, ImportContent, ImportStatement, PluginConfig } from "./types";
|
|
|
3
3
|
export interface MergedConfig extends Omit<Required<PluginConfig>, "groupSeparator" | "removeUnusedImports" | "nodeProtocol" | "otherPlugins" | "prettierOptions"> {
|
|
4
4
|
groupSeparator: PluginConfig["groupSeparator"];
|
|
5
5
|
removeUnusedImports: boolean;
|
|
6
|
-
nodeProtocol?:
|
|
6
|
+
nodeProtocol?: PluginConfig["nodeProtocol"];
|
|
7
7
|
}
|
|
8
8
|
/** 对导入语句进行排序 */
|
|
9
9
|
export declare function sortImports(imports: ImportStatement[], userConfig: PluginConfig): ImportStatement[];
|
package/dist/types.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export interface PluginConfig {
|
|
|
77
77
|
/** 是否删除未使用的导入,默认为 false */
|
|
78
78
|
removeUnusedImports?: boolean;
|
|
79
79
|
/** Whether to add/remove the node: prefix for Node.js builtin modules */
|
|
80
|
-
nodeProtocol?:
|
|
80
|
+
nodeProtocol?: "add" | "remove";
|
|
81
81
|
/** 要合并的其他 Prettier 插件,按传入顺序执行 */
|
|
82
82
|
otherPlugins?: Plugin[];
|
|
83
83
|
/** 传递给其他插件的 Prettier 配置选项 */
|