@w5s/dev 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,60 +7,81 @@ function toArray(value) {
7
7
  function concatArray(left, right) {
8
8
  return [...toArray(left), ...toArray(right)];
9
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
29
- },
30
- plugins: concatArray(returnValue.plugins, config.plugins),
31
- rules: {
32
- ...returnValue.rules,
33
- ...config.rules
34
- },
35
- settings: {
36
- ...returnValue.settings,
37
- ...config.settings
38
- }
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 = {}));
10
+ /**
11
+ *
12
+ * @param configs
13
+ */
14
+ function concat(...configs) {
15
+ return configs.reduce((returnValue, config) => ({
16
+ ...returnValue,
17
+ ...config,
18
+ env: {
19
+ ...returnValue.env,
20
+ ...config.env
21
+ },
22
+ extends: concatArray(returnValue.extends, config.extends),
23
+ globals: {
24
+ ...returnValue.globals,
25
+ ...config.globals
26
+ },
27
+ overrides: concatArray(returnValue.overrides, config.overrides),
28
+ parserOptions: {
29
+ ...returnValue.parserOptions,
30
+ ...config.parserOptions
31
+ },
32
+ plugins: concatArray(returnValue.plugins, config.plugins),
33
+ rules: {
34
+ ...returnValue.rules,
35
+ ...config.rules
36
+ },
37
+ settings: {
38
+ ...returnValue.settings,
39
+ ...config.settings
40
+ }
41
+ }), {
42
+ env: {},
43
+ extends: [],
44
+ globals: {},
45
+ overrides: [],
46
+ parserOptions: {},
47
+ plugins: [],
48
+ rules: {},
49
+ settings: {}
50
+ });
51
+ }
52
+ /**
53
+ * Always return 'off'. `_status` is the previous rule value.
54
+ *
55
+ * @param _status
56
+ */
57
+ function fixme(_status) {
58
+ return "off";
59
+ }
60
+ /**
61
+ * Renames rules in the given object according to the given map.
62
+ *
63
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
64
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
65
+ * `{ 'new-prefix/rule-name': 'error' }`.
66
+ *
67
+ * @param rules The object containing the rules to rename.
68
+ * @param map The object containing the rename map.
69
+ */
70
+ function renameRules(rules, map) {
71
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
72
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
73
+ else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
74
+ return [key, value];
75
+ }));
76
+ }
77
+ /**
78
+ * @namespace
79
+ */
80
+ const ESLintConfig = Object.freeze({
81
+ concat,
82
+ fixme,
83
+ renameRules
84
+ });
64
85
  //#endregion
65
86
  //#region src/interopDefault.ts
66
87
  const getDefaultOrElse = (_) => _?.default ?? _;
