@w5s/dev 3.29.0 → 3.30.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 +48 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +29 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Project.ts +72 -10
package/dist/index.cjs
CHANGED
|
@@ -148,9 +148,9 @@ function interopDefault(m) {
|
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/meta.ts
|
|
150
150
|
const meta = Object.freeze({
|
|
151
|
-
buildNumber:
|
|
151
|
+
buildNumber: 1789648672,
|
|
152
152
|
name: "@w5s/dev",
|
|
153
|
-
version: "3.
|
|
153
|
+
version: "3.30.0"
|
|
154
154
|
});
|
|
155
155
|
//#endregion
|
|
156
156
|
//#region src/Project.ts
|
|
@@ -293,13 +293,21 @@ const reExtension = /^\./;
|
|
|
293
293
|
* Return a glob matcher that will match any list of extensions
|
|
294
294
|
*
|
|
295
295
|
* @param extensions
|
|
296
|
+
* @param options
|
|
297
|
+
* @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
298
|
+
* @param options.nested whether to match files in nested folders
|
|
296
299
|
* @example
|
|
297
300
|
* ```ts
|
|
298
|
-
* Project.extensionsToGlob(['.js', '.ts']) // '
|
|
301
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'
|
|
302
|
+
* Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files
|
|
303
|
+
* Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })
|
|
304
|
+
* // '*.@(stories|story).@(ts|tsx)'
|
|
299
305
|
* ```
|
|
300
306
|
*/
|
|
301
|
-
function extensionsToGlob(extensions) {
|
|
302
|
-
|
|
307
|
+
function extensionsToGlob(extensions, options = {}) {
|
|
308
|
+
const language = globExt(extensions);
|
|
309
|
+
const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;
|
|
310
|
+
return `${options.nested === true ? "**/" : ""}${compoundGlob}`;
|
|
303
311
|
}
|
|
304
312
|
/**
|
|
305
313
|
* Return a list of test glob matchers for a list of extensions.
|
|
@@ -307,21 +315,51 @@ function extensionsToGlob(extensions) {
|
|
|
307
315
|
*
|
|
308
316
|
* @param extensions
|
|
309
317
|
* @param options
|
|
310
|
-
* @param options.testExtensions
|
|
318
|
+
* @param options.testExtensions dotted compound extensions (e.g. `.spec`, `.test`)
|
|
311
319
|
* @param options.testFolders
|
|
312
320
|
* @example
|
|
313
321
|
* ```ts
|
|
314
322
|
* Project.extensionsToTestGlob(['.js', '.ts']);
|
|
315
323
|
* // ['<tests-folder-glob>', '<test-suffix-glob>']
|
|
316
324
|
*
|
|
317
|
-
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });
|
|
325
|
+
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['.unit'] });
|
|
318
326
|
* // ['<tests-folder-glob>', '<custom-test-suffix-glob>']
|
|
319
327
|
* ```
|
|
320
328
|
*/
|
|
321
329
|
function extensionsToTestGlob(extensions, options = {}) {
|
|
322
|
-
const { testExtensions = ["spec", "test"], testFolders = ["__tests__"] } = options;
|
|
323
|
-
|
|
324
|
-
|
|
330
|
+
const { testExtensions = [".spec", ".test"], testFolders = ["__tests__"] } = options;
|
|
331
|
+
return [...testFolders.length === 0 ? [] : [`**/${globOr(testFolders)}/${extensionsToGlob(extensions, { nested: true })}`], ...testExtensions.length === 0 ? [] : [extensionsToGlob(extensions, {
|
|
332
|
+
compoundExtensions: testExtensions,
|
|
333
|
+
nested: true
|
|
334
|
+
})]];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Build an globExt fragment that matches exactly one of the given extensions.
|
|
338
|
+
*
|
|
339
|
+
* @param extensions
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* globExt([]) // ''
|
|
343
|
+
* globExt(['.js']) // '.js'
|
|
344
|
+
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
function globExt(extensions) {
|
|
348
|
+
const ext = globOr(extensions.map((_) => _.replace(reExtension, "")));
|
|
349
|
+
return ext === "" ? "" : `.${ext}`;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Build an globExt alternation group matching any of the given values.
|
|
353
|
+
*
|
|
354
|
+
* @param values
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* globOr(['js']) // 'js'
|
|
358
|
+
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
function globOr(values) {
|
|
362
|
+
return values.length === 0 ? "" : values.length === 1 ? values[0] : `@(${values.join("|")})`;
|
|
325
363
|
}
|
|
326
364
|
const Project = Object.freeze({
|
|
327
365
|
ecmaVersion,
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 * 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;CAEnF,OAAO,CACL,GAAG,YAAY,KAAK,WAAW,MAAM,OAAO,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.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 * @param options\n * @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)\n * @param options.nested whether to match files in nested folders\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'\n * Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files\n * Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })\n * // '*.@(stories|story).@(ts|tsx)'\n * ```\n */\nfunction extensionsToGlob(\n extensions: ReadonlyArray<Extension>,\n options: extensionToGlob.Options = {},\n): string {\n const language = globExt(extensions);\n const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;\n return `${options.nested === true ? '**/' : ''}${compoundGlob}`;\n}\nexport namespace extensionToGlob {\n /**\n * Options for the `extensionsToGlob` function.\n */\n export interface Options {\n /**\n * Optional dotted segments before the language extension (e.g. `.stories`, `.spec`)\n * Compound extensions are used to match files like `Component.stories.ts` where `.stories` is a compound extension.\n */\n compoundExtensions?: ReadonlyArray<Extension> | undefined;\n\n /**\n * Whether to match files in nested folders.\n *\n * @default false\n */\n nested?: boolean | undefined;\n }\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 dotted compound extensions (e.g. `.spec`, `.test`)\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<Extension>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['.spec', '.test'],\n testFolders = ['__tests__'],\n } = options;\n\n return [\n ...(testFolders.length === 0 ? [] : [`**/${globOr(testFolders)}/${extensionsToGlob(extensions, { nested: true })}`]),\n ...(testExtensions.length === 0\n ? []\n : [extensionsToGlob(extensions, { compoundExtensions: testExtensions, nested: true })]),\n ];\n}\n\n/**\n * Build an globExt fragment that matches exactly one of the given extensions.\n *\n * @param extensions\n * @example\n * ```ts\n * globExt([]) // ''\n * globExt(['.js']) // '.js'\n * globExt(['.js', '.ts']) // '.@(js|ts)'\n * ```\n */\nfunction globExt(extensions: ReadonlyArray<Extension>): string {\n const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));\n return ext === '' ? '' : `.${ext}`;\n}\n\n/**\n * Build an globExt alternation group matching any of the given values.\n *\n * @param values\n * @example\n * ```ts\n * globOr(['js']) // 'js'\n * globOr(['js', 'ts']) // '@(js|ts)'\n * ```\n */\nfunction globOr(values: ReadonlyArray<string>): string {\n // eslint-disable-next-line ts/no-non-null-assertion\n return values.length === 0 ? '' : values.length === 1 ? values[0]! : `@(${values.join('|')})`;\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,I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aAAa,EAAE,CAAC,CAAC;CACpE,OAAO,QAAQ,KAAK,KAAK,IAAI;AAC/B;;;;;;;;;;;AAYA,SAAS,OAAO,QAAuC;CAErD,OAAO,OAAO,WAAW,IAAI,KAAK,OAAO,WAAW,IAAI,OAAO,KAAM,KAAK,OAAO,KAAK,GAAG,EAAE;AAC7F;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AC/PD,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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -216,31 +216,55 @@ declare function ignored(): readonly string[];
|
|
|
216
216
|
* Return a glob matcher that will match any list of extensions
|
|
217
217
|
*
|
|
218
218
|
* @param extensions
|
|
219
|
+
* @param options
|
|
220
|
+
* @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
221
|
+
* @param options.nested whether to match files in nested folders
|
|
219
222
|
* @example
|
|
220
223
|
* ```ts
|
|
221
|
-
* Project.extensionsToGlob(['.js', '.ts']) // '
|
|
224
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'
|
|
225
|
+
* Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files
|
|
226
|
+
* Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })
|
|
227
|
+
* // '*.@(stories|story).@(ts|tsx)'
|
|
222
228
|
* ```
|
|
223
229
|
*/
|
|
224
|
-
declare function extensionsToGlob(extensions: ReadonlyArray<Extension
|
|
230
|
+
declare function extensionsToGlob(extensions: ReadonlyArray<Extension>, options?: extensionToGlob.Options): string;
|
|
231
|
+
export declare namespace extensionToGlob {
|
|
232
|
+
/**
|
|
233
|
+
* Options for the `extensionsToGlob` function.
|
|
234
|
+
*/
|
|
235
|
+
interface Options {
|
|
236
|
+
/**
|
|
237
|
+
* Optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
238
|
+
* Compound extensions are used to match files like `Component.stories.ts` where `.stories` is a compound extension.
|
|
239
|
+
*/
|
|
240
|
+
compoundExtensions?: ReadonlyArray<Extension> | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Whether to match files in nested folders.
|
|
243
|
+
*
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
nested?: boolean | undefined;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
225
249
|
/**
|
|
226
250
|
* Return a list of test glob matchers for a list of extensions.
|
|
227
251
|
* This is useful to generate globs for vitest/jest matchers
|
|
228
252
|
*
|
|
229
253
|
* @param extensions
|
|
230
254
|
* @param options
|
|
231
|
-
* @param options.testExtensions
|
|
255
|
+
* @param options.testExtensions dotted compound extensions (e.g. `.spec`, `.test`)
|
|
232
256
|
* @param options.testFolders
|
|
233
257
|
* @example
|
|
234
258
|
* ```ts
|
|
235
259
|
* Project.extensionsToTestGlob(['.js', '.ts']);
|
|
236
260
|
* // ['<tests-folder-glob>', '<test-suffix-glob>']
|
|
237
261
|
*
|
|
238
|
-
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });
|
|
262
|
+
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['.unit'] });
|
|
239
263
|
* // ['<tests-folder-glob>', '<custom-test-suffix-glob>']
|
|
240
264
|
* ```
|
|
241
265
|
*/
|
|
242
266
|
declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, options?: {
|
|
243
|
-
testExtensions?: ReadonlyArray<
|
|
267
|
+
testExtensions?: ReadonlyArray<Extension>;
|
|
244
268
|
testFolders?: ReadonlyArray<string>;
|
|
245
269
|
}): Array<string>;
|
|
246
270
|
export declare const Project: Readonly<{
|
package/dist/index.d.cts.map
CHANGED
|
@@ -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;;;;;;;;;;;;;;;;;;;;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
|
|
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/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D,wBAAwB,4BAA4B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -216,31 +216,55 @@ declare function ignored(): readonly string[];
|
|
|
216
216
|
* Return a glob matcher that will match any list of extensions
|
|
217
217
|
*
|
|
218
218
|
* @param extensions
|
|
219
|
+
* @param options
|
|
220
|
+
* @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
221
|
+
* @param options.nested whether to match files in nested folders
|
|
219
222
|
* @example
|
|
220
223
|
* ```ts
|
|
221
|
-
* Project.extensionsToGlob(['.js', '.ts']) // '
|
|
224
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'
|
|
225
|
+
* Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files
|
|
226
|
+
* Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })
|
|
227
|
+
* // '*.@(stories|story).@(ts|tsx)'
|
|
222
228
|
* ```
|
|
223
229
|
*/
|
|
224
|
-
declare function extensionsToGlob(extensions: ReadonlyArray<Extension
|
|
230
|
+
declare function extensionsToGlob(extensions: ReadonlyArray<Extension>, options?: extensionToGlob.Options): string;
|
|
231
|
+
export declare namespace extensionToGlob {
|
|
232
|
+
/**
|
|
233
|
+
* Options for the `extensionsToGlob` function.
|
|
234
|
+
*/
|
|
235
|
+
interface Options {
|
|
236
|
+
/**
|
|
237
|
+
* Optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
238
|
+
* Compound extensions are used to match files like `Component.stories.ts` where `.stories` is a compound extension.
|
|
239
|
+
*/
|
|
240
|
+
compoundExtensions?: ReadonlyArray<Extension> | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Whether to match files in nested folders.
|
|
243
|
+
*
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
nested?: boolean | undefined;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
225
249
|
/**
|
|
226
250
|
* Return a list of test glob matchers for a list of extensions.
|
|
227
251
|
* This is useful to generate globs for vitest/jest matchers
|
|
228
252
|
*
|
|
229
253
|
* @param extensions
|
|
230
254
|
* @param options
|
|
231
|
-
* @param options.testExtensions
|
|
255
|
+
* @param options.testExtensions dotted compound extensions (e.g. `.spec`, `.test`)
|
|
232
256
|
* @param options.testFolders
|
|
233
257
|
* @example
|
|
234
258
|
* ```ts
|
|
235
259
|
* Project.extensionsToTestGlob(['.js', '.ts']);
|
|
236
260
|
* // ['<tests-folder-glob>', '<test-suffix-glob>']
|
|
237
261
|
*
|
|
238
|
-
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });
|
|
262
|
+
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['.unit'] });
|
|
239
263
|
* // ['<tests-folder-glob>', '<custom-test-suffix-glob>']
|
|
240
264
|
* ```
|
|
241
265
|
*/
|
|
242
266
|
declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, options?: {
|
|
243
|
-
testExtensions?: ReadonlyArray<
|
|
267
|
+
testExtensions?: ReadonlyArray<Extension>;
|
|
244
268
|
testFolders?: ReadonlyArray<string>;
|
|
245
269
|
}): Array<string>;
|
|
246
270
|
export declare const Project: Readonly<{
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;;;;;;;;;;;;;;;;;;;;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
|
|
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;;;;;;;;;;;;;;;;iBAqBA,iBACP,YAAY,cAAc,YAC1B,UAAS,gBAAgB;yBAMV;;;;YAIE;;;;;IAKf,qBAAqB,cAAc;;;;;;IAOnC;;;;;;;;;;;;;;;;;;;;iBAqBK,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB,cAAc;EAC/B,cAAc;IAEf;qBA6CU,SAAO;;;;;;;;;;;;;;;qBCtPP;;;;;;;;;;;;;;;;;;YAkBD,wBAAwB,4BAA4B"}
|
package/dist/index.js
CHANGED
|
@@ -147,9 +147,9 @@ function interopDefault(m) {
|
|
|
147
147
|
//#endregion
|
|
148
148
|
//#region src/meta.ts
|
|
149
149
|
const meta = Object.freeze({
|
|
150
|
-
buildNumber:
|
|
150
|
+
buildNumber: 1789648672,
|
|
151
151
|
name: "@w5s/dev",
|
|
152
|
-
version: "3.
|
|
152
|
+
version: "3.30.0"
|
|
153
153
|
});
|
|
154
154
|
//#endregion
|
|
155
155
|
//#region src/Project.ts
|
|
@@ -292,13 +292,21 @@ const reExtension = /^\./;
|
|
|
292
292
|
* Return a glob matcher that will match any list of extensions
|
|
293
293
|
*
|
|
294
294
|
* @param extensions
|
|
295
|
+
* @param options
|
|
296
|
+
* @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
297
|
+
* @param options.nested whether to match files in nested folders
|
|
295
298
|
* @example
|
|
296
299
|
* ```ts
|
|
297
|
-
* Project.extensionsToGlob(['.js', '.ts']) // '
|
|
300
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'
|
|
301
|
+
* Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files
|
|
302
|
+
* Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })
|
|
303
|
+
* // '*.@(stories|story).@(ts|tsx)'
|
|
298
304
|
* ```
|
|
299
305
|
*/
|
|
300
|
-
function extensionsToGlob(extensions) {
|
|
301
|
-
|
|
306
|
+
function extensionsToGlob(extensions, options = {}) {
|
|
307
|
+
const language = globExt(extensions);
|
|
308
|
+
const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;
|
|
309
|
+
return `${options.nested === true ? "**/" : ""}${compoundGlob}`;
|
|
302
310
|
}
|
|
303
311
|
/**
|
|
304
312
|
* Return a list of test glob matchers for a list of extensions.
|
|
@@ -306,21 +314,51 @@ function extensionsToGlob(extensions) {
|
|
|
306
314
|
*
|
|
307
315
|
* @param extensions
|
|
308
316
|
* @param options
|
|
309
|
-
* @param options.testExtensions
|
|
317
|
+
* @param options.testExtensions dotted compound extensions (e.g. `.spec`, `.test`)
|
|
310
318
|
* @param options.testFolders
|
|
311
319
|
* @example
|
|
312
320
|
* ```ts
|
|
313
321
|
* Project.extensionsToTestGlob(['.js', '.ts']);
|
|
314
322
|
* // ['<tests-folder-glob>', '<test-suffix-glob>']
|
|
315
323
|
*
|
|
316
|
-
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });
|
|
324
|
+
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['.unit'] });
|
|
317
325
|
* // ['<tests-folder-glob>', '<custom-test-suffix-glob>']
|
|
318
326
|
* ```
|
|
319
327
|
*/
|
|
320
328
|
function extensionsToTestGlob(extensions, options = {}) {
|
|
321
|
-
const { testExtensions = ["spec", "test"], testFolders = ["__tests__"] } = options;
|
|
322
|
-
|
|
323
|
-
|
|
329
|
+
const { testExtensions = [".spec", ".test"], testFolders = ["__tests__"] } = options;
|
|
330
|
+
return [...testFolders.length === 0 ? [] : [`**/${globOr(testFolders)}/${extensionsToGlob(extensions, { nested: true })}`], ...testExtensions.length === 0 ? [] : [extensionsToGlob(extensions, {
|
|
331
|
+
compoundExtensions: testExtensions,
|
|
332
|
+
nested: true
|
|
333
|
+
})]];
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Build an globExt fragment that matches exactly one of the given extensions.
|
|
337
|
+
*
|
|
338
|
+
* @param extensions
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* globExt([]) // ''
|
|
342
|
+
* globExt(['.js']) // '.js'
|
|
343
|
+
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
function globExt(extensions) {
|
|
347
|
+
const ext = globOr(extensions.map((_) => _.replace(reExtension, "")));
|
|
348
|
+
return ext === "" ? "" : `.${ext}`;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Build an globExt alternation group matching any of the given values.
|
|
352
|
+
*
|
|
353
|
+
* @param values
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* globOr(['js']) // 'js'
|
|
357
|
+
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
function globOr(values) {
|
|
361
|
+
return values.length === 0 ? "" : values.length === 1 ? values[0] : `@(${values.join("|")})`;
|
|
324
362
|
}
|
|
325
363
|
const Project = Object.freeze({
|
|
326
364
|
ecmaVersion,
|
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 * 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,CAAC;CAC/D,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,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AO,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;AAClE;;;;;;;;;AAUA,SAAS,UAAU;CACjB,OAAO;AACT;AAEA,MAAM,cAAc;;;;;;;;;;AAWpB,SAAS,iBAAiB,YAA8C;CACtE,OAAO,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AAC5E;;;;;;;;;;;;;;;;;;AAmBA,SAAS,qBACP,YACA,UAGI,CAAC,GACU;CACf,MAAM,EACJ,iBAAiB,CAAC,QAAQ,MAAM,GAChC,cAAc,CAAC,WAAW,MACxB;CACJ,MAAM,mBAAmB,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG;CAEnF,OAAO,CACL,GAAG,YAAY,KAAK,WAAW,MAAM,OAAO,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 * @param options\n * @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)\n * @param options.nested whether to match files in nested folders\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'\n * Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files\n * Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })\n * // '*.@(stories|story).@(ts|tsx)'\n * ```\n */\nfunction extensionsToGlob(\n extensions: ReadonlyArray<Extension>,\n options: extensionToGlob.Options = {},\n): string {\n const language = globExt(extensions);\n const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;\n return `${options.nested === true ? '**/' : ''}${compoundGlob}`;\n}\nexport namespace extensionToGlob {\n /**\n * Options for the `extensionsToGlob` function.\n */\n export interface Options {\n /**\n * Optional dotted segments before the language extension (e.g. `.stories`, `.spec`)\n * Compound extensions are used to match files like `Component.stories.ts` where `.stories` is a compound extension.\n */\n compoundExtensions?: ReadonlyArray<Extension> | undefined;\n\n /**\n * Whether to match files in nested folders.\n *\n * @default false\n */\n nested?: boolean | undefined;\n }\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 dotted compound extensions (e.g. `.spec`, `.test`)\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<Extension>;\n testFolders?: ReadonlyArray<string>;\n } = {},\n): Array<string> {\n const {\n testExtensions = ['.spec', '.test'],\n testFolders = ['__tests__'],\n } = options;\n\n return [\n ...(testFolders.length === 0 ? [] : [`**/${globOr(testFolders)}/${extensionsToGlob(extensions, { nested: true })}`]),\n ...(testExtensions.length === 0\n ? []\n : [extensionsToGlob(extensions, { compoundExtensions: testExtensions, nested: true })]),\n ];\n}\n\n/**\n * Build an globExt fragment that matches exactly one of the given extensions.\n *\n * @param extensions\n * @example\n * ```ts\n * globExt([]) // ''\n * globExt(['.js']) // '.js'\n * globExt(['.js', '.ts']) // '.@(js|ts)'\n * ```\n */\nfunction globExt(extensions: ReadonlyArray<Extension>): string {\n const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));\n return ext === '' ? '' : `.${ext}`;\n}\n\n/**\n * Build an globExt alternation group matching any of the given values.\n *\n * @param values\n * @example\n * ```ts\n * globOr(['js']) // 'js'\n * globOr(['js', 'ts']) // '@(js|ts)'\n * ```\n */\nfunction globOr(values: ReadonlyArray<string>): string {\n // eslint-disable-next-line ts/no-non-null-assertion\n return values.length === 0 ? '' : values.length === 1 ? values[0]! : `@(${values.join('|')})`;\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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,UAGI,CAAC,GACU;CACf,MAAM,EACJ,iBAAiB,CAAC,SAAS,OAAO,GAClC,cAAc,CAAC,WAAW,MACxB;CAEJ,OAAO,CACL,GAAI,YAAY,WAAW,IAAI,CAAC,IAAI,CAAC,MAAM,OAAO,WAAW,EAAE,GAAG,iBAAiB,YAAY,EAAE,QAAQ,KAAK,CAAC,GAAG,GAClH,GAAI,eAAe,WAAW,IAC1B,CAAC,IACD,CAAC,iBAAiB,YAAY;EAAE,oBAAoB;EAAgB,QAAQ;CAAK,CAAC,CAAC,CACzF;AACF;;;;;;;;;;;;AAaA,SAAS,QAAQ,YAA8C;CAC7D,MAAM,MAAM,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC;CACpE,OAAO,QAAQ,KAAK,KAAK,IAAI;AAC/B;;;;;;;;;;;AAYA,SAAS,OAAO,QAAuC;CAErD,OAAO,OAAO,WAAW,IAAI,KAAK,OAAO,WAAW,IAAI,OAAO,KAAM,KAAK,OAAO,KAAK,GAAG,EAAE;AAC7F;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AC/PD,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/dev",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.30.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": "
|
|
50
|
+
"gitHead": "58c43b4db84b9fd3869a50cead3757333e6eedc6"
|
|
51
51
|
}
|
package/src/Project.ts
CHANGED
|
@@ -140,13 +140,43 @@ const reExtension = /^\./;
|
|
|
140
140
|
* Return a glob matcher that will match any list of extensions
|
|
141
141
|
*
|
|
142
142
|
* @param extensions
|
|
143
|
+
* @param options
|
|
144
|
+
* @param options.compoundExtensions optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
145
|
+
* @param options.nested whether to match files in nested folders
|
|
143
146
|
* @example
|
|
144
147
|
* ```ts
|
|
145
|
-
* Project.extensionsToGlob(['.js', '.ts']) // '
|
|
148
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.@(js|ts)'
|
|
149
|
+
* Project.extensionsToGlob(['.js', '.ts'], { nested: true }) // Matches nested JavaScript and TypeScript files
|
|
150
|
+
* Project.extensionsToGlob(['.ts', '.tsx'], { compoundExtensions: ['.stories', '.story'] })
|
|
151
|
+
* // '*.@(stories|story).@(ts|tsx)'
|
|
146
152
|
* ```
|
|
147
153
|
*/
|
|
148
|
-
function extensionsToGlob(
|
|
149
|
-
|
|
154
|
+
function extensionsToGlob(
|
|
155
|
+
extensions: ReadonlyArray<Extension>,
|
|
156
|
+
options: extensionToGlob.Options = {},
|
|
157
|
+
): string {
|
|
158
|
+
const language = globExt(extensions);
|
|
159
|
+
const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;
|
|
160
|
+
return `${options.nested === true ? '**/' : ''}${compoundGlob}`;
|
|
161
|
+
}
|
|
162
|
+
export namespace extensionToGlob {
|
|
163
|
+
/**
|
|
164
|
+
* Options for the `extensionsToGlob` function.
|
|
165
|
+
*/
|
|
166
|
+
export interface Options {
|
|
167
|
+
/**
|
|
168
|
+
* Optional dotted segments before the language extension (e.g. `.stories`, `.spec`)
|
|
169
|
+
* Compound extensions are used to match files like `Component.stories.ts` where `.stories` is a compound extension.
|
|
170
|
+
*/
|
|
171
|
+
compoundExtensions?: ReadonlyArray<Extension> | undefined;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Whether to match files in nested folders.
|
|
175
|
+
*
|
|
176
|
+
* @default false
|
|
177
|
+
*/
|
|
178
|
+
nested?: boolean | undefined;
|
|
179
|
+
}
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
/**
|
|
@@ -155,36 +185,68 @@ function extensionsToGlob(extensions: ReadonlyArray<Extension>): string {
|
|
|
155
185
|
*
|
|
156
186
|
* @param extensions
|
|
157
187
|
* @param options
|
|
158
|
-
* @param options.testExtensions
|
|
188
|
+
* @param options.testExtensions dotted compound extensions (e.g. `.spec`, `.test`)
|
|
159
189
|
* @param options.testFolders
|
|
160
190
|
* @example
|
|
161
191
|
* ```ts
|
|
162
192
|
* Project.extensionsToTestGlob(['.js', '.ts']);
|
|
163
193
|
* // ['<tests-folder-glob>', '<test-suffix-glob>']
|
|
164
194
|
*
|
|
165
|
-
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['unit'] });
|
|
195
|
+
* Project.extensionsToTestGlob(['.js', '.ts'], { testExtensions: ['.unit'] });
|
|
166
196
|
* // ['<tests-folder-glob>', '<custom-test-suffix-glob>']
|
|
167
197
|
* ```
|
|
168
198
|
*/
|
|
169
199
|
function extensionsToTestGlob(
|
|
170
200
|
extensions: ReadonlyArray<Extension>,
|
|
171
201
|
options: {
|
|
172
|
-
testExtensions?: ReadonlyArray<
|
|
202
|
+
testExtensions?: ReadonlyArray<Extension>;
|
|
173
203
|
testFolders?: ReadonlyArray<string>;
|
|
174
204
|
} = {},
|
|
175
205
|
): Array<string> {
|
|
176
206
|
const {
|
|
177
|
-
testExtensions = ['spec', 'test'],
|
|
207
|
+
testExtensions = ['.spec', '.test'],
|
|
178
208
|
testFolders = ['__tests__'],
|
|
179
209
|
} = options;
|
|
180
|
-
const extensionPattern = extensions.map((_) => _.replace(reExtension, '')).join('|');
|
|
181
210
|
|
|
182
211
|
return [
|
|
183
|
-
...testFolders.
|
|
184
|
-
|
|
212
|
+
...(testFolders.length === 0 ? [] : [`**/${globOr(testFolders)}/${extensionsToGlob(extensions, { nested: true })}`]),
|
|
213
|
+
...(testExtensions.length === 0
|
|
214
|
+
? []
|
|
215
|
+
: [extensionsToGlob(extensions, { compoundExtensions: testExtensions, nested: true })]),
|
|
185
216
|
];
|
|
186
217
|
}
|
|
187
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Build an globExt fragment that matches exactly one of the given extensions.
|
|
221
|
+
*
|
|
222
|
+
* @param extensions
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* globExt([]) // ''
|
|
226
|
+
* globExt(['.js']) // '.js'
|
|
227
|
+
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
function globExt(extensions: ReadonlyArray<Extension>): string {
|
|
231
|
+
const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));
|
|
232
|
+
return ext === '' ? '' : `.${ext}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Build an globExt alternation group matching any of the given values.
|
|
237
|
+
*
|
|
238
|
+
* @param values
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* globOr(['js']) // 'js'
|
|
242
|
+
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
function globOr(values: ReadonlyArray<string>): string {
|
|
246
|
+
// eslint-disable-next-line ts/no-non-null-assertion
|
|
247
|
+
return values.length === 0 ? '' : values.length === 1 ? values[0]! : `@(${values.join('|')})`;
|
|
248
|
+
}
|
|
249
|
+
|
|
188
250
|
export const Project = Object.freeze({
|
|
189
251
|
ecmaVersion,
|
|
190
252
|
extensionsToGlob,
|