@w5s/dev 3.3.0 → 3.3.3

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 CHANGED
@@ -1,67 +1,108 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/ESLintConfig.ts
3
- function toArray(value) {
4
- if (value == null) return [];
5
- if (Array.isArray(value)) return value;
6
- return [value];
7
- }
8
- function concatArray(left, right) {
9
- return [...toArray(left), ...toArray(right)];
10
- }
11
- let ESLintConfig;
12
- (function(_ESLintConfig) {
13
- function concat(...configs) {
14
- return configs.reduce((returnValue, config) => ({
15
- ...returnValue,
16
- ...config,
17
- env: {
18
- ...returnValue.env,
19
- ...config.env
20
- },
21
- extends: concatArray(returnValue.extends, config.extends),
22
- globals: {
23
- ...returnValue.globals,
24
- ...config.globals
25
- },
26
- overrides: concatArray(returnValue.overrides, config.overrides),
27
- parserOptions: {
28
- ...returnValue.parserOptions,
29
- ...config.parserOptions
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
30
19
  },
31
- plugins: concatArray(returnValue.plugins, config.plugins),
32
20
  rules: {
33
- ...returnValue.rules,
34
- ...config.rules
21
+ ...acc.rules,
22
+ ...cur.rules
35
23
  },
36
- settings: {
37
- ...returnValue.settings,
38
- ...config.settings
24
+ languageOptions: {
25
+ ...acc.languageOptions,
26
+ ...cur.languageOptions
27
+ },
28
+ linterOptions: {
29
+ ...acc.linterOptions,
30
+ ...cur.linterOptions
39
31
  }
40
- }), {
41
- env: {},
42
- extends: [],
43
- globals: {},
44
- overrides: [],
45
- parserOptions: {},
46
- plugins: [],
47
- rules: {},
48
- settings: {}
49
- });
50
- }
51
- _ESLintConfig.concat = concat;
52
- function fixme(_status) {
53
- return "off";
54
- }
55
- _ESLintConfig.fixme = fixme;
56
- function renameRules(rules, map) {
57
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
58
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
59
- else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
60
- return [key, value];
61
- }));
62
- }
63
- _ESLintConfig.renameRules = renameRules;
64
- })(ESLintConfig || (ESLintConfig = {}));
32
+ };
33
+ }, {});
34
+ for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
35
+ return merged;
36
+ }
37
+ /**
38
+ * Concat multiple flat configs into a single flat config array.
39
+ *
40
+ * It also resolves promises and flattens the result.
41
+ *
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * import eslint from '@eslint/js'
46
+ *
47
+ * export default ESLintConfig.concat(
48
+ * {
49
+ * plugins: {},
50
+ * rules: {},
51
+ * },
52
+ * // It can also takes a array of configs:
53
+ * [
54
+ * {
55
+ * plugins: {},
56
+ * rules: {},
57
+ * }
58
+ * // ...
59
+ * ],
60
+ * // Or promises:
61
+ * Promise.resolve({
62
+ * files: ['*.ts'],
63
+ * rules: {},
64
+ * })
65
+ * );
66
+ * ```
67
+ * @param configs
68
+ */
69
+ async function concat(...configs) {
70
+ return (await Promise.all(configs)).flat();
71
+ }
72
+ /**
73
+ * Always return 'off'. `_status` is the previous rule value.
74
+ *
75
+ * @param _status
76
+ */
77
+ function fixme(_status) {
78
+ return "off";
79
+ }
80
+ /**
81
+ * Renames rules in the given object according to the given map.
82
+ *
83
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
84
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
85
+ * `{ 'new-prefix/rule-name': 'error' }`.
86
+ *
87
+ * @param rules The object containing the rules to rename.
88
+ * @param map The object containing the rename map.
89
+ */
90
+ function renameRules(rules, map) {
91
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
92
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
93
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
94
+ return [key, value];
95
+ }));
96
+ }
97
+ /**
98
+ * @namespace
99
+ */
100
+ const ESLintConfig = Object.freeze({
101
+ merge,
102
+ concat,
103
+ fixme,
104
+ renameRules
105
+ });
65
106
  //#endregion
