@zayne-labs/prettier-config 0.11.9 → 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/dist/index.d.ts +1 -1
- package/dist/index.js +20 -14
- package/dist/index.js.map +1 -1
- package/dist/{types-B17hDweL.d.ts → types-RB-Voczh.d.ts} +5 -3
- 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 +2 -2
- package/dist/utils-CEqE7-_1.js.map +0 -1
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
|
|
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
|
|
@@ -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",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"publint": "0.3.16",
|
|
71
71
|
"tsdown": "0.18.2",
|
|
72
72
|
"typescript": "5.9.3",
|
|
73
|
-
"@zayne-labs/tsconfig": "0.11.
|
|
73
|
+
"@zayne-labs/tsconfig": "0.11.10"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
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"}
|