@nemigo/configs 0.0.4 → 0.2.0

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/eslint.d.ts CHANGED
@@ -1,13 +1,26 @@
1
- import { includeIgnoreFile } from "@eslint/compat";
1
+ import { convertIgnorePatternToMinimatch, includeIgnoreFile } from "@eslint/compat";
2
2
  import type { Config } from "@sveltejs/kit";
3
- import type { ConfigArray, InfiniteDepthConfigWithExtends } from "typescript-eslint";
3
+ import type { Linter } from "eslint";
4
+ import type { ConfigWithExtendsArray } from "./eslint.types.js";
5
+ export { includeIgnoreFile, convertIgnorePatternToMinimatch as convertIgnorePattern };
4
6
  export interface EslintConfigOptions {
7
+ /**
8
+ * Конфиг свелта для его линтига
9
+ */
5
10
  svelte?: Config;
11
+ /**
12
+ * Использование strict-правил tslint
13
+ */
6
14
  strict?: boolean;
15
+ /**
16
+ * Путь к проекту (`import.meta.dirname`) для более сложного линтинга типов (TypeChecked)
17
+ */
7
18
  service?: string;
8
- ignore?: false | string;
19
+ /**
20
+ * Путь к иному .eslint.ignore
21
+ */
22
+ ignore?: string;
9
23
  }
10
- export { includeIgnoreFile };
11
24
  /**
12
25
  * Универсальная сборка flat-конфига для 'eslint'.
13
26
  *
@@ -21,4 +34,4 @@ export { includeIgnoreFile };
21
34
  *
22
35
  * @see https://eslint.org/docs/latest/use/configure/configuration-files
23
36
  */
24
- export declare const defineConfig: ({ ignore, svelte, service, strict }?: EslintConfigOptions, ...other: InfiniteDepthConfigWithExtends[]) => ConfigArray;
37
+ export declare const defineConfig: (opts: EslintConfigOptions, ...rest: ConfigWithExtendsArray) => Linter.Config[];
package/dist/eslint.js CHANGED
@@ -1,11 +1,12 @@
1
- import { includeIgnoreFile } from "@eslint/compat";
1
+ import { convertIgnorePatternToMinimatch, includeIgnoreFile } from "@eslint/compat";
2
2
  import jslint from "@eslint/js";
3
3
  // import prettier from "eslint-config-prettier";
4
4
  import { configs as svelteConfigs } from "eslint-plugin-svelte";
5
+ import { defineConfig as eslintDefineConfig } from "eslint/config";
5
6
  import globals from "globals";
6
7
  import { join } from "node:path";
7
8
  import tslint from "typescript-eslint";
8
- export { includeIgnoreFile };
9
+ export { includeIgnoreFile, convertIgnorePatternToMinimatch as convertIgnorePattern };
9
10
  /**
10
11
  * Универсальная сборка flat-конфига для 'eslint'.
11
12
  *
@@ -19,53 +20,31 @@ export { includeIgnoreFile };
19
20
  *
20
21
  * @see https://eslint.org/docs/latest/use/configure/configuration-files
21
22
  */