@@ -71,7 +92,7 @@ function interopDefault(m) {
71
92
  //#region src/meta.ts
72
93
  const meta = Object.freeze({
73
94
  name: "@w5s/dev",
74
- version: "3.3.0",
95
+ version: "3.3.2",
75
96
  buildNumber: 1
76
97
  });
77
98
  //#endregion
@@ -79,98 +100,158 @@ const meta = Object.freeze({
79
100
  function escapeRegExp(value) {
80
101
  return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
81
102
  }
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/"
103
+ /**
104
+ * Supported ECMA version
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * Project.ecmaVersion() // 2022
109
+ * ```
110
+ */
111
+ function ecmaVersion() {
112
+ return 2022;
113
+ }
114
+ const registry = {
115
+ css: [".css"],
116
+ graphql: [".gql", ".graphql"],
117
+ javascript: [
118
+ ".js",
119
+ ".cjs",
120
+ ".mjs"
121
+ ],
122
+ javascriptreact: [".jsx"],
123
+ jpeg: [".jpg", ".jpeg"],
124
+ json: [".json"],
125
+ jsonc: [".jsonc"],
126
+ less: [".less"],
127
+ markdown: [
128
+ ".markdown",
129
+ ".mdown",
130
+ ".mkd",
131
+ ".md"
132
+ ],
133
+ sass: [".sass"],
134
+ scss: [".scss"],
135
+ typescript: [
136
+ ".ts",
137
+ ".cts",
138
+ ".mts"
139
+ ],
140
+ typescriptreact: [".tsx"],
141
+ vue: [".vue"],
142
+ yaml: [".yaml", ".yml"]
143
+ };
144
+ /**
145
+ * Return a list of extensions
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
150
+ * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
151
+ * ```
152
+ *
153
+ * @param languages
154
+ */
155
+ function queryExtensions(languages) {
156
+ return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
157
+ }
158
+ /**
159
+ * Supported file extensions
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * Project.sourceExtensions() // ['.ts', '.js', ...]
164
+ * ```
165
+ */
166
+ function sourceExtensions() {
167
+ return queryExtensions([
168
+ "javascript",
169
+ "javascriptreact",
170
+ "typescript",
171
+ "typescriptreact"
160
172
  ]);
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 = {}));
173
+ }
174
+ const RESOURCE_EXTENSIONS = Object.freeze([
175
+ ".gif",
176
+ ".png",
177
+ ".svg",
178
+ ...queryExtensions([
179
+ "css",
180
+ "graphql",
181
+ "jpeg",
182
+ "less",
183
+ "sass",
184
+ "sass",
185
+ "yaml"
186
+ ])
187
+ ]);
188
+ /**
189
+ * Resource file extensions
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * Project.resourceExtensions() // ['.css', '.sass', ...]
194
+ * ```
195
+ */
196
+ function resourceExtensions() {
197
+ return RESOURCE_EXTENSIONS;
198
+ }
199
+ const IGNORED = Object.freeze([
200
+ "node_modules/",
201
+ "build/",
202
+ "cjs/",
203
+ "coverage/",
204
+ "dist/",
205
+ "dts/",
206
+ "esm/",
207
+ "lib/",
208
+ "mjs/",
209
+ "umd/"
210
+ ]);
211
+ /**
212
+ * Files and folders to always ignore
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * IGNORED // ['node_modules/', 'build/', ...]
217
+ * ```
218
+ */
219
+ function ignored() {
220
+ return IGNORED;
221
+ }
222
+ /**
223
+ * Return a RegExp that will match any list of extensions
224
+ *
225
+ * @param extensions
226
+ * @example
227
+ * ```ts
228
+ * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
229
+ * ```
230
+ */
231
+ function extensionsToMatcher(extensions) {
232
+ return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
233
+ }
234
+ /**
235
+ * Return a glob matcher that will match any list of extensions
236
+ *
237
+ * @param extensions
238
+ * @example
239
+ * ```ts
240
+ * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
241
+ * ```
242
+ */
243
+ function extensionsToGlob(extensions) {
244
+ return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
245
+ }
246
+ const Project = Object.freeze({
247
+ ecmaVersion,
248
+ extensionsToGlob,
249
+ extensionsToMatcher,
250
+ ignored,
251
+ queryExtensions,
252
+ resourceExtensions,
253
+ sourceExtensions
254
+ });
174
255
  //#endregion
175
256
  //#region src/ProjectScript.ts
176
257
  /**
@@ -191,6 +272,7 @@ const ProjectScript = {
191
272
  Rescue: "rescue",
192
273
  Spellcheck: "spellcheck",
193
274
  Test: "test",
275
+ Typecheck: "typecheck",
194
276
  Validate: "validate"
195
277
  };
196
278
  //#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":";AAE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;EACA,GAAG,gBAAgB;GAAC;GAAO;GAAW;GAAQ;GAAQ;GAAQ;GAAQ;GAAO,CAAC;EAC/E,CAAC;CAUK,SAAS,qBAAqB;EACnC,OAAO;;;CAGT,MAAM,UAAU,OAAO,OAAO;EAC5B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAUK,SAAS,UAAU;EACxB,OAAO;;;CAYF,SAAS,oBAAoB,YAA0C;EAC5E,OAAO,IAAI,OAAO,IAAI,WAAW,IAAI,aAAa,CAAC,KAAK,IAAI,CAAC,IAAI;;;CAY5D,SAAS,iBAAiB,YAA0C;EACzE,OAAO,OAAO,WAAW,KAAK,MAAM,EAAE,QAAQ,OAAO,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.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\n/**\n *\n * @param configs\n */\nfunction concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {\n return configs.reduce(\n (returnValue, config) => ({\n ...returnValue,\n ...config,\n env: { ...returnValue.env, ...config.env },\n extends: concatArray(returnValue.extends, config.extends),\n globals: { ...returnValue.globals, ...config.globals },\n overrides: concatArray(returnValue.overrides, config.overrides),\n parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },\n plugins: concatArray(returnValue.plugins, config.plugins),\n rules: { ...returnValue.rules, ...config.rules },\n settings: { ...returnValue.settings, ...config.settings },\n }),\n {\n env: {},\n extends: [],\n globals: {},\n overrides: [],\n parserOptions: {},\n plugins: [],\n rules: {},\n settings: {},\n },\n );\n}\n\n/**\n * Always return 'off'. `_status` is the previous rule value.\n *\n * @param _status\n */\nfunction fixme(_status: string | number | [string | number, ...any[]] | undefined) {\n return 'off' as const;\n}\n\n/**\n * Renames rules in the given object according to the given map.\n *\n * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object\n * `{ 'old-prefix/rule-name': 'error' }`, this function will return\n * `{ 'new-prefix/rule-name': 'error' }`.\n *\n * @param rules The object containing the rules to rename.\n * @param map The object containing the rename map.\n */\nfunction renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {\n return Object.fromEntries(\n Object.entries(rules).map(([key, value]) => {\n for (const [from, to] of Object.entries(map)) {\n if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];\n else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];\n }\n return [key, value];\n }),\n );\n}\n\n/**\n * @namespace\n */\nexport const ESLintConfig = Object.freeze({\n concat,\n fixme,\n renameRules,\n});\n","const getDefaultOrElse = (_: any) => _?.default ?? _;\n\n/**\n * Resolves a module or promise-like object, returning the default export if available.\n *\n * @example\n * ```ts\n * // modules.ts\n * export default {\n * foo: true\n * };\n * // Async API\n * const modPromise = import('./module');\n * interopDefault(modPromise); // == Promise.resolve({ foo: true })\n * // Sync API\n * const mod = await import('./module');\n * interopDefault(mod); // == { foo: true }\n * ```\n *\n * @template T - The type of the module or promise-like object.\n * @param m The module or promise-like object to resolve.\n */\nexport function interopDefault<T>(m: PromiseLike<T>): Promise<T extends { default: infer U } ? U : T>;\nexport function interopDefault<T>(m: T): T extends { default: infer U } ? U : T;\nexport function interopDefault<T>(m: T | PromiseLike<T>): Promise<T extends { default: infer U } ? U : T> {\n // @ts-ignore We know what we are doing\n return m != null && typeof m.then === 'function' ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n // @ts-ignore - these variables are injected at build time\n buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n});\n","import type { LanguageId } from './LanguageId.js';\n\n/**\n * A type of a file extension\n */\nexport type Extension = `.${string}`;\n\n/**\n * Object hash of all well-known file extension category to file extensions mapping\n */\nexport type ExtensionRegistry = { [K in LanguageId]: readonly Extension[] };\n\nfunction escapeRegExp(value: string) {\n // eslint-disable-next-line unicorn/prefer-string-raw\n return value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&'); // $& means the whole matched string\n}\n\n/**\n * Supported ECMA version\n *\n * @example\n * ```ts\n * Project.ecmaVersion() // 2022\n * ```\n */\nfunction ecmaVersion() {\n return 2022 as const;\n}\n\nconst registry: ExtensionRegistry = {\n css: ['.css'],\n graphql: ['.gql', '.graphql'],\n javascript: ['.js', '.cjs', '.mjs'],\n javascriptreact: ['.jsx'],\n jpeg: ['.jpg', '.jpeg'],\n json: ['.json'],\n jsonc: ['.jsonc'],\n less: ['.less'],\n markdown: ['.markdown', '.mdown', '.mkd', '.md'],\n sass: ['.sass'],\n scss: ['.scss'],\n typescript: ['.ts', '.cts', '.mts'],\n typescriptreact: ['.tsx'],\n vue: ['.vue'],\n yaml: ['.yaml', '.yml'],\n};\n\n/**\n * Return a list of extensions\n *\n * @example\n * ```ts\n * Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]\n * Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']\n * ```\n *\n * @param languages\n */\nfunction queryExtensions(languages: LanguageId[]): readonly Extension[] {\n return languages\n .reduce<Extension[]>((previousValue, currentValue) =>\n // eslint-disable-next-line unicorn/prefer-spread\n previousValue.concat(registry[currentValue] ?? ([] as Extension[])), [])\n // eslint-disable-next-line unicorn/no-array-sort\n .sort();\n}\n\n/**\n * Supported file extensions\n *\n * @example\n * ```ts\n * Project.sourceExtensions() // ['.ts', '.js', ...]\n * ```\n */\nfunction sourceExtensions() {\n return queryExtensions(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);\n}\n\nconst RESOURCE_EXTENSIONS: readonly Extension[] = Object.freeze([\n '.gif',\n '.png',\n '.svg',\n ...queryExtensions(['css', 'graphql', 'jpeg', 'less', 'sass', 'sass', 'yaml']),\n]);\n\n/**\n * Resource file extensions\n *\n * @example\n * ```ts\n * Project.resourceExtensions() // ['.css', '.sass', ...]\n * ```\n */\nfunction resourceExtensions() {\n return RESOURCE_EXTENSIONS;\n}\n\nconst IGNORED = Object.freeze([\n 'node_modules/',\n 'build/',\n 'cjs/',\n 'coverage/',\n 'dist/',\n 'dts/',\n 'esm/',\n 'lib/',\n 'mjs/',\n 'umd/',\n]);\n\n/**\n * Files and folders to always ignore\n *\n * @example\n * ```ts\n * IGNORED // ['node_modules/', 'build/', ...]\n * ```\n */\nfunction ignored() {\n return IGNORED;\n}\n\n/**\n * Return a RegExp that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\\.js|\\.ts)$/\n * ```\n */\nfunction extensionsToMatcher(extensions: readonly Extension[]): RegExp {\n return new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);\n}\n\n/**\n * Return a glob matcher that will match any list of extensions\n *\n * @param extensions\n * @example\n * ```ts\n * Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'\n * ```\n */\nfunction extensionsToGlob(extensions: readonly Extension[]): string {\n return `*.+(${extensions.map((_) => _.replace(/^\\./, '')).join('|')})`;\n}\n\nexport const Project = Object.freeze({\n ecmaVersion,\n extensionsToGlob,\n extensionsToMatcher,\n ignored,\n queryExtensions,\n resourceExtensions,\n sourceExtensions,\n});\n","/**\n * Project common scripts\n */\nexport const ProjectScript = {\n Build: 'build',\n Clean: 'clean',\n CodeAnalysis: 'code-analysis',\n Coverage: 'coverage',\n Develop: 'develop',\n Docs: 'docs',\n Format: 'format',\n Install: 'install',\n Lint: 'lint',\n Prepare: 'prepare',\n Release: 'release',\n Rescue: 'rescue',\n Spellcheck: 'spellcheck',\n Test: 'test',\n Typecheck: 'typecheck',\n Validate: 'validate',\n} as const;\nexport type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];\n"],"mappings":";AAEA,SAAS,QAAW,OAAiC;CACnD,IAAI,SAAS,MACX,OAAO,CAAC;CAEV,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO;CAET,OAAO,CAAC,KAAK;AACf;AAEA,SAAS,YAAe,MAA2B,OAAiC;CAClF,OAAO,CAAC,GAAG,QAAQ,IAAI,GAAG,GAAG,QAAQ,KAAK,CAAC;AAC7C;;;;;AAMA,SAAS,OAAO,GAAG,SAAiD;CAClE,OAAO,QAAQ,QACZ,aAAa,YAAY;EACxB,GAAG;EACH,GAAG;EACH,KAAK;GAAE,GAAG,YAAY;GAAK,GAAG,OAAO;EAAI;EACzC,SAAS,YAAY,YAAY,SAAS,OAAO,OAAO;EACxD,SAAS;GAAE,GAAG,YAAY;GAAS,GAAG,OAAO;EAAQ;EACrD,WAAW,YAAY,YAAY,WAAW,OAAO,SAAS;EAC9D,eAAe;GAAE,GAAG,YAAY;GAAe,GAAG,OAAO;EAAc;EACvE,SAAS,YAAY,YAAY,SAAS,OAAO,OAAO;EACxD,OAAO;GAAE,GAAG,YAAY;GAAO,GAAG,OAAO;EAAM;EAC/C,UAAU;GAAE,GAAG,YAAY;GAAU,GAAG,OAAO;EAAS;CAC1D,IACA;EACE,KAAK,CAAC;EAC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P,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.2",
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": "ab7987a57772b2e7fb3ef7eb4cadb3cedd9cc9ae"
58
58
  }
