@zayne-labs/prettier-config 0.11.8 → 0.11.10
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 +8 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -15
- package/dist/index.js.map +1 -1
- package/dist/{types-nDUANBXB.d.ts → types-RB-Voczh.d.ts} +6 -4
- package/dist/{utils-CEqE7-_1.js → utils-AXdZ-_yx.js} +6 -2
- package/dist/utils-AXdZ-_yx.js.map +1 -0
- package/dist/utils.d.ts +5 -2
- package/dist/utils.js +2 -2
- package/package.json +35 -10
- package/dist/utils-CEqE7-_1.js.map +0 -1
package/README.md
CHANGED
|
@@ -26,9 +26,10 @@ import { zayne } from "@zayne-labs/prettier-config";
|
|
|
26
26
|
|
|
27
27
|
export default zayne({
|
|
28
28
|
base: true, // Enabled by default
|
|
29
|
-
sortImports: true,
|
|
29
|
+
sortImports: true, // Enabled by default
|
|
30
30
|
tailwindcss: true,
|
|
31
|
-
astro:
|
|
31
|
+
astro: true,
|
|
32
|
+
// ...more to come
|
|
32
33
|
});
|
|
33
34
|
```
|
|
34
35
|
|
|
@@ -39,13 +40,13 @@ The `zayne` factory accepts an options object as the first argument:
|
|
|
39
40
|
| Option | Type | Default | Description |
|
|
40
41
|
| ------------- | ------------------------------- | ------- | ---------------------------------------------- |
|
|
41
42
|
| `base` | `boolean \| Config` | `true` | Opinionated base defaults. |
|
|
42
|
-
| `sortImports` | `boolean \| OptionsSortImports` | `
|
|
43
|
+
| `sortImports` | `boolean \| OptionsSortImports` | `true` | Enables `@ianvs/prettier-plugin-sort-imports`. |
|
|
43
44
|
| `tailwindcss` | `boolean \| OptionsTailwindCss` | `false` | Enables Tailwind and ClassNames plugins. |
|
|
44
45
|
| `astro` | `boolean \| OptionsAstro` | `false` | Enables `prettier-plugin-astro`. |
|
|
45
46
|
|
|
46
47
|
### Default Import Sorting Rules
|
|
47
48
|
|
|
48
|
-
When `sortImports` is enabled, imports are organized by "distance" from the current file:
|
|
49
|
+
When `sortImports` is enabled (which it is by default), imports are organized by "distance" from the current file:
|
|
49
50
|
|
|
50
51
|
1. **User patterns**: Any custom patterns you pass via `importOrder` are prioritized at the top.
|
|
51
52
|
2. **URLs**: Remote modules (e.g., `https://esm.sh/...`).
|
|
@@ -80,7 +81,7 @@ import { zayne } from "@zayne-labs/prettier-config";
|
|
|
80
81
|
|
|
81
82
|
export default zayne(
|
|
82
83
|
{
|
|
83
|
-
|
|
84
|
+
tailwindcss: true,
|
|
84
85
|
},
|
|
85
86
|
// Extra config objects to merge
|
|
86
87
|
{
|
|
@@ -92,7 +93,8 @@ export default zayne(
|
|
|
92
93
|
|
|
93
94
|
## Plugin Auto-Installation
|
|
94
95
|
|
|
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.
|
|
96
|
+
This config won't bloat your `node_modules` with plugins you don't use. When you enable a feature (like `astro` or `tailwindcss` for instance), it checks if the required plugins are installed.
|
|
97
|
+
If missing, it will prompt you in the terminal to auto-install them when you run `prettier --write .` cli command.
|
|
96
98
|
|
|
97
99
|
## License
|
|
98
100
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as OptionsTailwindCss, i as OptionsSortImports, n as OptionsAstro, o as ResolvedPrettierConfig, r as OptionsPrettierConfig, t as ExtractOptions } from "./types-
|
|
1
|
+
import { a as OptionsTailwindCss, i as OptionsSortImports, n as OptionsAstro, o as ResolvedPrettierConfig, r as OptionsPrettierConfig, t as ExtractOptions } from "./types-RB-Voczh.js";
|
|
2
2
|
|
|
3
3
|
//#region src/configs/astro.d.ts
|
|
4
4
|
declare const astro: (options: ExtractOptions<OptionsPrettierConfig["astro"]>) => Promise<typeof options>;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ensurePackages, o as resolveOptions, r as interopDefault, t as combineConfigs } from "./utils-AXdZ-_yx.js";
|
|
2
2
|
import { n as getDefaultTailwindSettings, t as getDefaultImportSortingOrder } from "./defaults-DCbiIW5Q.js";
|
|
3
3
|
|
|
4
4
|
//#region src/configs/astro.ts
|
|
5
5
|
const astro = async (options) => {
|
|
6
|
-
|
|
7
|
-
await
|
|
6
|
+
await ensurePackages(["prettier-plugin-astro"]);
|
|
7
|
+
const prettierPluginAstro = await interopDefault(import("prettier-plugin-astro"));
|
|
8
8
|
return {
|
|
9
9
|
...options,
|
|
10
10
|
overrides: [{
|
|
11
11
|
files: "*.astro",
|
|
12
12
|
options: { parser: "astro" }
|
|
13
13
|
}, ...options.overrides ?? []],
|
|
14
|
-
plugins: [
|
|
14
|
+
plugins: [prettierPluginAstro, ...options.plugins ?? []]
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -34,11 +34,16 @@ const base = (options) => {
|
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/configs/tailwindcss.ts
|
|
36
36
|
const tailwindcss = async (options) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
await ensurePackages([
|
|
38
|
+
"prettier-plugin-tailwindcss",
|
|
39
|
+
"prettier-plugin-classnames",
|
|
40
|
+
"prettier-plugin-merge"
|
|
41
|
+
]);
|
|
42
|
+
const [prettierTailwindcssPlugin, prettierClassnamesPlugin, prettierMergePlugin] = await Promise.all([
|
|
43
|
+
interopDefault(import("prettier-plugin-tailwindcss")),
|
|
44
|
+
interopDefault(import("prettier-plugin-classnames")),
|
|
45
|
+
interopDefault(import("prettier-plugin-merge"))
|
|
46
|
+
]);
|
|
42
47
|
const tailwindSettings = getDefaultTailwindSettings();
|
|
43
48
|
return {
|
|
44
49
|
tailwindStylesheet: tailwindSettings.tailwindStylesheet,
|
|
@@ -46,9 +51,10 @@ const tailwindcss = async (options) => {
|
|
|
46
51
|
customAttributes: [...tailwindSettings.tailwindAttributes, ...options.customAttributes ?? []],
|
|
47
52
|
customFunctions: [...tailwindSettings.tailwindFunctions, ...options.customFunctions ?? []],
|
|
48
53
|
plugins: [
|
|
49
|
-
|
|
54
|
+
prettierTailwindcssPlugin,
|
|
55
|
+
prettierClassnamesPlugin,
|
|
50
56
|
...options.plugins ?? [],
|
|
51
|
-
|
|
57
|
+
prettierMergePlugin
|
|
52
58
|
],
|
|
53
59
|
tailwindAttributes: [...tailwindSettings.tailwindAttributes, ...options.tailwindAttributes ?? []],
|
|
54
60
|
tailwindFunctions: [...tailwindSettings.tailwindFunctions, ...options.tailwindFunctions ?? []]
|
|
@@ -58,8 +64,8 @@ const tailwindcss = async (options) => {
|
|
|
58
64
|
//#endregion
|
|
59
65
|
//#region src/configs/sort.ts
|
|
60
66
|
const sortImports = async (options) => {
|
|
61
|
-
|
|
62
|
-
await
|
|
67
|
+
await ensurePackages(["@ianvs/prettier-plugin-sort-imports"]);
|
|
68
|
+
const prettierSortImportsPlugin = await interopDefault(import("@ianvs/prettier-plugin-sort-imports"));
|
|
63
69
|
const sortingOrder = getDefaultImportSortingOrder();
|
|
64
70
|
return {
|
|
65
71
|
...options,
|
|
@@ -69,7 +75,7 @@ const sortImports = async (options) => {
|
|
|
69
75
|
sortingOrder.css
|
|
70
76
|
],
|
|
71
77
|
importOrderSafeSideEffects: [sortingOrder.css, ...options.importOrderSafeSideEffects ?? []],
|
|
72
|
-
plugins: [
|
|
78
|
+
plugins: [prettierSortImportsPlugin, ...options.plugins ?? []]
|
|
73
79
|
};
|
|
74
80
|
};
|
|
75
81
|
|
|
@@ -99,7 +105,7 @@ const sortImports = async (options) => {
|
|
|
99
105
|
* ```
|
|
100
106
|
*/
|
|
101
107
|
const zayne = async (options = {}, ...extraConfigs) => {
|
|
102
|
-
const { astro: enabledAstro = false, base: enabledBase = true, sortImports: enabledSortImports =
|
|
108
|
+
const { astro: enabledAstro = false, base: enabledBase = true, sortImports: enabledSortImports = true, tailwindcss: enabledTailwindcss = false } = options;
|
|
103
109
|
return await combineConfigs([
|
|
104
110
|
enabledBase ? base(resolveOptions(enabledBase)) : void 0,
|
|
105
111
|
enabledAstro ? astro(resolveOptions(enabledAstro)) : void 0,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\
|
|
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, interopDefault } from \"@/utils\";\n\nexport const astro = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"astro\"]>\n): Promise<typeof options> => {\n\tawait ensurePackages([\"prettier-plugin-astro\"]);\n\n\tconst prettierPluginAstro = await interopDefault(import(\"prettier-plugin-astro\"));\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: [prettierPluginAstro, ...(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, interopDefault } from \"@/utils\";\n\n\nexport const tailwindcss = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"tailwindcss\"]>\n): Promise<typeof options> => {\n\tawait ensurePackages([\n\t\t\"prettier-plugin-tailwindcss\",\n\t\t\"prettier-plugin-classnames\",\n\t\t\"prettier-plugin-merge\",\n\t]);\n\n\tconst [prettierTailwindcssPlugin, prettierClassnamesPlugin, prettierMergePlugin] = await Promise.all([\n\t\tinteropDefault(import(\"prettier-plugin-tailwindcss\")),\n\t\tinteropDefault(import(\"prettier-plugin-classnames\")),\n\t\tinteropDefault(import(\"prettier-plugin-merge\")),\n\t]);\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\tprettierTailwindcssPlugin,\n\t\t\tprettierClassnamesPlugin,\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\tprettierMergePlugin,\n\t\t],\n\n\t\ttailwindAttributes: [...tailwindSettings.tailwindAttributes, ...(options.tailwindAttributes ?? [])],\n\t\ttailwindFunctions: [...tailwindSettings.tailwindFunctions, ...(options.tailwindFunctions ?? [])],\n\t};\n};","import { getDefaultImportSortingOrder } from \"@/constants/defaults\";\nimport type { ExtractOptions, OptionsPrettierConfig } from \"@/types\";\nimport { ensurePackages, interopDefault } from \"@/utils\";\n\nexport const sortImports = async (\n\toptions: ExtractOptions<OptionsPrettierConfig[\"sortImports\"]>\n): Promise<typeof options> => {\n\tawait ensurePackages([\"@ianvs/prettier-plugin-sort-imports\"]);\n\n\tconst prettierSortImportsPlugin = await interopDefault(import(\"@ianvs/prettier-plugin-sort-imports\"));\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: [prettierSortImportsPlugin, ...(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 = true,\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;AAC7B,OAAM,eAAe,CAAC,wBAAwB,CAAC;CAE/C,MAAM,sBAAsB,MAAM,eAAe,OAAO,yBAAyB;AAEjF,QAAO;EACN,GAAG;EAEH,WAAW,CACV;GACC,OAAO;GACP,SAAS,EAAE,QAAQ,SAAS;GAC5B,EACD,GAAI,QAAQ,aAAa,EAAE,CAC3B;EAED,SAAS,CAAC,qBAAqB,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;;;;;ACTF,MAAa,cAAc,OAC1B,YAC6B;AAC7B,OAAM,eAAe;EACpB;EACA;EACA;EACA,CAAC;CAEF,MAAM,CAAC,2BAA2B,0BAA0B,uBAAuB,MAAM,QAAQ,IAAI;EACpG,eAAe,OAAO,+BAA+B;EACrD,eAAe,OAAO,8BAA8B;EACpD,eAAe,OAAO,yBAAyB;EAC/C,CAAC;CAEF,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;GACA;GAEA,GAAI,QAAQ,WAAW,EAAE;GAMzB;GACA;EAED,oBAAoB,CAAC,GAAG,iBAAiB,oBAAoB,GAAI,QAAQ,sBAAsB,EAAE,CAAE;EACnG,mBAAmB,CAAC,GAAG,iBAAiB,mBAAmB,GAAI,QAAQ,qBAAqB,EAAE,CAAE;EAChG;;;;;ACzCF,MAAa,cAAc,OAC1B,YAC6B;AAC7B,OAAM,eAAe,CAAC,sCAAsC,CAAC;CAE7D,MAAM,4BAA4B,MAAM,eAAe,OAAO,uCAAuC;CAErG,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,2BAA2B,GAAI,QAAQ,WAAW,EAAE,CAAE;EAChE;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSF,MAAa,QAAQ,OACpB,UAAiC,EAAE,EACnC,GAAG,iBACC;CACJ,MAAM,EACL,OAAO,eAAe,OACtB,MAAM,cAAc,MACpB,aAAa,qBAAqB,MAClC,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyString } from "@zayne-labs/toolkit-type-helpers";
|
|
1
|
+
import { AnyString, ExtractUnion } from "@zayne-labs/toolkit-type-helpers";
|
|
2
2
|
import { Config, Plugin } from "prettier";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
@@ -150,7 +150,7 @@ interface OptionsPrettierConfig {
|
|
|
150
150
|
* Requires installing:
|
|
151
151
|
* - `prettier-plugin-sort-imports`
|
|
152
152
|
*
|
|
153
|
-
* @default
|
|
153
|
+
* @default true
|
|
154
154
|
* @docs [prettier-plugin-sort-imports](https://github.com/ianvs/prettier-plugin-sort-imports#configuration)
|
|
155
155
|
*/
|
|
156
156
|
sortImports?: boolean | OptionsSortImports;
|
|
@@ -170,8 +170,10 @@ interface OptionsPrettierConfig {
|
|
|
170
170
|
*/
|
|
171
171
|
tailwindcss?: boolean | OptionsTailwindCss;
|
|
172
172
|
}
|
|
173
|
-
type ResolvedPrettierConfig = Config & OptionsAstro & OptionsSortImports & OptionsTailwindCss &
|
|
173
|
+
type ResolvedPrettierConfig = Omit<Config & OptionsAstro & OptionsSortImports & OptionsTailwindCss, "plugins"> & {
|
|
174
|
+
plugins?: Array<ExtractUnion<OptionsAstro["plugins"]> | ExtractUnion<OptionsSortImports["plugins"]> | ExtractUnion<OptionsTailwindCss["plugins"]>>;
|
|
175
|
+
};
|
|
174
176
|
type ExtractOptions<TUnion> = Extract<TUnion, object>;
|
|
175
177
|
//#endregion
|
|
176
178
|
export { OptionsTailwindCss as a, OptionsSortImports as i, OptionsAstro as n, ResolvedPrettierConfig as o, OptionsPrettierConfig as r, ExtractOptions as t };
|
|
177
|
-
//# sourceMappingURL=types-
|
|
179
|
+
//# sourceMappingURL=types-RB-Voczh.d.ts.map
|
|
@@ -22,6 +22,10 @@ const mergeTwoConfigs = (formerConfig, latterConfig) => {
|
|
|
22
22
|
}
|
|
23
23
|
return configAccumulator;
|
|
24
24
|
};
|
|
25
|
+
const interopDefault = async (module) => {
|
|
26
|
+
const resolved = await module;
|
|
27
|
+
return resolved.default ?? resolved;
|
|
28
|
+
};
|
|
25
29
|
const combineConfigs = async (configArray) => {
|
|
26
30
|
const resolvedConfigArray = await Promise.all(configArray);
|
|
27
31
|
let accumulatedConfig = {};
|
|
@@ -51,5 +55,5 @@ const ensurePackages = async (packages) => {
|
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
//#endregion
|
|
54
|
-
export {
|
|
55
|
-
//# sourceMappingURL=utils-
|
|
58
|
+
export { mergeTwoConfigs as a, isPackageInScope as i, ensurePackages as n, resolveOptions as o, interopDefault as r, combineConfigs as t };
|
|
59
|
+
//# sourceMappingURL=utils-AXdZ-_yx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-AXdZ-_yx.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 interopDefault = async <TModule>(\n\tmodule: Awaitable<TModule>\n): Promise<TModule extends { default: infer TDefaultExport } ? TDefaultExport : TModule> => {\n\tconst resolved = await module;\n\n\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- casting is necessary to prevent assignability ts issues at call-site\n\treturn (resolved as { default: never }).default ?? resolved;\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,WAC2F;CAC3F,MAAM,WAAW,MAAM;AAGvB,QAAQ,SAAgC,WAAW;;AAGpD,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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as ResolvedPrettierConfig } from "./types-
|
|
1
|
+
import { o as ResolvedPrettierConfig } from "./types-RB-Voczh.js";
|
|
2
2
|
import { Awaitable } from "@zayne-labs/toolkit-type-helpers";
|
|
3
3
|
|
|
4
4
|
//#region src/utils.d.ts
|
|
@@ -13,6 +13,9 @@ declare const resolveOptions: <TObject>(option: boolean | TObject | undefined) =
|
|
|
13
13
|
* Array values (like `plugins` or `overrides`) are concatenated, while other values from the latter config overwrite the former.
|
|
14
14
|
*/
|
|
15
15
|
declare const mergeTwoConfigs: (formerConfig: ResolvedPrettierConfig, latterConfig: ResolvedPrettierConfig) => ResolvedPrettierConfig;
|
|
16
|
+
declare const interopDefault: <TModule>(module: Awaitable<TModule>) => Promise<TModule extends {
|
|
17
|
+
default: infer TDefaultExport;
|
|
18
|
+
} ? TDefaultExport : TModule>;
|
|
16
19
|
declare const combineConfigs: (configArray: Array<Awaitable<ResolvedPrettierConfig | undefined>>) => Promise<ResolvedPrettierConfig>;
|
|
17
20
|
declare const isPackageInScope: (name: string) => boolean;
|
|
18
21
|
/**
|
|
@@ -26,5 +29,5 @@ declare const isPackageInScope: (name: string) => boolean;
|
|
|
26
29
|
*/
|
|
27
30
|
declare const ensurePackages: (packages: Array<string | undefined>) => Promise<void>;
|
|
28
31
|
//#endregion
|
|
29
|
-
export { combineConfigs, ensurePackages, isPackageInScope, mergeTwoConfigs, resolveOptions };
|
|
32
|
+
export { combineConfigs, ensurePackages, interopDefault, isPackageInScope, mergeTwoConfigs, resolveOptions };
|
|
30
33
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as mergeTwoConfigs, i as isPackageInScope, n as ensurePackages, o as resolveOptions, r as interopDefault, t as combineConfigs } from "./utils-AXdZ-_yx.js";
|
|
2
2
|
|
|
3
|
-
export { combineConfigs, ensurePackages, isPackageInScope, mergeTwoConfigs, resolveOptions };
|
|
3
|
+
export { combineConfigs, ensurePackages, interopDefault, isPackageInScope, mergeTwoConfigs, resolveOptions };
|
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.10",
|
|
5
5
|
"description": "Zayne Labs' Prettier config",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,22 +30,47 @@
|
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=18.x"
|
|
32
32
|
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"prettier": "3.x.x",
|
|
35
|
+
"prettier-plugin-astro": "0.x.x",
|
|
36
|
+
"prettier-plugin-classnames": "0.x.x",
|
|
37
|
+
"prettier-plugin-merge": "0.x.x",
|
|
38
|
+
"prettier-plugin-tailwindcss": "0.x.x"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"prettier-plugin-astro": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"prettier-plugin-classnames": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"prettier-plugin-merge": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"prettier-plugin-tailwindcss": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
33
54
|
"dependencies": {
|
|
34
55
|
"@antfu/install-pkg": "1.1.0",
|
|
35
56
|
"@clack/prompts": "0.11.0",
|
|
36
|
-
"@
|
|
57
|
+
"@ianvs/prettier-plugin-sort-imports": "4.x.x",
|
|
58
|
+
"@zayne-labs/toolkit-type-helpers": "0.12.17",
|
|
37
59
|
"local-pkg": "1.1.2"
|
|
38
60
|
},
|
|
39
61
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
62
|
+
"@total-typescript/ts-reset": "0.6.1",
|
|
63
|
+
"concurrently": "9.2.1",
|
|
64
|
+
"cross-env": "10.1.0",
|
|
65
|
+
"prettier": "3.7.4",
|
|
66
|
+
"prettier-plugin-astro": "0.14.1",
|
|
67
|
+
"prettier-plugin-classnames": "0.8.6",
|
|
68
|
+
"prettier-plugin-merge": "0.8.0",
|
|
69
|
+
"prettier-plugin-tailwindcss": "0.7.2",
|
|
70
|
+
"publint": "0.3.16",
|
|
71
|
+
"tsdown": "0.18.2",
|
|
47
72
|
"typescript": "5.9.3",
|
|
48
|
-
"@zayne-labs/tsconfig": "0.11.
|
|
73
|
+
"@zayne-labs/tsconfig": "0.11.10"
|
|
49
74
|
},
|
|
50
75
|
"publishConfig": {
|
|
51
76
|
"access": "public",
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|