@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.js CHANGED
@@ -1,66 +1,107 @@
1
1
  //#region src/ESLintConfig.ts
2
- function toArray(value) {
3
- if (value == null) return [];
4
- if (Array.isArray(value)) return value;
5
- return [value];
6
- }
7
- function concatArray(left, right) {
8
- return [...toArray(left), ...toArray(right)];
9
- }
10
- let ESLintConfig;
11
- (function(_ESLintConfig) {
12
- function concat(...configs) {
13
- return configs.reduce((returnValue, config) => ({
14
- ...returnValue,
15
- ...config,
16
- env: {
17
- ...returnValue.env,
18
- ...config.env
19
- },
20
- extends: concatArray(returnValue.extends, config.extends),
21
- globals: {
22
- ...returnValue.globals,
23
- ...config.globals
24
- },
25
- overrides: concatArray(returnValue.overrides, config.overrides),
26
- parserOptions: {
27
- ...returnValue.parserOptions,
28
- ...config.parserOptions
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
29
18
  },
30
- plugins: concatArray(returnValue.plugins, config.plugins),
31
19
  rules: {
32
- ...returnValue.rules,
33
- ...config.rules
20
+ ...acc.rules,
21
+ ...cur.rules
34
22
  },
35
- settings: {
36
- ...returnValue.settings,
37
- ...config.settings
23
+ languageOptions: {
24
+ ...acc.languageOptions,
25
+ ...cur.languageOptions
26
+ },
27
+ linterOptions: {
28
+ ...acc.linterOptions,
29
+ ...cur.linterOptions
38
30
  }
39
- }), {
40
- env: {},
41
- extends: [],
42
- globals: {},
43
- overrides: [],
44
- parserOptions: {},
45
- plugins: [],
46
- rules: {},
47
- settings: {}
48
- });
49
- }
50
- _ESLintConfig.concat = concat;
51
- function fixme(_status) {
52
- return "off";
53
- }
54
- _ESLintConfig.fixme = fixme;
55
- function renameRules(rules, map) {
56
- return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
57
- for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
58
- else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
59
- return [key, value];
60
- }));
61
- }
62
- _ESLintConfig.renameRules = renameRules;
63
- })(ESLintConfig || (ESLintConfig = {}));
31
+ };
32
+ }, {});
33
+ for (const key of Object.keys(merged)) if (!keys.has(key)) delete merged[key];
34
+ return merged;
35
+ }
36
+ /**
37
+ * Concat multiple flat configs into a single flat config array.
38
+ *
39
+ * It also resolves promises and flattens the result.
40
+ *
41
+ * @example
42
+ *
43
+ * ```ts
44
+ * import eslint from '@eslint/js'
45
+ *
46
+ * export default ESLintConfig.concat(
47
+ * {
48
+ * plugins: {},
49
+ * rules: {},
50
+ * },
51
+ * // It can also takes a array of configs:
52
+ * [
53
+ * {
54
+ * plugins: {},
55
+ * rules: {},
56
+ * }
57
+ * // ...
58
+ * ],
59
+ * // Or promises:
60
+ * Promise.resolve({
61
+ * files: ['*.ts'],
62
+ * rules: {},
63
+ * })
64
+ * );
65
+ * ```
66
+ * @param configs
67
+ */
68
+ async function concat(...configs) {
69
+ return (await Promise.all(configs)).flat();
70
+ }
71
+ /**
72
+ * Always return 'off'. `_status` is the previous rule value.
73
+ *
74
+ * @param _status
75
+ */
76
+ function fixme(_status) {
77
+ return "off";
78
+ }
79
+ /**
80
+ * Renames rules in the given object according to the given map.
81
+ *
82
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
83
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
84
+ * `{ 'new-prefix/rule-name': 'error' }`.
85
+ *
86
+ * @param rules The object containing the rules to rename.
87
+ * @param map The object containing the rename map.
88
+ */
89
+ function renameRules(rules, map) {
90
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
91
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
92
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
93
+ return [key, value];
94
+ }));
95
+ }
96
+ /**
97
+ * @namespace
98
+ */
99
+ const ESLintConfig = Object.freeze({
100
+ merge,
101
+ concat,
102
+ fixme,
103
+ renameRules
104
+ });
64
105
  //#endregion
65
106
  //#region src/interopDefault.ts
66
107
  const getDefaultOrElse = (_) => _?.default ?? _;
