@zayne-labs/prettier-config 0.11.6 → 0.11.8
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 +66 -67
- package/dist/constants/defaults.d.ts +17 -0
- package/dist/constants/defaults.js +3 -0
- package/dist/defaults-DCbiIW5Q.js +33 -0
- package/dist/defaults-DCbiIW5Q.js.map +1 -0
- package/dist/index.d.ts +7 -67
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/types-nDUANBXB.d.ts +177 -0
- package/dist/utils-CEqE7-_1.js +55 -0
- package/dist/utils-CEqE7-_1.js.map +1 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.js +3 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# @zayne-labs/prettier-config
|
|
2
2
|
|
|
3
|
-
Shared Prettier configuration for Zayne Labs projects.
|
|
3
|
+
Shared Prettier configuration for Zayne Labs projects, featuring a modular factory system with automatic plugin detection and refined sorting logic.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Modular Factory**: Easily toggle features like Tailwind, Astro, and Import Sorting.
|
|
8
|
+
- **Smart Import Sorting**: Distance-based sorting (URLs → Protocols → Packages → Aliases → Paths).
|
|
9
|
+
- **Tailwind CSS v4 Ready**: Support for `tailwindStylesheet` and advanced class sorting.
|
|
10
|
+
- **Auto-Installation**: Prompts to install missing plugins when needed.
|
|
11
|
+
- **Deduplicated Configs**: Merges arrays (plugins, overrides) intelligently without duplicates.
|
|
4
12
|
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
@@ -10,91 +18,82 @@ pnpm add -D @zayne-labs/prettier-config
|
|
|
10
18
|
|
|
11
19
|
## Usage
|
|
12
20
|
|
|
13
|
-
The package exports
|
|
14
|
-
|
|
15
|
-
### Base Config
|
|
16
|
-
|
|
17
|
-
Basic Prettier configuration without any plugins.
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import { baseConfig } from '@zayne-labs/prettier-config';
|
|
21
|
+
The package exports a factory function `zayne` that combines disparate config segments.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
```ts
|
|
24
|
+
// prettier.config.js
|
|
25
|
+
import { zayne } from "@zayne-labs/prettier-config";
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
jsxSingleQuote: false,
|
|
32
|
-
printWidth: 107,
|
|
33
|
-
singleQuote: false,
|
|
34
|
-
tabWidth: 3,
|
|
35
|
-
trailingComma: "es5",
|
|
36
|
-
useTabs: true
|
|
37
|
-
}
|
|
27
|
+
export default zayne({
|
|
28
|
+
base: true, // Enabled by default
|
|
29
|
+
sortImports: true,
|
|
30
|
+
tailwindcss: true,
|
|
31
|
+
astro: false,
|
|
32
|
+
});
|
|
38
33
|
```
|
|
39
34
|
|
|
40
|
-
###
|
|
41
|
-
|
|
42
|
-
Extended base configuration with Tailwind CSS support. Includes plugins for class sorting, merging, and formatting.
|
|
35
|
+
### Options
|
|
43
36
|
|
|
44
|
-
|
|
45
|
-
import { configWithTailwind } from '@zayne-labs/prettier-config';
|
|
37
|
+
The `zayne` factory accepts an options object as the first argument:
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
| Option | Type | Default | Description |
|
|
40
|
+
| ------------- | ------------------------------- | ------- | ---------------------------------------------- |
|
|
41
|
+
| `base` | `boolean \| Config` | `true` | Opinionated base defaults. |
|
|
42
|
+
| `sortImports` | `boolean \| OptionsSortImports` | `false` | Enables `@ianvs/prettier-plugin-sort-imports`. |
|
|
43
|
+
| `tailwindcss` | `boolean \| OptionsTailwindCss` | `false` | Enables Tailwind and ClassNames plugins. |
|
|
44
|
+
| `astro` | `boolean \| OptionsAstro` | `false` | Enables `prettier-plugin-astro`. |
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
### Default Import Sorting Rules
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
- `prettier-plugin-classnames` - Formats className strings
|
|
54
|
-
- `prettier-plugin-merge` - Merges plugin functionality
|
|
48
|
+
When `sortImports` is enabled, imports are organized by "distance" from the current file:
|
|
55
49
|
|
|
56
|
-
**
|
|
50
|
+
1. **User patterns**: Any custom patterns you pass via `importOrder` are prioritized at the top.
|
|
51
|
+
2. **URLs**: Remote modules (e.g., `https://esm.sh/...`).
|
|
52
|
+
3. **Protocols**: Built-ins and protocol imports (`node:`, `bun:`, `jsr:`, `npm:`).
|
|
53
|
+
4. **Packages**: Third-party modules (e.g., `react`, `lodash`).
|
|
54
|
+
5. **Aliases**: Local aliases like `@/`, `#`, `~`, `$`, `%`.
|
|
55
|
+
6. **Paths**: Relative and absolute file paths (excluding CSS).
|
|
56
|
+
7. **CSS**: Style files are always pushed to the absolute bottom.
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
- Custom functions: `cnMerge`, `cnJoin`, `cn`, `tv`, `tw`
|
|
60
|
-
- Tailwind stylesheet: `./tailwind.css`
|
|
58
|
+
### Tailwind & ClassNames Support
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
The Tailwind integration combines three plugins:
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
- `prettier-plugin-tailwindcss`: Sorts classes.
|
|
63
|
+
- `prettier-plugin-classnames`: Multi-line formatting & attribute support.
|
|
64
|
+
- `prettier-plugin-merge`: Ensures plugins work together.
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
**Configurable Options:**
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export default configWithAstro;
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**Note:** You'll need to install the plugin separately:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
pnpm add -D prettier-plugin-astro
|
|
82
|
-
```
|
|
68
|
+
- `customAttributes`: Additional attributes to sort classes in (e.g., `classNames`, `classes`).
|
|
69
|
+
- `customFunctions`: Functions to sort classes in (e.g., `cn`, `tv`, `tw`).
|
|
70
|
+
- `tailwindStylesheet`: Path to your CSS entry point (defaults to `./tailwind.css` for v4).
|
|
71
|
+
- `endPosition`: Criterion for ending class names (`absolute` or `relative`).
|
|
72
|
+
- `syntaxTransformation`: Auto-transform non-expression classes to expression syntax on wrap.
|
|
83
73
|
|
|
84
74
|
## Extending Configurations
|
|
85
75
|
|
|
86
|
-
|
|
76
|
+
The factory accepts any number of extra configuration objects as subsequent arguments:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { zayne } from "@zayne-labs/prettier-config";
|
|
80
|
+
|
|
81
|
+
export default zayne(
|
|
82
|
+
{
|
|
83
|
+
sortImports: true,
|
|
84
|
+
},
|
|
85
|
+
// Extra config objects to merge
|
|
86
|
+
{
|
|
87
|
+
printWidth: 120,
|
|
88
|
+
semi: true,
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
```
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
import { baseConfig } from '@zayne-labs/prettier-config';
|
|
93
|
+
## Plugin Auto-Installation
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
...baseConfig,
|
|
93
|
-
printWidth: 120,
|
|
94
|
-
semi: true,
|
|
95
|
-
};
|
|
96
|
-
```
|
|
95
|
+
This config won't bloat your `node_modules` with plugins you don't use. When you enable a feature (like `astro`), it checks if the required plugins are installed. If missing, it will prompt you in the terminal when you run prettier write . to auto-install them (local TTY only).
|
|
97
96
|
|
|
98
97
|
## License
|
|
99
98
|
|
|
100
|
-
MIT © Zayne Labs
|
|
99
|
+
MIT © [Zayne Labs](https://github.com/zayne-labs)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/constants/defaults.d.ts
|
|
2
|
+
declare const getDefaultTailwindSettings: () => {
|
|
3
|
+
tailwindAttributes: ["classNames", "classes"];
|
|
4
|
+
tailwindFunctions: ["cnMerge", "cnJoin", "cn", "tv", "tw"];
|
|
5
|
+
tailwindStylesheet: "./tailwind.css";
|
|
6
|
+
} & {
|
|
7
|
+
$inferUnion: "tailwindAttributes" | "tailwindFunctions" | "tailwindStylesheet";
|
|
8
|
+
};
|
|
9
|
+
declare const getDefaultImportSortingOrder: () => {
|
|
10
|
+
css: ".css$";
|
|
11
|
+
main: ["^https?://", "<BUILTIN_MODULES>", "^(bun|jsr|npm):", "<THIRD_PARTY_MODULES>", "^(@/|[#~$%])", "^(?!.*[.]css$)[./].*$"];
|
|
12
|
+
} & {
|
|
13
|
+
$inferUnion: "css" | "main";
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getDefaultImportSortingOrder, getDefaultTailwindSettings };
|
|
17
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineEnumDeep } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
+
|
|
3
|
+
//#region src/constants/defaults.ts
|
|
4
|
+
const getDefaultTailwindSettings = () => {
|
|
5
|
+
return defineEnumDeep({
|
|
6
|
+
tailwindAttributes: ["classNames", "classes"],
|
|
7
|
+
tailwindFunctions: [
|
|
8
|
+
"cnMerge",
|
|
9
|
+
"cnJoin",
|
|
10
|
+
"cn",
|
|
11
|
+
"tv",
|
|
12
|
+
"tw"
|
|
13
|
+
],
|
|
14
|
+
tailwindStylesheet: "./tailwind.css"
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const getDefaultImportSortingOrder = () => {
|
|
18
|
+
return defineEnumDeep({
|
|
19
|
+
css: ".css$",
|
|
20
|
+
main: [
|
|
21
|
+
"^https?://",
|
|
22
|
+
"<BUILTIN_MODULES>",
|
|
23
|
+
"^(bun|jsr|npm):",
|
|
24
|
+
"<THIRD_PARTY_MODULES>",
|
|
25
|
+
"^(@/|[#~$%])",
|
|
26
|
+
"^(?!.*[.]css$)[./].*$"
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getDefaultTailwindSettings as n, getDefaultImportSortingOrder as t };
|
|
33
|
+
//# sourceMappingURL=defaults-DCbiIW5Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults-DCbiIW5Q.js","names":[],"sources":["../src/constants/defaults.ts"],"sourcesContent":["import { defineEnumDeep } from \"@zayne-labs/toolkit-type-helpers\";\n\nexport const getDefaultTailwindSettings = () => {\n\treturn defineEnumDeep({\n\t\ttailwindAttributes: [\"classNames\", \"classes\"],\n\t\ttailwindFunctions: [\"cnMerge\", \"cnJoin\", \"cn\", \"tv\", \"tw\"],\n\t\ttailwindStylesheet: \"./tailwind.css\",\n\t});\n};\n\nexport const getDefaultImportSortingOrder = () => {\n\treturn defineEnumDeep({\n\t\t// CSS files (always last)\n\t\tcss: \".css$\",\n\n\t\tmain: [\n\t\t\t// URLs (e.g., https://example.org)\n\t\t\t\"^https?://\",\n\t\t\t// Protocol imports (node:, bun:, jsr:, npm:, etc.)\n\t\t\t\"<BUILTIN_MODULES>\",\n\t\t\t\"^(bun|jsr|npm):\",\n\t\t\t// Third-party packages\n\t\t\t\"<THIRD_PARTY_MODULES>\",\n\t\t\t// Aliases (@/, #, ~, $, %)\n\t\t\t\"^(@/|[#~$%])\",\n\t\t\t// Relative and absolute paths (excluding CSS)\n\t\t\t\"^(?!.*[.]css$)[./].*$\",\n\t\t],\n\t});\n};\n"],"mappings":";;;AAEA,MAAa,mCAAmC;AAC/C,QAAO,eAAe;EACrB,oBAAoB,CAAC,cAAc,UAAU;EAC7C,mBAAmB;GAAC;GAAW;GAAU;GAAM;GAAM;GAAK;EAC1D,oBAAoB;EACpB,CAAC;;AAGH,MAAa,qCAAqC;AACjD,QAAO,eAAe;EAErB,KAAK;EAEL,MAAM;GAEL;GAEA;GACA;GAEA;GAEA;GAEA;GACA;EACD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,73 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Config, Plugin } from "prettier";
|
|
1
|
+
import { a as OptionsTailwindCss, i as OptionsSortImports, n as OptionsAstro, o as ResolvedPrettierConfig, r as OptionsPrettierConfig, t as ExtractOptions } from "./types-nDUANBXB.js";
|
|
3
2
|
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type OptionsTailwindCss = {
|
|
6
|
-
/**
|
|
7
|
-
* @docs [prettier-plugin-classnames#custom-attributes](https://github.com/ony3000/prettier-plugin-classnames#custom-attributes)
|
|
8
|
-
*/
|
|
9
|
-
customAttributes?: string[];
|
|
10
|
-
/**
|
|
11
|
-
* @docs [prettier-plugin-classnames#custom-functions](https://github.com/ony3000/prettier-plugin-classnames#custom-functions)
|
|
12
|
-
*/
|
|
13
|
-
customFunctions?: string[];
|
|
14
|
-
/**
|
|
15
|
-
* @docs [prettier-plugin-classnames#ending-position](https://github.com/ony3000/prettier-plugin-classnames#ending-position)
|
|
16
|
-
*/
|
|
17
|
-
endPosition?: "absolute" | "relative";
|
|
18
|
-
plugins?: Array<"prettier-plugin-tailwindcss" | "prettier-plugin-classnames" | "prettier-plugin-merge" | AnyString | Plugin | URL>;
|
|
19
|
-
tailwindAttributes?: string[];
|
|
20
|
-
tailwindConfig?: `./${string}`;
|
|
21
|
-
tailwindFunctions?: string[];
|
|
22
|
-
tailwindPreserveDuplicates?: boolean;
|
|
23
|
-
tailwindPreserveWhitespace?: boolean;
|
|
24
|
-
tailwindStylesheet?: `./${string}`;
|
|
25
|
-
};
|
|
26
|
-
type OptionsAstro = {
|
|
27
|
-
astroAllowShorthand?: boolean;
|
|
28
|
-
astroSkipFrontmatter?: boolean;
|
|
29
|
-
overrides?: Array<{
|
|
30
|
-
files: "*.astro";
|
|
31
|
-
options: {
|
|
32
|
-
parser: "astro";
|
|
33
|
-
};
|
|
34
|
-
} | NonNullable<Config["overrides"]>[number]>;
|
|
35
|
-
plugins?: Array<"prettier-plugin-astro" | AnyString | Plugin | URL>;
|
|
36
|
-
};
|
|
37
|
-
type OptionsConfig = {
|
|
38
|
-
/**
|
|
39
|
-
* Astro configuration
|
|
40
|
-
* @default false
|
|
41
|
-
* @docs [prettier-plugin-astro](https://github.com/withastro/prettier-plugin-astro#configuration)
|
|
42
|
-
*/
|
|
43
|
-
astro?: boolean | OptionsAstro;
|
|
44
|
-
/**
|
|
45
|
-
* Base Prettier configuration with opinionated defaults.
|
|
46
|
-
* Includes settings for tabs, print width, quotes, trailing commas, and experimental features.
|
|
47
|
-
* @default true
|
|
48
|
-
*/
|
|
49
|
-
base?: boolean | Config;
|
|
50
|
-
/**
|
|
51
|
-
* Tailwind CSS configuration
|
|
52
|
-
* @default false
|
|
53
|
-
* @docs
|
|
54
|
-
* - [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
|
|
55
|
-
* - [prettier-plugin-classnames](https://github.com/ony3000/prettier-plugin-classnames)
|
|
56
|
-
* - [prettier-plugin-merge](https://github.com/ony3000/prettier-plugin-merge)
|
|
57
|
-
*/
|
|
58
|
-
tailwindcss?: boolean | OptionsTailwindCss;
|
|
59
|
-
};
|
|
60
|
-
type ResolvedPrettierConfig = Config & OptionsAstro & OptionsTailwindCss;
|
|
61
|
-
type ExtractOptions<TUnion> = Extract<TUnion, object>;
|
|
62
|
-
//#endregion
|
|
63
3
|
//#region src/configs/astro.d.ts
|
|
64
|
-
declare const astro: (options: ExtractOptions<
|
|
4
|
+
declare const astro: (options: ExtractOptions<OptionsPrettierConfig["astro"]>) => Promise<typeof options>;
|
|
65
5
|
//#endregion
|
|
66
6
|
//#region src/configs/base.d.ts
|
|
67
|
-
declare const base: (options: ExtractOptions<
|
|
7
|
+
declare const base: (options: ExtractOptions<OptionsPrettierConfig["base"]>) => typeof options;
|
|
68
8
|
//#endregion
|
|
69
9
|
//#region src/configs/tailwindcss.d.ts
|
|
70
|
-
declare const tailwindcss: (options: ExtractOptions<
|
|
10
|
+
declare const tailwindcss: (options: ExtractOptions<OptionsPrettierConfig["tailwindcss"]>) => Promise<typeof options>;
|
|
71
11
|
//#endregion
|
|
72
12
|
//#region src/factory.d.ts
|
|
73
13
|
/**
|
|
@@ -88,12 +28,12 @@ declare const tailwindcss: (options: ExtractOptions<OptionsConfig["tailwindcss"]
|
|
|
88
28
|
* },
|
|
89
29
|
* // Extra config to merge (optional)
|
|
90
30
|
* {
|
|
91
|
-
*
|
|
31
|
+
* useTabs: false,
|
|
92
32
|
* }
|
|
93
33
|
* );
|
|
94
34
|
* ```
|
|
95
35
|
*/
|
|
96
|
-
declare const zayne: (options?:
|
|
36
|
+
declare const zayne: (options?: OptionsPrettierConfig, ...extraConfigs: ResolvedPrettierConfig[]) => Promise<ResolvedPrettierConfig>;
|
|
97
37
|
//#endregion
|
|
98
|
-
export { ExtractOptions, OptionsAstro,
|
|
38
|
+
export { ExtractOptions, OptionsAstro, OptionsPrettierConfig, OptionsSortImports, OptionsTailwindCss, ResolvedPrettierConfig, astro, base, tailwindcss, zayne };
|
|
99
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as resolveOptions, n as ensurePackages, t as combineConfigs } from "./utils-CEqE7-_1.js";
|
|
2
|
+
import { n as getDefaultTailwindSettings, t as getDefaultImportSortingOrder } from "./defaults-DCbiIW5Q.js";
|
|
2
3
|
|
|
3
4
|
//#region src/configs/astro.ts
|
|
4
|
-
const astro = (options) => {
|
|
5
|
+
const astro = async (options) => {
|
|
6
|
+
const necessaryPlugins = ["prettier-plugin-astro"];
|
|
7
|
+
await ensurePackages(necessaryPlugins);
|
|
5
8
|
return {
|
|
6
9
|
...options,
|
|
7
10
|
overrides: [{
|
|
8
11
|
files: "*.astro",
|
|
9
12
|
options: { parser: "astro" }
|
|
10
13
|
}, ...options.overrides ?? []],
|
|
11
|
-
plugins: [
|
|
14
|
+
plugins: [...necessaryPlugins, ...options.plugins ?? []]
|
|
12
15
|
};
|
|
13
16
|
};
|
|
14
17
|
|
|
@@ -30,65 +33,44 @@ const base = (options) => {
|
|
|
30
33
|
|
|
31
34
|
//#endregion
|
|
32
35
|
//#region src/configs/tailwindcss.ts
|
|
33
|
-
const tailwindcss = (options) => {
|
|
36
|
+
const tailwindcss = async (options) => {
|
|
37
|
+
const necessaryPlugins = {
|
|
38
|
+
first: ["prettier-plugin-tailwindcss", "prettier-plugin-classnames"],
|
|
39
|
+
last: ["prettier-plugin-merge"]
|
|
40
|
+
};
|
|
41
|
+
await ensurePackages([...necessaryPlugins.first, ...necessaryPlugins.last]);
|
|
42
|
+
const tailwindSettings = getDefaultTailwindSettings();
|
|
34
43
|
return {
|
|
44
|
+
tailwindStylesheet: tailwindSettings.tailwindStylesheet,
|
|
35
45
|
...options,
|
|
36
|
-
customAttributes: [
|
|
37
|
-
|
|
38
|
-
"classes",
|
|
39
|
-
...options.customAttributes ?? []
|
|
40
|
-
],
|
|
41
|
-
customFunctions: [
|
|
42
|
-
"cnMerge",
|
|
43
|
-
"cnJoin",
|
|
44
|
-
"cn",
|
|
45
|
-
"tv",
|
|
46
|
-
"tw",
|
|
47
|
-
...options.customFunctions ?? []
|
|
48
|
-
],
|
|
46
|
+
customAttributes: [...tailwindSettings.tailwindAttributes, ...options.customAttributes ?? []],
|
|
47
|
+
customFunctions: [...tailwindSettings.tailwindFunctions, ...options.customFunctions ?? []],
|
|
49
48
|
plugins: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
...options.plugins ?? []
|
|
54
|
-
],
|
|
55
|
-
tailwindAttributes: [
|
|
56
|
-
"classNames",
|
|
57
|
-
"classes",
|
|
58
|
-
...options.tailwindAttributes ?? []
|
|
49
|
+
...necessaryPlugins.first,
|
|
50
|
+
...options.plugins ?? [],
|
|
51
|
+
...necessaryPlugins.last
|
|
59
52
|
],
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"cnJoin",
|
|
63
|
-
"cn",
|
|
64
|
-
"tv",
|
|
65
|
-
"tw",
|
|
66
|
-
...options.tailwindFunctions ?? []
|
|
67
|
-
],
|
|
68
|
-
tailwindStylesheet: options.tailwindStylesheet ?? "./tailwind.css"
|
|
53
|
+
tailwindAttributes: [...tailwindSettings.tailwindAttributes, ...options.tailwindAttributes ?? []],
|
|
54
|
+
tailwindFunctions: [...tailwindSettings.tailwindFunctions, ...options.tailwindFunctions ?? []]
|
|
69
55
|
};
|
|
70
56
|
};
|
|
71
57
|
|
|
72
58
|
//#endregion
|
|
73
|
-
//#region src/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const accumulatedConfigValue = configAccumulator[latterConfigKey];
|
|
89
|
-
configAccumulator[latterConfigKey] = isArray(latterConfigValue) && isArray(accumulatedConfigValue) ? [...accumulatedConfigValue, ...latterConfigValue] : latterConfigValue;
|
|
90
|
-
}
|
|
91
|
-
return configAccumulator;
|
|
59
|
+
//#region src/configs/sort.ts
|
|
60
|
+
const sortImports = async (options) => {
|
|
61
|
+
const necessaryPlugins = ["@ianvs/prettier-plugin-sort-imports"];
|
|
62
|
+
await ensurePackages(necessaryPlugins);
|
|
63
|
+
const sortingOrder = getDefaultImportSortingOrder();
|
|
64
|
+
return {
|
|
65
|
+
...options,
|
|
66
|
+
importOrder: [
|
|
67
|
+
...sortingOrder.main,
|
|
68
|
+
...options.importOrder ?? [],
|
|
69
|
+
sortingOrder.css
|
|
70
|
+
],
|
|
71
|
+
importOrderSafeSideEffects: [sortingOrder.css, ...options.importOrderSafeSideEffects ?? []],
|
|
72
|
+
plugins: [...necessaryPlugins, ...options.plugins ?? []]
|
|
73
|
+
};
|
|
92
74
|
};
|
|
93
75
|
|
|
94
76
|
//#endregion
|
|
@@ -111,25 +93,20 @@ const mergeTwoConfigs = (formerConfig, latterConfig) => {
|
|
|
111
93
|
* },
|
|
112
94
|
* // Extra config to merge (optional)
|
|
113
95
|
* {
|
|
114
|
-
*
|
|
96
|
+
* useTabs: false,
|
|
115
97
|
* }
|
|
116
98
|
* );
|
|
117
99
|
* ```
|
|
118
100
|
*/
|
|
119
|
-
const zayne = (options = {}, ...extraConfigs) => {
|
|
120
|
-
const { astro: enabledAstro = false, base: enabledBase = true, tailwindcss: enabledTailwindcss = false } = options;
|
|
121
|
-
|
|
101
|
+
const zayne = async (options = {}, ...extraConfigs) => {
|
|
102
|
+
const { astro: enabledAstro = false, base: enabledBase = true, sortImports: enabledSortImports = false, tailwindcss: enabledTailwindcss = false } = options;
|
|
103
|
+
return await combineConfigs([
|
|
122
104
|
enabledBase ? base(resolveOptions(enabledBase)) : void 0,
|
|
123
|
-
enabledTailwindcss ? tailwindcss(resolveOptions(enabledTailwindcss)) : void 0,
|
|
124
105
|
enabledAstro ? astro(resolveOptions(enabledAstro)) : void 0,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!config) continue;
|
|
130
|
-
resolvedConfig = mergeTwoConfigs(resolvedConfig, config);
|
|
131
|
-
}
|
|
132
|
-
return resolvedConfig;
|
|
106
|
+
enabledSortImports ? sortImports(resolveOptions(enabledSortImports)) : void 0,
|
|
107
|
+
...extraConfigs,
|
|
108
|
+
enabledTailwindcss ? tailwindcss(resolveOptions(enabledTailwindcss)) : void 0
|
|
109
|
+
]);
|
|
133
110
|
};
|
|
134
111
|
|
|
135
112
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/configs/astro.ts","../src/configs/base.ts","../src/configs/tailwindcss.ts","../src/configs/sort.ts","../src/factory.ts"],"sourcesContent":["import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\nimport { ensurePackages } from \"@/utils\";\n\nexport const astro = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"astro\"]>\n): Promise<typeof options> => {\n\tconst necessaryPlugins = [\"prettier-plugin-astro\"];\n\n\tawait ensurePackages(necessaryPlugins);\n\n\treturn {\n\t\t...options,\n\n\t\toverrides: [\n\t\t\t{\n\t\t\t\tfiles: \"*.astro\",\n\t\t\t\toptions: { parser: \"astro\" },\n\t\t\t},\n\t\t\t...(options.overrides ?? []),\n\t\t],\n\n\t\tplugins: [...necessaryPlugins, ...(options.plugins ?? [])],\n\t};\n};\n","import type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\n\nexport const base = (options: ExtractOptions<OptionsPrettierConfig[\"base\"]>): typeof options => {\n\treturn {\n\t\texperimentalOperatorPosition: \"start\",\n\t\texperimentalTernaries: true,\n\t\tjsxSingleQuote: false,\n\t\tprintWidth: 107,\n\t\tsingleQuote: false,\n\t\ttabWidth: 3,\n\t\ttrailingComma: \"es5\",\n\t\tuseTabs: true,\n\n\t\t...options,\n\t};\n};\n","import { getDefaultTailwindSettings } from \"@/constants/defaults\";\nimport type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\nimport { ensurePackages } from \"@/utils\";\n\nexport const tailwindcss = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"tailwindcss\"]>\n): Promise<typeof options> => {\n\tconst necessaryPlugins = {\n\t\tfirst: [\"prettier-plugin-tailwindcss\", \"prettier-plugin-classnames\"],\n\t\tlast: [\"prettier-plugin-merge\"],\n\t} as const;\n\n\tawait ensurePackages([...necessaryPlugins.first, ...necessaryPlugins.last]);\n\n\tconst tailwindSettings = getDefaultTailwindSettings();\n\n\treturn {\n\t\ttailwindStylesheet: tailwindSettings.tailwindStylesheet,\n\n\t\t...options,\n\n\t\tcustomAttributes: [...tailwindSettings.tailwindAttributes, ...(options.customAttributes ?? [])],\n\t\tcustomFunctions: [...tailwindSettings.tailwindFunctions, ...(options.customFunctions ?? [])],\n\n\t\tplugins: [\n\t\t\t...necessaryPlugins.first,\n\n\t\t\t...(options.plugins ?? []),\n\n\t\t\t/**\n\t\t\t * The 'merge' plugin must always come last\n\t\t\t * @see https://github.com/ony3000/prettier-plugin-merge#why-prettier-plugin-merge\n\t\t\t */\n\t\t\t...necessaryPlugins.last,\n\t\t],\n\n\t\ttailwindAttributes: [...tailwindSettings.tailwindAttributes, ...(options.tailwindAttributes ?? [])],\n\t\ttailwindFunctions: [...tailwindSettings.tailwindFunctions, ...(options.tailwindFunctions ?? [])],\n\t};\n};\n","import { getDefaultImportSortingOrder } from \"@/constants/defaults\";\nimport type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\nimport { ensurePackages } from \"@/utils\";\n\nexport const sortImports = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"sortImports\"]>\n): Promise<typeof options> => {\n\tconst necessaryPlugins = [\"@ianvs/prettier-plugin-sort-imports\"];\n\n\tawait ensurePackages(necessaryPlugins);\n\n\tconst sortingOrder = getDefaultImportSortingOrder();\n\n\treturn {\n\t\t...options,\n\n\t\timportOrder: [...sortingOrder.main, ...(options.importOrder ?? []), sortingOrder.css],\n\t\timportOrderSafeSideEffects: [sortingOrder.css, ...(options.importOrderSafeSideEffects ?? [])],\n\n\t\tplugins: [...necessaryPlugins, ...(options.plugins ?? [])],\n\t};\n};\n","import type { Awaitable } from \"@zayne-labs/toolkit-type-helpers\";\nimport { astro, base, tailwindcss } from \"./configs\";\nimport { sortImports } from \"./configs/sort\";\nimport type { OptionsPrettierConfig, ResolvedPrettierConfig } from \"./types\";\nimport { combineConfigs, resolveOptions } from \"./utils\";\n\n/**\n * @description Factory function for creating a customized Prettier configuration.\n * Combines base, Astro, and Tailwind CSS configurations based on the provided options.\n * Any Array values (like `plugins` and `overrides`) are merged, while other values are overwritten.\n *\n * @example\n * ```ts\n * // prettier.config.ts\n * import { zayne } from \"@zayne-labs/prettier-config\";\n *\n * export default zayne(\n * {\n * base: true,\n * tailwindcss: { tailwindStylesheet: \"./src/styles.css\" },\n * astro: true,\n * },\n * // Extra config to merge (optional)\n * {\n * useTabs: false,\n * }\n * );\n * ```\n */\nexport const zayne = async (\n\toptions: OptionsPrettierConfig = {},\n\t...extraConfigs: ResolvedPrettierConfig[]\n) => {\n\tconst {\n\t\tastro: enabledAstro = false,\n\t\tbase: enabledBase = true,\n\t\tsortImports: enabledSortImports = false,\n\t\ttailwindcss: enabledTailwindcss = false,\n\t} = options;\n\n\tconst configArray: Array<Awaitable<ResolvedPrettierConfig | undefined>> = [\n\t\tenabledBase ? base(resolveOptions(enabledBase)) : undefined,\n\t\tenabledAstro ? astro(resolveOptions(enabledAstro)) : undefined,\n\t\tenabledSortImports ? sortImports(resolveOptions(enabledSortImports)) : undefined,\n\n\t\t...extraConfigs,\n\n\t\t/**\n\t\t * Tailwind plugin most always be the last one to avoid conflicts\n\t\t * @see https://github.com/tailwindlabs/prettier-plugin-tailwindcss#compatibility-with-other-prettier-plugins\n\t\t */\n\t\tenabledTailwindcss ? tailwindcss(resolveOptions(enabledTailwindcss)) : undefined,\n\t];\n\n\tconst accumulatedConfig = await combineConfigs(configArray);\n\n\treturn accumulatedConfig;\n};\n"],"mappings":";;;;AAGA,MAAa,QAAQ,OACpB,YAC6B;CAC7B,MAAM,mBAAmB,CAAC,wBAAwB;AAElD,OAAM,eAAe,iBAAiB;AAEtC,QAAO;EACN,GAAG;EAEH,WAAW,CACV;GACC,OAAO;GACP,SAAS,EAAE,QAAQ,SAAS;GAC5B,EACD,GAAI,QAAQ,aAAa,EAAE,CAC3B;EAED,SAAS,CAAC,GAAG,kBAAkB,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC1D;;;;;ACpBF,MAAa,QAAQ,YAA2E;AAC/F,QAAO;EACN,8BAA8B;EAC9B,uBAAuB;EACvB,gBAAgB;EAChB,YAAY;EACZ,aAAa;EACb,UAAU;EACV,eAAe;EACf,SAAS;EAET,GAAG;EACH;;;;;ACVF,MAAa,cAAc,OAC1B,YAC6B;CAC7B,MAAM,mBAAmB;EACxB,OAAO,CAAC,+BAA+B,6BAA6B;EACpE,MAAM,CAAC,wBAAwB;EAC/B;AAED,OAAM,eAAe,CAAC,GAAG,iBAAiB,OAAO,GAAG,iBAAiB,KAAK,CAAC;CAE3E,MAAM,mBAAmB,4BAA4B;AAErD,QAAO;EACN,oBAAoB,iBAAiB;EAErC,GAAG;EAEH,kBAAkB,CAAC,GAAG,iBAAiB,oBAAoB,GAAI,QAAQ,oBAAoB,EAAE,CAAE;EAC/F,iBAAiB,CAAC,GAAG,iBAAiB,mBAAmB,GAAI,QAAQ,mBAAmB,EAAE,CAAE;EAE5F,SAAS;GACR,GAAG,iBAAiB;GAEpB,GAAI,QAAQ,WAAW,EAAE;GAMzB,GAAG,iBAAiB;GACpB;EAED,oBAAoB,CAAC,GAAG,iBAAiB,oBAAoB,GAAI,QAAQ,sBAAsB,EAAE,CAAE;EACnG,mBAAmB,CAAC,GAAG,iBAAiB,mBAAmB,GAAI,QAAQ,qBAAqB,EAAE,CAAE;EAChG;;;;;AClCF,MAAa,cAAc,OAC1B,YAC6B;CAC7B,MAAM,mBAAmB,CAAC,sCAAsC;AAEhE,OAAM,eAAe,iBAAiB;CAEtC,MAAM,eAAe,8BAA8B;AAEnD,QAAO;EACN,GAAG;EAEH,aAAa;GAAC,GAAG,aAAa;GAAM,GAAI,QAAQ,eAAe,EAAE;GAAG,aAAa;GAAI;EACrF,4BAA4B,CAAC,aAAa,KAAK,GAAI,QAAQ,8BAA8B,EAAE,CAAE;EAE7F,SAAS,CAAC,GAAG,kBAAkB,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSF,MAAa,QAAQ,OACpB,UAAiC,EAAE,EACnC,GAAG,iBACC;CACJ,MAAM,EACL,OAAO,eAAe,OACtB,MAAM,cAAc,MACpB,aAAa,qBAAqB,OAClC,aAAa,qBAAqB,UAC/B;AAkBJ,QAF0B,MAAM,eAd0C;EACzE,cAAc,KAAK,eAAe,YAAY,CAAC,GAAG;EAClD,eAAe,MAAM,eAAe,aAAa,CAAC,GAAG;EACrD,qBAAqB,YAAY,eAAe,mBAAmB,CAAC,GAAG;EAEvE,GAAG;EAMH,qBAAqB,YAAY,eAAe,mBAAmB,CAAC,GAAG;EACvE,CAE0D"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { AnyString } from "@zayne-labs/toolkit-type-helpers";
|
|
2
|
+
import { Config, Plugin } from "prettier";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type RestOfAllowedPluginTypes = AnyString | Plugin | URL;
|
|
6
|
+
type OptionsClassNames = {
|
|
7
|
+
/**
|
|
8
|
+
* List of additional attributes that enclose class names.
|
|
9
|
+
* The `class` and `className` attributes are always supported.
|
|
10
|
+
* @docs [prettier-plugin-classnames#custom-attributes](https://github.com/ony3000/prettier-plugin-classnames#custom-attributes)
|
|
11
|
+
*/
|
|
12
|
+
customAttributes?: string[];
|
|
13
|
+
/**
|
|
14
|
+
* List of additional functions that enclose class names.
|
|
15
|
+
* The `classNames` function is always supported.
|
|
16
|
+
* @docs [prettier-plugin-classnames#custom-functions](https://github.com/ony3000/prettier-plugin-classnames#custom-functions)
|
|
17
|
+
*/
|
|
18
|
+
customFunctions?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Criterion for ending the class name on each line when replacing with multi-line.
|
|
21
|
+
* @default "absolute"
|
|
22
|
+
* @docs [prettier-plugin-classnames#ending-position](https://github.com/ony3000/prettier-plugin-classnames#ending-position)
|
|
23
|
+
*/
|
|
24
|
+
endPosition?: "absolute" | "relative";
|
|
25
|
+
/**
|
|
26
|
+
* Transforms non-expression class names into expression syntax if line wrapping occurs.
|
|
27
|
+
* Note: This transformation does not support reversible formatting.
|
|
28
|
+
* @default false
|
|
29
|
+
* @docs [prettier-plugin-classnames#syntax-transformation](https://github.com/ony3000/prettier-plugin-classnames#syntax-transformation)
|
|
30
|
+
*/
|
|
31
|
+
syntaxTransformation?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type OptionsTailwindCss = OptionsClassNames & {
|
|
34
|
+
plugins?: Array<"prettier-plugin-tailwindcss" | "prettier-plugin-classnames" | "prettier-plugin-merge" | RestOfAllowedPluginTypes>;
|
|
35
|
+
/**
|
|
36
|
+
* List of attributes to sort classes in. Supports regex patterns.
|
|
37
|
+
* @docs [prettier-plugin-tailwindcss#sorting-non-standard-attributes](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-non-standard-attributes)
|
|
38
|
+
*/
|
|
39
|
+
tailwindAttributes?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Path to the Tailwind configuration file (v3).
|
|
42
|
+
* @docs [prettier-plugin-tailwindcss#specifying-your-tailwind-javascript-config-path-tailwind-css-v3](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-javascript-config-path-tailwind-css-v3)
|
|
43
|
+
*/
|
|
44
|
+
tailwindConfig?: `./${string}`;
|
|
45
|
+
/**
|
|
46
|
+
* List of functions or tagged templates to sort classes in. Supports regex patterns.
|
|
47
|
+
* @docs [prettier-plugin-tailwindcss#sorting-classes-in-function-calls](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#sorting-classes-in-function-calls)
|
|
48
|
+
*/
|
|
49
|
+
tailwindFunctions?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Prevent automatic removal of duplicate classes.
|
|
52
|
+
* @docs [prettier-plugin-tailwindcss#preserving-duplicate-classes](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-duplicate-classes)
|
|
53
|
+
*/
|
|
54
|
+
tailwindPreserveDuplicates?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Prevent automatic removal of unnecessary whitespace.
|
|
57
|
+
* @docs [prettier-plugin-tailwindcss#preserving-whitespace](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#preserving-whitespace)
|
|
58
|
+
*/
|
|
59
|
+
tailwindPreserveWhitespace?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Path to the CSS entry point (Tailwind CSS v4+).
|
|
62
|
+
* @default "./tailwind.css"
|
|
63
|
+
* @docs [prettier-plugin-tailwindcss#specifying-your-tailwind-stylesheet-path-tailwind-css-v4](https://github.com/tailwindlabs/prettier-plugin-tailwindcss#specifying-your-tailwind-stylesheet-path-tailwind-css-v4)
|
|
64
|
+
*/
|
|
65
|
+
tailwindStylesheet?: `./${string}`;
|
|
66
|
+
};
|
|
67
|
+
type OptionsAstro = {
|
|
68
|
+
/**
|
|
69
|
+
* Enable automatic formatting of attributes to shorthand form (e.g., `<element {name} />`).
|
|
70
|
+
* @default false
|
|
71
|
+
* @docs [prettier-plugin-astro#astroallowshorthand](https://github.com/withastro/prettier-plugin-astro#astroallowshorthand)
|
|
72
|
+
*/
|
|
73
|
+
astroAllowShorthand?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Skip formatting of JavaScript frontmatter.
|
|
76
|
+
* @default false
|
|
77
|
+
* @docs [prettier-plugin-astro#astroskipfrontmatter](https://github.com/withastro/prettier-plugin-astro#astroskipfrontmatter)
|
|
78
|
+
*/
|
|
79
|
+
astroSkipFrontmatter?: boolean;
|
|
80
|
+
overrides?: Array<
|
|
81
|
+
/**
|
|
82
|
+
* @docs [prettier-plugin-astro#recommended-configuration](https://github.com/withastro/prettier-plugin-astro#recommended-configuration)
|
|
83
|
+
*/
|
|
84
|
+
{
|
|
85
|
+
files: "*.astro";
|
|
86
|
+
options: {
|
|
87
|
+
parser: "astro";
|
|
88
|
+
};
|
|
89
|
+
} | NonNullable<Config["overrides"]>[number]>;
|
|
90
|
+
plugins?: Array<"prettier-plugin-astro" | RestOfAllowedPluginTypes>;
|
|
91
|
+
};
|
|
92
|
+
type OptionsSortImports = {
|
|
93
|
+
/**
|
|
94
|
+
* Regex patterns to control import grouping and order.
|
|
95
|
+
* Supports special words: `<BUILTIN_MODULES>`, `<THIRD_PARTY_MODULES>`, `<TYPES>`.
|
|
96
|
+
* Use empty strings (`""`) to add blank lines between groups.
|
|
97
|
+
* @default ["^https?://", "<BUILTIN_MODULES>", "^(bun|jsr|npm):", "<THIRD_PARTY_MODULES>", "^(@/|[#~$%])", "^(?!.*[.]css$)[./].*$", ".css$"]
|
|
98
|
+
* @docs [prettier-plugin-sort-imports#importorder](https://github.com/ianvs/prettier-plugin-sort-imports#importorder)
|
|
99
|
+
*/
|
|
100
|
+
importOrder?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Enable case-sensitive sorting within import groups.
|
|
103
|
+
* @default false
|
|
104
|
+
* @docs [prettier-plugin-sort-imports#importordercasesensitive](https://github.com/ianvs/prettier-plugin-sort-imports#importordercasesensitive)
|
|
105
|
+
*/
|
|
106
|
+
importOrderCaseSensitive?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Babel parser plugins to understand file syntax (e.g., `["typescript", "jsx"]`).
|
|
109
|
+
* Pass plugin options as JSON: `["decorators", { "decoratorsBeforeExport": true }]`.
|
|
110
|
+
* @default ["typescript", "jsx"]
|
|
111
|
+
* @docs [prettier-plugin-sort-imports#importorderparserplugins](https://github.com/ianvs/prettier-plugin-sort-imports#importorderparserplugins)
|
|
112
|
+
*/
|
|
113
|
+
importOrderParserPlugins?: string[];
|
|
114
|
+
/**
|
|
115
|
+
* Regex patterns for side-effect imports that are safe to reorder.
|
|
116
|
+
* By default, side-effect imports are not reordered. Use `^pattern$` for exact matches.
|
|
117
|
+
* @default [".css$"]
|
|
118
|
+
* @docs [prettier-plugin-sort-imports#importordersafesideeffects](https://github.com/ianvs/prettier-plugin-sort-imports#importordersafesideeffects)
|
|
119
|
+
*/
|
|
120
|
+
importOrderSafeSideEffects?: string[];
|
|
121
|
+
/**
|
|
122
|
+
* TypeScript version to enable modern import syntax features (e.g., mixed type/value imports).
|
|
123
|
+
* @default "1.0.0"
|
|
124
|
+
* @docs [prettier-plugin-sort-imports#importordertypescriptversion](https://github.com/ianvs/prettier-plugin-sort-imports#importordertypescriptversion)
|
|
125
|
+
*/
|
|
126
|
+
importOrderTypeScriptVersion?: string;
|
|
127
|
+
plugins?: Array<"@ianvs/prettier-plugin-sort-imports" | RestOfAllowedPluginTypes>;
|
|
128
|
+
};
|
|
129
|
+
interface OptionsPrettierConfig {
|
|
130
|
+
/**
|
|
131
|
+
* Astro configuration
|
|
132
|
+
*
|
|
133
|
+
* Requires installing:
|
|
134
|
+
* - `prettier-plugin-astro`
|
|
135
|
+
*
|
|
136
|
+
* @default false
|
|
137
|
+
* @docs [prettier-plugin-astro](https://github.com/withastro/prettier-plugin-astro#configuration)
|
|
138
|
+
*/
|
|
139
|
+
astro?: boolean | OptionsAstro;
|
|
140
|
+
/**
|
|
141
|
+
* Base Prettier configuration with opinionated defaults.
|
|
142
|
+
* Includes settings for tabs, print width, quotes, trailing commas, and experimental features.
|
|
143
|
+
*
|
|
144
|
+
* @default true
|
|
145
|
+
*/
|
|
146
|
+
base?: boolean | Config;
|
|
147
|
+
/**
|
|
148
|
+
* Sort imports configuration
|
|
149
|
+
*
|
|
150
|
+
* Requires installing:
|
|
151
|
+
* - `prettier-plugin-sort-imports`
|
|
152
|
+
*
|
|
153
|
+
* @default false
|
|
154
|
+
* @docs [prettier-plugin-sort-imports](https://github.com/ianvs/prettier-plugin-sort-imports#configuration)
|
|
155
|
+
*/
|
|
156
|
+
sortImports?: boolean | OptionsSortImports;
|
|
157
|
+
/**
|
|
158
|
+
* Tailwind CSS configuration
|
|
159
|
+
*
|
|
160
|
+
* Requires installing:
|
|
161
|
+
* - `prettier-plugin-tailwindcss`
|
|
162
|
+
* - `prettier-plugin-classnames`
|
|
163
|
+
* - `prettier-plugin-merge`
|
|
164
|
+
*
|
|
165
|
+
* @default false
|
|
166
|
+
* @docs
|
|
167
|
+
* - [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
|
|
168
|
+
* - [prettier-plugin-classnames](https://github.com/ony3000/prettier-plugin-classnames)
|
|
169
|
+
* - [prettier-plugin-merge](https://github.com/ony3000/prettier-plugin-merge)
|
|
170
|
+
*/
|
|
171
|
+
tailwindcss?: boolean | OptionsTailwindCss;
|
|
172
|
+
}
|
|
173
|
+
type ResolvedPrettierConfig = Config & OptionsAstro & OptionsSortImports & OptionsTailwindCss & Record<string, unknown>;
|
|
174
|
+
type ExtractOptions<TUnion> = Extract<TUnion, object>;
|
|
175
|
+
//#endregion
|
|
176
|
+
export { OptionsTailwindCss as a, OptionsSortImports as i, OptionsAstro as n, ResolvedPrettierConfig as o, OptionsPrettierConfig as r, ExtractOptions as t };
|
|
177
|
+
//# sourceMappingURL=types-nDUANBXB.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { isArray, isObject } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
+
import { isPackageExists } from "local-pkg";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.ts
|
|
6
|
+
/**
|
|
7
|
+
* @description Resolves a boolean or object option to an object.
|
|
8
|
+
* If the option is an object, it returns it as-is. Otherwise, returns an empty object.
|
|
9
|
+
*/
|
|
10
|
+
const resolveOptions = (option) => {
|
|
11
|
+
return isObject(option) ? option : {};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @description Merges two Prettier configurations.
|
|
15
|
+
* Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.
|
|
16
|
+
*/
|
|
17
|
+
const mergeTwoConfigs = (formerConfig, latterConfig) => {
|
|
18
|
+
const configAccumulator = { ...formerConfig };
|
|
19
|
+
for (const [latterConfigKey, latterConfigValue] of Object.entries(latterConfig)) {
|
|
20
|
+
const accumulatedConfigValue = configAccumulator[latterConfigKey];
|
|
21
|
+
configAccumulator[latterConfigKey] = isArray(latterConfigValue) && isArray(accumulatedConfigValue) ? [...accumulatedConfigValue, ...latterConfigValue] : latterConfigValue;
|
|
22
|
+
}
|
|
23
|
+
return configAccumulator;
|
|
24
|
+
};
|
|
25
|
+
const combineConfigs = async (configArray) => {
|
|
26
|
+
const resolvedConfigArray = await Promise.all(configArray);
|
|
27
|
+
let accumulatedConfig = {};
|
|
28
|
+
for (const config of resolvedConfigArray) {
|
|
29
|
+
if (!config) continue;
|
|
30
|
+
accumulatedConfig = mergeTwoConfigs(accumulatedConfig, config);
|
|
31
|
+
}
|
|
32
|
+
return accumulatedConfig;
|
|
33
|
+
};
|
|
34
|
+
const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
|
|
35
|
+
const isCwdInScope = isPackageExists("@zayne-labs/prettier-config");
|
|
36
|
+
const isPackageInScope = (name) => isPackageExists(name, { paths: [scopeUrl] });
|
|
37
|
+
/**
|
|
38
|
+
* @description
|
|
39
|
+
* - Ensures that packages are installed in the current scope.
|
|
40
|
+
* - If they are not installed, and the user is in a TTY, and the user is not in a CI environment,
|
|
41
|
+
* and the user is in the same scope as this package, then prompt the user to
|
|
42
|
+
* install the packages.
|
|
43
|
+
*
|
|
44
|
+
* @param packages - The packages to ensure are installed.
|
|
45
|
+
*/
|
|
46
|
+
const ensurePackages = async (packages) => {
|
|
47
|
+
if (process.env.CI || !process.stdout.isTTY || !isCwdInScope) return;
|
|
48
|
+
const nonExistingPackages = packages.filter((pkg) => pkg && !isPackageInScope(pkg));
|
|
49
|
+
if (nonExistingPackages.length === 0) return;
|
|
50
|
+
if (await (await import("@clack/prompts")).confirm({ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?` })) await (await import("@antfu/install-pkg")).installPackage(nonExistingPackages, { dev: true });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { resolveOptions as a, mergeTwoConfigs as i, ensurePackages as n, isPackageInScope as r, combineConfigs as t };
|
|
55
|
+
//# sourceMappingURL=utils-CEqE7-_1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-CEqE7-_1.js","names":["configAccumulator: ResolvedPrettierConfig","accumulatedConfig: ResolvedPrettierConfig"],"sources":["../src/utils.ts"],"sourcesContent":["import { fileURLToPath } from \"node:url\";\nimport { isArray, isObject, type Awaitable } from \"@zayne-labs/toolkit-type-helpers\";\nimport { isPackageExists } from \"local-pkg\";\nimport type { ResolvedPrettierConfig } from \"./types\";\n\n/**\n * @description Resolves a boolean or object option to an object.\n * If the option is an object, it returns it as-is. Otherwise, returns an empty object.\n */\nexport const resolveOptions = <TObject>(option: boolean | TObject | undefined) => {\n\treturn isObject(option) ? option : ({} as TObject);\n};\n\n/**\n * @description Merges two Prettier configurations.\n * Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.\n */\nexport const mergeTwoConfigs = (\n\tformerConfig: ResolvedPrettierConfig,\n\tlatterConfig: ResolvedPrettierConfig\n): ResolvedPrettierConfig => {\n\tconst configAccumulator: ResolvedPrettierConfig = {\n\t\t...formerConfig,\n\t};\n\n\tfor (const [latterConfigKey, latterConfigValue] of Object.entries(latterConfig)) {\n\t\tconst accumulatedConfigValue = configAccumulator[latterConfigKey];\n\n\t\tconfigAccumulator[latterConfigKey] =\n\t\t\tisArray(latterConfigValue) && isArray(accumulatedConfigValue) ?\n\t\t\t\t[...accumulatedConfigValue, ...latterConfigValue]\n\t\t\t:\tlatterConfigValue;\n\t}\n\n\treturn configAccumulator;\n};\n\nexport const combineConfigs = async (\n\tconfigArray: Array<Awaitable<ResolvedPrettierConfig | undefined>>\n): Promise<ResolvedPrettierConfig> => {\n\t// eslint-disable-next-line ts-eslint/await-thenable -- Ignore\n\tconst resolvedConfigArray = await Promise.all(configArray);\n\n\tlet accumulatedConfig: ResolvedPrettierConfig = {};\n\n\tfor (const config of resolvedConfigArray) {\n\t\tif (!config) continue;\n\n\t\taccumulatedConfig = mergeTwoConfigs(accumulatedConfig, config);\n\t}\n\n\treturn accumulatedConfig;\n};\n\nconst scopeUrl = fileURLToPath(new URL(\".\", import.meta.url));\nconst isCwdInScope = isPackageExists(\"@zayne-labs/prettier-config\");\n\nexport const isPackageInScope = (name: string): boolean => isPackageExists(name, { paths: [scopeUrl] });\n\n/**\n * @description\n * - Ensures that packages are installed in the current scope.\n * - If they are not installed, and the user is in a TTY, and the user is not in a CI environment,\n * and the user is in the same scope as this package, then prompt the user to\n * install the packages.\n *\n * @param packages - The packages to ensure are installed.\n */\nexport const ensurePackages = async (packages: Array<string | undefined>): Promise<void> => {\n\tif (process.env.CI || !process.stdout.isTTY || !isCwdInScope) return;\n\n\tconst nonExistingPackages = packages.filter((pkg) => pkg && !isPackageInScope(pkg));\n\n\tif (nonExistingPackages.length === 0) return;\n\n\tconst clackPrompt = await import(\"@clack/prompts\");\n\n\tconst result = await clackPrompt.confirm({\n\t\tmessage: `${nonExistingPackages.length === 1 ? \"Package is\" : \"Packages are\"} required for this config: ${nonExistingPackages.join(\", \")}. Do you want to install them?`,\n\t});\n\n\tif (result) {\n\t\tconst antfuPkg = await import(\"@antfu/install-pkg\");\n\n\t\tawait antfuPkg.installPackage(nonExistingPackages as string[], { dev: true });\n\t}\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,kBAA2B,WAA0C;AACjF,QAAO,SAAS,OAAO,GAAG,SAAU,EAAE;;;;;;AAOvC,MAAa,mBACZ,cACA,iBAC4B;CAC5B,MAAMA,oBAA4C,EACjD,GAAG,cACH;AAED,MAAK,MAAM,CAAC,iBAAiB,sBAAsB,OAAO,QAAQ,aAAa,EAAE;EAChF,MAAM,yBAAyB,kBAAkB;AAEjD,oBAAkB,mBACjB,QAAQ,kBAAkB,IAAI,QAAQ,uBAAuB,GAC5D,CAAC,GAAG,wBAAwB,GAAG,kBAAkB,GAChD;;AAGJ,QAAO;;AAGR,MAAa,iBAAiB,OAC7B,gBACqC;CAErC,MAAM,sBAAsB,MAAM,QAAQ,IAAI,YAAY;CAE1D,IAAIC,oBAA4C,EAAE;AAElD,MAAK,MAAM,UAAU,qBAAqB;AACzC,MAAI,CAAC,OAAQ;AAEb,sBAAoB,gBAAgB,mBAAmB,OAAO;;AAG/D,QAAO;;AAGR,MAAM,WAAW,cAAc,IAAI,IAAI,KAAK,OAAO,KAAK,IAAI,CAAC;AAC7D,MAAM,eAAe,gBAAgB,8BAA8B;AAEnE,MAAa,oBAAoB,SAA0B,gBAAgB,MAAM,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;;;;;;;;;;AAWvG,MAAa,iBAAiB,OAAO,aAAuD;AAC3F,KAAI,QAAQ,IAAI,MAAM,CAAC,QAAQ,OAAO,SAAS,CAAC,aAAc;CAE9D,MAAM,sBAAsB,SAAS,QAAQ,QAAQ,OAAO,CAAC,iBAAiB,IAAI,CAAC;AAEnF,KAAI,oBAAoB,WAAW,EAAG;AAQtC,KAJe,OAFK,MAAM,OAAO,mBAEA,QAAQ,EACxC,SAAS,GAAG,oBAAoB,WAAW,IAAI,eAAe,eAAe,6BAA6B,oBAAoB,KAAK,KAAK,CAAC,iCACzI,CAAC,CAKD,QAFiB,MAAM,OAAO,uBAEf,eAAe,qBAAiC,EAAE,KAAK,MAAM,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { o as ResolvedPrettierConfig } from "./types-nDUANBXB.js";
|
|
2
|
+
import { Awaitable } from "@zayne-labs/toolkit-type-helpers";
|
|
3
|
+
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description Resolves a boolean or object option to an object.
|
|
8
|
+
* If the option is an object, it returns it as-is. Otherwise, returns an empty object.
|
|
9
|
+
*/
|
|
10
|
+
declare const resolveOptions: <TObject>(option: boolean | TObject | undefined) => TObject;
|
|
11
|
+
/**
|
|
12
|
+
* @description Merges two Prettier configurations.
|
|
13
|
+
* Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.
|
|
14
|
+
*/
|
|
15
|
+
declare const mergeTwoConfigs: (formerConfig: ResolvedPrettierConfig, latterConfig: ResolvedPrettierConfig) => ResolvedPrettierConfig;
|
|
16
|
+
declare const combineConfigs: (configArray: Array<Awaitable<ResolvedPrettierConfig | undefined>>) => Promise<ResolvedPrettierConfig>;
|
|
17
|
+
declare const isPackageInScope: (name: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @description
|
|
20
|
+
* - Ensures that packages are installed in the current scope.
|
|
21
|
+
* - If they are not installed, and the user is in a TTY, and the user is not in a CI environment,
|
|
22
|
+
* and the user is in the same scope as this package, then prompt the user to
|
|
23
|
+
* install the packages.
|
|
24
|
+
*
|
|
25
|
+
* @param packages - The packages to ensure are installed.
|
|
26
|
+
*/
|
|
27
|
+
declare const ensurePackages: (packages: Array<string | undefined>) => Promise<void>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { combineConfigs, ensurePackages, isPackageInScope, mergeTwoConfigs, resolveOptions };
|
|
30
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/prettier-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.8",
|
|
5
5
|
"description": "Zayne Labs' Prettier config",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"exports": {
|
|
23
|
-
".": "./dist/index.js"
|
|
23
|
+
".": "./dist/index.js",
|
|
24
|
+
"./utils": "./dist/utils.js",
|
|
25
|
+
"./constants/*": "./dist/constants/*.js"
|
|
24
26
|
},
|
|
25
27
|
"files": [
|
|
26
28
|
"dist"
|
|
@@ -29,7 +31,10 @@
|
|
|
29
31
|
"node": ">=18.x"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@
|
|
34
|
+
"@antfu/install-pkg": "1.1.0",
|
|
35
|
+
"@clack/prompts": "0.11.0",
|
|
36
|
+
"@zayne-labs/toolkit-type-helpers": "^0.12.17",
|
|
37
|
+
"local-pkg": "1.1.2"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
@@ -40,7 +45,7 @@
|
|
|
40
45
|
"publint": "^0.3.16",
|
|
41
46
|
"tsdown": "^0.18.2",
|
|
42
47
|
"typescript": "5.9.3",
|
|
43
|
-
"@zayne-labs/tsconfig": "0.11.
|
|
48
|
+
"@zayne-labs/tsconfig": "0.11.8"
|
|
44
49
|
},
|
|
45
50
|
"publishConfig": {
|
|
46
51
|
"access": "public",
|