@bemedev/dev-utils 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -170,6 +170,60 @@ exclude.withPattern(
170
170
 
171
171
  ---
172
172
 
173
+ ### `create(args?)`
174
+
175
+ Plain async function (not a plugin) that resolves glob patterns and returns
176
+ `{ files, coverage }` string arrays using the default patterns.
177
+
178
+ ```typescript
179
+ import { create } from '@bemedev/dev-utils/vitest-exclude';
180
+
181
+ const { files, coverage } = await create({
182
+ ignoreTestFiles: ['src/fixtures/**'],
183
+ ignoreCoverageFiles: ['src/**/*.types.ts'],
184
+ });
185
+ ```
186
+
187
+ **Parameters (`args`)**
188
+
189
+ | Property | Type | Description |
190
+ | --------------------- | ----------------------- | -------------------------------------------- |
191
+ | `ignoreTestFiles` | `string[] \| undefined` | Glob patterns to exclude from test discovery |
192
+ | `ignoreCoverageFiles` | `string[] \| undefined` | Glob patterns to exclude from coverage |
193
+
194
+ **Returns** `Promise<{ files: string[]; coverage: string[] }>`.
195
+
196
+ ---
197
+
198
+ ### `create.withPattern(patterns, args)`
199
+
200
+ Same as `create`, but accepts custom glob patterns for both test and
201
+ coverage discovery.
202
+
203
+ ```typescript
204
+ import { create } from '@bemedev/dev-utils/vitest-exclude';
205
+
206
+ const { files, coverage } = await create.withPattern(
207
+ {
208
+ patternTest: 'tests/**/*.test.ts',
209
+ patternCov: 'src/**/*.ts',
210
+ },
211
+ { ignoreTestFiles: ['tests/fixtures/**'] },
212
+ );
213
+ ```
214
+
215
+ **Parameters**
216
+
217
+ | Name | Type | Description |
218
+ | ------------- | -------------------- | ----------------------------------- |
219
+ | `patternTest` | `string \| string[]` | Glob(s) for test file discovery |
220
+ | `patternCov` | `string \| string[]` | Glob(s) for coverage file discovery |
221
+ | `args` | same as `create` | Optional ignore lists |
222
+
223
+ **Returns** `Promise<{ files: string[]; coverage: string[] }>`.
224
+
225
+ ---
226
+
173
227
  ## `vitestExtended`
174
228
 
175
229
  Extended helpers for writing structured, type-safe Vitest tests.
@@ -1,3 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_vitest_exclude_vitest = require("./vitest.cjs");
3
+ exports.create = require_vitest_exclude_vitest.create;
3
4
  exports.exclude = require_vitest_exclude_vitest.exclude;
@@ -1,2 +1,2 @@
1
- import { exclude } from "./vitest.js";
2
- export { exclude };
1
+ import { create, exclude } from "./vitest.js";
2
+ export { create, exclude };
@@ -3,6 +3,25 @@ const require_vitest_exclude_vitest_utils = require("./vitest.utils.cjs");
3
3
  const require_vitest_exclude_constants = require("./constants.cjs");
4
4
  //#region src/vitest-exclude/vitest.ts
5
5
  /**
6
+ * Create includeTest and includeCoverage arrays from glob patterns
7
+ *
8
+ * @param args Globs to ignore for test and coverage files
9
+ * @returns an object with includeTest and includeCoverage string arrays
10
+ */
11
+ async function create(args = {}) {
12
+ const firsts = {
13
+ patternTest: require_vitest_exclude_vitest_utils.testPattern(),
14
+ patternCov: require_vitest_exclude_vitest_utils.defaultCovPattern()
15
+ };
16
+ return create.withPattern(firsts, args);
17
+ }
18
+ create.withPattern = async ({ patternTest = require_vitest_exclude_vitest_utils.testPattern(), patternCov = require_vitest_exclude_vitest_utils.defaultCovPattern() } = {}, { ignoreTestFiles, ignoreCoverageFiles } = {}) => {
19
+ return {
20
+ files: await require_vitest_exclude_vitest_utils.buildInclude(patternTest, ignoreTestFiles),
21
+ coverage: await require_vitest_exclude_vitest_utils.buildInclude(patternCov, ignoreCoverageFiles)
22
+ };
23
+ };
24
+ /**
6
25
  * Plugin to add files with glob patterns to vitest
7
26
  *
8
27
  * @param ignore globs to exclude inside
@@ -35,16 +54,21 @@ exclude.withPattern = (({ patternTest, patternCov }, { ignoreCoverageFiles, igno
35
54
  config: async (options) => {
36
55
  const testConfig = options?.test;
37
56
  const coverage = options?.test?.coverage;
38
- const includeCov = await require_vitest_exclude_vitest_utils.buildInclude(patternCov, ignoreCoverageFiles);
39
- const includeTest = await require_vitest_exclude_vitest_utils.buildInclude(patternTest, ignoreTestFiles);
57
+ const all = await create.withPattern({
58
+ patternTest,
59
+ patternCov
60
+ }, {
61
+ ignoreCoverageFiles,
62
+ ignoreTestFiles
63
+ });
40
64
  return {
41
65
  ...options,
42
66
  test: {
43
67
  ...testConfig,
44
- include: includeTest,
68
+ include: all.files,
45
69
  coverage: {
46
70
  ...coverage,
47
- include: includeCov
71
+ include: all.coverage
48
72
  }
49
73
  }
50
74
  };
@@ -52,6 +76,7 @@ exclude.withPattern = (({ patternTest, patternCov }, { ignoreCoverageFiles, igno
52
76
  };
53
77
  });
54
78
  //#endregion
79
+ exports.create = create;
55
80
  exports.exclude = exclude;
56
81
 
57
82
  //# sourceMappingURL=vitest.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest.cjs","names":["defaultCovPattern","testPattern","buildInclude"],"sources":["../../src/vitest-exclude/vitest.ts"],"sourcesContent":["import { name } from './constants';\nimport type { Args, Plugin, WithPattern } from './types';\nimport {\n buildInclude,\n defaultCovPattern,\n testPattern,\n} from './vitest.utils';\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param ignore globs to exclude inside\n * @returns a vitest config\n *\n * @see {@link exclude.withPattern}\n * @remarks\n * You don't have to use test.exclude.\n * The default search patter is './src/**\\/*.ts'\n */\nexport function exclude(args: Args[1] = {}) {\n const patternCov = defaultCovPattern();\n const patternTest = testPattern();\n return exclude.withPattern({ patternCov, patternTest }, args);\n}\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param pattern The pattern where searching files\n * @param ignore globs to exclude inside\n * @returns a vitest config\n */\nexclude.withPattern = ((\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n): Plugin => {\n return {\n name,\n enforce: 'pre',\n config: async options => {\n const testConfig = options?.test;\n const coverage = options?.test?.coverage;\n\n const includeCov = await buildInclude(\n patternCov,\n ignoreCoverageFiles,\n );\n const includeTest = await buildInclude(patternTest, ignoreTestFiles);\n\n return {\n ...options,\n test: {\n ...testConfig,\n include: includeTest,\n coverage: {\n ...coverage,\n include: includeCov,\n },\n },\n };\n },\n };\n}) as WithPattern;\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,QAAQ,OAAgB,EAAE,EAAE;CAC1C,MAAM,aAAaA,oCAAAA,mBAAmB;CACtC,MAAM,cAAcC,oCAAAA,aAAa;AACjC,QAAO,QAAQ,YAAY;EAAE;EAAY;EAAa,EAAE,KAAK;;;;;;;;;AAU/D,QAAQ,gBACN,EAAE,aAAa,cACf,EAAE,qBAAqB,sBACZ;AACX,QAAO;EACL,MAAA,iCAAA;EACA,SAAS;EACT,QAAQ,OAAM,YAAW;GACvB,MAAM,aAAa,SAAS;GAC5B,MAAM,WAAW,SAAS,MAAM;GAEhC,MAAM,aAAa,MAAMC,oCAAAA,aACvB,YACA,oBACD;GACD,MAAM,cAAc,MAAMA,oCAAAA,aAAa,aAAa,gBAAgB;AAEpE,UAAO;IACL,GAAG;IACH,MAAM;KACJ,GAAG;KACH,SAAS;KACT,UAAU;MACR,GAAG;MACH,SAAS;MACV;KACF;IACF;;EAEJ"}
1
+ {"version":3,"file":"vitest.cjs","names":["testPattern","defaultCovPattern","buildInclude"],"sources":["../../src/vitest-exclude/vitest.ts"],"sourcesContent":["import { name } from './constants';\nimport type { Args, Plugin, WithPattern } from './types';\nimport {\n buildInclude,\n defaultCovPattern,\n testPattern,\n} from './vitest.utils';\n\n/**\n * Create includeTest and includeCoverage arrays from glob patterns\n *\n * @param args Globs to ignore for test and coverage files\n * @returns an object with includeTest and includeCoverage string arrays\n */\nexport async function create(args: Args[1] = {}) {\n const firsts = {\n patternTest: testPattern(),\n patternCov: defaultCovPattern(),\n };\n\n return create.withPattern(firsts, args);\n}\n\ncreate.withPattern = async (\n {\n patternTest = testPattern(),\n patternCov = defaultCovPattern(),\n }: Partial<Args[0]> = {},\n { ignoreTestFiles, ignoreCoverageFiles }: Args[1] = {},\n) => {\n const files = await buildInclude(patternTest, ignoreTestFiles);\n const coverage = await buildInclude(patternCov, ignoreCoverageFiles);\n return { files, coverage };\n};\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param ignore globs to exclude inside\n * @returns a vitest config\n *\n * @see {@link exclude.withPattern}\n * @remarks\n * You don't have to use test.exclude.\n * The default search patter is './src/**\\/*.ts'\n */\nexport function exclude(args: Args[1] = {}) {\n const patternCov = defaultCovPattern();\n const patternTest = testPattern();\n return exclude.withPattern({ patternCov, patternTest }, args);\n}\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param pattern The pattern where searching files\n * @param ignore globs to exclude inside\n * @returns a vitest config\n */\nexclude.withPattern = ((\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n): Plugin => {\n return {\n name,\n enforce: 'pre',\n config: async options => {\n const testConfig = options?.test;\n const coverage = options?.test?.coverage;\n\n const all = await create.withPattern(\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n );\n\n return {\n ...options,\n test: {\n ...testConfig,\n include: all.files,\n coverage: {\n ...coverage,\n include: all.coverage,\n },\n },\n };\n },\n };\n}) as WithPattern;\n"],"mappings":";;;;;;;;;;AAcA,eAAsB,OAAO,OAAgB,EAAE,EAAE;CAC/C,MAAM,SAAS;EACb,aAAaA,oCAAAA,aAAa;EAC1B,YAAYC,oCAAAA,mBAAmB;EAChC;AAED,QAAO,OAAO,YAAY,QAAQ,KAAK;;AAGzC,OAAO,cAAc,OACnB,EACE,cAAcD,oCAAAA,aAAa,EAC3B,aAAaC,oCAAAA,mBAAmB,KACZ,EAAE,EACxB,EAAE,iBAAiB,wBAAiC,EAAE,KACnD;AAGH,QAAO;EAAE,OAFK,MAAMC,oCAAAA,aAAa,aAAa,gBAAgB;EAE9C,UADC,MAAMA,oCAAAA,aAAa,YAAY,oBAAoB;EAC1C;;;;;;;;;;;;;AAc5B,SAAgB,QAAQ,OAAgB,EAAE,EAAE;CAC1C,MAAM,aAAaD,oCAAAA,mBAAmB;CACtC,MAAM,cAAcD,oCAAAA,aAAa;AACjC,QAAO,QAAQ,YAAY;EAAE;EAAY;EAAa,EAAE,KAAK;;;;;;;;;AAU/D,QAAQ,gBACN,EAAE,aAAa,cACf,EAAE,qBAAqB,sBACZ;AACX,QAAO;EACL,MAAA,iCAAA;EACA,SAAS;EACT,QAAQ,OAAM,YAAW;GACvB,MAAM,aAAa,SAAS;GAC5B,MAAM,WAAW,SAAS,MAAM;GAEhC,MAAM,MAAM,MAAM,OAAO,YACvB;IAAE;IAAa;IAAY,EAC3B;IAAE;IAAqB;IAAiB,CACzC;AAED,UAAO;IACL,GAAG;IACH,MAAM;KACJ,GAAG;KACH,SAAS,IAAI;KACb,UAAU;MACR,GAAG;MACH,SAAS,IAAI;MACd;KACF;IACF;;EAEJ"}
@@ -1,4 +1,20 @@
1
1
  import type { Args, WithPattern } from './types';
2
+ /**
3
+ * Create includeTest and includeCoverage arrays from glob patterns
4
+ *
5
+ * @param args Globs to ignore for test and coverage files
6
+ * @returns an object with includeTest and includeCoverage string arrays
7
+ */
8
+ export declare function create(args?: Args[1]): Promise<{
9
+ files: string[];
10
+ coverage: string[];
11
+ }>;
12
+ export declare namespace create {
13
+ var withPattern: ({ patternTest, patternCov, }?: Partial<Args[0]>, { ignoreTestFiles, ignoreCoverageFiles }?: Args[1]) => Promise<{
14
+ files: string[];
15
+ coverage: string[];
16
+ }>;
17
+ }
2
18
  /**
3
19
  * Plugin to add files with glob patterns to vitest
4
20
  *
@@ -2,6 +2,25 @@ import { buildInclude, defaultCovPattern, testPattern } from "./vitest.utils.js"
2
2
  import { name } from "./constants.js";
3
3
  //#region src/vitest-exclude/vitest.ts
4
4
  /**
5
+ * Create includeTest and includeCoverage arrays from glob patterns
6
+ *
7
+ * @param args Globs to ignore for test and coverage files
8
+ * @returns an object with includeTest and includeCoverage string arrays
9
+ */
10
+ async function create(args = {}) {
11
+ const firsts = {
12
+ patternTest: testPattern(),
13
+ patternCov: defaultCovPattern()
14
+ };
15
+ return create.withPattern(firsts, args);
16
+ }
17
+ create.withPattern = async ({ patternTest = testPattern(), patternCov = defaultCovPattern() } = {}, { ignoreTestFiles, ignoreCoverageFiles } = {}) => {
18
+ return {
19
+ files: await buildInclude(patternTest, ignoreTestFiles),
20
+ coverage: await buildInclude(patternCov, ignoreCoverageFiles)
21
+ };
22
+ };
23
+ /**
5
24
  * Plugin to add files with glob patterns to vitest
6
25
  *
7
26
  * @param ignore globs to exclude inside
@@ -34,16 +53,21 @@ exclude.withPattern = (({ patternTest, patternCov }, { ignoreCoverageFiles, igno
34
53
  config: async (options) => {
35
54
  const testConfig = options?.test;
36
55
  const coverage = options?.test?.coverage;
37
- const includeCov = await buildInclude(patternCov, ignoreCoverageFiles);
38
- const includeTest = await buildInclude(patternTest, ignoreTestFiles);
56
+ const all = await create.withPattern({
57
+ patternTest,
58
+ patternCov
59
+ }, {
60
+ ignoreCoverageFiles,
61
+ ignoreTestFiles
62
+ });
39
63
  return {
40
64
  ...options,
41
65
  test: {
42
66
  ...testConfig,
43
- include: includeTest,
67
+ include: all.files,
44
68
  coverage: {
45
69
  ...coverage,
46
- include: includeCov
70
+ include: all.coverage
47
71
  }
48
72
  }
49
73
  };
@@ -51,6 +75,6 @@ exclude.withPattern = (({ patternTest, patternCov }, { ignoreCoverageFiles, igno
51
75
  };
52
76
  });
53
77
  //#endregion
54
- export { exclude };
78
+ export { create, exclude };
55
79
 
56
80
  //# sourceMappingURL=vitest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitest.js","names":[],"sources":["../../src/vitest-exclude/vitest.ts"],"sourcesContent":["import { name } from './constants';\nimport type { Args, Plugin, WithPattern } from './types';\nimport {\n buildInclude,\n defaultCovPattern,\n testPattern,\n} from './vitest.utils';\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param ignore globs to exclude inside\n * @returns a vitest config\n *\n * @see {@link exclude.withPattern}\n * @remarks\n * You don't have to use test.exclude.\n * The default search patter is './src/**\\/*.ts'\n */\nexport function exclude(args: Args[1] = {}) {\n const patternCov = defaultCovPattern();\n const patternTest = testPattern();\n return exclude.withPattern({ patternCov, patternTest }, args);\n}\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param pattern The pattern where searching files\n * @param ignore globs to exclude inside\n * @returns a vitest config\n */\nexclude.withPattern = ((\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n): Plugin => {\n return {\n name,\n enforce: 'pre',\n config: async options => {\n const testConfig = options?.test;\n const coverage = options?.test?.coverage;\n\n const includeCov = await buildInclude(\n patternCov,\n ignoreCoverageFiles,\n );\n const includeTest = await buildInclude(patternTest, ignoreTestFiles);\n\n return {\n ...options,\n test: {\n ...testConfig,\n include: includeTest,\n coverage: {\n ...coverage,\n include: includeCov,\n },\n },\n };\n },\n };\n}) as WithPattern;\n"],"mappings":";;;;;;;;;;;;;;AAmBA,SAAgB,QAAQ,OAAgB,EAAE,EAAE;CAC1C,MAAM,aAAa,mBAAmB;CACtC,MAAM,cAAc,aAAa;AACjC,QAAO,QAAQ,YAAY;EAAE;EAAY;EAAa,EAAE,KAAK;;;;;;;;;AAU/D,QAAQ,gBACN,EAAE,aAAa,cACf,EAAE,qBAAqB,sBACZ;AACX,QAAO;EACL;EACA,SAAS;EACT,QAAQ,OAAM,YAAW;GACvB,MAAM,aAAa,SAAS;GAC5B,MAAM,WAAW,SAAS,MAAM;GAEhC,MAAM,aAAa,MAAM,aACvB,YACA,oBACD;GACD,MAAM,cAAc,MAAM,aAAa,aAAa,gBAAgB;AAEpE,UAAO;IACL,GAAG;IACH,MAAM;KACJ,GAAG;KACH,SAAS;KACT,UAAU;MACR,GAAG;MACH,SAAS;MACV;KACF;IACF;;EAEJ"}
1
+ {"version":3,"file":"vitest.js","names":[],"sources":["../../src/vitest-exclude/vitest.ts"],"sourcesContent":["import { name } from './constants';\nimport type { Args, Plugin, WithPattern } from './types';\nimport {\n buildInclude,\n defaultCovPattern,\n testPattern,\n} from './vitest.utils';\n\n/**\n * Create includeTest and includeCoverage arrays from glob patterns\n *\n * @param args Globs to ignore for test and coverage files\n * @returns an object with includeTest and includeCoverage string arrays\n */\nexport async function create(args: Args[1] = {}) {\n const firsts = {\n patternTest: testPattern(),\n patternCov: defaultCovPattern(),\n };\n\n return create.withPattern(firsts, args);\n}\n\ncreate.withPattern = async (\n {\n patternTest = testPattern(),\n patternCov = defaultCovPattern(),\n }: Partial<Args[0]> = {},\n { ignoreTestFiles, ignoreCoverageFiles }: Args[1] = {},\n) => {\n const files = await buildInclude(patternTest, ignoreTestFiles);\n const coverage = await buildInclude(patternCov, ignoreCoverageFiles);\n return { files, coverage };\n};\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param ignore globs to exclude inside\n * @returns a vitest config\n *\n * @see {@link exclude.withPattern}\n * @remarks\n * You don't have to use test.exclude.\n * The default search patter is './src/**\\/*.ts'\n */\nexport function exclude(args: Args[1] = {}) {\n const patternCov = defaultCovPattern();\n const patternTest = testPattern();\n return exclude.withPattern({ patternCov, patternTest }, args);\n}\n\n/**\n * Plugin to add files with glob patterns to vitest\n *\n * @param pattern The pattern where searching files\n * @param ignore globs to exclude inside\n * @returns a vitest config\n */\nexclude.withPattern = ((\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n): Plugin => {\n return {\n name,\n enforce: 'pre',\n config: async options => {\n const testConfig = options?.test;\n const coverage = options?.test?.coverage;\n\n const all = await create.withPattern(\n { patternTest, patternCov },\n { ignoreCoverageFiles, ignoreTestFiles },\n );\n\n return {\n ...options,\n test: {\n ...testConfig,\n include: all.files,\n coverage: {\n ...coverage,\n include: all.coverage,\n },\n },\n };\n },\n };\n}) as WithPattern;\n"],"mappings":";;;;;;;;;AAcA,eAAsB,OAAO,OAAgB,EAAE,EAAE;CAC/C,MAAM,SAAS;EACb,aAAa,aAAa;EAC1B,YAAY,mBAAmB;EAChC;AAED,QAAO,OAAO,YAAY,QAAQ,KAAK;;AAGzC,OAAO,cAAc,OACnB,EACE,cAAc,aAAa,EAC3B,aAAa,mBAAmB,KACZ,EAAE,EACxB,EAAE,iBAAiB,wBAAiC,EAAE,KACnD;AAGH,QAAO;EAAE,OAFK,MAAM,aAAa,aAAa,gBAAgB;EAE9C,UADC,MAAM,aAAa,YAAY,oBAAoB;EAC1C;;;;;;;;;;;;;AAc5B,SAAgB,QAAQ,OAAgB,EAAE,EAAE;CAC1C,MAAM,aAAa,mBAAmB;CACtC,MAAM,cAAc,aAAa;AACjC,QAAO,QAAQ,YAAY;EAAE;EAAY;EAAa,EAAE,KAAK;;;;;;;;;AAU/D,QAAQ,gBACN,EAAE,aAAa,cACf,EAAE,qBAAqB,sBACZ;AACX,QAAO;EACL;EACA,SAAS;EACT,QAAQ,OAAM,YAAW;GACvB,MAAM,aAAa,SAAS;GAC5B,MAAM,WAAW,SAAS,MAAM;GAEhC,MAAM,MAAM,MAAM,OAAO,YACvB;IAAE;IAAa;IAAY,EAC3B;IAAE;IAAqB;IAAiB,CACzC;AAED,UAAO;IACL,GAAG;IACH,MAAM;KACJ,GAAG;KACH,SAAS,IAAI;KACb,UAAU;MACR,GAAG;MACH,SAAS,IAAI;MACd;KACF;IACF;;EAEJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemedev/dev-utils",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A collection of utilities for Node.js development, including build tools, testing utilities, and configuration management.",
5
5
  "author": {
6
6
  "email": "bri_lvi@icloud.com",