@w5s/dev 3.3.3 → 3.4.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 +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Project.ts +3 -1
package/dist/index.cjs
CHANGED
|
@@ -113,7 +113,7 @@ function interopDefault(m) {
|
|
|
113
113
|
//#region src/meta.ts
|
|
114
114
|
const meta = Object.freeze({
|
|
115
115
|
name: "@w5s/dev",
|
|
116
|
-
version: "3.
|
|
116
|
+
version: "3.4.0",
|
|
117
117
|
buildNumber: 1
|
|
118
118
|
});
|
|
119
119
|
//#endregion
|
|
@@ -252,6 +252,7 @@ function ignored() {
|
|
|
252
252
|
function extensionsToMatcher(extensions) {
|
|
253
253
|
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
254
254
|
}
|
|
255
|
+
const reExtension = /^\./;
|
|
255
256
|
/**
|
|
256
257
|
* Return a glob matcher that will match any list of extensions
|
|
257
258
|
*
|
|
@@ -262,7 +263,7 @@ function extensionsToMatcher(extensions) {
|
|
|
262
263
|
* ```
|
|
263
264
|
*/
|
|
264
265
|
function extensionsToGlob(extensions) {
|
|
265
|
-
return `*.+(${extensions.map((_) => _.replace(
|
|
266
|
+
return `*.+(${extensions.map((_) => _.replace(reExtension, "")).join("|")})`;
|
|
266
267
|
}
|
|
267
268
|
const Project = Object.freeze({
|
|
268
269
|
ecmaVersion,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * 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 plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n };\n // eslint-disable-next-line ts/consistent-type-assertions\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\n delete (merged as any)[key];\n }\n\n return merged as T;\n}\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<T | ReadonlyArray<T> | Promise<T> | Promise<ReadonlyArray<T>>>\n): Promise<Array<T>> {\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: 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 merge,\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":";;;;;;;AAOA,SAAS,MAA+C,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AM,sBAA4C,OAAO,OAAO;CAC9D;CACA;CACA;CACA,GAAG,gBAAgB;EAAC;EAAO;EAAW;EAAQ;EAAQ;EAAQ;EAAQ;CAAM,CAAC;AAC/E,CAAC;;;;;;;;;AAUD,SAAS,qBAAqB;CAC5B,OAAO;AACT;AAEA,MAAM,UAAU,OAAO,OAAO;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAUD,SAAS,UAAU;CACjB,OAAO;AACT;;;;;;;;;;AAWA,SAAS,oBAAoB,YAA0C;CACrE,OAAO,IAAI,OAAO,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;AAClE;;;;;;;;;;AAWA,SAAS,iBAAiB,YAA0C;CAClE,OAAO,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AACtE;AAEA,MAAa,UAAU,OAAO,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"}
|
|
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 * 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 plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n };\n // eslint-disable-next-line ts/consistent-type-assertions\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\n delete (merged as any)[key];\n }\n\n return merged as T;\n}\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<T | ReadonlyArray<T> | Promise<T> | Promise<ReadonlyArray<T>>>\n): Promise<Array<T>> {\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: 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 merge,\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\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).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":";;;;;;;AAOA,SAAS,MAA+C,GAAG,SAAsB;CAC/E,MAAM,OAAO,IAAI,IAAI,QAAQ,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC,CAAC;CAC3D,M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AQ;CAAM,CAAC;AAC/E,CAAC;;;;;;;;;AAUD,SAAS,qBAAqB;CAC5B,OAAO;AACT;AAEA,MAAM,UAAU,OAAO,OAAO;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAUD,SAAS,UAAU;CACjB,OAAO;AACT;;;;;;;;;;AAWA,SAAS,oBAAoB,YAA0C;CACrE,OAAO,IAAI,OAAO,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;AAClE;AAEA,MAAM,cAAc;;;;;;;;;;AAWpB,SAAS,iBAAiB,YAA0C;CAClE,OAAO,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,aAAa,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AAC5E;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AC5JD,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.js
CHANGED
|
@@ -112,7 +112,7 @@ function interopDefault(m) {
|
|
|
112
112
|
//#region src/meta.ts
|
|
113
113
|
const meta = Object.freeze({
|
|
114
114
|
name: "@w5s/dev",
|
|
115
|
-
version: "3.
|
|
115
|
+
version: "3.4.0",
|
|
116
116
|
buildNumber: 1
|
|
117
117
|
});
|
|
118
118
|
//#endregion
|
|
@@ -251,6 +251,7 @@ function ignored() {
|
|
|
251
251
|
function extensionsToMatcher(extensions) {
|
|
252
252
|
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
253
253
|
}
|
|
254
|
+
const reExtension = /^\./;
|
|
254
255
|
/**
|
|
255
256
|
* Return a glob matcher that will match any list of extensions
|
|
256
257
|
*
|
|
@@ -261,7 +262,7 @@ function extensionsToMatcher(extensions) {
|
|
|
261
262
|
* ```
|
|
262
263
|
*/
|
|
263
264
|
function extensionsToGlob(extensions) {
|
|
264
|
-
return `*.+(${extensions.map((_) => _.replace(
|
|
265
|
+
return `*.+(${extensions.map((_) => _.replace(reExtension, "")).join("|")})`;
|
|
265
266
|
}
|
|
266
267
|
const Project = Object.freeze({
|
|
267
268
|
ecmaVersion,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/ESLintConfig.ts","../src/interopDefault.ts","../src/meta.ts","../src/Project.ts","../src/ProjectScript.ts"],"sourcesContent":["import type { Linter } from 'eslint';\n\n/**\n * 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 plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n };\n // eslint-disable-next-line ts/consistent-type-assertions\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\n delete (merged as any)[key];\n }\n\n return merged as T;\n}\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<T | ReadonlyArray<T> | Promise<T> | Promise<ReadonlyArray<T>>>\n): Promise<Array<T>> {\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: 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 merge,\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":";;;;;;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,SAAS;IACP,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,OAAO;IACL,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,iBAAiB;IACf,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,eAAe;IACb,GAAG,IAAI;IACP,GAAG,IAAI;GACT;EACF;CAEF,GAAG,CAAC,CAAM;CAGV,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,KAAK,IAAI,GAAG,GAEf,OAAQ,OAAe;CAG3B,OAAO;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;;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"}
|
|
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 * 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 plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n };\n // eslint-disable-next-line ts/consistent-type-assertions\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\n delete (merged as any)[key];\n }\n\n return merged as T;\n}\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<T | ReadonlyArray<T> | Promise<T> | Promise<ReadonlyArray<T>>>\n): Promise<Array<T>> {\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: 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 merge,\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\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(reExtension, '')).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":";;;;;;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,SAAS;IACP,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,OAAO;IACL,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,iBAAiB;IACf,GAAG,IAAI;IACP,GAAG,IAAI;GACT;GACA,eAAe;IACb,GAAG,IAAI;IACP,GAAG,IAAI;GACT;EACF;CAEF,GAAG,CAAC,CAAM;CAGV,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,KAAK,IAAI,GAAG,GAEf,OAAQ,OAAe;CAG3B,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAEnB,QAAO,MADgB,QAAQ,IAAI,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MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/dev",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Shared development constants and functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"sideEffect": false,
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9102f7149f4d1faa4a9c96e7e910cbb296bd63e5"
|
|
58
58
|
}
|
package/src/Project.ts
CHANGED
|
@@ -134,6 +134,8 @@ function extensionsToMatcher(extensions: readonly Extension[]): RegExp {
|
|
|
134
134
|
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
const reExtension = /^\./;
|
|
138
|
+
|
|
137
139
|
/**
|
|
138
140
|
* Return a glob matcher that will match any list of extensions
|
|
139
141
|
*
|
|
@@ -144,7 +146,7 @@ function extensionsToMatcher(extensions: readonly Extension[]): RegExp {
|
|
|
144
146
|
* ```
|
|
145
147
|
*/
|
|
146
148
|
function extensionsToGlob(extensions: readonly Extension[]): string {
|
|
147
|
-
return `*.+(${extensions.map((_) => _.replace(
|
|
149
|
+
return `*.+(${extensions.map((_) => _.replace(reExtension, '')).join('|')})`;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
export const Project = Object.freeze({
|