@w5s/dev 3.25.0 → 3.27.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/index.cjs CHANGED
@@ -44,6 +44,36 @@ function fixme(_status) {
44
44
  return "off";
45
45
  }
46
46
  /**
47
+ * Maps rule names and values using the provided mapping function.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * ESLintConfig.mapRules(
52
+ * {
53
+ * 'rule-name': 'error',
54
+ * 'rule-to-drop': 'error',
55
+ * },
56
+ * (rule, value) => {
57
+ * if (rule === 'rule-name') return ['new-rule-name', value];
58
+ * return undefined;
59
+ * }
60
+ * ); // { 'new-rule-name': 'error' }
61
+ * ```
62
+ * @param rules
63
+ * @param mapFn
64
+ */
65
+ function mapRules(rules, mapFn) {
66
+ const mappedRules = Object.create(null);
67
+ for (let index = 0, keys = Object.keys(rules); index < keys.length; index++) {
68
+ const key = keys[index];
69
+ const mapped = mapFn(key, rules[key]);
70
+ if (mapped == null) continue;
71
+ mappedRules[mapped[0]] = mapped[1];
72
+ }
73
+ Object.setPrototypeOf(mappedRules, Object.getPrototypeOf(rules));
74
+ return mappedRules;
75
+ }
76
+ /**
47
77
  * Return a new merged flat configuration
48
78
  *
49
79
  * @param configs
@@ -88,11 +118,16 @@ function merge(...configs) {
88
118
  * @param map The object containing the rename map.
89
119
  */
90
120
  function renameRules(rules, map) {
91
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
92
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
93
- else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
121
+ const mapKeys = Object.keys(map);
122
+ return mapRules(rules, (key, value) => {
123
+ for (let index = 0; index < mapKeys.length; index++) {
124
+ const from = mapKeys[index];
125
+ const to = map[from];
126
+ if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
127
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
128
+ }
94
129
  return [key, value];
95
- }));
130
+ });
96
131
  }