@@ -14,66 +14,73 @@ function concatArray<T>(left: T[] | T | undefined, right: T[] | T | undefined):
14
14
  return [...toArray(left), ...toArray(right)];
15
15
  }
16
16
 
17
- export namespace ESLintConfig {
18
- /**
19
- *
20
- * @param configs
21
- */
22
- export function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {
23
- return configs.reduce(
24
- (returnValue, config) => ({
25
- ...returnValue,
26
- ...config,
27
- env: { ...returnValue.env, ...config.env },
28
- extends: concatArray(returnValue.extends, config.extends),
29
- globals: { ...returnValue.globals, ...config.globals },
30
- overrides: concatArray(returnValue.overrides, config.overrides),
31
- parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },
32
- plugins: concatArray(returnValue.plugins, config.plugins),
33
- rules: { ...returnValue.rules, ...config.rules },
34
- settings: { ...returnValue.settings, ...config.settings },
35
- }),
36
- {
37
- env: {},
38
- extends: [],
39
- globals: {},
40
- overrides: [],
41
- parserOptions: {},
42
- plugins: [],
43
- rules: {},
44
- settings: {},
45
- },
46
- );
47
- }
17
+ /**
18
+ *
19
+ * @param configs
20
+ */
21
+ function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData {
22
+ return configs.reduce(
23
+ (returnValue, config) => ({
24
+ ...returnValue,
25
+ ...config,
26
+ env: { ...returnValue.env, ...config.env },
27
+ extends: concatArray(returnValue.extends, config.extends),
28
+ globals: { ...returnValue.globals, ...config.globals },
29
+ overrides: concatArray(returnValue.overrides, config.overrides),
30
+ parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },
31
+ plugins: concatArray(returnValue.plugins, config.plugins),
32
+ rules: { ...returnValue.rules, ...config.rules },
33
+ settings: { ...returnValue.settings, ...config.settings },
34
+ }),
35
+ {
36
+ env: {},
37
+ extends: [],
38
+ globals: {},
39
+ overrides: [],
40
+ parserOptions: {},
41
+ plugins: [],
42
+ rules: {},
43
+ settings: {},
44
+ },
45
+ );
46
+ }
48
47
 
