@w5s/dev 3.31.0 → 4.0.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 +44 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -47
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +82 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -51
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Project.ts +108 -75
package/dist/index.cjs
CHANGED
|
@@ -148,12 +148,13 @@ function interopDefault(m) {
|
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/meta.ts
|
|
150
150
|
const meta = Object.freeze({
|
|
151
|
-
buildNumber:
|
|
151
|
+
buildNumber: 1790065426,
|
|
152
152
|
name: "@w5s/dev",
|
|
153
|
-
version: "
|
|
153
|
+
version: "4.0.0"
|
|
154
154
|
});
|
|
155
155
|
//#endregion
|
|
156
156
|
//#region src/Project.ts
|
|
157
|
+
const reExtension = /^\./;
|
|
157
158
|
/**
|
|
158
159
|
* Supported ECMA version
|
|
159
160
|
*
|
|
@@ -271,45 +272,13 @@ const IGNORED = Object.freeze([
|
|
|
271
272
|
* @param extensions
|
|
272
273
|
* @example
|
|
273
274
|
* ```ts
|
|
274
|
-
* Project.
|
|
275
|
+
* Project.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
275
276
|
* ```
|
|
276
277
|
*/
|
|
277
|
-
function
|
|
278
|
+
function extensionsToRegExp(extensions) {
|
|
278
279
|
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
279
280
|
}
|
|
280
281
|
/**
|
|
281
|
-
* Files and folders to always ignore
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```ts
|
|
285
|
-
* IGNORED // ['node_modules/', 'build/', ...]
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
function ignored() {
|
|
289
|
-
return IGNORED;
|
|
290
|
-
}
|
|
291
|
-
const reExtension = /^\./;
|
|
292
|
-
/**
|
|
293
|
-
* Return a glob matcher that will match any list of extensions
|
|
294
|
-
*
|
|
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
|
|
299
|
-
* @example
|
|
300
|
-
* ```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)'
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
function extensionsToGlob(extensions, options = {}) {
|
|
308
|
-
const language = globExt(extensions);
|
|
309
|
-
const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;
|
|
310
|
-
return `${options.nested === true ? "**/" : ""}${compoundGlob}`;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
282
|
* Return a list of test glob matchers for a list of extensions.
|
|
314
283
|
* This is useful to generate globs for vitest/jest matchers
|
|
315
284
|
*
|
|
@@ -328,44 +297,68 @@ function extensionsToGlob(extensions, options = {}) {
|
|
|
328
297
|
*/
|
|
329
298
|
function extensionsToTestGlob(extensions, options = {}) {
|
|
330
299
|
const { testExtensions = [".spec", ".test"], testFolders = ["__tests__"] } = options;
|
|
331
|
-
return [...testFolders.length === 0 ? [] : [
|
|
332
|
-
|
|
300
|
+
return [...testFolders.length === 0 ? [] : [glob({
|
|
301
|
+
fileExtensions: [extensions],
|
|
302
|
+
folderAncestors: testFolders,
|
|
303
|
+
nested: true
|
|
304
|
+
})], ...testExtensions.length === 0 ? [] : [glob({
|
|
305
|
+
fileExtensions: [testExtensions, extensions],
|
|
333
306
|
nested: true
|
|
334
307
|
})]];
|
|
335
308
|
}
|
|
336
309
|
/**
|
|
337
|
-
*
|
|
310
|
+
* Create a new glob pattern based on the provided options.
|
|
311
|
+
*
|
|
312
|
+
* @param options The glob options to use when generating the glob pattern.
|
|
338
313
|
*
|
|
339
|
-
* @param extensions
|
|
340
314
|
* @example
|
|
341
315
|
* ```ts
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
316
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
317
|
+
* Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\/*.js'
|
|
345
318
|
* ```
|
|
346
319
|
*/
|
|
320
|
+
function glob(options) {
|
|
321
|
+
const { fileExtensions = [], fileStem = "*", folderAncestors = [], folderParents = [], nested = false } = options;
|
|
322
|
+
const nestedGlob = nested === true ? "**/" : "";
|
|
323
|
+
const ancestorGlob = globAppendIfNotEmpty(globFrom(folderAncestors), "/**/");
|
|
324
|
+
const parentGlob = globAppendIfNotEmpty(globFrom(folderParents), "/");
|
|
325
|
+
const stemGlob = typeof fileStem === "string" ? fileStem : fileStem.length === 0 ? "*" : globOr(fileStem);
|
|
326
|
+
let extensionsGlob = "";
|
|
327
|
+
for (const extensionExpression of fileExtensions) {
|
|
328
|
+
const extensionGlob = typeof extensionExpression === "string" ? extensionExpression : globExt(extensionExpression);
|
|
329
|
+
extensionsGlob += extensionGlob;
|
|
330
|
+
}
|
|
331
|
+
return `${nestedGlob}${ancestorGlob}${parentGlob}${stemGlob}${extensionsGlob}`;
|
|
332
|
+
}
|
|
333
|
+
function globAppendIfNotEmpty(base, append) {
|
|
334
|
+
return base.length === 0 ? base : `${base}${append}`;
|
|
335
|
+
}
|
|
347
336
|
function globExt(extensions) {
|
|
348
337
|
const ext = globOr(extensions.map((_) => _.replace(reExtension, "")));
|
|
349
338
|
return ext === "" ? "" : `.${ext}`;
|
|
350
339
|
}
|
|
340
|
+
function globFrom(expression) {
|
|
341
|
+
return typeof expression === "string" ? expression : globOr(expression);
|
|
342
|
+
}
|
|
343
|
+
function globOr(values) {
|
|
344
|
+
return values.length === 0 ? "" : values.length === 1 ? values[0] : `@(${values.join("|")})`;
|
|
345
|
+
}
|
|
351
346
|
/**
|
|
352
|
-
*
|
|
347
|
+
* Files and folders to always ignore
|
|
353
348
|
*
|
|
354
|
-
* @param values
|
|
355
349
|
* @example
|
|
356
350
|
* ```ts
|
|
357
|
-
*
|
|
358
|
-
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
351
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
359
352
|
* ```
|
|
360
353
|
*/
|
|
361
|
-
function
|
|
362
|
-
return
|
|
354
|
+
function ignored() {
|
|
355
|
+
return IGNORED;
|
|
363
356
|
}
|
|
364
357
|
const Project = Object.freeze({
|
|
365
358
|
ecmaVersion,
|
|
366
|
-
|
|
367
|
-
extensionsToMatcher,
|
|
359
|
+
extensionsToRegExp,
|
|
368
360
|
extensionsToTestGlob,
|
|
361
|
+
glob,
|
|
369
362
|
ignored,
|
|
370
363
|
queryExtensions,
|
|
371
364
|
resourceExtensions,
|
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 * @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;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AAC,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"}
|
|
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\nconst reExtension = /^\\./;\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.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToRegExp(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).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 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 ? [] : [glob({ fileExtensions: [extensions], folderAncestors: testFolders, nested: true })]),\n ...(testExtensions.length === 0\n ? []\n : [glob({ fileExtensions: [testExtensions, extensions], nested: true })]),\n ];\n}\n\n/**\n * Create a new glob pattern based on the provided options.\n *\n * @param options The glob options to use when generating the glob pattern.\n *\n * @example\n * ```ts\n * Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\\/*.js'\n * ```\n */\nfunction glob(options: Project.glob.Options) {\n const { fileExtensions = [], fileStem = '*', folderAncestors = [], folderParents = [], nested = false } = options;\n const nestedGlob = nested === true ? '**/' : '';\n const ancestorGlob = globAppendIfNotEmpty(globFrom(folderAncestors), '/**/');\n const parentGlob = globAppendIfNotEmpty(globFrom(folderParents), '/');\n const stemGlob = typeof fileStem === 'string' ? fileStem : fileStem.length === 0 ? '*' : globOr(fileStem);\n let extensionsGlob = '';\n for (const extensionExpression of fileExtensions) {\n const extensionGlob = typeof extensionExpression === 'string' ? extensionExpression : globExt(extensionExpression);\n extensionsGlob += extensionGlob;\n }\n\n return `${nestedGlob}${ancestorGlob}${parentGlob}${stemGlob}${extensionsGlob}`;\n}\n\nfunction globAppendIfNotEmpty(base: string, append: string): string {\n return base.length === 0 ? base : `${base}${append}`;\n}\n\nfunction globExt(extensions: ReadonlyArray<Extension>): string {\n const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));\n return ext === '' ? '' : `.${ext}`;\n}\n\nfunction globFrom(expression: ReadonlyArray<string> | string): string {\n return typeof expression === 'string' ? expression : globOr(expression);\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\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\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToRegExp,\n extensionsToTestGlob,\n glob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\nexport namespace Project {\n // eslint-disable-next-line ts/no-shadow\n export namespace glob {\n export interface Options {\n\n /**\n * An extension stack\n *\n * @example\n * ```ts\n * Project.glob({ fileExtensions: [['.js']] }); // '*.js'\n * Project.glob({ fileExtensions: ['.@(js|ts)'] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.spec', '.test'], ['.js', '.ts', '.tsx']] }); // '*.@(spec|test).@(js|ts|tsx)'\n * Project.glob({ fileExtensions: [] }); // '*'\n * ```\n */\n fileExtensions?: ReadonlyArray<ReadonlyArray<Extension> | string> | undefined;\n\n /**\n * The stem (basename without extension) of the file to match.\n *\n * @example\n * ```ts\n * Project.glob({ fileStem: 'index', fileExtensions: ['.*'] }); // 'index.*'\n * ```\n */\n fileStem?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Ancestor folders to include in the glob pattern.\n *\n * @example\n * ```ts\n * Project.glob({ ancestorFolders: ['src'] }); // 'src/**/*'\n * ```\n */\n folderAncestors?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Parent folders to include in the glob pattern (immediate parent folders).\n *\n * @example\n * ```ts\n * Project.glob({ folderParents: ['src'] }); // 'src/*'\n * ```\n */\n folderParents?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Whether to match files in nested folders.\n *\n * @default false\n * @example\n * ```ts\n * Project.glob({ nested: true }); // '* /*'\n * Project.glob({ nested: true, fileExtensions: [['.js']] }); // '**\\/*.js'\n * ```\n */\n nested?: boolean | undefined;\n }\n }\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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qBAAqB,MAAc,QAAwB;CAClE,OAAO,KAAK,WAAW,IAAI,OAAO,GAAG,OAAO;AAC9C;AAEA,SAAS,QAAQ,YAA8C;CAC7D,MAAM,MAAM,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC;CACpE,OAAO,QAAQ,KAAK,KAAK,IAAI;AAC/B;AAEA,SAAS,SAAS,YAAoD;CACpE,OAAO,OAAO,eAAe,WAAW,aAAa,OAAO,UAAU;AACxE;AAEA,SAAS,OAAO,QAAuC;CAErD,OAAO,OAAO,WAAW,IAAI,KAAK,OAAO,WAAW,IAAI,OAAO,KAAM,KAAK,OAAO,KAAK,GAAG,EAAE;AAC7F;;;;;;;;;AAUA,SAAS,UAAU;CACjB,OAAO;AACT;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;ACjOD,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
|
@@ -199,53 +199,10 @@ declare function resourceExtensions(): readonly `.${string}`[];
|
|
|
199
199
|
* @param extensions
|
|
200
200
|
* @example
|
|
201
201
|
* ```ts
|
|
202
|
-
* Project.
|
|
202
|
+
* Project.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
203
203
|
* ```
|
|
204
204
|
*/
|
|
205
|
-
declare function
|
|
206
|
-
/**
|
|
207
|
-
* Files and folders to always ignore
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* IGNORED // ['node_modules/', 'build/', ...]
|
|
212
|
-
* ```
|
|
213
|
-
*/
|
|
214
|
-
declare function ignored(): readonly string[];
|
|
215
|
-
/**
|
|
216
|
-
* Return a glob matcher that will match any list of extensions
|
|
217
|
-
*
|
|
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
|
|
222
|
-
* @example
|
|
223
|
-
* ```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)'
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
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
|
-
}
|
|
205
|
+
declare function extensionsToRegExp(extensions: ReadonlyArray<Extension>): RegExp;
|
|
249
206
|
/**
|
|
250
207
|
* Return a list of test glob matchers for a list of extensions.
|
|
251
208
|
* This is useful to generate globs for vitest/jest matchers
|
|
@@ -267,16 +224,94 @@ declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, opti
|
|
|
267
224
|
testExtensions?: ReadonlyArray<Extension>;
|
|
268
225
|
testFolders?: ReadonlyArray<string>;
|
|
269
226
|
}): Array<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Create a new glob pattern based on the provided options.
|
|
229
|
+
*
|
|
230
|
+
* @param options The glob options to use when generating the glob pattern.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
235
|
+
* Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\/*.js'
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function glob(options: Project.glob.Options): string;
|
|
239
|
+
/**
|
|
240
|
+
* Files and folders to always ignore
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
declare function ignored(): readonly string[];
|
|
270
248
|
export declare const Project: Readonly<{
|
|
271
249
|
ecmaVersion: typeof ecmaVersion;
|
|
272
|
-
|
|
273
|
-
extensionsToMatcher: typeof extensionsToMatcher;
|
|
250
|
+
extensionsToRegExp: typeof extensionsToRegExp;
|
|
274
251
|
extensionsToTestGlob: typeof extensionsToTestGlob;
|
|
252
|
+
glob: typeof glob;
|
|
275
253
|
ignored: typeof ignored;
|
|
276
254
|
queryExtensions: typeof queryExtensions;
|
|
277
255
|
resourceExtensions: typeof resourceExtensions;
|
|
278
256
|
sourceExtensions: typeof sourceExtensions;
|
|
279
257
|
}>;
|
|
258
|
+
export declare namespace Project {
|
|
259
|
+
namespace glob {
|
|
260
|
+
interface Options {
|
|
261
|
+
/**
|
|
262
|
+
* An extension stack
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* Project.glob({ fileExtensions: [['.js']] }); // '*.js'
|
|
267
|
+
* Project.glob({ fileExtensions: ['.@(js|ts)'] }); // '*.@(js|ts)'
|
|
268
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
269
|
+
* Project.glob({ fileExtensions: [['.spec', '.test'], ['.js', '.ts', '.tsx']] }); // '*.@(spec|test).@(js|ts|tsx)'
|
|
270
|
+
* Project.glob({ fileExtensions: [] }); // '*'
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
fileExtensions?: ReadonlyArray<ReadonlyArray<Extension> | string> | undefined;
|
|
274
|
+
/**
|
|
275
|
+
* The stem (basename without extension) of the file to match.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* Project.glob({ fileStem: 'index', fileExtensions: ['.*'] }); // 'index.*'
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
fileStem?: ReadonlyArray<string> | string | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Ancestor folders to include in the glob pattern.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* Project.glob({ ancestorFolders: ['src'] }); // 'src/**/*'
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
folderAncestors?: ReadonlyArray<string> | string | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Parent folders to include in the glob pattern (immediate parent folders).
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* Project.glob({ folderParents: ['src'] }); // 'src/*'
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
folderParents?: ReadonlyArray<string> | string | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Whether to match files in nested folders.
|
|
303
|
+
*
|
|
304
|
+
* @default false
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* Project.glob({ nested: true }); // '* /*'
|
|
308
|
+
* Project.glob({ nested: true, fileExtensions: [['.js']] }); // '**\/*.js'
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
nested?: boolean | undefined;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
280
315
|
//#endregion
|
|
281
316
|
//#region src/ProjectScript.d.ts
|
|
282
317
|
/**
|
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;;;;;;;
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;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7RO;;;;;;;;;;;;;;;;;;YAkBD,wBAAwB,4BAA4B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -199,53 +199,10 @@ declare function resourceExtensions(): readonly `.${string}`[];
|
|
|
199
199
|
* @param extensions
|
|
200
200
|
* @example
|
|
201
201
|
* ```ts
|
|
202
|
-
* Project.
|
|
202
|
+
* Project.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
203
203
|
* ```
|
|
204
204
|
*/
|
|
205
|
-
declare function
|
|
206
|
-
/**
|
|
207
|
-
* Files and folders to always ignore
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* IGNORED // ['node_modules/', 'build/', ...]
|
|
212
|
-
* ```
|
|
213
|
-
*/
|
|
214
|
-
declare function ignored(): readonly string[];
|
|
215
|
-
/**
|
|
216
|
-
* Return a glob matcher that will match any list of extensions
|
|
217
|
-
*
|
|
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
|
|
222
|
-
* @example
|
|
223
|
-
* ```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)'
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
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
|
-
}
|
|
205
|
+
declare function extensionsToRegExp(extensions: ReadonlyArray<Extension>): RegExp;
|
|
249
206
|
/**
|
|
250
207
|
* Return a list of test glob matchers for a list of extensions.
|
|
251
208
|
* This is useful to generate globs for vitest/jest matchers
|
|
@@ -267,16 +224,94 @@ declare function extensionsToTestGlob(extensions: ReadonlyArray<Extension>, opti
|
|
|
267
224
|
testExtensions?: ReadonlyArray<Extension>;
|
|
268
225
|
testFolders?: ReadonlyArray<string>;
|
|
269
226
|
}): Array<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Create a new glob pattern based on the provided options.
|
|
229
|
+
*
|
|
230
|
+
* @param options The glob options to use when generating the glob pattern.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
235
|
+
* Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\/*.js'
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
declare function glob(options: Project.glob.Options): string;
|
|
239
|
+
/**
|
|
240
|
+
* Files and folders to always ignore
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
declare function ignored(): readonly string[];
|
|
270
248
|
export declare const Project: Readonly<{
|
|
271
249
|
ecmaVersion: typeof ecmaVersion;
|
|
272
|
-
|
|
273
|
-
extensionsToMatcher: typeof extensionsToMatcher;
|
|
250
|
+
extensionsToRegExp: typeof extensionsToRegExp;
|
|
274
251
|
extensionsToTestGlob: typeof extensionsToTestGlob;
|
|
252
|
+
glob: typeof glob;
|
|
275
253
|
ignored: typeof ignored;
|
|
276
254
|
queryExtensions: typeof queryExtensions;
|
|
277
255
|
resourceExtensions: typeof resourceExtensions;
|
|
278
256
|
sourceExtensions: typeof sourceExtensions;
|
|
279
257
|
}>;
|
|
258
|
+
export declare namespace Project {
|
|
259
|
+
namespace glob {
|
|
260
|
+
interface Options {
|
|
261
|
+
/**
|
|
262
|
+
* An extension stack
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* Project.glob({ fileExtensions: [['.js']] }); // '*.js'
|
|
267
|
+
* Project.glob({ fileExtensions: ['.@(js|ts)'] }); // '*.@(js|ts)'
|
|
268
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
269
|
+
* Project.glob({ fileExtensions: [['.spec', '.test'], ['.js', '.ts', '.tsx']] }); // '*.@(spec|test).@(js|ts|tsx)'
|
|
270
|
+
* Project.glob({ fileExtensions: [] }); // '*'
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
fileExtensions?: ReadonlyArray<ReadonlyArray<Extension> | string> | undefined;
|
|
274
|
+
/**
|
|
275
|
+
* The stem (basename without extension) of the file to match.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* Project.glob({ fileStem: 'index', fileExtensions: ['.*'] }); // 'index.*'
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
fileStem?: ReadonlyArray<string> | string | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Ancestor folders to include in the glob pattern.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* Project.glob({ ancestorFolders: ['src'] }); // 'src/**/*'
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
folderAncestors?: ReadonlyArray<string> | string | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Parent folders to include in the glob pattern (immediate parent folders).
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* Project.glob({ folderParents: ['src'] }); // 'src/*'
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
folderParents?: ReadonlyArray<string> | string | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Whether to match files in nested folders.
|
|
303
|
+
*
|
|
304
|
+
* @default false
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* Project.glob({ nested: true }); // '* /*'
|
|
308
|
+
* Project.glob({ nested: true, fileExtensions: [['.js']] }); // '**\/*.js'
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
nested?: boolean | undefined;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
280
315
|
//#endregion
|
|
281
316
|
//#region src/ProjectScript.d.ts
|
|
282
317
|
/**
|
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;;;;;;;
|
|
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;;;;;;;YCC1E;;;;YAKA,oBAAoB,OAAO,YAAY,cAAc;;;;;;;;;iBAUxD;;;;;;;;;;;;iBAsCA,gBAAgB,WAAW,MAAM,cAAc,cAAc;;;;;;;;;iBAiB7D;;;;;;;;;iBAmBA;;;;;;;;;;iBA0BA,mBAAmB,YAAY,cAAc,aAAa;;;;;;;;;;;;;;;;;;iBAqB1D,qBACP,YAAY,cAAc,YAC1B;EACE,iBAAiB,cAAc;EAC/B,cAAc;IAEf;;;;;;;;;;;;iBAyBM,KAAK,SAAS,QAAQ,KAAK;;;;;;;;;iBAyC3B;qBAII,SAAO;;;;;;;;;;yBAUH;YAEE;cACE;;;;;;;;;;;;;MAcf,iBAAiB,cAAc,cAAc;;;;;;;;;MAU7C,WAAW;;;;;;;;;MAUX,kBAAkB;;;;;;;;;MAUlB,gBAAgB;;;;;;;;;;;MAYhB;;;;;;;;;qBC7RO;;;;;;;;;;;;;;;;;;YAkBD,wBAAwB,4BAA4B"}
|
package/dist/index.js
CHANGED
|
@@ -147,12 +147,13 @@ function interopDefault(m) {
|
|
|
147
147
|
//#endregion
|
|
148
148
|
//#region src/meta.ts
|
|
149
149
|
const meta = Object.freeze({
|
|
150
|
-
buildNumber:
|
|
150
|
+
buildNumber: 1790065426,
|
|
151
151
|
name: "@w5s/dev",
|
|
152
|
-
version: "
|
|
152
|
+
version: "4.0.0"
|
|
153
153
|
});
|
|
154
154
|
//#endregion
|
|
155
155
|
//#region src/Project.ts
|
|
156
|
+
const reExtension = /^\./;
|
|
156
157
|
/**
|
|
157
158
|
* Supported ECMA version
|
|
158
159
|
*
|
|
@@ -270,45 +271,13 @@ const IGNORED = Object.freeze([
|
|
|
270
271
|
* @param extensions
|
|
271
272
|
* @example
|
|
272
273
|
* ```ts
|
|
273
|
-
* Project.
|
|
274
|
+
* Project.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
274
275
|
* ```
|
|
275
276
|
*/
|
|
276
|
-
function
|
|
277
|
+
function extensionsToRegExp(extensions) {
|
|
277
278
|
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
278
279
|
}
|
|
279
280
|
/**
|
|
280
|
-
* Files and folders to always ignore
|
|
281
|
-
*
|
|
282
|
-
* @example
|
|
283
|
-
* ```ts
|
|
284
|
-
* IGNORED // ['node_modules/', 'build/', ...]
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
function ignored() {
|
|
288
|
-
return IGNORED;
|
|
289
|
-
}
|
|
290
|
-
const reExtension = /^\./;
|
|
291
|
-
/**
|
|
292
|
-
* Return a glob matcher that will match any list of extensions
|
|
293
|
-
*
|
|
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
|
|
298
|
-
* @example
|
|
299
|
-
* ```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)'
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
function extensionsToGlob(extensions, options = {}) {
|
|
307
|
-
const language = globExt(extensions);
|
|
308
|
-
const compoundGlob = `*${globExt(options.compoundExtensions ?? [])}${language}`;
|
|
309
|
-
return `${options.nested === true ? "**/" : ""}${compoundGlob}`;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
281
|
* Return a list of test glob matchers for a list of extensions.
|
|
313
282
|
* This is useful to generate globs for vitest/jest matchers
|
|
314
283
|
*
|
|
@@ -327,44 +296,68 @@ function extensionsToGlob(extensions, options = {}) {
|
|
|
327
296
|
*/
|
|
328
297
|
function extensionsToTestGlob(extensions, options = {}) {
|
|
329
298
|
const { testExtensions = [".spec", ".test"], testFolders = ["__tests__"] } = options;
|
|
330
|
-
return [...testFolders.length === 0 ? [] : [
|
|
331
|
-
|
|
299
|
+
return [...testFolders.length === 0 ? [] : [glob({
|
|
300
|
+
fileExtensions: [extensions],
|
|
301
|
+
folderAncestors: testFolders,
|
|
302
|
+
nested: true
|
|
303
|
+
})], ...testExtensions.length === 0 ? [] : [glob({
|
|
304
|
+
fileExtensions: [testExtensions, extensions],
|
|
332
305
|
nested: true
|
|
333
306
|
})]];
|
|
334
307
|
}
|
|
335
308
|
/**
|
|
336
|
-
*
|
|
309
|
+
* Create a new glob pattern based on the provided options.
|
|
310
|
+
*
|
|
311
|
+
* @param options The glob options to use when generating the glob pattern.
|
|
337
312
|
*
|
|
338
|
-
* @param extensions
|
|
339
313
|
* @example
|
|
340
314
|
* ```ts
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
315
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
316
|
+
* Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\/*.js'
|
|
344
317
|
* ```
|
|
345
318
|
*/
|
|
319
|
+
function glob(options) {
|
|
320
|
+
const { fileExtensions = [], fileStem = "*", folderAncestors = [], folderParents = [], nested = false } = options;
|
|
321
|
+
const nestedGlob = nested === true ? "**/" : "";
|
|
322
|
+
const ancestorGlob = globAppendIfNotEmpty(globFrom(folderAncestors), "/**/");
|
|
323
|
+
const parentGlob = globAppendIfNotEmpty(globFrom(folderParents), "/");
|
|
324
|
+
const stemGlob = typeof fileStem === "string" ? fileStem : fileStem.length === 0 ? "*" : globOr(fileStem);
|
|
325
|
+
let extensionsGlob = "";
|
|
326
|
+
for (const extensionExpression of fileExtensions) {
|
|
327
|
+
const extensionGlob = typeof extensionExpression === "string" ? extensionExpression : globExt(extensionExpression);
|
|
328
|
+
extensionsGlob += extensionGlob;
|
|
329
|
+
}
|
|
330
|
+
return `${nestedGlob}${ancestorGlob}${parentGlob}${stemGlob}${extensionsGlob}`;
|
|
331
|
+
}
|
|
332
|
+
function globAppendIfNotEmpty(base, append) {
|
|
333
|
+
return base.length === 0 ? base : `${base}${append}`;
|
|
334
|
+
}
|
|
346
335
|
function globExt(extensions) {
|
|
347
336
|
const ext = globOr(extensions.map((_) => _.replace(reExtension, "")));
|
|
348
337
|
return ext === "" ? "" : `.${ext}`;
|
|
349
338
|
}
|
|
339
|
+
function globFrom(expression) {
|
|
340
|
+
return typeof expression === "string" ? expression : globOr(expression);
|
|
341
|
+
}
|
|
342
|
+
function globOr(values) {
|
|
343
|
+
return values.length === 0 ? "" : values.length === 1 ? values[0] : `@(${values.join("|")})`;
|
|
344
|
+
}
|
|
350
345
|
/**
|
|
351
|
-
*
|
|
346
|
+
* Files and folders to always ignore
|
|
352
347
|
*
|
|
353
|
-
* @param values
|
|
354
348
|
* @example
|
|
355
349
|
* ```ts
|
|
356
|
-
*
|
|
357
|
-
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
350
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
358
351
|
* ```
|
|
359
352
|
*/
|
|
360
|
-
function
|
|
361
|
-
return
|
|
353
|
+
function ignored() {
|
|
354
|
+
return IGNORED;
|
|
362
355
|
}
|
|
363
356
|
const Project = Object.freeze({
|
|
364
357
|
ecmaVersion,
|
|
365
|
-
|
|
366
|
-
extensionsToMatcher,
|
|
358
|
+
extensionsToRegExp,
|
|
367
359
|
extensionsToTestGlob,
|
|
360
|
+
glob,
|
|
368
361
|
ignored,
|
|
369
362
|
queryExtensions,
|
|
370
363
|
resourceExtensions,
|
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 * @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,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,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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,GAAG,QAAQ,WAAW,OAAO,QAAQ,KAAK;AACnD;;;;;;;;;;;;;;;;;;AAsCA,SAAS,qBACP,YACA,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"}
|
|
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\nconst reExtension = /^\\./;\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.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToRegExp(extensions: ReadonlyArray<Extension>): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).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 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 ? [] : [glob({ fileExtensions: [extensions], folderAncestors: testFolders, nested: true })]),\n ...(testExtensions.length === 0\n ? []\n : [glob({ fileExtensions: [testExtensions, extensions], nested: true })]),\n ];\n}\n\n/**\n * Create a new glob pattern based on the provided options.\n *\n * @param options The glob options to use when generating the glob pattern.\n *\n * @example\n * ```ts\n * Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\\/*.js'\n * ```\n */\nfunction glob(options: Project.glob.Options) {\n const { fileExtensions = [], fileStem = '*', folderAncestors = [], folderParents = [], nested = false } = options;\n const nestedGlob = nested === true ? '**/' : '';\n const ancestorGlob = globAppendIfNotEmpty(globFrom(folderAncestors), '/**/');\n const parentGlob = globAppendIfNotEmpty(globFrom(folderParents), '/');\n const stemGlob = typeof fileStem === 'string' ? fileStem : fileStem.length === 0 ? '*' : globOr(fileStem);\n let extensionsGlob = '';\n for (const extensionExpression of fileExtensions) {\n const extensionGlob = typeof extensionExpression === 'string' ? extensionExpression : globExt(extensionExpression);\n extensionsGlob += extensionGlob;\n }\n\n return `${nestedGlob}${ancestorGlob}${parentGlob}${stemGlob}${extensionsGlob}`;\n}\n\nfunction globAppendIfNotEmpty(base: string, append: string): string {\n return base.length === 0 ? base : `${base}${append}`;\n}\n\nfunction globExt(extensions: ReadonlyArray<Extension>): string {\n const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));\n return ext === '' ? '' : `.${ext}`;\n}\n\nfunction globFrom(expression: ReadonlyArray<string> | string): string {\n return typeof expression === 'string' ? expression : globOr(expression);\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\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\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToRegExp,\n extensionsToTestGlob,\n glob,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\nexport namespace Project {\n // eslint-disable-next-line ts/no-shadow\n export namespace glob {\n export interface Options {\n\n /**\n * An extension stack\n *\n * @example\n * ```ts\n * Project.glob({ fileExtensions: [['.js']] }); // '*.js'\n * Project.glob({ fileExtensions: ['.@(js|ts)'] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'\n * Project.glob({ fileExtensions: [['.spec', '.test'], ['.js', '.ts', '.tsx']] }); // '*.@(spec|test).@(js|ts|tsx)'\n * Project.glob({ fileExtensions: [] }); // '*'\n * ```\n */\n fileExtensions?: ReadonlyArray<ReadonlyArray<Extension> | string> | undefined;\n\n /**\n * The stem (basename without extension) of the file to match.\n *\n * @example\n * ```ts\n * Project.glob({ fileStem: 'index', fileExtensions: ['.*'] }); // 'index.*'\n * ```\n */\n fileStem?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Ancestor folders to include in the glob pattern.\n *\n * @example\n * ```ts\n * Project.glob({ ancestorFolders: ['src'] }); // 'src/**/*'\n * ```\n */\n folderAncestors?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Parent folders to include in the glob pattern (immediate parent folders).\n *\n * @example\n * ```ts\n * Project.glob({ folderParents: ['src'] }); // 'src/*'\n * ```\n */\n folderParents?: ReadonlyArray<string> | string | undefined;\n\n /**\n * Whether to match files in nested folders.\n *\n * @default false\n * @example\n * ```ts\n * Project.glob({ nested: true }); // '* /*'\n * Project.glob({ nested: true, fileExtensions: [['.js']] }); // '**\\/*.js'\n * ```\n */\n nested?: boolean | undefined;\n }\n }\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,M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WAAW,IAAI,MAAM,OAAO,QAAQ;CACxG,IAAI,iBAAiB;CACrB,KAAK,MAAM,uBAAuB,gBAAgB;EAChD,MAAM,gBAAgB,OAAO,wBAAwB,WAAW,sBAAsB,QAAQ,mBAAmB;EACjH,kBAAkB;CACpB;CAEA,OAAO,GAAG,aAAa,eAAe,aAAa,WAAW;AAChE;AAEA,SAAS,qBAAqB,MAAc,QAAwB;CAClE,OAAO,KAAK,WAAW,IAAI,OAAO,GAAG,OAAO;AAC9C;AAEA,SAAS,QAAQ,YAA8C;CAC7D,MAAM,MAAM,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC;CACpE,OAAO,QAAQ,KAAK,KAAK,IAAI;AAC/B;AAEA,SAAS,SAAS,YAAoD;CACpE,OAAO,OAAO,eAAe,WAAW,aAAa,OAAO,UAAU;AACxE;AAEA,SAAS,OAAO,QAAuC;CAErD,OAAO,OAAO,WAAW,IAAI,KAAK,OAAO,WAAW,IAAI,OAAO,KAAM,KAAK,OAAO,KAAK,GAAG,EAAE;AAC7F;;;;;;;;;AAUA,SAAS,UAAU;CACjB,OAAO;AACT;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;ACjOD,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
|
+
"version": "4.0.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": "ed181ba68ebff886310db849facb938bb00f61ca"
|
|
51
51
|
}
|
package/src/Project.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { LanguageId } from './LanguageId.js';
|
|
2
2
|
|
|
3
|
+
const reExtension = /^\./;
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* A type of a file extension
|
|
5
7
|
*/
|
|
@@ -115,70 +117,13 @@ const IGNORED = Object.freeze([
|
|
|
115
117
|
* @param extensions
|
|
116
118
|
* @example
|
|
117
119
|
* ```ts
|
|
118
|
-
* Project.
|
|
120
|
+
* Project.extensionsToRegExp(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
119
121
|
* ```
|
|
120
122
|
*/
|
|
121
|
-
function
|
|
123
|
+
function extensionsToRegExp(extensions: ReadonlyArray<Extension>): RegExp {
|
|
122
124
|
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
/**
|
|
126
|
-
* Files and folders to always ignore
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* IGNORED // ['node_modules/', 'build/', ...]
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
function ignored() {
|
|
134
|
-
return IGNORED;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const reExtension = /^\./;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Return a glob matcher that will match any list of extensions
|
|
141
|
-
*
|
|
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
|
|
146
|
-
* @example
|
|
147
|
-
* ```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)'
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
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
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
127
|
/**
|
|
183
128
|
* Return a list of test glob matchers for a list of extensions.
|
|
184
129
|
* This is useful to generate globs for vitest/jest matchers
|
|
@@ -209,51 +154,139 @@ function extensionsToTestGlob(
|
|
|
209
154
|
} = options;
|
|
210
155
|
|
|
211
156
|
return [
|
|
212
|
-
...(testFolders.length === 0 ? [] : [
|
|
157
|
+
...(testFolders.length === 0 ? [] : [glob({ fileExtensions: [extensions], folderAncestors: testFolders, nested: true })]),
|
|
213
158
|
...(testExtensions.length === 0
|
|
214
159
|
? []
|
|
215
|
-
: [
|
|
160
|
+
: [glob({ fileExtensions: [testExtensions, extensions], nested: true })]),
|
|
216
161
|
];
|
|
217
162
|
}
|
|
218
163
|
|
|
219
164
|
/**
|
|
220
|
-
*
|
|
165
|
+
* Create a new glob pattern based on the provided options.
|
|
166
|
+
*
|
|
167
|
+
* @param options The glob options to use when generating the glob pattern.
|
|
221
168
|
*
|
|
222
|
-
* @param extensions
|
|
223
169
|
* @example
|
|
224
170
|
* ```ts
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* globExt(['.js', '.ts']) // '.@(js|ts)'
|
|
171
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
172
|
+
* Project.glob({ fileExtensions: [['.js']], nested: true }); // '**\/*.js'
|
|
228
173
|
* ```
|
|
229
174
|
*/
|
|
175
|
+
function glob(options: Project.glob.Options) {
|
|
176
|
+
const { fileExtensions = [], fileStem = '*', folderAncestors = [], folderParents = [], nested = false } = options;
|
|
177
|
+
const nestedGlob = nested === true ? '**/' : '';
|
|
178
|
+
const ancestorGlob = globAppendIfNotEmpty(globFrom(folderAncestors), '/**/');
|
|
179
|
+
const parentGlob = globAppendIfNotEmpty(globFrom(folderParents), '/');
|
|
180
|
+
const stemGlob = typeof fileStem === 'string' ? fileStem : fileStem.length === 0 ? '*' : globOr(fileStem);
|
|
181
|
+
let extensionsGlob = '';
|
|
182
|
+
for (const extensionExpression of fileExtensions) {
|
|
183
|
+
const extensionGlob = typeof extensionExpression === 'string' ? extensionExpression : globExt(extensionExpression);
|
|
184
|
+
extensionsGlob += extensionGlob;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return `${nestedGlob}${ancestorGlob}${parentGlob}${stemGlob}${extensionsGlob}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function globAppendIfNotEmpty(base: string, append: string): string {
|
|
191
|
+
return base.length === 0 ? base : `${base}${append}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
230
194
|
function globExt(extensions: ReadonlyArray<Extension>): string {
|
|
231
195
|
const ext = globOr(extensions.map((_) => _.replace(reExtension, '')));
|
|
232
196
|
return ext === '' ? '' : `.${ext}`;
|
|
233
197
|
}
|
|
234
198
|
|
|
199
|
+
function globFrom(expression: ReadonlyArray<string> | string): string {
|
|
200
|
+
return typeof expression === 'string' ? expression : globOr(expression);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function globOr(values: ReadonlyArray<string>): string {
|
|
204
|
+
// eslint-disable-next-line ts/no-non-null-assertion
|
|
205
|
+
return values.length === 0 ? '' : values.length === 1 ? values[0]! : `@(${values.join('|')})`;
|
|
206
|
+
}
|
|
207
|
+
|
|
235
208
|
/**
|
|
236
|
-
*
|
|
209
|
+
* Files and folders to always ignore
|
|
237
210
|
*
|
|
238
|
-
* @param values
|
|
239
211
|
* @example
|
|
240
212
|
* ```ts
|
|
241
|
-
*
|
|
242
|
-
* globOr(['js', 'ts']) // '@(js|ts)'
|
|
213
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
243
214
|
* ```
|
|
244
215
|
*/
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
return values.length === 0 ? '' : values.length === 1 ? values[0]! : `@(${values.join('|')})`;
|
|
216
|
+
function ignored() {
|
|
217
|
+
return IGNORED;
|
|
248
218
|
}
|
|
249
219
|
|
|
250
220
|
export const Project = Object.freeze({
|
|
251
221
|
ecmaVersion,
|
|
252
|
-
|
|
253
|
-
extensionsToMatcher,
|
|
222
|
+
extensionsToRegExp,
|
|
254
223
|
extensionsToTestGlob,
|
|
224
|
+
glob,
|
|
255
225
|
ignored,
|
|
256
226
|
queryExtensions,
|
|
257
227
|
resourceExtensions,
|
|
258
228
|
sourceExtensions,
|
|
259
229
|
});
|
|
230
|
+
export namespace Project {
|
|
231
|
+
// eslint-disable-next-line ts/no-shadow
|
|
232
|
+
export namespace glob {
|
|
233
|
+
export interface Options {
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* An extension stack
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* Project.glob({ fileExtensions: [['.js']] }); // '*.js'
|
|
241
|
+
* Project.glob({ fileExtensions: ['.@(js|ts)'] }); // '*.@(js|ts)'
|
|
242
|
+
* Project.glob({ fileExtensions: [['.js', '.ts']] }); // '*.@(js|ts)'
|
|
243
|
+
* Project.glob({ fileExtensions: [['.spec', '.test'], ['.js', '.ts', '.tsx']] }); // '*.@(spec|test).@(js|ts|tsx)'
|
|
244
|
+
* Project.glob({ fileExtensions: [] }); // '*'
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
fileExtensions?: ReadonlyArray<ReadonlyArray<Extension> | string> | undefined;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The stem (basename without extension) of the file to match.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* Project.glob({ fileStem: 'index', fileExtensions: ['.*'] }); // 'index.*'
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
fileStem?: ReadonlyArray<string> | string | undefined;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Ancestor folders to include in the glob pattern.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* Project.glob({ ancestorFolders: ['src'] }); // 'src/**/*'
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
folderAncestors?: ReadonlyArray<string> | string | undefined;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Parent folders to include in the glob pattern (immediate parent folders).
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* Project.glob({ folderParents: ['src'] }); // 'src/*'
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
folderParents?: ReadonlyArray<string> | string | undefined;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Whether to match files in nested folders.
|
|
281
|
+
*
|
|
282
|
+
* @default false
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* Project.glob({ nested: true }); // '* /*'
|
|
286
|
+
* Project.glob({ nested: true, fileExtensions: [['.js']] }); // '**\/*.js'
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
nested?: boolean | undefined;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|