66
107
  //#region src/interopDefault.ts
67
108
  const getDefaultOrElse = (_) => _?.default ?? _;
@@ -72,7 +113,7 @@ function interopDefault(m) {
72
113
  //#region src/meta.ts
73
114
  const meta = Object.freeze({
74
115
  name: "@w5s/dev",
75
- version: "3.3.0",
116
+ version: "3.3.3",
76
117
  buildNumber: 1
77
118
  });
78
119
  //#endregion
@@ -80,98 +121,158 @@ const meta = Object.freeze({
80
121
  function escapeRegExp(value) {
81
122
  return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
82
123
  }
83
- let Project;
84
- (function(_Project) {
85
- function ecmaVersion() {
86
- return 2022;
87
- }
88
- _Project.ecmaVersion = ecmaVersion;
89
- const registry = {
90
- css: [".css"],
91
- graphql: [".gql", ".graphql"],
92
- javascript: [
93
- ".js",
94
- ".cjs",
95
- ".mjs"
96
- ],
97
- javascriptreact: [".jsx"],
98
- jpeg: [".jpg", ".jpeg"],
99
- json: [".json"],
100
- jsonc: [".jsonc"],
101
- less: [".less"],
102
- markdown: [
103
- ".markdown",
104
- ".mdown",
105
- ".mkd",
106
- ".md"
107
- ],
108
- sass: [".sass"],
109
- scss: [".scss"],
110
- typescript: [
111
- ".ts",
112
- ".cts",
113
- ".mts"
114
- ],
115
- typescriptreact: [".tsx"],
116
- vue: [".vue"],
117
- yaml: [".yaml", ".yml"]
118
- };
119
- function queryExtensions(languages) {
120
- return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
121
- }
122
- _Project.queryExtensions = queryExtensions;
123
- function sourceExtensions() {
124
- return queryExtensions([
125
- "javascript",
126
- "javascriptreact",
127
- "typescript",
128
- "typescriptreact"
129
- ]);
130
- }
131
- _Project.sourceExtensions = sourceExtensions;
132
- const RESOURCE_EXTENSIONS = Object.freeze([
133
- ".gif",
134
- ".png",
135
- ".svg",
136
- ...queryExtensions([
137
- "css",
138
- "graphql",
139
- "jpeg",
140
- "less",
141
- "sass",
142
- "sass",
143
- "yaml"
144
- ])
145
- ]);
146
- function resourceExtensions() {
147
- return RESOURCE_EXTENSIONS;
148
- }
149
- _Project.resourceExtensions = resourceExtensions;
150
- const IGNORED = Object.freeze([
151
- "node_modules/",
152
- "build/",
153
- "cjs/",
154
- "coverage/",
155
- "dist/",
156
- "dts/",
157
- "esm/",
158
- "lib/",
159
- "mjs/",
160
- "umd/"
124
+ /**
125
+ * Supported ECMA version
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * Project.ecmaVersion() // 2022
130
+ * ```
131
+ */
132
+ function ecmaVersion() {
133
+ return 2022;
134
+ }
135
+ const registry = {
136
+ css: [".css"],
137
+ graphql: [".gql", ".graphql"],
138
+ javascript: [
139
+ ".js",
140
+ ".cjs",
141
+ ".mjs"
142
+ ],
143
+ javascriptreact: [".jsx"],
144
+ jpeg: [".jpg", ".jpeg"],
145
+ json: [".json"],
146
+ jsonc: [".jsonc"],
147
+ less: [".less"],
148
+ markdown: [
149
+ ".markdown",
150
+ ".mdown",
151
+ ".mkd",
152
+ ".md"
153
+ ],
154
+ sass: [".sass"],
155
+ scss: [".scss"],
156
+ typescript: [
157
+ ".ts",
158
+ ".cts",
159
+ ".mts"
160
+ ],
161
+ typescriptreact: [".tsx"],
162
+ vue: [".vue"],
163
+ yaml: [".yaml", ".yml"]
164
+ };
165
+ /**
166
+ * Return a list of extensions
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
171
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
172
+ * ```
173
+ *
174
+ * @param languages
175
+ */
176
+ function queryExtensions(languages) {
177
+ return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
178
+ }
179
+ /**
180
+ * Supported file extensions
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
185
+ * ```
186
+ */
187
+ function sourceExtensions() {
188
+ return queryExtensions([
189
+ "javascript",
190
+ "javascriptreact",
191
+ "typescript",
192
+ "typescriptreact"
161
193
  ]);
162
- function ignored() {
163
- return IGNORED;
164
- }
165
- _Project.ignored = ignored;
166
- function extensionsToMatcher(extensions) {
167
- return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
168
- }
169
- _Project.extensionsToMatcher = extensionsToMatcher;
170
- function extensionsToGlob(extensions) {
171
- return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
172
- }
173
- _Project.extensionsToGlob = extensionsToGlob;
174
- })(Project || (Project = {}));
194
+ }
195
+ const RESOURCE_EXTENSIONS = Object.freeze([
196
+ ".gif",
197
+ ".png",
198
+ ".svg",
199
+ ...queryExtensions([
200
+ "css",
201
+ "graphql",
202
+ "jpeg",
203
+ "less",
204
+ "sass",
205
+ "sass",
206
+ "yaml"
207
+ ])
208
+ ]);
209
+ /**
210
+ * Resource file extensions
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
215
+ * ```
216
+ */
217
+ function resourceExtensions() {
218
+ return RESOURCE_EXTENSIONS;
219
+ }
220
+ const IGNORED = Object.freeze([
221
+ "node_modules/",
222
+ "build/",
223
+ "cjs/",
224
+ "coverage/",
225
+ "dist/",
226
+ "dts/",
227
+ "esm/",
228
+ "lib/",
229
+ "mjs/",
230
+ "umd/"
231
+ ]);
232
+ /**
233
+ * Files and folders to always ignore
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * IGNORED // ['node_modules/', 'build/', ...]
238
+ * ```
239
+ */
240
+ function ignored() {
241
+ return IGNORED;
242
+ }
243
+ /**
244
+ * Return a RegExp that will match any list of extensions
245
+ *
246
+ * @param extensions
247
+ * @example
248
+ * ```ts
249
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
250
+ * ```
251
+ */
252
+ function extensionsToMatcher(extensions) {
253
+ return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
254
+ }
255
+ /**
256
+ * Return a glob matcher that will match any list of extensions
257
+ *
258
+ * @param extensions
259
+ * @example
260
+ * ```ts
261
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
262
+ * ```
263
+ */
264
+ function extensionsToGlob(extensions) {
265
+ return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
266
+ }
267
+ const Project = Object.freeze({
268
+ ecmaVersion,
269
+ extensionsToGlob,
270
+ extensionsToMatcher,
271
+ ignored,
272
+ queryExtensions,
273
+ resourceExtensions,
274
+ sourceExtensions
275
+ });
175
276
  //#endregion
176
277
  //#region src/ProjectScript.ts
177
278
  /**
@@ -192,21 +293,12 @@ const ProjectScript = {
192
293
  Rescue: "rescue",
193
294
  Spellcheck: "spellcheck",
194
295
  Test: "test",
296
+ Typecheck: "typecheck",
195
297
  Validate: "validate"
196
298
  };
197
299
  //#endregion
198
- Object.defineProperty(exports, "ESLintConfig", {
199
- enumerable: true,
200
- get: function() {
201
- return ESLintConfig;
202
- }
203
- });
204
- Object.defineProperty(exports, "Project", {
205
- enumerable: true,
206
- get: function() {
207
- return Project;
208
- }
209
- });
300
+ exports.ESLintConfig = ESLintConfig;
301
+ exports.Project = Project;
210
302
  exports.ProjectScript = ProjectScript;
211
303
  exports.interopDefault = interopDefault;
212
304
  exports.meta = meta;
@@ -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 { ESLint } from 'eslint';\n\nfunction toArray<T>(value: T[] | T | undefined): T[] {\n if (value == null) {\n return [];\n }\n if (Array.isArray(value)) {\n return value;\n }\n return [value];\n}\n\nfunction concatArray<T>(left: T[] | T | undefined, right: T[] | T | undefined): T[] {\n return [...toArray(left), ...toArray(right)];\n}\n\nexport namespace ESLintConfig {\n /**\n *\n * @param configs\n */\n export function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {\n return configs.reduce(\n (returnValue, config) => ({\n ...returnValue,\n ...config,\n env: { ...returnValue.env, ...config.env },\n extends: concatArray(returnValue.extends, config.extends),\n globals: { ...returnValue.globals, ...config.globals },\n overrides: concatArray(returnValue.overrides, config.overrides),\n parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },\n plugins: concatArray(returnValue.plugins, config.plugins),\n rules: { ...returnValue.rules, ...config.rules },\n settings: { ...returnValue.settings, ...config.settings },\n }),\n {\n env: {},\n extends: [],\n globals: {},\n overrides: [],\n parserOptions: {},\n plugins: [],\n rules: {},\n settings: {},\n },\n );\n }\n\n /**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\n export function fixme(_status: string | number | [string | number, ...any[]] | undefined) {\n return 'off' as const;\n }\n\n /**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\n export function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n }\n}\n","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\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\nexport namespace Project {\n /**\n * A type of a file extension\n */\n export type Extension = `.${string}`;\n\n /**\n * Object hash of all well-known file extension category to file extensions mapping\n */\n export type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };\n\n /**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\n export function ecmaVersion() {\n return 2022 as const;\n }\n\n const registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n };\n\n /**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\n export function queryExtensions(languages: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n // eslint-disable-next-line unicorn/prefer-spread\n previousValue.concat(registry[currentValue] ?? ([] as Extension[])), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort();\n }\n\n /**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\n export function sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n }\n\n const RESOURCE_EXTENSIONS: readonly Extension[] = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n ]);\n\n /**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\n export function resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n }\n\n const IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n ]);\n\n /**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\n export function ignored() {\n return IGNORED;\n }\n\n /**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\n export function extensionsToMatcher(extensions: readonly Extension[]): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n }\n\n /**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\n export function extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(/^\\./, '')).join('|')})`;\n }\n}\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";;AAEA,SAAS,QAAW,OAAiC;CACnD,IAAI,SAAS,MACX,OAAO,EAAE;CAEX,IAAI,MAAM,QAAQ,MAAM,EACtB,OAAO;CAET,OAAO,CAAC,MAAM;;AAGhB,SAAS,YAAe,MAA2B,OAAiC;CAClF,OAAO,CAAC,GAAG,QAAQ,KAAK,EAAE,GAAG,QAAQ,MAAM,CAAC;;AAGvC,IAAA;;CAKE,SAAS,OAAO,GAAG,SAAiD;EACzE,OAAO,QAAQ,QACZ,aAAa,YAAY;GACxB,GAAG;GACH,GAAG;GACH,KAAK;IAAE,GAAG,YAAY;IAAK,GAAG,OAAO;IAAK;GAC1C,SAAS,YAAY,YAAY,SAAS,OAAO,QAAQ;GACzD,SAAS;IA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GAAG,CAAC,CAAC,KAAK,IAAI,CAAC;;;6BAEvE;;;;;;AClJD,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,UAAU;CACX"}
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,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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