@w5s/dev 3.2.3 → 3.3.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["exists","constants","constants"],"sources":["../src/directory.ts","../src/ESLintConfig.ts","../src/file.ts","../src/block.ts","../src/interopDefault.ts","../src/json.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { existsSync, mkdirSync, rmSync } from 'node:fs';\nimport { access, constants, mkdir, rm } from 'node:fs/promises';\n\nasync function exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface DirectoryOptions {\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'present' | 'absent';\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { path, state } = options;\n const isPresent = await exists(path);\n if (state === 'present') {\n if (!isPresent) {\n await mkdir(path, { recursive: true });\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { path, state } = options;\n const isPresent = existsSync(path);\n if (state === 'present') {\n if (!isPresent) {\n mkdirSync(path, { recursive: true });\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import type { ESLint } from 'eslint';\n\nfunction toArray<T>(value: T[] | T | undefined): T[] {\n if (value == null) {\n return [];\n }\n if (Array.isArray(value)) {\n return value;\n }\n return [value];\n}\n\nfunction concatArray<T>(left: T[] | T | undefined, right: T[] | T | undefined): T[] {\n return [...toArray(left), ...toArray(right)];\n}\n\nexport namespace ESLintConfig {\n /**\n *\n * @param configs\n */\n export function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {\n return configs.reduce(\n (returnValue, config) => ({\n ...returnValue,\n ...config,\n env: { ...returnValue.env, ...config.env },\n extends: concatArray(returnValue.extends, config.extends),\n globals: { ...returnValue.globals, ...config.globals },\n overrides: concatArray(returnValue.overrides, config.overrides),\n parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },\n plugins: concatArray(returnValue.plugins, config.plugins),\n rules: { ...returnValue.rules, ...config.rules },\n settings: { ...returnValue.settings, ...config.settings },\n }),\n {\n env: {},\n extends: [],\n globals: {},\n overrides: [],\n parserOptions: {},\n plugins: [],\n rules: {},\n settings: {},\n },\n );\n }\n\n /**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\n export function fixme(_status: string | number | [string | number, ...any[]] | undefined) {\n return 'off' as const;\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 */\n export function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n }\n}\n","import { readFile, rm, writeFile, access } from 'node:fs/promises';\nimport { accessSync, constants, readFileSync, rmSync, writeFileSync } from 'node:fs';\n\nasync function exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\nexport interface FileOptions {\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { path, state, update, encoding = 'utf8' } = options;\n if (state === 'present') {\n const isPresent = await exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? '' : update(previousContent);\n if (newContent != null) {\n await writeFile(path, newContent, encoding);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { path, state, update, encoding = 'utf8' } = options;\n if (state === 'present') {\n const isPresent = existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? '' : update(previousContent);\n if (newContent != null) {\n writeFileSync(path, newContent, encoding);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import { type FileOptions, file, fileSync } from './file.js';\n\nexport interface BlockOptions {\n /**\n * The marker builder function that will take either `markerBegin` or `markerEnd`\n *\n * @default '# ${mark} MANAGED BLOCK'\n */\n marker?: (mark: 'Begin' | 'End') => string;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];\n\n /**\n * Block target state\n */\n state?: 'present' | 'absent';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const {\n marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,\n path,\n block: blockName,\n insertPosition = ['after', EOF],\n state = 'present',\n } = options;\n\n const EOL = '\\n';\n const beginBlock = marker('Begin');\n const endBlock = marker('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n","const 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: T | PromiseLike<T>): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","import { type FileOptions, file, fileSync } from './file.js';\n\nexport type JSONValue = null | number | string | boolean | JSONValue[] | { [key: string]: JSONValue };\n\nexport interface JSONOption<V = JSONValue> {\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File content mapping function\n */\n readonly update?: ((content: V | undefined) => V | undefined) | undefined;\n\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n","export const meta = Object.freeze({\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 // @ts-ignore - these variables are injected at build time\n buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n});\n","import type { LanguageId } from './LanguageId.js';\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\nexport namespace Project {\n /**\n * A type of a file extension\n */\n export type Extension = `.${string}`;\n\n /**\n * Object hash of all well-known file extension category to file extensions mapping\n */\n export type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };\n\n /**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\n export function ecmaVersion() {\n return 2022 as const;\n }\n\n const 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 */\n export function queryExtensions(languages: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n // eslint-disable-next-line unicorn/prefer-spread\n previousValue.concat(registry[currentValue] ?? ([] as Extension[])), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort();\n }\n\n /**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\n export function sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n }\n\n const RESOURCE_EXTENSIONS: readonly 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 */\n export function resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n }\n\n const 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 * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\n export function ignored() {\n return IGNORED;\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 */\n export function extensionsToMatcher(extensions: readonly Extension[]): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n }\n\n /**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\n export function extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(/^\\./, '')).join('|')})`;\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 Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'inherit' | 'pipe' | 'ignore';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stdout: string; stderr: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stdout: result.stdout.toString(encoding), stderr: result.stderr.toString(encoding) };\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stdout, stderr });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', String(key)]);\n execSync('yarn', ['config', 'set', String(key), `${update == null ? '' : update(stdout)}`]);\n } else {\n execSync('yarn', ['config', 'unset']);\n }\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', String(key)]);\n await exec('yarn', ['config', 'set', String(key), `${update == null ? '' : update(stdout)}`]);\n } else {\n await exec('yarn', ['config', 'unset']);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => YarnVersionKind | undefined) | undefined;\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;;AAGA,eAAeA,SAAO,MAAc;AAClC,KAAI;AACF,SAAA,GAAA,iBAAA,QAAa,MAAMC,iBAAAA,UAAU,KAAK;AAClC,SAAO;SACD;AACN,SAAO;;;;;;;;;;;;;;;;AA6BX,eAAsB,UAAU,SAA0C;CACxE,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,YAAY,MAAMD,SAAO,KAAK;AACpC,KAAI,UAAU;MACR,CAAC,UACH,QAAA,GAAA,iBAAA,OAAY,MAAM,EAAE,WAAW,MAAM,CAAC;YAE/B,UACT,QAAA,GAAA,iBAAA,IAAS,MAAM,EAAE,WAAW,MAAM,CAAC;;;;;;;;;;;;;;;AAiBvC,SAAgB,cAAc,SAAiC;CAC7D,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,aAAA,GAAA,QAAA,YAAuB,KAAK;AAClC,KAAI,UAAU;MACR,CAAC,UACH,EAAA,GAAA,QAAA,WAAU,MAAM,EAAE,WAAW,MAAM,CAAC;YAE7B,UACT,EAAA,GAAA,QAAA,QAAO,MAAM,EAAE,WAAW,MAAM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,QAAQ,CAAC;;;;;;;;;;;;;AAezC,eAAsB,WAAW,SAA2C;CAC1E,MAAM,EAAE,KAAK,OAAO,WAAW;AAC/B,KAAI,UAAU,WAAW;EACvB,MAAM,EAAE,WAAW,MAAM,KAAK,QAAQ;GAAC;GAAU;GAAO,OAAO,IAAI;GAAC,CAAC;AACrE,QAAM,KAAK,QAAQ;GAAC;GAAU;GAAO,OAAO,IAAI;GAAE,GAAG,UAAU,OAAO,KAAK,OAAO,OAAO;GAAG,CAAC;OAE7F,OAAM,KAAK,QAAQ,CAAC,UAAU,QAAQ,CAAC;;;;;;;;;;;;;;AC/B3C,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;AAC1B,KAAI,UAAU,UACZ,UAAS,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;KAG9E,OAAM,IAAI,MAAM,kBAAkB;;;;;;;;;;;;AActC,eAAsB,YAAY,SAA4C;CAC5E,MAAM,EAAE,OAAO,WAAW;AAC1B,KAAI,UAAU,UACZ,OAAM,KAAK,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;KAGhF,OAAM,IAAI,MAAM,kBAAkB"}
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 { ESLint } from 'eslint';\n\nfunction toArray<T>(value: T[] | T | undefined): T[] {\n if (value == null) {\n return [];\n }\n if (Array.isArray(value)) {\n return value;\n }\n return [value];\n}\n\nfunction concatArray<T>(left: T[] | T | undefined, right: T[] | T | undefined): T[] {\n return [...toArray(left), ...toArray(right)];\n}\n\n/**\n *\n * @param configs\n */\nfunction concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {\n return configs.reduce(\n (returnValue, config) => ({\n ...returnValue,\n ...config,\n env: { ...returnValue.env, ...config.env },\n extends: concatArray(returnValue.extends, config.extends),\n globals: { ...returnValue.globals, ...config.globals },\n overrides: concatArray(returnValue.overrides, config.overrides),\n parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },\n plugins: concatArray(returnValue.plugins, config.plugins),\n rules: { ...returnValue.rules, ...config.rules },\n settings: { ...returnValue.settings, ...config.settings },\n }),\n {\n env: {},\n extends: [],\n globals: {},\n overrides: [],\n parserOptions: {},\n plugins: [],\n rules: {},\n settings: {},\n },\n );\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: string | number | [string | number, ...any[]] | undefined) {\n return 'off' as const;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n renameRules,\n});\n","const 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: T | PromiseLike<T>): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\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 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 // @ts-ignore - these variables are injected at build time\n buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\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 = { [K in LanguageId]: readonly Extension[] };\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\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\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: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n // eslint-disable-next-line unicorn/prefer-spread\n previousValue.concat(registry[currentValue] ?? ([] as Extension[])), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort();\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: readonly 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 * 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\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: readonly Extension[]): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(/^\\./, '')).join('|')})`;\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\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":";;AAEA,SAAS,QAAW,OAAiC;CACnD,IAAI,SAAS,MACX,OAAO,CAAC;CAEV,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;CAET,OAAO,CAAC,KAAK;AACf;AAEA,SAAS,YAAe,MAA2B,OAAiC;CAClF,OAAO,CAAC,GAAG,QAAQ,IAAI,GAAG,GAAG,QAAQ,KAAK,CAAC;AAC7C;;;;;AAMA,SAAS,OAAO,GAAG,SAAiD;CAClE,OAAO,QAAQ,QACZ,aAAa,YAAY;EACxB,GAAG;EACH,GAAG;EACH,KAAK;GAAE,GAAG,YAAY;GAAK,GAAG,OAAO;EAAI;EACzC,SAAS,YAAY,YAAY,SAAS,OAAO,OAAO;EACxD,SAAS;GAAE,GAAG,YAAY;GAAS,GAAG,OAAO;EAAQ;EACrD,WAAW,YAAY,YAAY,WAAW,OAAO,SAAS;EAC9D,eAAe;GAAE,GAAG,YAAY;GAAe,GAAG,OAAO;EAAc;EACvE,SAAS,YAAY,YAAY,SAAS,OAAO,OAAO;EACxD,OAAO;GAAE,GAAG,YAAY;GAAO,GAAG,O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O,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AC1JD,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
@@ -1,167 +1,36 @@
1
1
  import { ESLint } from "eslint";