22
- export const defineConfig = ({ ignore, svelte, service, strict } = {}, ...other) => tslint.config(ignore === false ? {} : includeIgnoreFile(ignore || join(import.meta.dirname, "../.eslint.ignore")), jslint.configs.recommended, ...(strict
23
- ? service
23
+ export const defineConfig = (opts, ...rest) => eslintDefineConfig(includeIgnoreFile(opts.ignore || join(import.meta.dirname, "../.eslint.ignore"), "@nemigo/configs/.eslint.ignore"), jslint.configs.recommended, ...(opts.strict
24
+ ? opts.service
24
25
  ? tslint.configs.strictTypeChecked
25
26
  : tslint.configs.strict
26
- : service
27
+ : opts.service
27
28
  ? tslint.configs.recommendedTypeChecked
28
- : tslint.configs.recommended), ...(svelte ? svelteConfigs["flat/recommended"] : []),
29
- // prettier,
30
- // ...(svelte ? svelteConfigs["flat/prettier"] : []),
31
- service
29
+ : tslint.configs.recommended), opts.service
32
30
  ? {
33
31
  languageOptions: {
34
32
  parserOptions: {
35
33
  projectService: true,
36
- tsconfigRootDir: service,
34
+ tsconfigRootDir: opts.service,
37
35
  },
38
36
  },
39
37
  }
40
- : {}, {
38
+ : {}, ...(opts.svelte ? svelteConfigs["flat/recommended"] : []),
39
+ // prettier,
40
+ // ...(svelte ? svelteConfigs["flat/prettier"] : []),
41
+ {
41
42
  languageOptions: {
42
43
  globals: {
43
44
  ...globals.browser,
44
45
  ...globals.node,
45
46
  },
46
47
  },
47
- }, svelte
48
- ? {
49
- files: [
50
- "./**/*.svelte",
51
- "./**/*.svelte.{ts,js}",
52
- "./**/*.svelte.{test,spec}.{ts,js}",
53
- ],
54
- languageOptions: {
55
- parserOptions: {
56
- projectService: true,
57
- extraFileExtensions: [".svelte"],
58
- parser: tslint.parser,
59
- svelteConfig: svelte,
60
- },
61
- },
62
- rules: {
63
- "svelte/no-at-html-tags": 0,
64
- "svelte/no-navigation-without-resolve": 0,
65
- "svelte/prefer-svelte-reactivity": 0,
66
- },
67
- }
68
- : {}, {
69
48
  rules: {
70
49
  "@typescript-eslint/no-confusing-void-expression": 0,
71
50
  "@typescript-eslint/no-duplicate-type-constituents": 0,
@@ -101,4 +80,25 @@ service
101
80
  "@typescript-eslint/restrict-template-expressions": 0,
102
81
  "no-import-assign": 0,
103
82
  },
104
- }, ...other);
83
+ }, opts.svelte
84
+ ? {
85
+ files: [
86
+ "**/*.svelte",
87
+ "**/*.svelte.ts",
88
+ "**/*.svelte.js",
89
+ ],
90
+ languageOptions: {
91
+ parserOptions: {
92
+ projectService: true,
93
+ extraFileExtensions: [".svelte"],
94
+ parser: tslint.parser,
95
+ svelteConfig: opts.svelte,
96
+ },
97
+ },
98
+ rules: {
99
+ "svelte/no-at-html-tags": 0,
100
+ "svelte/no-navigation-without-resolve": 0,
101
+ "svelte/prefer-svelte-reactivity": 0,
102
+ },
103
+ }
104
+ : {}, ...rest);
@@ -0,0 +1,8 @@
1
+ import type { Linter } from "eslint";
2
+ export type InfiniteArray<T> = T | InfiniteArray<T>[];
3
+ export type SimpleExtendsElement = string | Linter.Config;
4
+ export type ExtendsElement = SimpleExtendsElement | InfiniteArray<Linter.Config>;
5
+ export interface ConfigWithExtends extends Linter.Config {
6
+ extends?: ExtendsElement[];
7
+ }
8
+ export type ConfigWithExtendsArray = InfiniteArray<ConfigWithExtends>[];
@@ -0,0 +1,2 @@
1
+ // Взято из @eslint/config-helpers/types (0.3.1), т.к. нужный тип (ConfigWithExtendsArray) не экспортируется пакетом
2
+ export {};
@@ -1,3 +1,13 @@
1
1
  import type { Config, Options } from "prettier";
2
- export declare const defineConfig: () => Config;
3
- export declare const pretty: (content: string, parser: Options["parser"]) => Promise<string>;
2
+ /**
3
+ * @param tailwindStylesheet - путь к конфигу Tailwind V4 (`./src/tailwind.css`)
4
+ */
5
+ export declare const defineConfig: (tailwindStylesheet?: string) => Config;
6
+ /**
7
+ * Форматирование с помощью *prettier*
8
+ *
9
+ * @param content - содержимое
10
+ * @param parser - какой парсер
11
+ * @param tailwindStylesheet - путь к конфигу Tailwind V4 (ex. `./src/tailwind.css`)
12
+ */
13
+ export declare const pretty: (content: string, parser: Options["parser"], tailwindStylesheet?: string) => Promise<string>;
package/dist/prettier.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { format } from "prettier";
2
+ // noinspection TypeScriptCheckImport (у пакетов нет типов)
2
3
  import * as css from "prettier-plugin-css-order";