49
- /**
50
- * Always return 'off'. `_status` is the previous rule value.
51
- *
52
- * @param _status
53
- */
54
- export function fixme(_status: string | number | [string | number, ...any[]] | undefined) {
55
- return 'off' as const;
56
- }
48
+ /**
49
+ * Always return 'off'. `_status` is the previous rule value.
50
+ *
51
+ * @param _status
52
+ */
53
+ function fixme(_status: string | number | [string | number, ...any[]] | undefined) {
54
+ return 'off' as const;
55
+ }
57
56
 
58
- /**
59
- * Renames rules in the given object according to the given map.
60
- *
61
- * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
62
- * `{ 'old-prefix/rule-name': 'error' }`, this function will return
63
- * `{ 'new-prefix/rule-name': 'error' }`.
64
- *
65
- * @param rules The object containing the rules to rename.
66
- * @param map The object containing the rename map.
67
- */
68
- export function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {
69
- return Object.fromEntries(
70
- Object.entries(rules).map(([key, value]) => {
71
- for (const [from, to] of Object.entries(map)) {
72
- if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
73
- else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];
74
- }
75
- return [key, value];
76
- }),
77
- );
78
- }
57
+ /**
58
+ * Renames rules in the given object according to the given map.
59
+ *
60
+ * Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
61
+ * `{ 'old-prefix/rule-name': 'error' }`, this function will return
62
+ * `{ 'new-prefix/rule-name': 'error' }`.
63
+ *
64
+ * @param rules The object containing the rules to rename.
65
+ * @param map The object containing the rename map.
66
+ */
67
+ function renameRules(rules: Record<string, any>, map: Record<string, string>): Record<string, any> {
68
+ return Object.fromEntries(
69
+ Object.entries(rules).map(([key, value]) => {
70
+ for (const [from, to] of Object.entries(map)) {
71
+ if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
72
+ else if (from === '' && !key.includes('/') && to !== '') return [to + key, value];
73
+ }
74
+ return [key, value];
75
+ }),
76
+ );
79
77
  }
78
+
79
+ /**
80
+ * @namespace
81
+ */
82
+ export const ESLintConfig = Object.freeze({
83
+ concat,
84
+ fixme,
85
+ renameRules,
86
+ });