97
132
  /**
98
133
  * @namespace
@@ -100,6 +135,7 @@ function renameRules(rules, map) {
100
135
  const ESLintConfig = Object.freeze({
101
136
  concat,
102
137
  fixme,
138
+ mapRules,
103
139
  merge,
104
140
  renameRules
105
141
  });
@@ -112,9 +148,9 @@ function interopDefault(m) {
112
148
  //#endregion
113
149
  //#region src/meta.ts
114
150
  const meta = Object.freeze({
115
- buildNumber: 1788194737,
151
+ buildNumber: 1788793943,
116
152
  name: "@w5s/dev",
117
- version: "3.25.0"
153
+ version: "3.27.0"
118
154
  });
119
155
  //#endregion
120
156
  //#region src/Project.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * Concat multiple flat configs into a single flat config array.\n *\n * It also resolves promises and flattens the result.\n *\n * @example\n *\n * ```ts\n * import eslint from '@eslint/js'\n *\n * export default ESLintConfig.concat(\n * {\n * plugins: {},\n * rules: {},\n * },\n * // It can also takes a array of configs:\n * [\n * {\n * plugins: {},\n * rules: {},\n * }\n * // ...\n * ],\n * // Or promises:\n * Promise.resolve({\n * files: ['*.ts'],\n * rules: {},\n * })\n * );\n * ```\n * @param configs\n */\nasync function concat<T extends Linter.Config = Linter.Config>(\n ...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>\n): Promise<Array<T>> {\n // eslint-disable-next-line ts/await-thenable\n const resolved = await Promise.all(configs);\n return resolved.flat() as Array<T>;\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: [number | string, ...Array<any>] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n }, {} as T);\n\n // Remove unused keys\n for (const key of Object.keys(merged)) {\n if (!keys.has(key))\n // eslint-disable-next-line ts/no-dynamic-delete, ts/no-unsafe-member-access\n delete (merged as any)[key];\n }\n\n return merged;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n merge,\n renameRules,\n});\n","// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\nconst getDefaultOrElse = (_: any) => _?.default ?? _;\n\n/**\n * Resolves a module or promise-like object, returning the default export if available.\n *\n * @example\n * ```ts\n * // modules.ts\n * export default {\n * foo: true\n * };\n * // Async API\n * const modPromise = import('./module');\n * interopDefault(modPromise); // == Promise.resolve({ foo: true })\n * // Sync API\n * const mod = await import('./module');\n * interopDefault(mod); // == { foo: true }\n * ```\n *\n * @template T - The type of the module or promise-like object.\n * @param m The module or promise-like object to resolve.\n */\nexport function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;\nexport function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;\nexport function interopDefault<T>(m: PromiseLike<T> | T): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n // eslint-disable-next-line unicorn/prefer-await, ts/no-unsafe-return\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import type { LanguageId } from './LanguageId.js';\n\n/**\n * A type of a file extension\n */\nexport type Extension = `.${string}`;\n\n/**\n * Object hash of all well-known file extension category to file extensions mapping\n */\nexport type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;\n\n/**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\nfunction ecmaVersion() {\n return 2022 as const;\n}\n\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\nconst registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n};\n\n/**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\nfunction queryExtensions(languages: Array<LanguageId>): ReadonlyArray<Extension> {\n return languages\n .reduce<Array<Extension>>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as Array<Extension>)), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort((left, right) => left.localeCompare(right));\n}\n\n/**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\nfunction sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n}\n\nconst RESOURCE_EXTENSIONS: ReadonlyArray<Extension> = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n]);\n\n/**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\nfunction resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n}\n\nconst IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n]);\n\n/**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToMatcher(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: ReadonlyArray<Extension>): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).join('|')})`;\n}\n\n/**\n * Return a list of test glob matchers for a list of extensions.\n * This is useful to generate globs for vitest/jest matchers\n *\n * @param extensions\n * @param options\n * @param options.testExtensions\n * @param options.testFolders\n * @example\n * ```ts\n * Project.extensionsToTestGlob(['.js', '.ts']);\n * // ['<tests-folder-glob>', '<test-suffix-glob>']\n *\n * Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });\n * // ['<tests-folder-glob>', '<custom-test-suffix-glob>']\n * ```\n */\nfunction extensionsToTestGlob(\n extensions: ReadonlyArray<Extension>,\n options: {\n testExtensions?: ReadonlyArray<string>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['spec', 'test'],\n testFolders = ['__tests__'],\n } = options;\n const extensionPattern = extensions.map((_) => _.replace(reExtension, '')).join('|');\n\n return [\n ...testFolders.map((folder) => `**/${folder}/**/*.+(${extensionPattern})`),\n `**/*.+(${testExtensions.join('|')}).+(${extensionPattern})`,\n ];\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\n extensionsToTestGlob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Typecheck: 'typecheck',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAGnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAyE;CACtF,OAAO;AACT;;;;;;AAOA,SAAS,MAA+C,GAAG,SAAsB;CAC/E,MAAM,OAAO,IAAI,IAAI,QAAQ,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,MAAM,SAAS,QAAQ,QAAQ,KAAK,QAAQ;EAC1C,OAAO;GACL,GAAG;GACH,GAAG;GACH,OAAO,CACL,GAAI,IAAI,SAAS,CAAC,GAClB,GAAI,IAAI,SAAS,CAAC,CACpB;GACA,SAAS,CACP,GAAI,IAAI,WAAW,CAAC,GACpB,GAAI,IAAI,WAAW,CAAC,CACtB;GACA,iBAAiB;IACf,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,eAAe;IACb,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,SAAS;IACP,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,OAAO;IACL,GAAG,IAAI;IACP,GAAG,IAAI;GACT;EACF;CACF,GAAG,CAAC,CAAM;CAGV,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,KAAK,IAAI,GAAG,GAEf,OAAQ,OAAe;CAG3B,OAAO;AACT;;;;;;;;;;;AAYA,SAAS,YAAY,OAA4B,KAAkD;CACjG,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW;EAC1C,KAAK,MAAM,CAAC,MAAM,OAAO,OAAO,QAAQ,GAAG,GACzC,IAAI,IAAI,WAAW,GAAG,K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A;CACA;CACA;CACA;AACF,CAAC;;;;;;ACjMD,MAAa,gBAAgB;CAC3B,OAAO;CACP,OAAO;CACP,cAAc;CACd,UAAU;CACV,SAAS;CACT,MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * Concat multiple flat configs into a single flat config array.\n *\n * It also resolves promises and flattens the result.\n *\n * @example\n *\n * ```ts\n * import eslint from '@eslint/js'\n *\n * export default ESLintConfig.concat(\n * {\n * plugins: {},\n * rules: {},\n * },\n * // It can also takes a array of configs:\n * [\n * {\n * plugins: {},\n * rules: {},\n * }\n * // ...\n * ],\n * // Or promises:\n * Promise.resolve({\n * files: ['*.ts'],\n * rules: {},\n * })\n * );\n * ```\n * @param configs\n */\nasync function concat<T extends Linter.Config = Linter.Config>(\n ...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>\n): Promise<Array<T>> {\n // eslint-disable-next-line ts/await-thenable\n const resolved = await Promise.all(configs);\n return resolved.flat() as Array<T>;\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: [number | string, ...Array<any>] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Maps rule names and values using the provided mapping function.\n *\n * @example\n * ```ts\n * ESLintConfig.mapRules(\n * {\n * 'rule-name': 'error',\n * 'rule-to-drop': 'error',\n * },\n * (rule, value) => {\n * if (rule === 'rule-name') return ['new-rule-name', value];\n * return undefined;\n * }\n * ); // { 'new-rule-name': 'error' }\n * ```\n * @param rules\n * @param mapFn\n */\nfunction mapRules(rules: Record<string, any>, mapFn: (rule: string, value: any) => [string, any] | undefined): Record<string, any> {\n const mappedRules = Object.create(null) as Record<string, any>;\n for (let index = 0, keys = Object.keys(rules); index < keys.length; index++) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const key = keys[index]!;\n const mapped = mapFn(key, rules[key]);\n if (mapped == null) continue;\n // eslint-disable-next-line ts/no-unsafe-assignment\n mappedRules[mapped[0]] = mapped[1];\n }\n // eslint-disable-next-line ts/no-unsafe-argument\n Object.setPrototypeOf(mappedRules, Object.getPrototypeOf(rules));\n return mappedRules;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n }, {} as T);\n\n // Remove unused keys\n for (const key of Object.keys(merged)) {\n if (!keys.has(key))\n // eslint-disable-next-line ts/no-dynamic-delete, ts/no-unsafe-member-access\n delete (merged as any)[key];\n }\n\n return merged;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n const mapKeys = Object.keys(map);\n return mapRules(rules, (key, value) => {\n // eslint-disable-next-line ts/prefer-for-of\n for (let index = 0; index < mapKeys.length; index++) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const from = mapKeys[index]!;\n // eslint-disable-next-line ts/no-non-null-assertion\n const to = map[from]!;\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n });\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n mapRules,\n merge,\n renameRules,\n});\n","// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\nconst getDefaultOrElse = (_: any) => _?.default ?? _;\n\n/**\n * Resolves a module or promise-like object, returning the default export if available.\n *\n * @example\n * ```ts\n * // modules.ts\n * export default {\n * foo: true\n * };\n * // Async API\n * const modPromise = import('./module');\n * interopDefault(modPromise); // == Promise.resolve({ foo: true })\n * // Sync API\n * const mod = await import('./module');\n * interopDefault(mod); // == { foo: true }\n * ```\n *\n * @template T - The type of the module or promise-like object.\n * @param m The module or promise-like object to resolve.\n */\nexport function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;\nexport function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;\nexport function interopDefault<T>(m: PromiseLike<T> | T): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n // eslint-disable-next-line unicorn/prefer-await, ts/no-unsafe-return\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import type { LanguageId } from './LanguageId.js';\n\n/**\n * A type of a file extension\n */\nexport type Extension = `.${string}`;\n\n/**\n * Object hash of all well-known file extension category to file extensions mapping\n */\nexport type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;\n\n/**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\nfunction ecmaVersion() {\n return 2022 as const;\n}\n\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\nconst registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n};\n\n/**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\nfunction queryExtensions(languages: Array<LanguageId>): ReadonlyArray<Extension> {\n return languages\n .reduce<Array<Extension>>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as Array<Extension>)), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort((left, right) => left.localeCompare(right));\n}\n\n/**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\nfunction sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n}\n\nconst RESOURCE_EXTENSIONS: ReadonlyArray<Extension> = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n]);\n\n/**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\nfunction resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n}\n\nconst IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n]);\n\n/**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToMatcher(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: ReadonlyArray<Extension>): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).join('|')})`;\n}\n\n/**\n * Return a list of test glob matchers for a list of extensions.\n * This is useful to generate globs for vitest/jest matchers\n *\n * @param extensions\n * @param options\n * @param options.testExtensions\n * @param options.testFolders\n * @example\n * ```ts\n * Project.extensionsToTestGlob(['.js', '.ts']);\n * // ['<tests-folder-glob>', '<test-suffix-glob>']\n *\n * Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });\n * // ['<tests-folder-glob>', '<custom-test-suffix-glob>']\n * ```\n */\nfunction extensionsToTestGlob(\n extensions: ReadonlyArray<Extension>,\n options: {\n testExtensions?: ReadonlyArray<string>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['spec', 'test'],\n testFolders = ['__tests__'],\n } = options;\n const extensionPattern = extensions.map((_) => _.replace(reExtension, '')).join('|');\n\n return [\n ...testFolders.map((folder) => `**/${folder}/**/*.+(${extensionPattern})`),\n `**/*.+(${testExtensions.join('|')}).+(${extensionPattern})`,\n ];\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\n extensionsToTestGlob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Typecheck: 'typecheck',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAGnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAyE;CACtF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,SAAS,OAA4B,OAAqF;CACjI,MAAM,cAAc,OAAO,OAAO,IAAI;CACtC,KAAK,IAAI,QAAQ,GAAG,OAAO,OAAO,KAAK,KAAK,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAE3E,MAAM,MAAM,KAAK;EACjB,MAAM,SAAS,MAAM,KAAK,MAAM,IAAI;EACpC,IAAI,UAAU,MAAM;EAEpB,YAAY,OAAO,MAAM,OAAO;CAClC;CAEA,OAAO,eAAe,aAAa,OAAO,eAAe,KAAK,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ist/index.d.cts CHANGED
@@ -39,6 +39,26 @@ declare function concat<T extends Linter.Config = Linter.Config>(...configs: Arr
39
39
  * @param _status
40
40
  */
41
41
  declare function fixme(_status: [number | string, ...Array<any>] | number | string | undefined): "off";
42
+ /**
43
+ * Maps rule names and values using the provided mapping function.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * ESLintConfig.mapRules(
48
+ * {
49
+ * 'rule-name': 'error',
50
+ * 'rule-to-drop': 'error',
51
+ * },
52
+ * (rule, value) => {
53
+ * if (rule === 'rule-name') return ['new-rule-name', value];
54
+ * return undefined;
55
+ * }
56
+ * ); // { 'new-rule-name': 'error' }
57
+ * ```
58
+ * @param rules
59
+ * @param mapFn
60
+ */
61
+ declare function mapRules(rules: Record<string, any>, mapFn: (rule: string, value: any) => [string, any] | undefined): Record<string, any>;
42
62
  /**
43
63
  * Return a new merged flat configuration
44
64
  *
@@ -59,9 +79,10 @@ declare function renameRules(rules: Record<string, any>, map: Record<string, str
59
79
  /**
60
80
  * @namespace
61
81
  */
62
- declare const ESLintConfig: Readonly<{
82
+ export declare const ESLintConfig: Readonly<{
63
83
  concat: typeof concat;
64
84
  fixme: typeof fixme;
85
+ mapRules: typeof mapRules;
65
86
  merge: typeof merge;
66
87
  renameRules: typeof renameRules;
67
88
  }>;
@@ -87,10 +108,10 @@ declare const ESLintConfig: Readonly<{
87
108
  * @template T - The type of the module or promise-like object.
88
109
  * @param m The module or promise-like object to resolve.
89
110
  */
90
- declare function interopDefault<T>(m: PromiseLike<T>): Promise<T extends {
111
+ export declare function interopDefault<T>(m: PromiseLike<T>): Promise<T extends {
91
112
  default: infer U;
92
113
  } ? U : T>;
93
- declare function interopDefault<T>(m: T): T extends {
114
+ export declare function interopDefault<T>(m: T): T extends {
94
115
  default: infer U;
95
116
  } ? U : T;
96
117
  //#endregion
@@ -98,8 +119,8 @@ declare function interopDefault<T>(m: T): T extends {
98
119
  /**
99
120
  * A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
100
121
  */
101
- type LanguageId = keyof LanguageIdMap;
102
- interface LanguageIdMap {
122
+ export type LanguageId = keyof LanguageIdMap;
123
+ export interface LanguageIdMap {
103
124
  css: true;
104
125
  graphql: true;
105
126
  javascript: true;
@@ -118,7 +139,7 @@ interface LanguageIdMap {
118
139
  }
119
140
  //#endregion
120
141
  //#region src/meta.d.ts
121
- declare const meta: Readonly<{
142
+ export declare const meta: Readonly<{
122
143
  buildNumber: number;
123
144
  name: string;
124
145
  version: string;
@@ -128,11 +149,11 @@ declare const meta: Readonly<{
128
149
  /**
129
150
  * A type of a file extension
130
151
  */
131
- type Extension = `.${string}`;
152
+ export type Extension = `.${string}`;
132
153
  /**
133
154
  * Object hash of all well-known file extension category to file extensions mapping
134
155
  */
135
- type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;
156
+ export type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;
136
157
  /**
137
158
  * Supported ECMA version
138
159
  *
@@ -222,7 +243,7 @@ declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, opti
222
243
  testExtensions?: ReadonlyArray<string>;
223
244
  testFolders?: ReadonlyArray<string>;
224
245
  }): Array<string>;
225
- declare const Project: Readonly<{
246
+ export declare const Project: Readonly<{
226
247
  ecmaVersion: typeof ecmaVersion;
227
248
  extensionsToGlob: typeof extensionsToGlob;
228
249
  extensionsToMatcher: typeof extensionsToMatcher;
@@ -237,7 +258,7 @@ declare const Project: Readonly<{
237
258
  /**
238
259
  * Project common scripts
239
260
  */
240
- declare const ProjectScript: {
261
+ export declare const ProjectScript: {
241
262
  readonly Build: "build";
242
263
  readonly Clean: "clean";
243
264
  readonly CodeAnalysis: "code-analysis";
@@ -255,7 +276,6 @@ declare const ProjectScript: {
255
276
  readonly Typecheck: "typecheck";
256
277
  readonly Validate: "validate";
257
278
  };
258
- type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
279
+ export type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
259
280
  //#endregion
260
- export { ESLintConfig, Extension, ExtensionRegistry, LanguageId, LanguageIdMap, Project, ProjectScript, interopDefault, meta };
261
281
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/LanguageId.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCe,OAAO,UAAU,OAAO,SAAS,OAAO,WAClD,SAAS,MAAM,QAAQ,cAAc,MAAM,QAAQ,KAAK,cAAc,KAAK,KAC7E,QAAQ,MAAM;;;;;;iBAWR,MAAM,8BAA8B;;;;;;iBASpC,MAAM,UAAU,OAAO,SAAS,OAAO,WAAW,SAAS,MAAM,KAAK;;;;;;;;;;;iBAqDtE,YAAY,OAAO,qBAAqB,KAAK,yBAAyB;;;;cAelE,cAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCrGT,eAAe,GAAG,GAAG,YAAY,KAAK,QAAQ;EAAY,eAAe;IAAM,IAAI;iBACnF,eAAe,GAAG,GAAG,IAAI;EAAY,eAAe;IAAM,IAAI;;;;;;KCrBlE,mBAAmB;UAEd;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;cCpBW,MAAI;EAEkF;EAEtB;EAES;;;;;;;KCD1E;;;;KAKA,oBAAoB,OAAO,YAAY,cAAc;;;;;;;;;iBAUxD;;;;;;;;;;;;iBAsCA,gBAAgB,WAAW,MAAM,cAAc,cAAc;;;;;;;;;iBAiB7D;;;;;;;;;iBAmBA;;;;;;;;;;iBA0BA,oBAAoB,YAAY,cAAc,aAAa;;;;;;;;;iBAY3D;;;;;;;;;;iBAeA,iBAAiB,YAAY,cAAc;;;;;;;;;;;;;;;;;;iBAqB3C,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB;EACjB,cAAc;IAEf;cAaU,SAAO;;;;;;;;;;;;;;;cCxLP;;;;;;;;;;;;;;;;;;KAkBD,wBAAwB,4BAA4B"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/LanguageId.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCe,OAAO,UAAU,OAAO,SAAS,OAAO,WAClD,SAAS,MAAM,QAAQ,cAAc,MAAM,QAAQ,KAAK,cAAc,KAAK,KAC7E,QAAQ,MAAM;;;;;;iBAWR,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;iBAuBpC,SAAS,OAAO,qBAAqB,QAAQ,cAAc,2CAA2C;;;;;;iBAoBtG,MAAM,UAAU,OAAO,SAAS,OAAO,WAAW,SAAS,MAAM,KAAK;;;;;;;;;;;iBAqDtE,YAAY,OAAO,qBAAqB,KAAK,yBAAyB;;;;qBAmBlE,cAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBC3IT,eAAe,GAAG,GAAG,YAAY,KAAK,QAAQ;EAAY,eAAe;IAAM,IAAI;wBACnF,eAAe,GAAG,GAAG,IAAI;EAAY,eAAe;IAAM,IAAI;;;;;;YCrBlE,mBAAmB;iBAEd;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;qBCpBW,MAAI;EAEkF;EAEtB;EAES;;;;;;;YCD1E;;;;YAKA,oBAAoB,OAAO,YAAY,cAAc;;;;;;;;;iBAUxD;;;;;;;;;;;;iBAsCA,gBAAgB,WAAW,MAAM,cAAc,cAAc;;;;;;;;;iBAiB7D;;;;;;;;;iBAmBA;;;;;;;;;;iBA0BA,oBAAoB,YAAY,cAAc,aAAa;;;;;;;;;iBAY3D;;;;;;;;;;iBAeA,iBAAiB,YAAY,cAAc;;;;;;;;;;;;;;;;;;iBAqB3C,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB;EACjB,cAAc;IAEf;qBAaU,SAAO;;;;;;;;;;;;;;;qBCxLP;;;;;;;;;;;;;;;;;;YAkBD,wBAAwB,4BAA4B"}
package/dist/index.d.ts CHANGED
@@ -39,6 +39,26 @@ declare function concat<T extends Linter.Config = Linter.Config>(...configs: Arr
39
39
  * @param _status
40
40
  */
41
41
  declare function fixme(_status: [number | string, ...Array<any>] | number | string | undefined): "off";
42
+ /**
43
+ * Maps rule names and values using the provided mapping function.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * ESLintConfig.mapRules(
48
+ * {
49
+ * 'rule-name': 'error',
50
+ * 'rule-to-drop': 'error',
51
+ * },
52
+ * (rule, value) => {
53
+ * if (rule === 'rule-name') return ['new-rule-name', value];
54
+ * return undefined;
55
+ * }
56
+ * ); // { 'new-rule-name': 'error' }
57
+ * ```
58
+ * @param rules
59
+ * @param mapFn
60
+ */
61
+ declare function mapRules(rules: Record<string, any>, mapFn: (rule: string, value: any) => [string, any] | undefined): Record<string, any>;
42
62
  /**
43
63
  * Return a new merged flat configuration
44
64
  *
@@ -59,9 +79,10 @@ declare function renameRules(rules: Record<string, any>, map: Record<string, str
59
79
  /**
60
80
  * @namespace
61
81
  */
62
- declare const ESLintConfig: Readonly<{
82
+ export declare const ESLintConfig: Readonly<{
63
83
  concat: typeof concat;
64
84
  fixme: typeof fixme;
85
+ mapRules: typeof mapRules;
65
86
  merge: typeof merge;
66
87
  renameRules: typeof renameRules;
67
88
  }>;
@@ -87,10 +108,10 @@ declare const ESLintConfig: Readonly<{
87
108
  * @template T - The type of the module or promise-like object.
88
109
  * @param m The module or promise-like object to resolve.
89
110
  */
90
- declare function interopDefault<T>(m: PromiseLike<T>): Promise<T extends {
111
+ export declare function interopDefault<T>(m: PromiseLike<T>): Promise<T extends {
91
112
  default: infer U;
92
113
  } ? U : T>;
93
- declare function interopDefault<T>(m: T): T extends {
114
+ export declare function interopDefault<T>(m: T): T extends {
94
115
  default: infer U;
95
116
  } ? U : T;
96
117
  //#endregion
@@ -98,8 +119,8 @@ declare function interopDefault<T>(m: T): T extends {
98
119
  /**
99
120
  * A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
100
121
  */
101
- type LanguageId = keyof LanguageIdMap;
102
- interface LanguageIdMap {
122
+ export type LanguageId = keyof LanguageIdMap;
123
+ export interface LanguageIdMap {
103
124
  css: true;
104
125
  graphql: true;
105
126
  javascript: true;
@@ -118,7 +139,7 @@ interface LanguageIdMap {
118
139
  }
119
140
  //#endregion
120
141
  //#region src/meta.d.ts
121
- declare const meta: Readonly<{
142
+ export declare const meta: Readonly<{
122
143
  buildNumber: number;
123
144
  name: string;
124
145
  version: string;
@@ -128,11 +149,11 @@ declare const meta: Readonly<{
128
149
  /**
129
150
  * A type of a file extension
130
151
  */
131
- type Extension = `.${string}`;
152
+ export type Extension = `.${string}`;
132
153
  /**
133
154
  * Object hash of all well-known file extension category to file extensions mapping
134
155
  */
135
- type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;
156
+ export type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;
136
157
  /**
137
158
  * Supported ECMA version
138
159
  *
@@ -222,7 +243,7 @@ declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, opti
222
243
  testExtensions?: ReadonlyArray<string>;
223
244
  testFolders?: ReadonlyArray<string>;
224
245
  }): Array<string>;
225
- declare const Project: Readonly<{
246
+ export declare const Project: Readonly<{
226
247
  ecmaVersion: typeof ecmaVersion;
227
248
  extensionsToGlob: typeof extensionsToGlob;
228
249
  extensionsToMatcher: typeof extensionsToMatcher;
@@ -237,7 +258,7 @@ declare const Project: Readonly<{
237
258
  /**
238
259
  * Project common scripts
239
260
  */
240
- declare const ProjectScript: {
261
+ export declare const ProjectScript: {
241
262
  readonly Build: "build";
242
263
  readonly Clean: "clean";
243
264
  readonly CodeAnalysis: "code-analysis";
@@ -255,7 +276,6 @@ declare const ProjectScript: {
255
276
  readonly Typecheck: "typecheck";
256
277
  readonly Validate: "validate";
257
278
  };
258
- type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
279
+ export type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
259
280
  //#endregion
260
- export { ESLintConfig, Extension, ExtensionRegistry, LanguageId, LanguageIdMap, Project, ProjectScript, interopDefault, meta };
261
281
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/LanguageId.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCe,OAAO,UAAU,OAAO,SAAS,OAAO,WAClD,SAAS,MAAM,QAAQ,cAAc,MAAM,QAAQ,KAAK,cAAc,KAAK,KAC7E,QAAQ,MAAM;;;;;;iBAWR,MAAM,8BAA8B;;;;;;iBASpC,MAAM,UAAU,OAAO,SAAS,OAAO,WAAW,SAAS,MAAM,KAAK;;;;;;;;;;;iBAqDtE,YAAY,OAAO,qBAAqB,KAAK,yBAAyB;;;;cAelE,cAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCrGT,eAAe,GAAG,GAAG,YAAY,KAAK,QAAQ;EAAY,eAAe;IAAM,IAAI;iBACnF,eAAe,GAAG,GAAG,IAAI;EAAY,eAAe;IAAM,IAAI;;;;;;KCrBlE,mBAAmB;UAEd;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;cCpBW,MAAI;EAEkF;EAEtB;EAES;;;;;;;KCD1E;;;;KAKA,oBAAoB,OAAO,YAAY,cAAc;;;;;;;;;iBAUxD;;;;;;;;;;;;iBAsCA,gBAAgB,WAAW,MAAM,cAAc,cAAc;;;;;;;;;iBAiB7D;;;;;;;;;iBAmBA;;;;;;;;;;iBA0BA,oBAAoB,YAAY,cAAc,aAAa;;;;;;;;;iBAY3D;;;;;;;;;;iBAeA,iBAAiB,YAAY,cAAc;;;;;;;;;;;;;;;;;;iBAqB3C,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB;EACjB,cAAc;IAEf;cAaU,SAAO;;;;;;;;;;;;;;;cCxLP;;;;;;;;;;;;;;;;;;KAkBD,wBAAwB,4BAA4B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/LanguageId.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCe,OAAO,UAAU,OAAO,SAAS,OAAO,WAClD,SAAS,MAAM,QAAQ,cAAc,MAAM,QAAQ,KAAK,cAAc,KAAK,KAC7E,QAAQ,MAAM;;;;;;iBAWR,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;iBAuBpC,SAAS,OAAO,qBAAqB,QAAQ,cAAc,2CAA2C;;;;;;iBAoBtG,MAAM,UAAU,OAAO,SAAS,OAAO,WAAW,SAAS,MAAM,KAAK;;;;;;;;;;;iBAqDtE,YAAY,OAAO,qBAAqB,KAAK,yBAAyB;;;;qBAmBlE,cAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBC3IT,eAAe,GAAG,GAAG,YAAY,KAAK,QAAQ;EAAY,eAAe;IAAM,IAAI;wBACnF,eAAe,GAAG,GAAG,IAAI;EAAY,eAAe;IAAM,IAAI;;;;;;YCrBlE,mBAAmB;iBAEd;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;qBCpBW,MAAI;EAEkF;EAEtB;EAES;;;;;;;YCD1E;;;;YAKA,oBAAoB,OAAO,YAAY,cAAc;;;;;;;;;iBAUxD;;;;;;;;;;;;iBAsCA,gBAAgB,WAAW,MAAM,cAAc,cAAc;;;;;;;;;iBAiB7D;;;;;;;;;iBAmBA;;;;;;;;;;iBA0BA,oBAAoB,YAAY,cAAc,aAAa;;;;;;;;;iBAY3D;;;;;;;;;;iBAeA,iBAAiB,YAAY,cAAc;;;;;;;;;;;;;;;;;;iBAqB3C,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB;EACjB,cAAc;IAEf;qBAaU,SAAO;;;;;;;;;;;;;;;qBCxLP;;;;;;;;;;;;;;;;;;YAkBD,wBAAwB,4BAA4B"}
package/dist/index.js CHANGED
@@ -43,6 +43,36 @@ function fixme(_status) {
43
43
  return "off";
44
44
  }
45
45
  /**
46
+ * Maps rule names and values using the provided mapping function.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * ESLintConfig.mapRules(
51
+ * {
52
+ * 'rule-name': 'error',
53
+ * 'rule-to-drop': 'error',
54
+ * },
55
+ * (rule, value) => {
56
+ * if (rule === 'rule-name') return ['new-rule-name', value];
57
+ * return undefined;
58
+ * }
59
+ * ); // { 'new-rule-name': 'error' }
60
+ * ```
61
+ * @param rules
62
+ * @param mapFn
63
+ */
64
+ function mapRules(rules, mapFn) {
65
+ const mappedRules = Object.create(null);
66
+ for (let index = 0, keys = Object.keys(rules); index < keys.length; index++) {
67
+ const key = keys[index];
68
+ const mapped = mapFn(key, rules[key]);
69
+ if (mapped == null) continue;
70
+ mappedRules[mapped[0]] = mapped[1];
71
+ }
72
+ Object.setPrototypeOf(mappedRules, Object.getPrototypeOf(rules));
73
+ return mappedRules;
74
+ }
75
+ /**
46
76
  * Return a new merged flat configuration
47
77
  *
48
78
  * @param configs
@@ -87,11 +117,16 @@ function merge(...configs) {
87
117
  * @param map The object containing the rename map.
88
118
  */
89
119
  function renameRules(rules, map) {
90
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
91
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
92
- else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
120
+ const mapKeys = Object.keys(map);
121
+ return mapRules(rules, (key, value) => {
122
+ for (let index = 0; index < mapKeys.length; index++) {
123
+ const from = mapKeys[index];
124
+ const to = map[from];
125
+ if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
126
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
127
+ }
93
128
  return [key, value];
94
- }));
129
+ });
95
130
  }
96
131
  /**
97
132
  * @namespace
@@ -99,6 +134,7 @@ function renameRules(rules, map) {
99
134
  const ESLintConfig = Object.freeze({
100
135
  concat,
101
136
  fixme,
137
+ mapRules,
102
138
  merge,
103
139
  renameRules
104
140
  });
@@ -111,9 +147,9 @@ function interopDefault(m) {
111
147
  //#endregion
112
148
  //#region src/meta.ts
113
149
  const meta = Object.freeze({
114
- buildNumber: 1788194737,
150
+ buildNumber: 1788793943,
115
151
  name: "@w5s/dev",
116
- version: "3.25.0"
152
+ version: "3.27.0"
117
153
  });
118
154
  //#endregion
119
155
  //#region src/Project.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * Concat multiple flat configs into a single flat config array.\n *\n * It also resolves promises and flattens the result.\n *\n * @example\n *\n * ```ts\n * import eslint from '@eslint/js'\n *\n * export default ESLintConfig.concat(\n * {\n * plugins: {},\n * rules: {},\n * },\n * // It can also takes a array of configs:\n * [\n * {\n * plugins: {},\n * rules: {},\n * }\n * // ...\n * ],\n * // Or promises:\n * Promise.resolve({\n * files: ['*.ts'],\n * rules: {},\n * })\n * );\n * ```\n * @param configs\n */\nasync function concat<T extends Linter.Config = Linter.Config>(\n ...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>\n): Promise<Array<T>> {\n // eslint-disable-next-line ts/await-thenable\n const resolved = await Promise.all(configs);\n return resolved.flat() as Array<T>;\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: [number | string, ...Array<any>] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n }, {} as T);\n\n // Remove unused keys\n for (const key of Object.keys(merged)) {\n if (!keys.has(key))\n // eslint-disable-next-line ts/no-dynamic-delete, ts/no-unsafe-member-access\n delete (merged as any)[key];\n }\n\n return merged;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n merge,\n renameRules,\n});\n","// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\nconst getDefaultOrElse = (_: any) => _?.default ?? _;\n\n/**\n * Resolves a module or promise-like object, returning the default export if available.\n *\n * @example\n * ```ts\n * // modules.ts\n * export default {\n * foo: true\n * };\n * // Async API\n * const modPromise = import('./module');\n * interopDefault(modPromise); // == Promise.resolve({ foo: true })\n * // Sync API\n * const mod = await import('./module');\n * interopDefault(mod); // == { foo: true }\n * ```\n *\n * @template T - The type of the module or promise-like object.\n * @param m The module or promise-like object to resolve.\n */\nexport function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;\nexport function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;\nexport function interopDefault<T>(m: PromiseLike<T> | T): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n // eslint-disable-next-line unicorn/prefer-await, ts/no-unsafe-return\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import type { LanguageId } from './LanguageId.js';\n\n/**\n * A type of a file extension\n */\nexport type Extension = `.${string}`;\n\n/**\n * Object hash of all well-known file extension category to file extensions mapping\n */\nexport type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;\n\n/**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\nfunction ecmaVersion() {\n return 2022 as const;\n}\n\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\nconst registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n};\n\n/**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\nfunction queryExtensions(languages: Array<LanguageId>): ReadonlyArray<Extension> {\n return languages\n .reduce<Array<Extension>>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as Array<Extension>)), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort((left, right) => left.localeCompare(right));\n}\n\n/**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\nfunction sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n}\n\nconst RESOURCE_EXTENSIONS: ReadonlyArray<Extension> = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n]);\n\n/**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\nfunction resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n}\n\nconst IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n]);\n\n/**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToMatcher(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: ReadonlyArray<Extension>): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).join('|')})`;\n}\n\n/**\n * Return a list of test glob matchers for a list of extensions.\n * This is useful to generate globs for vitest/jest matchers\n *\n * @param extensions\n * @param options\n * @param options.testExtensions\n * @param options.testFolders\n * @example\n * ```ts\n * Project.extensionsToTestGlob(['.js', '.ts']);\n * // ['<tests-folder-glob>', '<test-suffix-glob>']\n *\n * Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });\n * // ['<tests-folder-glob>', '<custom-test-suffix-glob>']\n * ```\n */\nfunction extensionsToTestGlob(\n extensions: ReadonlyArray<Extension>,\n options: {\n testExtensions?: ReadonlyArray<string>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['spec', 'test'],\n testFolders = ['__tests__'],\n } = options;\n const extensionPattern = extensions.map((_) => _.replace(reExtension, '')).join('|');\n\n return [\n ...testFolders.map((folder) => `**/${folder}/**/*.+(${extensionPattern})`),\n `**/*.+(${testExtensions.join('|')}).+(${extensionPattern})`,\n ];\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\n extensionsToTestGlob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Typecheck: 'typecheck',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAGnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAyE;CACtF,OAAO;AACT;;;;;;AAOA,SAAS,MAA+C,GAAG,SAAsB;CAC/E,MAAM,OAAO,IAAI,IAAI,QAAQ,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,MAAM,SAAS,QAAQ,QAAQ,KAAK,QAAQ;EAC1C,OAAO;GACL,GAAG;GACH,GAAG;GACH,OAAO,CACL,GAAI,IAAI,SAAS,CAAC,GAClB,GAAI,IAAI,SAAS,CAAC,CACpB;GACA,SAAS,CACP,GAAI,IAAI,WAAW,CAAC,GACpB,GAAI,IAAI,WAAW,CAAC,CACtB;GACA,iBAAiB;IACf,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,eAAe;IACb,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,SAAS;IACP,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,OAAO;IACL,GAAG,IAAI;IACP,GAAG,IAAI;GACT;EACF;CACF,GAAG,CAAC,CAAM;CAGV,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,KAAK,IAAI,GAAG,GAEf,OAAQ,OAAe;CAG3B,OAAO;AACT;;;;;;;;;;;AAYA,SAAS,YAAY,OAA4B,KAAkD;CACjG,OAAO,OAAO,YACZ,OAAO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O,UAAU,iBAAiB,EAAE,GACzE,UAAU,eAAe,KAAK,GAAG,EAAE,MAAM,iBAAiB,EAC5D;AACF;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;ACjMD,MAAa,gBAAgB;CAC3B,OAAO;CACP,OAAO;CACP,cAAc;CACd,UAAU;CACV,SAAS;CACT,MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * Concat multiple flat configs into a single flat config array.\n *\n * It also resolves promises and flattens the result.\n *\n * @example\n *\n * ```ts\n * import eslint from '@eslint/js'\n *\n * export default ESLintConfig.concat(\n * {\n * plugins: {},\n * rules: {},\n * },\n * // It can also takes a array of configs:\n * [\n * {\n * plugins: {},\n * rules: {},\n * }\n * // ...\n * ],\n * // Or promises:\n * Promise.resolve({\n * files: ['*.ts'],\n * rules: {},\n * })\n * );\n * ```\n * @param configs\n */\nasync function concat<T extends Linter.Config = Linter.Config>(\n ...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>\n): Promise<Array<T>> {\n // eslint-disable-next-line ts/await-thenable\n const resolved = await Promise.all(configs);\n return resolved.flat() as Array<T>;\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: [number | string, ...Array<any>] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Maps rule names and values using the provided mapping function.\n *\n * @example\n * ```ts\n * ESLintConfig.mapRules(\n * {\n * 'rule-name': 'error',\n * 'rule-to-drop': 'error',\n * },\n * (rule, value) => {\n * if (rule === 'rule-name') return ['new-rule-name', value];\n * return undefined;\n * }\n * ); // { 'new-rule-name': 'error' }\n * ```\n * @param rules\n * @param mapFn\n */\nfunction mapRules(rules: Record<string, any>, mapFn: (rule: string, value: any) => [string, any] | undefined): Record<string, any> {\n const mappedRules = Object.create(null) as Record<string, any>;\n for (let index = 0, keys = Object.keys(rules); index < keys.length; index++) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const key = keys[index]!;\n const mapped = mapFn(key, rules[key]);\n if (mapped == null) continue;\n // eslint-disable-next-line ts/no-unsafe-assignment\n mappedRules[mapped[0]] = mapped[1];\n }\n // eslint-disable-next-line ts/no-unsafe-argument\n Object.setPrototypeOf(mappedRules, Object.getPrototypeOf(rules));\n return mappedRules;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n }, {} as T);\n\n // Remove unused keys\n for (const key of Object.keys(merged)) {\n if (!keys.has(key))\n // eslint-disable-next-line ts/no-dynamic-delete, ts/no-unsafe-member-access\n delete (merged as any)[key];\n }\n\n return merged;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n const mapKeys = Object.keys(map);\n return mapRules(rules, (key, value) => {\n // eslint-disable-next-line ts/prefer-for-of\n for (let index = 0; index < mapKeys.length; index++) {\n // eslint-disable-next-line ts/no-non-null-assertion\n const from = mapKeys[index]!;\n // eslint-disable-next-line ts/no-non-null-assertion\n const to = map[from]!;\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n });\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n mapRules,\n merge,\n renameRules,\n});\n","// eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\nconst getDefaultOrElse = (_: any) => _?.default ?? _;\n\n/**\n * Resolves a module or promise-like object, returning the default export if available.\n *\n * @example\n * ```ts\n * // modules.ts\n * export default {\n * foo: true\n * };\n * // Async API\n * const modPromise = import('./module');\n * interopDefault(modPromise); // == Promise.resolve({ foo: true })\n * // Sync API\n * const mod = await import('./module');\n * interopDefault(mod); // == { foo: true }\n * ```\n *\n * @template T - The type of the module or promise-like object.\n * @param m The module or promise-like object to resolve.\n */\nexport function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;\nexport function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;\nexport function interopDefault<T>(m: PromiseLike<T> | T): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n // eslint-disable-next-line unicorn/prefer-await, ts/no-unsafe-return\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import type { LanguageId } from './LanguageId.js';\n\n/**\n * A type of a file extension\n */\nexport type Extension = `.${string}`;\n\n/**\n * Object hash of all well-known file extension category to file extensions mapping\n */\nexport type ExtensionRegistry = Record<LanguageId, ReadonlyArray<Extension>>;\n\n/**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\nfunction ecmaVersion() {\n return 2022 as const;\n}\n\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\nconst registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n};\n\n/**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\nfunction queryExtensions(languages: Array<LanguageId>): ReadonlyArray<Extension> {\n return languages\n .reduce<Array<Extension>>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as Array<Extension>)), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort((left, right) => left.localeCompare(right));\n}\n\n/**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\nfunction sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n}\n\nconst RESOURCE_EXTENSIONS: ReadonlyArray<Extension> = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n]);\n\n/**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\nfunction resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n}\n\nconst IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n]);\n\n/**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToMatcher(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: ReadonlyArray<Extension>): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).join('|')})`;\n}\n\n/**\n * Return a list of test glob matchers for a list of extensions.\n * This is useful to generate globs for vitest/jest matchers\n *\n * @param extensions\n * @param options\n * @param options.testExtensions\n * @param options.testFolders\n * @example\n * ```ts\n * Project.extensionsToTestGlob(['.js', '.ts']);\n * // ['<tests-folder-glob>', '<test-suffix-glob>']\n *\n * Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });\n * // ['<tests-folder-glob>', '<custom-test-suffix-glob>']\n * ```\n */\nfunction extensionsToTestGlob(\n extensions: ReadonlyArray<Extension>,\n options: {\n testExtensions?: ReadonlyArray<string>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['spec', 'test'],\n testFolders = ['__tests__'],\n } = options;\n const extensionPattern = extensions.map((_) => _.replace(reExtension, '')).join('|');\n\n return [\n ...testFolders.map((folder) => `**/${folder}/**/*.+(${extensionPattern})`),\n `**/*.+(${testExtensions.join('|')}).+(${extensionPattern})`,\n ];\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\n extensionsToTestGlob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Typecheck: 'typecheck',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAGnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAyE;CACtF,OAAO;AACT;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,SAAS,OAA4B,OAAqF;CACjI,MAAM,cAAc,OAAO,OAAO,IAAI;CACtC,KAAK,IAAI,QAAQ,GAAG,OAAO,OAAO,KAAK,KAAK,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAE3E,MAAM,MAAM,KAAK;EACjB,MAAM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CACT,MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/dev",
3
- "version": "3.25.0",
3
+ "version": "3.27.0",
4
4
  "description": "Shared development constants and functions",
5
5
  "keywords": [
6
6
  "config",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "5f5e5d054cec6e06bce7759585cc8482977b0fb7"
50
+ "gitHead": "f01e374782fdf338f411115d7e82a0353540282b"
51
51
  }
@@ -49,6 +49,40 @@ function fixme(_status: [number | string, ...Array<any>] | number | string | und
49
49
  return 'off' as const;
50
50
  }
51
51
 
52
+ /**
53
+ * Maps rule names and values using the provided mapping function.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * ESLintConfig.mapRules(
58
+ * {
59
+ * 'rule-name': 'error',
60
+ * 'rule-to-drop': 'error',
61
+ * },
62
+ * (rule, value) => {
63
+ * if (rule === 'rule-name') return ['new-rule-name', value];
64
+ * return undefined;
65
+ * }
66
+ * ); // { 'new-rule-name': 'error' }
67
+ * ```
68
+ * @param rules
69
+ * @param mapFn
70
+ */
71
+ function mapRules(rules: Record<string, any>, mapFn: (rule: string, value: any) => [string, any] | undefined): Record<string, any> {
72
+ const mappedRules = Object.create(null) as Record<string, any>;
73
+ for (let index = 0, keys = Object.keys(rules); index < keys.length; index++) {
74
+ // eslint-disable-next-line ts/no-non-null-assertion
75
+ const key = keys[index]!;
76
+ const mapped = mapFn(key, rules[key]);
77
+ if (mapped == null) continue;
78
+ // eslint-disable-next-line ts/no-unsafe-assignment
79
+ mappedRules[mapped[0]] = mapped[1];
80
+ }
81
+ // eslint-disable-next-line ts/no-unsafe-argument
82
+ Object.setPrototypeOf(mappedRules, Object.getPrototypeOf(rules));
83
+ return mappedRules;
84
+ }
85
+
52
86
  /**
53
87
  * Return a new merged flat configuration
54
88
  *
@@ -108,15 +142,19 @@ function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T
108
142
  * @param map The object containing the rename map.
109
143
  */
110
144
  function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {
111
- return Object.fromEntries(
112
- Object.entries(rules).map(([key, value]) => {
113
- for (const [from, to] of Object.entries(map)) {
114
- if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
115
- else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];
116
- }
117
- return [key, value];
118
- }),
119
- );
145
+ const mapKeys = Object.keys(map);
146
+ return mapRules(rules, (key, value) => {
147
+ // eslint-disable-next-line ts/prefer-for-of
148
+ for (let index = 0; index < mapKeys.length; index++) {
149
+ // eslint-disable-next-line ts/no-non-null-assertion
150
+ const from = mapKeys[index]!;
151
+ // eslint-disable-next-line ts/no-non-null-assertion
152
+ const to = map[from]!;
153
+ if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
154
+ else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];
155
+ }
156
+ return [key, value];
157
+ });
120
158
  }
121
159
 
122
160
  /**
@@ -125,6 +163,7 @@ function renameRules(rules: Record<string, any>, map: Record<string, string>): R
125
163
  export const ESLintConfig = Object.freeze({
126
164
  concat,
127
165
  fixme,
166
+ mapRules,
128
167
  merge,
129
168
  renameRules,
130
169
  });