2
2
 
3
- //#region src/directory.d.ts
4
- interface DirectoryOptions {
5
- /**
6
- * Directory path
7
- */
8
- readonly path: string;
9
- /**
10
- * Directory target state
11
- */
12
- readonly state: 'present' | 'absent';
13
- }
14
- /**
15
- * Ensure directory is present/absent
16
- *
17
- * @example
18
- * ```ts
19
- * await directory({
20
- * path: 'foo/bar',
21
- * state: 'present',
22
- * })
23
- * ```
24
- *
25
- * @param options
26
- */
27
- declare function directory(options: DirectoryOptions): Promise<void>;
28
- /**
29
- * Ensure directory is present/absent
30
- *
31
- * @example
32
- * ```ts
33
- * await directorySync({
34
- * path: 'foo/bar',
35
- * state: 'present',
36
- * })
37
- * ```
38
- *
39
- * @param options
40
- */
41
- declare function directorySync(options: DirectoryOptions): void;
42
- //#endregion
43
3
  //#region src/ESLintConfig.d.ts
44
- declare namespace ESLintConfig {
45
- /**
46
- *
47
- * @param configs
48
- */
49
- function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData;
50
- /**
51
- * Always return 'off'. `_status` is the previous rule value.
52
- *
53
- * @param _status
54
- */
55
- function fixme(_status: string | number | [string | number, ...any[]] | undefined): "off";
56
- /**
57
- * Renames rules in the given object according to the given map.
58
- *
59
- * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
60
- * `{ 'old-prefix/rule-name': 'error' }`, this function will return
61
- * `{ 'new-prefix/rule-name': 'error' }`.
62
- *
63
- * @param rules The object containing the rules to rename.
64
- * @param map The object containing the rename map.
65
- */
66
- function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any>;
67
- }
68
- //#endregion
69
- //#region src/block.d.ts
70
- interface BlockOptions {
71
- /**
72
- * The marker builder function that will take either `markerBegin` or `markerEnd`
73
- *
74
- * @default '# ${mark} MANAGED BLOCK'
75
- */
76
- marker?: (mark: 'Begin' | 'End') => string;
77
- /**
78
- * File path
79
- */
80
- path: string;
81
- /**
82
- * Block content to insert
83
- */
84
- block: string;
85
- /**
86
- * Insert position
87
- */
88
- insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];
89
- /**
90
- * Block target state
91
- */
92
- state?: 'present' | 'absent';
93
- }
94
4
  /**
95
- * Replace asynchronously a block in file that follows pattern :
96
- *
97
- * marker(markerBegin)
98
- * ...
99
- * marker(markerEnd)
100
5
  *
101
- * @param options
6
+ * @param configs
102
7
  */