3
4
  import * as arrays from "prettier-plugin-multiline-arrays";
4
5
  import * as svelte from "prettier-plugin-svelte";
5
6
  import * as tailwind from "prettier-plugin-tailwindcss";
6
- export const defineConfig = () => ({
7
+ /**
8
+ * @param tailwindStylesheet - путь к конфигу Tailwind V4 (`./src/tailwind.css`)
9
+ */
10
+ export const defineConfig = (tailwindStylesheet) => ({
7
11
  tabWidth: 2,
8
12
  useTabs: true,
9
13
  printWidth: 150,
@@ -24,7 +28,15 @@ export const defineConfig = () => ({
24
28
  options: { parser: "svelte" },
25
29
  },
26
30
  ],
31
+ tailwindStylesheet,
27
32
  });
28
33
  //...
29
- const prettier = defineConfig();
30
- export const pretty = (content, parser) => format(content, { ...prettier, parser });
34
+ const config = defineConfig();
35
+ /**
36
+ * Форматирование с помощью *prettier*
37
+ *
38
+ * @param content - содержимое
39
+ * @param parser - какой парсер
40
+ * @param tailwindStylesheet - путь к конфигу Tailwind V4 (ex. `./src/tailwind.css`)
41
+ */
42
+ export const pretty = (content, parser, tailwindStylesheet) => format(content, { ...config, parser, tailwindStylesheet });
@@ -0,0 +1,65 @@
1
+ import type { Adapter, Config } from "@sveltejs/kit";
2
+ export interface SvelteConfigOptions {
3
+ /**
4
+ * Адаптер серверной платформы
5
+ *
6
+ * @see https://svelte.dev/docs/kit/adapters
7
+ */
8
+ adapter: Adapter;
9
+ /**
10
+ * Только руны
11
+ *
12
+ * @see https://svelte.dev/docs/svelte/what-are-runes
13
+ *
14
+ * @default true
15
+ */
16
+ runes?: boolean;
17
+ /**
18
+ * Проверка источника запроса (CSRF-защита)
19
+ *
20
+ * Отключить, если нужна возможность обращения с локалки на прод-приложения
21
+ *
22
+ * @see https://svelte.dev/docs/kit/configuration#csrf
23
+ * @see https://developer.mozilla.org/en-US/docs/Web/Security/Types_of_attacks#cross-site_request_forgery_csrf
24
+ *
25
+ * @default `true`
26
+ */
27
+ csrfCheckOrigin?: boolean;
28
+ /**
29
+ * Алиасы путей
30
+ *
31
+ * @default {}
32
+ */
33
+ alias?: Record<string, string>;
34
+ /**
35
+ * Переопледеление путей кита
36
+ */
37
+ files?: {
38
+ /**
39
+ * @default "./static"
40
+ */
41
+ assets?: string;
42
+ /**
43
+ * @default "./src/app.html"
44
+ */
45
+ app_html?: string;
46
+ /**
47
+ * @default "./src/error.html"
48
+ */
49
+ error_html?: string;
50
+ };
51
+ /**
52
+ * Глобусы исключений из tsconfig-а
53
+ */
54
+ exclude?: string[];
55
+ /**
56
+ * Глобусы включений из tsconfig-а
57
+ */
58
+ include?: string[];
59
+ }
60
+ /**
61
+ * Конфиг для приложений на `@sveltejs/kit`
62
+ *
63
+ * @see https://svelte.dev/docs/kit/introduction
64
+ */
65
+ export declare const defineConfig: (options: SvelteConfigOptions) => Config;
@@ -0,0 +1,87 @@
1
+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
2
+ //...
3
+ const isObject = (value) => typeof value === "object" && value !== null;
4
+ const getOptionalObject = (value) => (isObject(value) ? value : {});
5
+ const getOptionalArray = (value) => (Array.isArray(value) ? value : []);
6
+ const setifyArray = (array) => Array.from(new Set(array));
7
+ /**
8
+ * Конфиг для приложений на `@sveltejs/kit`
9
+ *
10
+ * @see https://svelte.dev/docs/kit/introduction
11
+ */
12
+ export const defineConfig = (options) => ({
13
+ /**
14
+ * Настройки поведения svelte-компилятора
15
+ *
16
+ * @see https://svelte.dev/docs/svelte/svelte-compiler#CompileOptions
17
+ */
18
+ compilerOptions: {
19
+ runes: options.runes ?? true,
20
+ /**
21
+ * Использование современного AST (не знаю, на что влияет)
22
+ */
23
+ modernAst: true,
24
+ },
25
+ /**
26
+ * Расширение поддержки всякого в svelte (в т.ч. и полной для typescript)
27
+ *
28
+ * @see https://svelte.dev/docs/kit/integrations
29
+ */
30
+ preprocess: vitePreprocess({ script: true }),
31
+ kit: {
32
+ adapter: options.adapter,
33
+ csrf: {
34
+ checkOrigin: options.csrfCheckOrigin,
35
+ },
36
+ alias: options.alias,
37
+ files: {
38
+ assets: options?.files?.assets,
39
+ appTemplate: options?.files?.app_html,
40
+ errorTemplate: options?.files?.error_html,
41
+ },
42
+ /**
43
+ * Переопределение и дополнения к `tsconfig.json`
44
+ *
45
+ * @see https://svelte.dev/docs/kit/configuration#typescript
46
+ */
47
+ typescript: {
48
+ config: (config) => {
49
+ config["compilerOptions"] = {
50
+ ...getOptionalObject(config["compilerOptions"]),
51
+ allowJs: true,
52
+ checkJs: true,
53
+ target: "ES2023", // override
54
+ module: "NodeNext", // override
55
+ moduleResolution: "NodeNext", // override
56
+ // noEmit: true,
57
+ strict: true,
58
+ noImplicitAny: false,
59
+ // isolatedModules: true,
60
+ esModuleInterop: true,
61
+ allowSyntheticDefaultImports: true,
62
+ // verbatimModuleSyntax: true,
63
+ resolveJsonModule: true,
64
+ skipLibCheck: true,
65
+ disableSizeLimit: true,
66
+ erasableSyntaxOnly: true,
67
+ };
68
+ config["exclude"] = setifyArray([
69
+ ...getOptionalArray(config["exclude"]),
70
+ "../**/trash/**",
71
+ "../drafts/**",
72
+ ...(options.exclude ?? []),
73
+ ]);
74
+ config["include"] = setifyArray([
75
+ ...getOptionalArray(config["include"]),
76
+ "../scripts/**/*.ts",
77
+ "../scripts/**/*.js",
78
+ "../types/**/*.ts",
79
+ "../*.ts",
80
+ "../*.js",
81
+ ...(options.include ?? []),
82
+ ]);
83
+ return config;
84
+ },
85
+ },
86
+ },
87
+ });
@@ -1,16 +1,24 @@
1
1
  import type { Config } from "@sveltejs/kit";
2
- export interface SveltePackageOptions {
2
+ export interface SveltePackageConfigOptions {
3
3
  /**
4
+ * Только руны
5
+ *
6
+ * @see https://svelte.dev/docs/svelte/what-are-runes
7
+ *
4
8
  * @default true
5
9
  */
6
10
  runes?: boolean;
7
11
  /**
12
+ * Добавляет алиас `{ "#": "src" }`
13
+ *
8
14
  * @default true
9
15
  */
10
16
  isolate?: boolean;
11
17
  /**
18
+ * Алиасы путей
19
+ *
12
20
  * @default {}
13
21
  */
14
22
  alias?: Record<string, string>;
15
23
  }
16
- export declare const definePackageConfig: ({ runes, isolate, alias }?: SveltePackageOptions) => Config;
24
+ export declare const definePackageConfig: ({ runes, isolate, alias }?: SveltePackageConfigOptions) => Config;
@@ -6,11 +6,6 @@ export const definePackageConfig = ({ runes = true, isolate = true, alias = {} }
6
6
  * @see https://svelte.dev/docs/svelte/svelte-compiler#CompileOptions
7
7
  */
8
8
  compilerOptions: {
9
- /**
10
- * Только руны
11
- *
12
- * @see https://svelte.dev/docs/svelte/what-are-runes
13
- */
14
9
  runes,
15
10
  /**
16
11
  * Использование современного AST
@@ -23,11 +18,11 @@ export const definePackageConfig = ({ runes = true, isolate = true, alias = {} }
23
18
  * @see https://svelte.dev/docs/kit/integrations
24
19
  */
25
20
  preprocess: vitePreprocess({ script: true }),
26
- /**
27
- * Алиас корня пакета и его путь
28
- */
29
21
  kit: {
30
22
  files: {
23
+ /**
24
+ * Путь к библиотеке
25
+ */
31
26
  lib: "src",
32
27
  },
33
28
  alias: {
@@ -0,0 +1,50 @@
1
+ import type { BuildOptions, PluginOption, ServerOptions } from "vite";
2
+ import type { ViteUserConfig } from "vitest/config";
3
+ /**
4
+ * Настройка конфигурации для {@link defineConfig}
5
+ */
6
+ export interface ViteConfigOptions {
7
+ /**
8
+ * Порт приложения
9
+ *
10
+ * @see https://vite.dev/config/server-options.html#server-port
11
+ */
12
+ port?: ServerOptions["port"];
13
+ /**
14
+ * Отключение использования фиксированного порта
15
+ *
16
+ * @see https://vite.dev/config/server-options.html#server-strictport
17
+ */
18
+ offStrictPort?: boolean;
19
+ /**
20
+ * Конфигурация минификации при сборке
21
+ *
22
+ * @see https://vite.dev/config/build-options.html#build-minify
23
+ */
24
+ minify?: BuildOptions["minify"];
25
+ /**
26
+ * Проксирование запросов
27
+ *
28
+ * @see https://vite.dev/config/server-options.html#server-proxy
29
+ */
30
+ proxy?: ServerOptions["proxy"];
31
+ /**
32
+ * Разрешение доступа к общим папкам
33
+ *
34
+ * @see https://vite.dev/config/server-options.html#server-fs-allow
35
+ */
36
+ allow?: string[];
37
+ /**
38
+ * Различные плагины
39
+ *
40
+ * @see https://vite.dev/config/shared-options.html#plugins
41
+ */
42
+ plugins?: PluginOption[];
43
+ }
44
+ /**
45
+ * Реструктурированная конфигурация `vite` через `vitest`
46
+ *
47
+ * @see https://vite.dev/ Документация Vite
48
+ * @see https://vitest.dev/ Документация Vitest
49
+ */
50
+ export declare const defineConfig: (options?: ViteConfigOptions, test?: ViteUserConfig["test"]) => ViteUserConfig;
@@ -0,0 +1,61 @@
1
+ import { defineConfig as defineVitestConfig } from "vitest/config";
2
+ /**
3
+ * Реструктурированная конфигурация `vite` через `vitest`
4
+ *
5
+ * @see https://vite.dev/ Документация Vite
6
+ * @see https://vitest.dev/ Документация Vitest
7
+ */
8
+ export const defineConfig = (options = {}, test) => defineVitestConfig({
9
+ /**
10
+ * Где смотрит .env-файлы. Отключено, т.к. файлы читаются через dotenv
11
+ *
12
+ * @see https://vite.dev/config/shared-options.html#envdir
13
+ */
14
+ envDir: false,
15
+ /**
16
+ * Префикс публичных env-переменных (чтобы совпадало с svelte-kit)
17
+ *
18
+ * @see https://vite.dev/config/shared-options.html#envprefix
19
+ */
20
+ envPrefix: "PUBLIC_",
21
+ /**
22
+ * Конфигурация сервера
23
+ *
24
+ * @see https://vite.dev/config/server-options.html
25
+ */
26
+ server: {
27
+ port: options.port,
28
+ /**
29
+ * Выдаёт ошибку, если порт занят
30
+ *
31
+ * @see https://vite.dev/config/server-options.html#server-strictport
32
+ */
33
+ strictPort: !options.offStrictPort,
34
+ proxy: options.proxy,
35
+ fs: {
36
+ allow: options.allow,
37
+ },
38
+ },
39
+ /**
40
+ * Конфигурация сборки
41
+ *
42
+ * @see https://vite.dev/config/build-options.html
43
+ */
44
+ build: {
45
+ minify: options.minify,
46
+ },
47
+ plugins: options.plugins,
48
+ /**
49
+ * Конфигурация `vitest`
50
+ *
51
+ * @see https://vitest.dev/config
52
+ */
53
+ test: test ?? {
54
+ /**
55
+ * glob-путь к файлам тестов
56
+ *
57
+ * @see https://vitest.dev/config/#include
58
+ */
59
+ include: ["src/**/*.{test,spec}.{ts,js}"],
60
+ },
61
+ });
@@ -0,0 +1,30 @@
1
+ import type { ServerOptions } from "vite";
2
+ /**
3
+ * Настройка конфигурации для {@link defineProxyConfig}
4
+ */
5
+ export interface ViteProxyConfigOptions {
6
+ /**
7
+ * URL-адрес сервера, на который будет направляться прокси
8
+ *
9
+ * @example `http://localhost:3000`
10
+ */
11
+ domain: string;
12
+ /**
13
+ * Префикс маршрута, который будет перенаправляться.
14
+ *
15
+ * @example `/api/`
16
+ */
17
+ prefix: string;
18
+ /**
19
+ * Определяет, должен ли изменяться заголовок `Origin` при проксировании
20
+ *
21
+ * @default true
22
+ */
23
+ changeOrigin?: boolean;
24
+ }
25
+ /**
26
+ * Создания прокси-конфига для Vite
27
+ *
28
+ * Используется для проксирования запросов на основной сервер у приложений
29
+ */
30
+ export declare const defineProxyConfig: ({ domain: target, prefix, changeOrigin }: ViteProxyConfigOptions) => ServerOptions["proxy"];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Создания прокси-конфига для Vite
3
+ *
4
+ * Используется для проксирования запросов на основной сервер у приложений
5
+ */
6
+ export const defineProxyConfig = ({ domain: target, prefix, changeOrigin = true }) => {
7
+ const pad = (v) => v.toString().padStart(2, "0");
8
+ const now = new Date();
9
+ const hours = pad(now.getHours());
10
+ const mins = pad(now.getMinutes());
11
+ const secs = pad(now.getSeconds());
12
+ const PROXY = "\x1b[1m\x1b[96m[PROXY]\x1b[0m\x1b[22m";
13
+ console.log(`${hours}:${mins}:${secs} ${PROXY} ${target} \n`);
14
+ return { [prefix]: { target, changeOrigin } };
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/configs",
3
- "version": "0.0.4",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -17,14 +17,25 @@
17
17
  "typescript.json"
18
18
  ],
19
19
  "exports": {
20
+ "./.eslint.ignore": {
21
+ "default": "./.eslint.ignore"
22
+ },
20
23
  "./eslint": {
21
24
  "types": "./dist/eslint.d.ts",
22
25
  "default": "./dist/eslint.js"
23
26
  },
27
+ "./eslint/types": {
28
+ "types": "./dist/eslint/types.d.ts",
29
+ "default": "./dist/eslint/types.js"
30
+ },
24
31
  "./prettier": {
25
32
  "types": "./dist/prettier.d.ts",
26
33
  "default": "./dist/prettier.js"
27
34
  },
35
+ "./svelte": {
36
+ "types": "./dist/svelte/index.d.ts",
37
+ "default": "./dist/svelte/index.js"
38
+ },
28
39
  "./svelte/package": {
29
40
  "types": "./dist/svelte/package.d.ts",
30
41
  "default": "./dist/svelte/package.js"
@@ -32,8 +43,13 @@
32
43
  "./typescript.json": {
33
44
  "default": "./typescript.json"
34
45
  },
35
- "./.eslint.ignore": {
36
- "default": "./.eslint.ignore"
46
+ "./vite": {
47
+ "types": "./dist/vite/index.d.ts",
48
+ "default": "./dist/vite/index.js"
49
+ },
50
+ "./vite/proxy": {
51
+ "types": "./dist/vite/proxy.d.ts",
52
+ "default": "./dist/vite/proxy.js"
37
53
  }
38
54
  },
39
55
  "peerDependencies": {