@@ -71,7 +112,7 @@ function interopDefault(m) {
71
112
  //#region src/meta.ts
72
113
  const meta = Object.freeze({
73
114
  name: "@w5s/dev",
74
- version: "3.3.0",
115
+ version: "3.3.3",
75
116
  buildNumber: 1
76
117
  });
77
118
  //#endregion
@@ -79,98 +120,158 @@ const meta = Object.freeze({
79
120
  function escapeRegExp(value) {
80
121
  return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
81
122
  }
82
- let Project;
83
- (function(_Project) {
84
- function ecmaVersion() {
85
- return 2022;
86
- }
87
- _Project.ecmaVersion = ecmaVersion;
88
- const registry = {
89
- css: [".css"],
90
- graphql: [".gql", ".graphql"],
91
- javascript: [
92
- ".js",
93
- ".cjs",
94
- ".mjs"
95
- ],
96
- javascriptreact: [".jsx"],
97
- jpeg: [".jpg", ".jpeg"],
98
- json: [".json"],
99
- jsonc: [".jsonc"],
100
- less: [".less"],
101
- markdown: [
102
- ".markdown",
103
- ".mdown",
104
- ".mkd",
105
- ".md"
106
- ],
107
- sass: [".sass"],
108
- scss: [".scss"],
109
- typescript: [
110
- ".ts",
111
- ".cts",
112
- ".mts"
113
- ],
114
- typescriptreact: [".tsx"],
115
- vue: [".vue"],
116
- yaml: [".yaml", ".yml"]
117
- };
118
- function queryExtensions(languages) {
119
- return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
120
- }
121
- _Project.queryExtensions = queryExtensions;
122
- function sourceExtensions() {
123
- return queryExtensions([
124
- "javascript",
125
- "javascriptreact",
126
- "typescript",
127
- "typescriptreact"
128
- ]);
129
- }
130
- _Project.sourceExtensions = sourceExtensions;
131
- const RESOURCE_EXTENSIONS = Object.freeze([
132
- ".gif",
133
- ".png",
134
- ".svg",
135
- ...queryExtensions([
136
- "css",
137
- "graphql",
138
- "jpeg",
139
- "less",
140
- "sass",
141
- "sass",
142
- "yaml"
143
- ])
144
- ]);
145
- function resourceExtensions() {
146
- return RESOURCE_EXTENSIONS;
147
- }
148
- _Project.resourceExtensions = resourceExtensions;
149
- const IGNORED = Object.freeze([
150
- "node_modules/",
151
- "build/",
152
- "cjs/",
153
- "coverage/",
154
- "dist/",
155
- "dts/",
156
- "esm/",
157
- "lib/",
158
- "mjs/",
159
- "umd/"
123
+ /**
124
+ * Supported ECMA version
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * Project.ecmaVersion() // 2022
129
+ * ```
130
+ */
131
+ function ecmaVersion() {
132
+ return 2022;
133
+ }
134
+ const registry = {
135
+ css: [".css"],
136
+ graphql: [".gql", ".graphql"],
137
+ javascript: [
138
+ ".js",
139
+ ".cjs",
140
+ ".mjs"
141
+ ],
142
+ javascriptreact: [".jsx"],
143
+ jpeg: [".jpg", ".jpeg"],
144
+ json: [".json"],
145
+ jsonc: [".jsonc"],
146
+ less: [".less"],
147
+ markdown: [
148
+ ".markdown",
149
+ ".mdown",
150
+ ".mkd",
151
+ ".md"
152
+ ],
153
+ sass: [".sass"],
154
+ scss: [".scss"],
155
+ typescript: [
156
+ ".ts",
157
+ ".cts",
158
+ ".mts"
159
+ ],
160
+ typescriptreact: [".tsx"],
161
+ vue: [".vue"],
162
+ yaml: [".yaml", ".yml"]
163
+ };
164
+ /**
165
+ * Return a list of extensions
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
170
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
171
+ * ```
172
+ *
173
+ * @param languages
174
+ */
175
+ function queryExtensions(languages) {
176
+ return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
177
+ }
178
+ /**
179
+ * Supported file extensions
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
184
+ * ```
185
+ */
186
+ function sourceExtensions() {
187
+ return queryExtensions([
188
+ "javascript",
189
+ "javascriptreact",
190
+ "typescript",
191
+ "typescriptreact"
160
192
  ]);
161
- function ignored() {
162
- return IGNORED;
163
- }
164
- _Project.ignored = ignored;
165
- function extensionsToMatcher(extensions) {
166
- return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
167
- }
168
- _Project.extensionsToMatcher = extensionsToMatcher;
169
- function extensionsToGlob(extensions) {
170
- return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
171
- }
172
- _Project.extensionsToGlob = extensionsToGlob;
173
- })(Project || (Project = {}));
193
+ }
194
+ const RESOURCE_EXTENSIONS = Object.freeze([
195
+ ".gif",
196
+ ".png",
197
+ ".svg",
198
+ ...queryExtensions([
199
+ "css",
200
+ "graphql",
201
+ "jpeg",
202
+ "less",
203
+ "sass",
204
+ "sass",
205
+ "yaml"
206
+ ])
207
+ ]);
208
+ /**
209
+ * Resource file extensions
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
214
+ * ```
215
+ */
216
+ function resourceExtensions() {
217
+ return RESOURCE_EXTENSIONS;
218
+ }
219
+ const IGNORED = Object.freeze([
220
+ "node_modules/",
221
+ "build/",
222
+ "cjs/",
223
+ "coverage/",
224
+ "dist/",
225
+ "dts/",
226
+ "esm/",
227
+ "lib/",
228
+ "mjs/",
229
+ "umd/"
230
+ ]);
231
+ /**
232
+ * Files and folders to always ignore
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * IGNORED // ['node_modules/', 'build/', ...]
237
+ * ```
238
+ */
239
+ function ignored() {
240
+ return IGNORED;
241
+ }
242
+ /**
243
+ * Return a RegExp that will match any list of extensions
244
+ *
245
+ * @param extensions
246
+ * @example
247
+ * ```ts
248
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
249
+ * ```
250
+ */
251
+ function extensionsToMatcher(extensions) {
252
+ return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
253
+ }
254
+ /**
255
+ * Return a glob matcher that will match any list of extensions
256
+ *
257
+ * @param extensions
258
+ * @example
259
+ * ```ts
260
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
261
+ * ```
262
+ */
263
+ function extensionsToGlob(extensions) {
264
+ return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
265
+ }
266
+ const Project = Object.freeze({
267
+ ecmaVersion,
268
+ extensionsToGlob,
269
+ extensionsToMatcher,
270
+ ignored,
271
+ queryExtensions,
272
+ resourceExtensions,
273
+ sourceExtensions
274
+ });
174
275
  //#endregion
175
276
  //#region src/ProjectScript.ts
176
277
  /**
@@ -191,6 +292,7 @@ const ProjectScript = {
191
292
  Rescue: "rescue",
192
293
  Spellcheck: "spellcheck",
193
294
  Test: "test",
295
+ Typecheck: "typecheck",
194
296
  Validate: "validate"
195
297
  };
196
298
  //#endregion
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 { 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;IAAE,GAAG,YAAY;IAAS,GAAG,OAAO;IAAS;GACtD,WAAW,YAAY,YAAY,WAAW,OAAO,UAAU;GAC/D,eAAe;IAAE,GAAG,YAAY;IAAe,GAAG,OAAO;IAAe;GACxE,SAAS,YAAY,YAAY,SAAS,OAAO,QAAQ;GACzD,OAAO;IAAE,GAAG,YAAY;IAAO,GAAG,OAAO;IAAO;GAChD,UAAU;IAAE,GAAG,YAAY;IAAU,GAAG,OAAO;IAAU;GAC1D,GACD;G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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,QAAQ,IAAI,OAAO,EAAA,CAC1B,KAAK;AACvB;;;;;;AAOA,SAAS,MAAM,SAAoE;CACjF,OAAO;AACT;;;;;;;;;;;AAYA,SAAS,YAAY,OAA4B,KAAkD;CACjG,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW;EAC1C,KAAK,MAAM,CAAC,MAAM,OAAO,OAAO,QAAQ,GAAG,GACzC,IAAI,IAAI,WAAW,GAAG,K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BAAkB,CAAC,CAAiB,GAAG,CAAC,CAAC,CAAC,CAEzE,KAAK;AACV;;;;;;;;;AAUA,SAAS,mBAAmB;CAC1B,OAAO,gBAAgB;EAAC;EAAc;EAAmB;EAAc;CAAiB,CAAC;AAC3F;AAEA,MAAM,sBAA4C,OAAO,OAAO;CAC9D;CACA;CACA;CACA,GAAG,gBAAgB;EAAC;EAAO;EAAW;EAAQ;EAAQ;EAAQ;EAAQ;CAAM,CAAC;AAC/E,CAAC;;;;;;;;;AAUD,SAAS,qBAAqB;CAC5B,OAAO;AACT;AAEA,MAAM,UAAU,OAAO,OAAO;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAUD,SAAS,UAAU;CACjB,OAAO;AACT;;;;;;;;;;AAWA,SAAS,oBAAoB,YAA0C;CACrE,OAAO,IAAI,OAAO,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG;AAClE;;;;;;;;;;AAWA,SAAS,iBAAiB,YAA0C;CAClE,OAAO,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;AACtE;AAEA,MAAa,UAAU,OAAO,OAAO;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AC1JD,MAAa,gBAAgB;CAC3B,OAAO;CACP,OAAO;CACP,cAAc;CACd,UAAU;CACV,SAAS;CACT,MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,YAAY;CACZ,MAAM;CACN,WAAW;CACX,UAAU;AACZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/dev",
3
- "version": "3.3.0",
3
+ "version": "3.3.3",
4
4
  "description": "Shared development constants and functions",
5
5
  "keywords": [
6
6
  "config",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git@github.com:w5s/project-config.git",
15
+ "url": "git+ssh@github.com:w5s/project-config.git",
16
16
  "directory": "packages/dev"
17
17
  },
18
18
  "license": "MIT",
@@ -54,5 +54,5 @@
54
54
  "access": "public"
55
55
  },
56
56
  "sideEffect": false,
57
- "gitHead": "38cf5f5877af4c8a1c292b9b7039c5a11863fc00"
57
+ "gitHead": "fc447207d2af5368f809a9a90d0e4056344b812a"
58
58
  }