103
- declare function block(options: BlockOptions): Promise<void>;
8
+ declare function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData;
104
9
  /**
105
- * Replace synchronously a block in file that follows pattern :
106
- *
107
- * marker(markerBegin)
108
- * ...
109
- * marker(markerEnd)
10
+ * Always return 'off'. `_status` is the previous rule value.
110
11
  *
111
- * @param options
12
+ * @param _status
112
13
  */
113
- declare function blockSync(options: BlockOptions): void;
114
- //#endregion
115
- //#region src/file.d.ts
116
- interface FileOptions {
117
- /**
118
- * File path
119
- */
120
- readonly path: string;
121
- /**
122
- * File target state
123
- */
124
- readonly state: 'present' | 'absent';
125
- /**
126
- * File content mapping function
127
- *
128
- */
129
- readonly update?: ((content: string) => string | undefined) | undefined;
130
- /**
131
- * File encoding
132
- */
133
- readonly encoding?: BufferEncoding;
134
- }
14
+ declare function fixme(_status: string | number | [string | number, ...any[]] | undefined): "off";
135
15
  /**
136
- * Ensure file is present/absent with content initialized or modified with `update
16
+ * Renames rules in the given object according to the given map.
137
17
  *
138
- * @example
139
- * ```ts
140
- * await file({
141
- * path: 'foo/bar',
142
- * state: 'present',
143
- * update: (content) => content + '_test', // This will append '_test' after current content
144
- * })
145
- * ```
18
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
19
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
20
+ * `{ 'new-prefix/rule-name': 'error' }`.
146
21
  *
147
- * @param options
22
+ * @param rules The object containing the rules to rename.
23
+ * @param map The object containing the rename map.
148
24
  */
