@w5s/dev 3.4.7 → 3.4.9
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 +49 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ESLintConfig.ts +52 -52
- package/src/LanguageId.ts +5 -5
- package/src/Project.ts +15 -15
- package/src/interopDefault.ts +1 -1
- package/src/meta.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,40 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/ESLintConfig.ts
|
|
3
3
|
/**
|
|
4
|
-
* Return a new merged flat configuration
|
|
5
|
-
*
|
|
6
|
-
* @param configs
|
|
7
|
-
*/
|
|
8
|
-
function merge(...configs) {
|
|
9
|
-
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
10
|
-
const merged = configs.reduce((acc, cur) => {
|
|
11
|
-
return {
|
|
12
|
-
...acc,
|
|
13
|
-
...cur,
|
|
14
|
-
files: [...acc.files ?? [], ...cur.files ?? []],
|
|
15
|
-
ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
|
|
16
|
-
plugins: {
|
|
17
|
-
...acc.plugins,
|
|
18
|
-
...cur.plugins
|
|
19
|
-
},
|
|
20
|
-
rules: {
|
|
21
|
-
...acc.rules,
|
|
22
|
-
...cur.rules
|
|
23
|
-
},
|
|
24
|
-
languageOptions: {
|
|
25
|
-
...acc.languageOptions,
|
|
26
|
-
...cur.languageOptions
|
|
27
|
-
},
|
|
28
|
-
linterOptions: {
|
|
29
|
-
...acc.linterOptions,
|
|
30
|
-
...cur.linterOptions
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}, {});
|
|
34
|
-
for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
|
|
35
|
-
return merged;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
4
|
* Concat multiple flat configs into a single flat config array.
|
|
39
5
|
*
|
|
40
6
|
* It also resolves promises and flattens the result.
|
|
@@ -78,6 +44,40 @@ function fixme(_status) {
|
|
|
78
44
|
return "off";
|
|
79
45
|
}
|
|
80
46
|
/**
|
|
47
|
+
* Return a new merged flat configuration
|
|
48
|
+
*
|
|
49
|
+
* @param configs
|
|
50
|
+
*/
|
|
51
|
+
function merge(...configs) {
|
|
52
|
+
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
53
|
+
const merged = configs.reduce((acc, cur) => {
|
|
54
|
+
return {
|
|
55
|
+
...acc,
|
|
56
|
+
...cur,
|
|
57
|
+
files: [...acc.files ?? [], ...cur.files ?? []],
|
|
58
|
+
ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
|
|
59
|
+
languageOptions: {
|
|
60
|
+
...acc.languageOptions,
|
|
61
|
+
...cur.languageOptions
|
|
62
|
+
},
|
|
63
|
+
linterOptions: {
|
|
64
|
+
...acc.linterOptions,
|
|
65
|
+
...cur.linterOptions
|
|
66
|
+
},
|
|
67
|
+
plugins: {
|
|
68
|
+
...acc.plugins,
|
|
69
|
+
...cur.plugins
|
|
70
|
+
},
|
|
71
|
+
rules: {
|
|
72
|
+
...acc.rules,
|
|
73
|
+
...cur.rules
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, {});
|
|
77
|
+
for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
|
|
78
|
+
return merged;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
81
|
* Renames rules in the given object according to the given map.
|
|
82
82
|
*
|
|
83
83
|
* Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
|
|
@@ -98,9 +98,9 @@ function renameRules(rules, map) {
|
|
|
98
98
|
* @namespace
|
|
99
99
|
*/
|
|
100
100
|
const ESLintConfig = Object.freeze({
|
|
101
|
-
merge,
|
|
102
101
|
concat,
|
|
103
102
|
fixme,
|
|
103
|
+
merge,
|
|
104
104
|
renameRules
|
|
105
105
|
});
|
|
106
106
|
//#endregion
|
|
@@ -112,15 +112,12 @@ function interopDefault(m) {
|
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/meta.ts
|
|
114
114
|
const meta = Object.freeze({
|
|
115
|
+
buildNumber: 1,
|
|
115
116
|
name: "@w5s/dev",
|
|
116
|
-
version: "3.4.
|
|
117
|
-
buildNumber: 1
|
|
117
|
+
version: "3.4.9"
|
|
118
118
|
});
|
|
119
119
|
//#endregion
|
|
120
120
|
//#region src/Project.ts
|
|
121
|
-
function escapeRegExp(value) {
|
|
122
|
-
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
123
|
-
}
|
|
124
121
|
/**
|
|
125
122
|
* Supported ECMA version
|
|
126
123
|
*
|
|
@@ -132,6 +129,9 @@ function escapeRegExp(value) {
|
|
|
132
129
|
function ecmaVersion() {
|
|
133
130
|
return 2022;
|
|
134
131
|
}
|
|
132
|
+
function escapeRegExp(value) {
|
|
133
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
134
|
+
}
|
|
135
135
|
const registry = {
|
|
136
136
|
css: [".css"],
|
|
137
137
|
graphql: [".gql", ".graphql"],
|
|
@@ -230,27 +230,27 @@ const IGNORED = Object.freeze([
|
|
|
230
230
|
"umd/"
|
|
231
231
|
]);
|
|
232
232
|
/**
|
|
233
|
-
*
|
|
233
|
+
* Return a RegExp that will match any list of extensions
|
|
234
234
|
*
|
|
235
|
+
* @param extensions
|
|
235
236
|
* @example
|
|
236
237
|
* ```ts
|
|
237
|
-
*
|
|
238
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
238
239
|
* ```
|
|
239
240
|
*/
|
|
240
|
-
function
|
|
241
|
-
return
|
|
241
|
+
function extensionsToMatcher(extensions) {
|
|
242
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
242
243
|
}
|
|
243
244
|
/**
|
|
244
|
-
*
|
|
245
|
+
* Files and folders to always ignore
|
|
245
246
|
*
|
|
246
|
-
* @param extensions
|
|
247
247
|
* @example
|
|
248
248
|
* ```ts
|
|
249
|
-
*
|
|
249
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
250
250
|
* ```
|
|
251
251
|
*/
|
|
252
|
-
function
|
|
253
|
-
return
|
|
252
|
+
function ignored() {
|
|
253
|
+
return IGNORED;
|
|
254
254
|
}
|
|
255
255
|
const reExtension = /^\./;
|
|
256
256
|
/**
|
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 // eslint-disable-next-line unicorn/prefer-await\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((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: 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,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AAG,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"}
|
|
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 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, ...any[]] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n // 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 * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n merge,\n renameRules,\n});\n","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: 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\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: 1 as number, // (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 = { [K in LanguageId]: readonly 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: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as 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: 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 * 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 * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAEnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAoE;CACjF,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,I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AEA,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.d.cts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Linter } from "eslint";
|
|
2
2
|
|
|
3
3
|
//#region src/ESLintConfig.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Return a new merged flat configuration
|
|
6
|
-
*
|
|
7
|
-
* @param configs
|
|
8
|
-
*/
|
|
9
|
-
declare function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T;
|
|
10
4
|
/**
|
|
11
5
|
* Concat multiple flat configs into a single flat config array.
|
|
12
6
|
*
|
|
@@ -39,13 +33,19 @@ declare function merge<T extends Linter.Config = Linter.Config>(...configs: Arra
|
|
|
39
33
|
* ```
|
|
40
34
|
* @param configs
|
|
41
35
|
*/
|
|
42
|
-
declare function concat<T extends Linter.Config = Linter.Config>(...configs: Array<T |
|
|
36
|
+
declare function concat<T extends Linter.Config = Linter.Config>(...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>): Promise<Array<T>>;
|
|
43
37
|
/**
|
|
44
38
|
* Always return 'off'. `_status` is the previous rule value.
|
|
45
39
|
*
|
|
46
40
|
* @param _status
|
|
47
41
|
*/
|
|
48
|
-
declare function fixme(_status:
|
|
42
|
+
declare function fixme(_status: [number | string, ...any[]] | number | string | undefined): "off";
|
|
43
|
+
/**
|
|
44
|
+
* Return a new merged flat configuration
|
|
45
|
+
*
|
|
46
|
+
* @param configs
|
|
47
|
+
*/
|
|
48
|
+
declare function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T;
|
|
49
49
|
/**
|
|
50
50
|
* Renames rules in the given object according to the given map.
|
|
51
51
|
*
|
|
@@ -61,9 +61,9 @@ declare function renameRules(rules: Record<string, any>, map: Record<string, str
|
|
|
61
61
|
* @namespace
|
|
62
62
|
*/
|
|
63
63
|
declare const ESLintConfig: Readonly<{
|
|
64
|
-
merge: typeof merge;
|
|
65
64
|
concat: typeof concat;
|
|
66
65
|
fixme: typeof fixme;
|
|
66
|
+
merge: typeof merge;
|
|
67
67
|
renameRules: typeof renameRules;
|
|
68
68
|
}>;
|
|
69
69
|
//#endregion
|
|
@@ -96,6 +96,10 @@ declare function interopDefault<T>(m: T): T extends {
|
|
|
96
96
|
} ? U : T;
|
|
97
97
|
//#endregion
|
|
98
98
|
//#region src/LanguageId.d.ts
|
|
99
|
+
/**
|
|
100
|
+
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
101
|
+
*/
|
|
102
|
+
type LanguageId = keyof LanguageIdMap;
|
|
99
103
|
interface LanguageIdMap {
|
|
100
104
|
css: true;
|
|
101
105
|
graphql: true;
|
|
@@ -113,16 +117,12 @@ interface LanguageIdMap {
|
|
|
113
117
|
vue: true;
|
|
114
118
|
yaml: true;
|
|
115
119
|
}
|
|
116
|
-
/**
|
|
117
|
-
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
118
|
-
*/
|
|
119
|
-
type LanguageId = keyof LanguageIdMap;
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region src/meta.d.ts
|
|
122
122
|
declare const meta: Readonly<{
|
|
123
|
+
buildNumber: number;
|
|
123
124
|
name: string;
|
|
124
125
|
version: string;
|
|
125
|
-
buildNumber: number;
|
|
126
126
|
}>;
|
|
127
127
|
//#endregion
|
|
128
128
|
//#region src/Project.d.ts
|
|
@@ -174,24 +174,24 @@ declare function sourceExtensions(): readonly `.${string}`[];
|
|
|
174
174
|
*/
|
|
175
175
|
declare function resourceExtensions(): readonly `.${string}`[];
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
177
|
+
* Return a RegExp that will match any list of extensions
|
|
178
178
|
*
|
|
179
|
+
* @param extensions
|
|
179
180
|
* @example
|
|
180
181
|
* ```ts
|
|
181
|
-
*
|
|
182
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
182
183
|
* ```
|
|
183
184
|
*/
|
|
184
|
-
declare function
|
|
185
|
+
declare function extensionsToMatcher(extensions: readonly Extension[]): RegExp;
|
|
185
186
|
/**
|
|
186
|
-
*
|
|
187
|
+
* Files and folders to always ignore
|
|
187
188
|
*
|
|
188
|
-
* @param extensions
|
|
189
189
|
* @example
|
|
190
190
|
* ```ts
|
|
191
|
-
*
|
|
191
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
192
192
|
* ```
|
|
193
193
|
*/
|
|
194
|
-
declare function
|
|
194
|
+
declare function ignored(): readonly string[];
|
|
195
195
|
/**
|
|
196
196
|
* Return a glob matcher that will match any list of extensions
|
|
197
197
|
*
|
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":";;;;;AAAqC
|
|
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":";;;;;AAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCtB,MAAA,WAAiB,MAAA,CAAO,MAAA,GAAS,MAAA,CAAO,MAAA,K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A,CAAoB,UAAA,WAAqB,SAAA,KAAc,MAAM;;;;;;;;AJjEU;iBI6EvE,OAAA;;;;;;;;;;iBAeA,gBAAA,CAAiB,UAAgC,WAAX,SAAS;AAAA,cAI3C,OAAA,EAAO,QAAA;;;;;;;;;;;;;;cCpJP,aAAA;EAAA;;;;;;;;;;;;;;;;;KAkBD,aAAA,WAAwB,aAAA,eAA4B,aAAa"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Linter } from "eslint";
|
|
2
2
|
|
|
3
3
|
//#region src/ESLintConfig.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Return a new merged flat configuration
|
|
6
|
-
*
|
|
7
|
-
* @param configs
|
|
8
|
-
*/
|
|
9
|
-
declare function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T;
|
|
10
4
|
/**
|
|
11
5
|
* Concat multiple flat configs into a single flat config array.
|
|
12
6
|
*
|
|
@@ -39,13 +33,19 @@ declare function merge<T extends Linter.Config = Linter.Config>(...configs: Arra
|
|
|
39
33
|
* ```
|
|
40
34
|
* @param configs
|
|
41
35
|
*/
|
|
42
|
-
declare function concat<T extends Linter.Config = Linter.Config>(...configs: Array<T |
|
|
36
|
+
declare function concat<T extends Linter.Config = Linter.Config>(...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>): Promise<Array<T>>;
|
|
43
37
|
/**
|
|
44
38
|
* Always return 'off'. `_status` is the previous rule value.
|
|
45
39
|
*
|
|
46
40
|
* @param _status
|
|
47
41
|
*/
|
|
48
|
-
declare function fixme(_status:
|
|
42
|
+
declare function fixme(_status: [number | string, ...any[]] | number | string | undefined): "off";
|
|
43
|
+
/**
|
|
44
|
+
* Return a new merged flat configuration
|
|
45
|
+
*
|
|
46
|
+
* @param configs
|
|
47
|
+
*/
|
|
48
|
+
declare function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T;
|
|
49
49
|
/**
|
|
50
50
|
* Renames rules in the given object according to the given map.
|
|
51
51
|
*
|
|
@@ -61,9 +61,9 @@ declare function renameRules(rules: Record<string, any>, map: Record<string, str
|
|
|
61
61
|
* @namespace
|
|
62
62
|
*/
|
|
63
63
|
declare const ESLintConfig: Readonly<{
|
|
64
|
-
merge: typeof merge;
|
|
65
64
|
concat: typeof concat;
|
|
66
65
|
fixme: typeof fixme;
|
|
66
|
+
merge: typeof merge;
|
|
67
67
|
renameRules: typeof renameRules;
|
|
68
68
|
}>;
|
|
69
69
|
//#endregion
|
|
@@ -96,6 +96,10 @@ declare function interopDefault<T>(m: T): T extends {
|
|
|
96
96
|
} ? U : T;
|
|
97
97
|
//#endregion
|
|
98
98
|
//#region src/LanguageId.d.ts
|
|
99
|
+
/**
|
|
100
|
+
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
101
|
+
*/
|
|
102
|
+
type LanguageId = keyof LanguageIdMap;
|
|
99
103
|
interface LanguageIdMap {
|
|
100
104
|
css: true;
|
|
101
105
|
graphql: true;
|
|
@@ -113,16 +117,12 @@ interface LanguageIdMap {
|
|
|
113
117
|
vue: true;
|
|
114
118
|
yaml: true;
|
|
115
119
|
}
|
|
116
|
-
/**
|
|
117
|
-
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
118
|
-
*/
|
|
119
|
-
type LanguageId = keyof LanguageIdMap;
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region src/meta.d.ts
|
|
122
122
|
declare const meta: Readonly<{
|
|
123
|
+
buildNumber: number;
|
|
123
124
|
name: string;
|
|
124
125
|
version: string;
|
|
125
|
-
buildNumber: number;
|
|
126
126
|
}>;
|
|
127
127
|
//#endregion
|
|
128
128
|
//#region src/Project.d.ts
|
|
@@ -174,24 +174,24 @@ declare function sourceExtensions(): readonly `.${string}`[];
|
|
|
174
174
|
*/
|
|
175
175
|
declare function resourceExtensions(): readonly `.${string}`[];
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
177
|
+
* Return a RegExp that will match any list of extensions
|
|
178
178
|
*
|
|
179
|
+
* @param extensions
|
|
179
180
|
* @example
|
|
180
181
|
* ```ts
|
|
181
|
-
*
|
|
182
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
182
183
|
* ```
|
|
183
184
|
*/
|
|
184
|
-
declare function
|
|
185
|
+
declare function extensionsToMatcher(extensions: readonly Extension[]): RegExp;
|
|
185
186
|
/**
|
|
186
|
-
*
|
|
187
|
+
* Files and folders to always ignore
|
|
187
188
|
*
|
|
188
|
-
* @param extensions
|
|
189
189
|
* @example
|
|
190
190
|
* ```ts
|
|
191
|
-
*
|
|
191
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
192
192
|
* ```
|
|
193
193
|
*/
|
|
194
|
-
declare function
|
|
194
|
+
declare function ignored(): readonly string[];
|
|
195
195
|
/**
|
|
196
196
|
* Return a glob matcher that will match any list of extensions
|
|
197
197
|
*
|
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":";;;;;AAAqC
|
|
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":";;;;;AAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkCtB,MAAA,WAAiB,MAAA,CAAO,MAAA,GAAS,MAAA,CAAO,MAAA,KAClD,OAAA,EAAS,KAAA,CAAM,OAAA,CAAQ,aAAA,CAAc,CAAA,KAAM,OAAA,CAAQ,CAAA,IAAK,aAAA,CAAc,CAAA,IAAK,CAAA,IAC7E,OAAA,CAAQ,KAAA,CAAM,CAAA;;;;;;iBAUR,KAAA,CAAM,OAAkE;;AAV/D;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;;;;;;;KAkBD,aAAA,WAAwB,aAAA,eAA4B,aAAa"}
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
1
|
//#region src/ESLintConfig.ts
|
|
2
2
|
/**
|
|
3
|
-
* Return a new merged flat configuration
|
|
4
|
-
*
|
|
5
|
-
* @param configs
|
|
6
|
-
*/
|
|
7
|
-
function merge(...configs) {
|
|
8
|
-
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
9
|
-
const merged = configs.reduce((acc, cur) => {
|
|
10
|
-
return {
|
|
11
|
-
...acc,
|
|
12
|
-
...cur,
|
|
13
|
-
files: [...acc.files ?? [], ...cur.files ?? []],
|
|
14
|
-
ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
|
|
15
|
-
plugins: {
|
|
16
|
-
...acc.plugins,
|
|
17
|
-
...cur.plugins
|
|
18
|
-
},
|
|
19
|
-
rules: {
|
|
20
|
-
...acc.rules,
|
|
21
|
-
...cur.rules
|
|
22
|
-
},
|
|
23
|
-
languageOptions: {
|
|
24
|
-
...acc.languageOptions,
|
|
25
|
-
...cur.languageOptions
|
|
26
|
-
},
|
|
27
|
-
linterOptions: {
|
|
28
|
-
...acc.linterOptions,
|
|
29
|
-
...cur.linterOptions
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}, {});
|
|
33
|
-
for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
|
|
34
|
-
return merged;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
3
|
* Concat multiple flat configs into a single flat config array.
|
|
38
4
|
*
|
|
39
5
|
* It also resolves promises and flattens the result.
|
|
@@ -77,6 +43,40 @@ function fixme(_status) {
|
|
|
77
43
|
return "off";
|
|
78
44
|
}
|
|
79
45
|
/**
|
|
46
|
+
* Return a new merged flat configuration
|
|
47
|
+
*
|
|
48
|
+
* @param configs
|
|
49
|
+
*/
|
|
50
|
+
function merge(...configs) {
|
|
51
|
+
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
52
|
+
const merged = configs.reduce((acc, cur) => {
|
|
53
|
+
return {
|
|
54
|
+
...acc,
|
|
55
|
+
...cur,
|
|
56
|
+
files: [...acc.files ?? [], ...cur.files ?? []],
|
|
57
|
+
ignores: [...acc.ignores ?? [], ...cur.ignores ?? []],
|
|
58
|
+
languageOptions: {
|
|
59
|
+
...acc.languageOptions,
|
|
60
|
+
...cur.languageOptions
|
|
61
|
+
},
|
|
62
|
+
linterOptions: {
|
|
63
|
+
...acc.linterOptions,
|
|
64
|
+
...cur.linterOptions
|
|
65
|
+
},
|
|
66
|
+
plugins: {
|
|
67
|
+
...acc.plugins,
|
|
68
|
+
...cur.plugins
|
|
69
|
+
},
|
|
70
|
+
rules: {
|
|
71
|
+
...acc.rules,
|
|
72
|
+
...cur.rules
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}, {});
|
|
76
|
+
for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
|
|
77
|
+
return merged;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
80
|
* Renames rules in the given object according to the given map.
|
|
81
81
|
*
|
|
82
82
|
* Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
|
|
@@ -97,9 +97,9 @@ function renameRules(rules, map) {
|
|
|
97
97
|
* @namespace
|
|
98
98
|
*/
|
|
99
99
|
const ESLintConfig = Object.freeze({
|
|
100
|
-
merge,
|
|
101
100
|
concat,
|
|
102
101
|
fixme,
|
|
102
|
+
merge,
|
|
103
103
|
renameRules
|
|
104
104
|
});
|
|
105
105
|
//#endregion
|
|
@@ -111,15 +111,12 @@ function interopDefault(m) {
|
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/meta.ts
|
|
113
113
|
const meta = Object.freeze({
|
|
114
|
+
buildNumber: 1,
|
|
114
115
|
name: "@w5s/dev",
|
|
115
|
-
version: "3.4.
|
|
116
|
-
buildNumber: 1
|
|
116
|
+
version: "3.4.9"
|
|
117
117
|
});
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/Project.ts
|
|
120
|
-
function escapeRegExp(value) {
|
|
121
|
-
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
122
|
-
}
|
|
123
120
|
/**
|
|
124
121
|
* Supported ECMA version
|
|
125
122
|
*
|
|
@@ -131,6 +128,9 @@ function escapeRegExp(value) {
|
|
|
131
128
|
function ecmaVersion() {
|
|
132
129
|
return 2022;
|
|
133
130
|
}
|
|
131
|
+
function escapeRegExp(value) {
|
|
132
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
133
|
+
}
|
|
134
134
|
const registry = {
|
|
135
135
|
css: [".css"],
|
|
136
136
|
graphql: [".gql", ".graphql"],
|
|
@@ -229,27 +229,27 @@ const IGNORED = Object.freeze([
|
|
|
229
229
|
"umd/"
|
|
230
230
|
]);
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
232
|
+
* Return a RegExp that will match any list of extensions
|
|
233
233
|
*
|
|
234
|
+
* @param extensions
|
|
234
235
|
* @example
|
|
235
236
|
* ```ts
|
|
236
|
-
*
|
|
237
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
237
238
|
* ```
|
|
238
239
|
*/
|
|
239
|
-
function
|
|
240
|
-
return
|
|
240
|
+
function extensionsToMatcher(extensions) {
|
|
241
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
241
242
|
}
|
|
242
243
|
/**
|
|
243
|
-
*
|
|
244
|
+
* Files and folders to always ignore
|
|
244
245
|
*
|
|
245
|
-
* @param extensions
|
|
246
246
|
* @example
|
|
247
247
|
* ```ts
|
|
248
|
-
*
|
|
248
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
249
249
|
* ```
|
|
250
250
|
*/
|
|
251
|
-
function
|
|
252
|
-
return
|
|
251
|
+
function ignored() {
|
|
252
|
+
return IGNORED;
|
|
253
253
|
}
|
|
254
254
|
const reExtension = /^\./;
|
|
255
255
|
/**
|
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 // eslint-disable-next-line unicorn/prefer-await\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((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: 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,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAoE;CACjF,OAAO;AACT;;;;;;;;;;;AAYA,SAA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ACT,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 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, ...any[]] | number | string | undefined) {\n return 'off' as const;\n}\n\n/**\n * Return a new merged flat configuration\n *\n * @param configs\n */\nfunction merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {\n const keys = new Set(configs.flatMap((i) => Object.keys(i)));\n const merged = configs.reduce((acc, cur) => {\n return {\n ...acc,\n ...cur,\n files: [\n ...(acc.files ?? []),\n ...(cur.files ?? []),\n ],\n ignores: [\n ...(acc.ignores ?? []),\n ...(cur.ignores ?? []),\n ],\n languageOptions: {\n ...acc.languageOptions,\n ...cur.languageOptions,\n },\n linterOptions: {\n ...acc.linterOptions,\n ...cur.linterOptions,\n },\n plugins: {\n ...acc.plugins,\n ...cur.plugins,\n },\n rules: {\n ...acc.rules,\n ...cur.rules,\n },\n };\n // 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 * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n merge,\n renameRules,\n});\n","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: 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\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: 1 as number, // (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 = { [K in LanguageId]: readonly 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: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n\n previousValue.concat(registry[currentValue] ?? ([] as 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: 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 * 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 * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\nconst reExtension = /^\\./;\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,eAAe,OACb,GAAG,SACgB;CAEnB,QAAO,MADgB,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAoE;CACjF,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;CAEF,GAAG,CAAC,CAAM;CAGV,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,IAAI,CAAC,KAAK,IAAI,GAAG,GAEf,OAAQ,OAAe;CAG3B,OAAO;AACT;;;;;;;;;;;AAYA,SAAS,YAAY,OAA4B,KAAkD;CACjG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MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/dev",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.9",
|
|
4
4
|
"description": "Shared development constants and functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"sideEffect": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "456aac7a7b05abae48365ae944a31c494ed078cf"
|
|
51
51
|
}
|
package/src/ESLintConfig.ts
CHANGED
|
@@ -1,54 +1,5 @@
|
|
|
1
1
|
import type { Linter } from 'eslint';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Return a new merged flat configuration
|
|
5
|
-
*
|
|
6
|
-
* @param configs
|
|
7
|
-
*/
|
|
8
|
-
function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {
|
|
9
|
-
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
10
|
-
const merged = configs.reduce((acc, cur) => {
|
|
11
|
-
return {
|
|
12
|
-
...acc,
|
|
13
|
-
...cur,
|
|
14
|
-
files: [
|
|
15
|
-
...(acc.files ?? []),
|
|
16
|
-
...(cur.files ?? []),
|
|
17
|
-
],
|
|
18
|
-
ignores: [
|
|
19
|
-
...(acc.ignores ?? []),
|
|
20
|
-
...(cur.ignores ?? []),
|
|
21
|
-
],
|
|
22
|
-
plugins: {
|
|
23
|
-
...acc.plugins,
|
|
24
|
-
...cur.plugins,
|
|
25
|
-
},
|
|
26
|
-
rules: {
|
|
27
|
-
...acc.rules,
|
|
28
|
-
...cur.rules,
|
|
29
|
-
},
|
|
30
|
-
languageOptions: {
|
|
31
|
-
...acc.languageOptions,
|
|
32
|
-
...cur.languageOptions,
|
|
33
|
-
},
|
|
34
|
-
linterOptions: {
|
|
35
|
-
...acc.linterOptions,
|
|
36
|
-
...cur.linterOptions,
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
// eslint-disable-next-line ts/consistent-type-assertions
|
|
40
|
-
}, {} as T);
|
|
41
|
-
|
|
42
|
-
// Remove unused keys
|
|
43
|
-
for (const key of Object.keys(merged)) {
|
|
44
|
-
if (!keys.has(key))
|
|
45
|
-
// eslint-disable-next-line ts/no-dynamic-delete
|
|
46
|
-
delete (merged as any)[key];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return merged as T;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
3
|
/**
|
|
53
4
|
* Concat multiple flat configs into a single flat config array.
|
|
54
5
|
*
|
|
@@ -82,7 +33,7 @@ function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T
|
|
|
82
33
|
* @param configs
|
|
83
34
|
*/
|
|
84
35
|
async function concat<T extends Linter.Config = Linter.Config>(
|
|
85
|
-
...configs: Array<T |
|
|
36
|
+
...configs: Array<Promise<ReadonlyArray<T>> | Promise<T> | ReadonlyArray<T> | T>
|
|
86
37
|
): Promise<Array<T>> {
|
|
87
38
|
const resolved = await Promise.all(configs);
|
|
88
39
|
return resolved.flat() as Array<T>;
|
|
@@ -93,10 +44,59 @@ async function concat<T extends Linter.Config = Linter.Config>(
|
|
|
93
44
|
*
|
|
94
45
|
* @param _status
|
|
95
46
|
*/
|
|
96
|
-
function fixme(_status:
|
|
47
|
+
function fixme(_status: [number | string, ...any[]] | number | string | undefined) {
|
|
97
48
|
return 'off' as const;
|
|
98
49
|
}
|
|
99
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Return a new merged flat configuration
|
|
53
|
+
*
|
|
54
|
+
* @param configs
|
|
55
|
+
*/
|
|
56
|
+
function merge<T extends Linter.Config = Linter.Config>(...configs: Array<T>): T {
|
|
57
|
+
const keys = new Set(configs.flatMap((i) => Object.keys(i)));
|
|
58
|
+
const merged = configs.reduce((acc, cur) => {
|
|
59
|
+
return {
|
|
60
|
+
...acc,
|
|
61
|
+
...cur,
|
|
62
|
+
files: [
|
|
63
|
+
...(acc.files ?? []),
|
|
64
|
+
...(cur.files ?? []),
|
|
65
|
+
],
|
|
66
|
+
ignores: [
|
|
67
|
+
...(acc.ignores ?? []),
|
|
68
|
+
...(cur.ignores ?? []),
|
|
69
|
+
],
|
|
70
|
+
languageOptions: {
|
|
71
|
+
...acc.languageOptions,
|
|
72
|
+
...cur.languageOptions,
|
|
73
|
+
},
|
|
74
|
+
linterOptions: {
|
|
75
|
+
...acc.linterOptions,
|
|
76
|
+
...cur.linterOptions,
|
|
77
|
+
},
|
|
78
|
+
plugins: {
|
|
79
|
+
...acc.plugins,
|
|
80
|
+
...cur.plugins,
|
|
81
|
+
},
|
|
82
|
+
rules: {
|
|
83
|
+
...acc.rules,
|
|
84
|
+
...cur.rules,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
// eslint-disable-next-line ts/consistent-type-assertions
|
|
88
|
+
}, {} as T);
|
|
89
|
+
|
|
90
|
+
// Remove unused keys
|
|
91
|
+
for (const key of Object.keys(merged)) {
|
|
92
|
+
if (!keys.has(key))
|
|
93
|
+
// eslint-disable-next-line ts/no-dynamic-delete
|
|
94
|
+
delete (merged as any)[key];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return merged as T;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
100
|
/**
|
|
101
101
|
* Renames rules in the given object according to the given map.
|
|
102
102
|
*
|
|
@@ -123,8 +123,8 @@ function renameRules(rules: Record<string, any>, map: Record<string, string>): R
|
|
|
123
123
|
* @namespace
|
|
124
124
|
*/
|
|
125
125
|
export const ESLintConfig = Object.freeze({
|
|
126
|
-
merge,
|
|
127
126
|
concat,
|
|
128
127
|
fixme,
|
|
128
|
+
merge,
|
|
129
129
|
renameRules,
|
|
130
130
|
});
|
package/src/LanguageId.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
3
|
+
*/
|
|
4
|
+
export type LanguageId = keyof LanguageIdMap;
|
|
5
|
+
|
|
1
6
|
export interface LanguageIdMap {
|
|
2
7
|
css: true;
|
|
3
8
|
graphql: true;
|
|
@@ -15,8 +20,3 @@ export interface LanguageIdMap {
|
|
|
15
20
|
vue: true;
|
|
16
21
|
yaml: true;
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
21
|
-
*/
|
|
22
|
-
export type LanguageId = keyof LanguageIdMap;
|
package/src/Project.ts
CHANGED
|
@@ -10,11 +10,6 @@ export type Extension = `.${string}`;
|
|
|
10
10
|
*/
|
|
11
11
|
export type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };
|
|
12
12
|
|
|
13
|
-
function escapeRegExp(value: string) {
|
|
14
|
-
// eslint-disable-next-line unicorn/prefer-string-raw
|
|
15
|
-
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&'); // $& means the whole matched string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
/**
|
|
19
14
|
* Supported ECMA version
|
|
20
15
|
*
|
|
@@ -27,6 +22,11 @@ function ecmaVersion() {
|
|
|
27
22
|
return 2022 as const;
|
|
28
23
|
}
|
|
29
24
|
|
|
25
|
+
function escapeRegExp(value: string) {
|
|
26
|
+
// eslint-disable-next-line unicorn/prefer-string-raw
|
|
27
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&'); // $& means the whole matched string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
30
|
const registry: ExtensionRegistry = {
|
|
31
31
|
css: ['.css'],
|
|
32
32
|
graphql: ['.gql', '.graphql'],
|
|
@@ -59,7 +59,7 @@ const registry: ExtensionRegistry = {
|
|
|
59
59
|
function queryExtensions(languages: LanguageId[]): readonly Extension[] {
|
|
60
60
|
return languages
|
|
61
61
|
.reduce<Extension[]>((previousValue, currentValue) =>
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
previousValue.concat(registry[currentValue] ?? ([] as Extension[])), [])
|
|
64
64
|
// eslint-disable-next-line unicorn/no-array-sort
|
|
65
65
|
.sort((left, right) => left.localeCompare(right));
|
|
@@ -110,28 +110,28 @@ const IGNORED = Object.freeze([
|
|
|
110
110
|
]);
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
113
|
+
* Return a RegExp that will match any list of extensions
|
|
114
114
|
*
|
|
115
|
+
* @param extensions
|
|
115
116
|
* @example
|
|
116
117
|
* ```ts
|
|
117
|
-
*
|
|
118
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
118
119
|
* ```
|
|
119
120
|
*/
|
|
120
|
-
function
|
|
121
|
-
return
|
|
121
|
+
function extensionsToMatcher(extensions: readonly Extension[]): RegExp {
|
|
122
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
|
-
*
|
|
126
|
+
* Files and folders to always ignore
|
|
126
127
|
*
|
|
127
|
-
* @param extensions
|
|
128
128
|
* @example
|
|
129
129
|
* ```ts
|
|
130
|
-
*
|
|
130
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
131
131
|
* ```
|
|
132
132
|
*/
|
|
133
|
-
function
|
|
134
|
-
return
|
|
133
|
+
function ignored() {
|
|
134
|
+
return IGNORED;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
const reExtension = /^\./;
|
package/src/interopDefault.ts
CHANGED
|
@@ -22,7 +22,7 @@ const getDefaultOrElse = (_: any) => _?.default ?? _;
|
|
|
22
22
|
*/
|
|
23
23
|
export function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;
|
|
24
24
|
export function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;
|
|
25
|
-
export function interopDefault<T>(m: T |
|
|
25
|
+
export function interopDefault<T>(m: PromiseLike<T> | T): Promise<T extends { default: infer U } ? U : T> {
|
|
26
26
|
// @ts-ignore We know what we are doing
|
|
27
27
|
// eslint-disable-next-line unicorn/prefer-await
|
|
28
28
|
return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
|
package/src/meta.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const meta = Object.freeze({
|
|
2
|
+
// @ts-ignore - these variables are injected at build time
|
|
3
|
+
buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,
|
|
2
4
|
// @ts-ignore - these variables are injected at build time
|
|
3
5
|
name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,
|
|
4
6
|
// @ts-ignore - these variables are injected at build time
|
|
5
7
|
version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,
|
|
6
|
-
// @ts-ignore - these variables are injected at build time
|
|
7
|
-
buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,
|
|
8
8
|
});
|