149
- declare function file(options: FileOptions): Promise<void>;
25
+ declare function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any>;
150
26
  /**
151
- * Ensure file is present/absent with content initialized or modified with `update
152
- *
153
- * @example
154
- * ```ts
155
- * fileSync({
156
- * path: 'foo/bar',
157
- * state: 'present',
158
- * update: (content) => content + '_test', // This will append '_test' after current content
159
- * })
160
- * ```
161
- *
162
- * @param options
27
+ * @namespace
163
28
  */
164
- declare function fileSync(options: FileOptions): void;
29
+ declare const ESLintConfig: Readonly<{
30
+ concat: typeof concat;
31
+ fixme: typeof fixme;
32
+ renameRules: typeof renameRules;
33
+ }>;
165
34
  //#endregion
166
35
  //#region src/interopDefault.d.ts
167
36
  /**
@@ -214,41 +83,6 @@ interface LanguageIdMap {
214
83
  */
215
84
  type LanguageId = keyof LanguageIdMap;
216
85
  //#endregion
217
- //#region src/json.d.ts
218
- type JSONValue = null | number | string | boolean | JSONValue[] | {
219
- [key: string]: JSONValue;
220
- };
221
- interface JSONOption<V = JSONValue> {
222
- /**
223
- * File path
224
- */
225
- readonly path: string;
226
- /**
227
- * File target state
228
- */
229
- readonly state: 'present' | 'absent';
230
- /**
231
- * File content mapping function
232
- */
233
- readonly update?: ((content: V | undefined) => V | undefined) | undefined;
234
- /**
235
- * File encoding
236
- */
237
- readonly encoding?: BufferEncoding;
238
- }
239
- /**
240
- * Ensure file is present/absent asynchronously with content value initialized or modified with `update`
241
- *
242
- * @param options
243
- */
244
- declare function json<Value>(options: JSONOption<Value>): Promise<void>;
245
- /**
246
- * Ensure file is present/absent synchronously with content value initialized or modified with `update`
247
- *
248
- * @param options
249
- */
250
- declare function jsonSync<Value>(options: JSONOption<Value>): void;
251
- //#endregion
252
86
  //#region src/meta.d.ts
253
87
  declare const meta: Readonly<{
254
88
  name: string;
@@ -257,84 +91,91 @@ declare const meta: Readonly<{
257
91
  }>;
258
92
  //#endregion
259
93
  //#region src/Project.d.ts
260
- declare namespace Project {
261
- /**
262
- * A type of a file extension
263
- */
264
- type Extension = `.${string}`;
265
- /**
266
- * Object hash of all well-known file extension category to file extensions mapping
267
- */
268
- type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };
269
- /**
270
- * Supported ECMA version
271
- *
272
- * @example
273
- * ```ts
274
- * Project.ecmaVersion() // 2022
275
- * ```
276
- */
277
- function ecmaVersion(): 2022;
278
- /**
279
- * Return a list of extensions
280
- *
281
- * @example
282
- * ```ts
283
- * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
284
- * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
285
- * ```
286
- *
287
- * @param languages
288
- */
289
- function queryExtensions(languages: LanguageId[]): readonly Extension[];
290
- /**
291
- * Supported file extensions
292
- *
293
- * @example
294
- * ```ts
295
- * Project.sourceExtensions() // ['.ts', '.js', ...]
296
- * ```
297
- */
298
- function sourceExtensions(): readonly `.${string}`[];
299
- /**
300
- * Resource file extensions
301
- *
302
- * @example
303
- * ```ts
304
- * Project.resourceExtensions() // ['.css', '.sass', ...]
305
- * ```
306
- */
307
- function resourceExtensions(): readonly `.${string}`[];
308
- /**
309
- * Files and folders to always ignore
310
- *
311
- * @example
312
- * ```ts
313
- * IGNORED // ['node_modules/', 'build/', ...]
314
- * ```
315
- */
316
- function ignored(): readonly string[];
317
- /**
318
- * Return a RegExp that will match any list of extensions
319
- *
320
- * @param extensions
321
- * @example
322
- * ```ts
323
- * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
324
- * ```
325
- */
326
- function extensionsToMatcher(extensions: readonly Extension[]): RegExp;
327
- /**
328
- * Return a glob matcher that will match any list of extensions
329
- *
330
- * @param extensions
331
- * @example
332
- * ```ts
333
- * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
334
- * ```
335
- */
336
- function extensionsToGlob(extensions: readonly Extension[]): string;
337
- }
94
+ /**
95
+ * A type of a file extension
96
+ */
97
+ type Extension = `.${string}`;
98
+ /**
99
+ * Object hash of all well-known file extension category to file extensions mapping
100
+ */
101
+ type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };
102
+ /**
103
+ * Supported ECMA version
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * Project.ecmaVersion() // 2022
108
+ * ```
109
+ */
110
+ declare function ecmaVersion(): 2022;
111
+ /**
112
+ * Return a list of extensions
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
117
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
118
+ * ```
119
+ *
120
+ * @param languages
121
+ */
122
+ declare function queryExtensions(languages: LanguageId[]): readonly Extension[];
123
+ /**
124
+ * Supported file extensions
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
129
+ * ```
130
+ */
131
+ declare function sourceExtensions(): readonly `.${string}`[];
132
+ /**
133
+ * Resource file extensions
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
138
+ * ```
139
+ */
140
+ declare function resourceExtensions(): readonly `.${string}`[];
141
+ /**
142
+ * Files and folders to always ignore
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * IGNORED // ['node_modules/', 'build/', ...]
147
+ * ```
148
+ */
149
+ declare function ignored(): readonly string[];
150
+ /**
151
+ * Return a RegExp that will match any list of extensions
152
+ *
153
+ * @param extensions
154
+ * @example
155
+ * ```ts
156
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
157
+ * ```
158
+ */
159
+ declare function extensionsToMatcher(extensions: readonly Extension[]): RegExp;
160
+ /**
161
+ * Return a glob matcher that will match any list of extensions
162
+ *
163
+ * @param extensions
164
+ * @example
165
+ * ```ts
166
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
167
+ * ```
168
+ */
169
+ declare function extensionsToGlob(extensions: readonly Extension[]): string;
170
+ declare const Project: Readonly<{
171
+ ecmaVersion: typeof ecmaVersion;
172
+ extensionsToGlob: typeof extensionsToGlob;
173
+ extensionsToMatcher: typeof extensionsToMatcher;
174
+ ignored: typeof ignored;
175
+ queryExtensions: typeof queryExtensions;
176
+ resourceExtensions: typeof resourceExtensions;
177
+ sourceExtensions: typeof sourceExtensions;
178
+ }>;
338
179
  //#endregion
339
180
  //#region src/ProjectScript.d.ts
340
181
  /**
@@ -355,86 +196,10 @@ declare const ProjectScript: {
355
196
  readonly Rescue: "rescue";
356
197
  readonly Spellcheck: "spellcheck";
357
198
  readonly Test: "test";
199
+ readonly Typecheck: "typecheck";
358
200
  readonly Validate: "validate";
359
201
  };
360
202
  type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
361
203
  //#endregion
362
- //#region src/yarnConfig.d.ts
363
- interface YarnConfigOptions {
364
- /**
365
- * Configuration key
366
- */
367
- readonly key: string;
368
- /**
369
- * Option target state
370
- */
371
- readonly state: 'present' | 'absent';
372
- /**
373
- * File content mapping function
374
- *
375
- */
376
- readonly update?: ((content: string) => string | undefined) | undefined;
377
- }
378
- /**
379
- * Synchronous version of {@link yarnConfig}
380
- *
381
- * @param options
382
- * @example
383
- * yarnConfigSync({
384
- * key: 'nodeLinker',
385
- * state: 'present',
386
- * update: (content) => content.replace('node-modules', 'hoisted'),
387
- * })
388
- */
389
- declare function yarnConfigSync(options: YarnConfigOptions): void;
390
- /**
391
- * Set/Unset yarn configuration value
392
- *
393
- * @param options
394
- * @example
395
- * await yarnConfig({
396
- * key: 'nodeLinker',
397
- * state: 'present',
398
- * update: (content) => content.replace('node-modules', 'hoisted'),
399
- * })
400
- */
401
- declare function yarnConfig(options: YarnConfigOptions): Promise<void>;
402
- //#endregion
403
- //#region src/yarnVersion.d.ts
404
- type YarnVersionKind = 'berry' | 'classic';
405
- interface YarnVersionOptions {
406
- /**
407
- * Option target state
408
- */
409
- readonly state: 'present' | 'absent';
410
- /**
411
- * Version mapping function
412
- *
413
- */
414
- readonly update?: (() => YarnVersionKind | undefined) | undefined;
415
- }
416
- /**
417
- * Synchronous version of {@link yarnVersion}
418
- *
419
- * @param options
420
- * @example
421
- * yarnVersionSync({
422
- * state: 'present',
423
- * update: () => 'berry', // or 'classic'
424
- * })
425
- */
426
- declare function yarnVersionSync(options: YarnVersionOptions): void;
427
- /**
428
- * Set/Unset yarn configuration value
429
- *
430
- * @param options
431
- * @example
432
- * await yarnVersion({
433
- * state: 'present',
434
- * update: () => 'berry', // or 'classic'
435
- * })
436
- */
437
- declare function yarnVersion(options: YarnVersionOptions): Promise<void>;
438
- //#endregion
439
- export { BlockOptions, DirectoryOptions, ESLintConfig, FileOptions, JSONOption, JSONValue, LanguageId, LanguageIdMap, Project, ProjectScript, YarnConfigOptions, YarnVersionKind, YarnVersionOptions, block, blockSync, directory, directorySync, file, fileSync, interopDefault, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
204
+ export { ESLintConfig, Extension, ExtensionRegistry, LanguageId, LanguageIdMap, Project, ProjectScript, interopDefault, meta };
440
205
  //# sourceMappingURL=index.d.cts.map