@bemedev/dev-utils 0.7.0 → 0.8.1

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.
Files changed (113) hide show
  1. package/lib/build-tests/addTarball.cjs.map +1 -1
  2. package/lib/build-tests/addTarball.js.map +1 -1
  3. package/lib/build-tests/buildPackageJson.cjs.map +1 -1
  4. package/lib/build-tests/buildPackageJson.js.map +1 -1
  5. package/lib/build-tests/cleanup.cjs.map +1 -1
  6. package/lib/build-tests/cleanup.js.map +1 -1
  7. package/lib/build-tests/cli/index.js +0 -0
  8. package/lib/build-tests/cli/test.cjs.map +1 -1
  9. package/lib/build-tests/cli/test.js.map +1 -1
  10. package/lib/build-tests/getRelativePath.cjs.map +1 -1
  11. package/lib/build-tests/getRelativePath.js.map +1 -1
  12. package/lib/build-tests/getTypescriptOutdir.cjs +10 -2
  13. package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -1
  14. package/lib/build-tests/getTypescriptOutdir.js +9 -2
  15. package/lib/build-tests/getTypescriptOutdir.js.map +1 -1
  16. package/lib/build-tests/import.cjs.map +1 -1
  17. package/lib/build-tests/import.js.map +1 -1
  18. package/lib/build-tests/imports/create.cjs.map +1 -1
  19. package/lib/build-tests/imports/create.js.map +1 -1
  20. package/lib/build-tests/imports/helper.cjs.map +1 -1
  21. package/lib/build-tests/imports/helper.js.map +1 -1
  22. package/lib/build-tests/pack.cjs.map +1 -1
  23. package/lib/build-tests/pack.js.map +1 -1
  24. package/lib/rolldown-config/config.cjs +3 -3
  25. package/lib/rolldown-config/config.cjs.map +1 -1
  26. package/lib/rolldown-config/config.js +3 -3
  27. package/lib/rolldown-config/config.js.map +1 -1
  28. package/lib/rolldown-config/helpers.cjs.map +1 -1
  29. package/lib/rolldown-config/helpers.js.map +1 -1
  30. package/lib/rolldown-config/index.d.ts +1 -0
  31. package/lib/rolldown-config/input.cjs.map +1 -1
  32. package/lib/rolldown-config/input.js.map +1 -1
  33. package/lib/rolldown-config/output.cjs +2 -1
  34. package/lib/rolldown-config/output.cjs.map +1 -1
  35. package/lib/rolldown-config/output.d.ts +1 -1
  36. package/lib/rolldown-config/output.js +2 -1
  37. package/lib/rolldown-config/output.js.map +1 -1
  38. package/lib/rolldown-config/plugins/alias.cjs.map +1 -1
  39. package/lib/rolldown-config/plugins/alias.js.map +1 -1
  40. package/lib/rolldown-config/plugins/circulars.cjs.map +1 -1
  41. package/lib/rolldown-config/plugins/circulars.js.map +1 -1
  42. package/lib/rolldown-config/plugins/clean.cjs +10 -4
  43. package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
  44. package/lib/rolldown-config/plugins/clean.d.ts +1 -1
  45. package/lib/rolldown-config/plugins/clean.js +8 -3
  46. package/lib/rolldown-config/plugins/clean.js.map +1 -1
  47. package/lib/rolldown-config/plugins/externals.cjs.map +1 -1
  48. package/lib/rolldown-config/plugins/externals.js.map +1 -1
  49. package/lib/rolldown-config/plugins/index.d.ts +2 -2
  50. package/lib/rolldown-config/plugins/tsPaths.cjs.map +1 -1
  51. package/lib/rolldown-config/plugins/tsPaths.js.map +1 -1
  52. package/lib/rolldown-config/plugins/typescript.cjs +4 -2
  53. package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
  54. package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
  55. package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
  56. package/lib/rolldown-config/plugins/typescript.d.ts +1 -1
  57. package/lib/rolldown-config/plugins/typescript.js +4 -2
  58. package/lib/rolldown-config/plugins/typescript.js.map +1 -1
  59. package/lib/rolldown-config/utils.cjs.map +1 -1
  60. package/lib/rolldown-config/utils.js.map +1 -1
  61. package/lib/utils/sleep.cjs.map +1 -1
  62. package/lib/utils/sleep.js.map +1 -1
  63. package/lib/vitest-exclude/vitest.cjs +39 -14
  64. package/lib/vitest-exclude/vitest.cjs.map +1 -1
  65. package/lib/vitest-exclude/vitest.d.ts +4 -3
  66. package/lib/vitest-exclude/vitest.js +39 -14
  67. package/lib/vitest-exclude/vitest.js.map +1 -1
  68. package/lib/vitest-exclude/vitest.utils.cjs +8 -8
  69. package/lib/vitest-exclude/vitest.utils.cjs.map +1 -1
  70. package/lib/vitest-exclude/vitest.utils.d.ts +4 -4
  71. package/lib/vitest-exclude/vitest.utils.js +8 -8
  72. package/lib/vitest-exclude/vitest.utils.js.map +1 -1
  73. package/lib/vitest-extended/acceptation.cjs.map +1 -1
  74. package/lib/vitest-extended/acceptation.js.map +1 -1
  75. package/lib/vitest-extended/createTests.cjs.map +1 -1
  76. package/lib/vitest-extended/createTests.js.map +1 -1
  77. package/lib/vitest-extended/done.cjs.map +1 -1
  78. package/lib/vitest-extended/done.js.map +1 -1
  79. package/lib/vitest-extended/each/error.cjs.map +1 -1
  80. package/lib/vitest-extended/each/error.js.map +1 -1
  81. package/lib/vitest-extended/each/pass.cjs.map +1 -1
  82. package/lib/vitest-extended/each/pass.js.map +1 -1
  83. package/lib/vitest-extended/fakeWaiter.cjs.map +1 -1
  84. package/lib/vitest-extended/fakeWaiter.js.map +1 -1
  85. package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -1
  86. package/lib/vitest-extended/fixtures/partialCall.js.map +1 -1
  87. package/lib/vitest-extended/fixtures/toUpper.cjs.map +1 -1
  88. package/lib/vitest-extended/fixtures/toUpper.js.map +1 -1
  89. package/lib/vitest-extended/fixtures/zod.cjs.map +1 -1
  90. package/lib/vitest-extended/fixtures/zod.js.map +1 -1
  91. package/lib/vitest-extended/identity.cjs.map +1 -1
  92. package/lib/vitest-extended/identity.js.map +1 -1
  93. package/lib/vitest-extended/index.d.ts +1 -0
  94. package/lib/vitest-extended/isDefined.cjs.map +1 -1
  95. package/lib/vitest-extended/isDefined.d.ts +1 -0
  96. package/lib/vitest-extended/isDefined.js.map +1 -1
  97. package/lib/vitest-extended/isFunction.cjs.map +1 -1
  98. package/lib/vitest-extended/isFunction.js.map +1 -1
  99. package/lib/vitest-extended/toArray.cjs.map +1 -1
  100. package/lib/vitest-extended/toArray.js.map +1 -1
  101. package/lib/vitest-extended/toStringFlat.cjs.map +1 -1
  102. package/lib/vitest-extended/toStringFlat.js.map +1 -1
  103. package/lib/vitest-extended/types.d.ts +1 -1
  104. package/package.json +23 -67
  105. package/README.md +0 -696
  106. package/lib/vitest-alias/index.cjs +0 -4
  107. package/lib/vitest-alias/index.d.ts +0 -1
  108. package/lib/vitest-alias/index.js +0 -2
  109. package/lib/vitest-alias/vitest.cjs +0 -77
  110. package/lib/vitest-alias/vitest.cjs.map +0 -1
  111. package/lib/vitest-alias/vitest.d.ts +0 -38
  112. package/lib/vitest-alias/vitest.js +0 -74
  113. package/lib/vitest-alias/vitest.js.map +0 -1
package/README.md DELETED
@@ -1,696 +0,0 @@
1
- # @bemedev/dev-utils
2
-
3
- A collection of utilities for Node.js development, including build tools,
4
- testing utilities, and configuration management.
5
-
6
- ## Modules
7
-
8
- | Module | Description |
9
- | ----------------------------------- | --------------------------------------------- |
10
- | [`vitestAlias`](#vitestalias) | Vitest plugin to inject tsconfig path aliases |
11
- | [`vitestExclude`](#vitestexclude) | Vitest plugin for glob-based include/exclude |
12
- | [`vitestExtended`](#vitestextended) | Extended test helpers for Vitest |
13
- | [`rolldownConfig`](#rolldownconfig) | Rolldown bundler configuration factory |
14
- | [`buildTests`](#buildtests) | CLI tooling to build and test packages |
15
-
16
- <br/>
17
-
18
- ## Installation
19
-
20
- ```bash
21
- pnpm add @bemedev/dev-utils
22
- # or
23
- npm install @bemedev/dev-utils
24
- # or
25
- yarn add @bemedev/dev-utils
26
- ```
27
-
28
- **Peer dependencies:** `typescript ^5 || ^6`
29
-
30
- <br/>
31
-
32
- ## Usage
33
-
34
- Each module is available as a dedicated sub-path export — there is no root
35
- barrel export:
36
-
37
- ```typescript
38
- import { createAlias, aliasTs } from '@bemedev/dev-utils/vitest-alias';
39
- import { exclude } from '@bemedev/dev-utils/vitest-exclude';
40
- import {
41
- createTests,
42
- createFakeWaiter,
43
- } from '@bemedev/dev-utils/vitest-extended';
44
- import { defineConfig } from '@bemedev/dev-utils/rolldown';
45
- import { addTarball, cleanup } from '@bemedev/dev-utils/build-tests';
46
- ```
47
-
48
- ---
49
-
50
- ## `vitestAlias`
51
-
52
- Vitest plugin that reads your `tsconfig.json` path mappings and injects
53
- them as Vitest/Vite aliases — no manual duplication needed.
54
-
55
- ### `createAlias(tsconfig?)`
56
-
57
- Converts `compilerOptions.paths` (and optional `baseUrl`) from a tsconfig
58
- object into a Vite-compatible alias map.
59
-
60
- ```typescript
61
- import tsconfig from './tsconfig.json';
62
- import { createAlias } from '@bemedev/dev-utils/vitest-alias';
63
-
64
- // vitest.config.ts
65
- export default defineConfig({
66
- test: {
67
- alias: createAlias(tsconfig),
68
- },
69
- });
70
- ```
71
-
72
- **Parameters**
73
-
74
- | Name | Type | Description |
75
- | ---------- | --------------------- | --------------------------- |
76
- | `tsconfig` | `TsConf \| undefined` | Parsed tsconfig JSON object |
77
-
78
- **Returns** `Record<string, string>` — alias map ready for `test.alias`.
79
-
80
- ---
81
-
82
- ### `aliasTs(tsconfig?)`
83
-
84
- A Vitest/Vite plugin that automatically calls `createAlias` and merges the
85
- result into `test.alias`.
86
-
87
- > **Note:** Make sure `"resolveJsonModule": true` is set in your
88
- > `compilerOptions`, or pass the parsed JSON directly.
89
-
90
- ```typescript
91
- import tsconfig from './tsconfig.json';
92
- import { aliasTs } from '@bemedev/dev-utils/vitest-alias';
93
-
94
- // vitest.config.ts
95
- export default defineConfig({
96
- plugins: [aliasTs(tsconfig)],
97
- });
98
- ```
99
-
100
- **Parameters**
101
-
102
- | Name | Type | Description |
103
- | ---------- | --------------------- | --------------------------- |
104
- | `tsconfig` | `TsConf \| undefined` | Parsed tsconfig JSON object |
105
-
106
- **Returns** a Vitest `Plugin`.
107
-
108
- ---
109
-
110
- ## `vitestExclude`
111
-
112
- Vitest plugin that uses glob patterns to dynamically build `test.include`
113
- and `coverage.include` lists — no need to maintain `test.exclude` manually.
114
-
115
- ### `exclude(args?)`
116
-
117
- Uses default patterns (`src/**/*.ts` for coverage,
118
- `src/**/*.{test,spec}.{ts,js,tsx,jsx}` for tests) and applies optional
119
- ignore lists.
120
-
121
- ```typescript
122
- import { exclude } from '@bemedev/dev-utils/vitest-exclude';
123
-
124
- // vitest.config.ts
125
- export default defineConfig({
126
- plugins: [
127
- exclude({
128
- ignoreTestFiles: ['src/fixtures/**'],
129
- ignoreCoverageFiles: ['src/**/*.types.ts'],
130
- }),
131
- ],
132
- });
133
- ```
134
-
135
- **Parameters (`args`)**
136
-
137
- | Property | Type | Description |
138
- | --------------------- | ----------------------- | -------------------------------------------- |
139
- | `ignoreTestFiles` | `string[] \| undefined` | Glob patterns to exclude from test discovery |
140
- | `ignoreCoverageFiles` | `string[] \| undefined` | Glob patterns to exclude from coverage |
141
-
142
- **Returns** a Vitest `Plugin`.
143
-
144
- ---
145
-
146
- ### `exclude.withPattern(patterns, args)`
147
-
148
- Same as `exclude`, but lets you provide custom glob patterns instead of the
149
- defaults.
150
-
151
- ```typescript
152
- exclude.withPattern(
153
- {
154
- patternTest: 'tests/**/*.test.ts',
155
- patternCov: 'src/**/*.ts',
156
- },
157
- { ignoreTestFiles: ['tests/fixtures/**'] },
158
- );
159
- ```
160
-
161
- **Parameters**
162
-
163
- | Name | Type | Description |
164
- | ------------- | -------------------- | ----------------------------------- |
165
- | `patternTest` | `string \| string[]` | Glob(s) for test file discovery |
166
- | `patternCov` | `string \| string[]` | Glob(s) for coverage file discovery |
167
- | `args` | same as `exclude` | Optional ignore lists |
168
-
169
- **Returns** a Vitest `Plugin`.
170
-
171
- ---
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
-
227
- ## `vitestExtended`
228
-
229
- Extended helpers for writing structured, type-safe Vitest tests.
230
-
231
- ### `createTests(func, args?)`
232
-
233
- Creates a reusable test suite for a function with `acceptation`, `success`,
234
- and `fails` runners.
235
-
236
- ```typescript
237
- import { createTests } from '@bemedev/dev-utils/vitest-extended';
238
-
239
- // add.ts
240
- export const add = (a: number, b: number) => a + b;
241
-
242
- // add.test.ts
243
- const { acceptation, success, fails } = createTests(add);
244
-
245
- describe('add', () => {
246
- describe('acceptation', acceptation());
247
-
248
- describe(
249
- 'success',
250
- success(
251
- { invite: '1 + 2 = 3', parameters: [1, 2], expected: 3 },
252
- { invite: '0 + 0 = 0', parameters: [0, 0], expected: 0 },
253
- ),
254
- );
255
- });
256
- ```
257
-
258
- > **Note:** When the first parameter is an array, wrap it in another array:
259
- > `parameters: [[1, 2, 3]]`.
260
-
261
- **Parameters**
262
-
263
- | Name | Type | Description |
264
- | ---------------- | --------------------------- | --------------------------------------------------------------- |
265
- | `func` | `Fn` | The function under test |
266
- | `args.transform` | `NextFn<F> \| undefined` | Optional transformer applied to the return value |
267
- | `args.toError` | `ToError_F<F> \| undefined` | Optional function that derives an expected error from the input |
268
-
269
- **Returns** `{ acceptation, success, fails }`:
270
-
271
- | Method | Signature | Description |
272
- | ------------------- | ------------ | ------------------------------------------------------ |
273
- | `acceptation()` | `() => void` | Runs two checks: function is defined and is a function |
274
- | `success(...cases)` | `() => void` | Runs `test.concurrent.each` for passing cases |
275
- | `fails(...cases)` | `() => void` | Runs `test.concurrent.each` and expects thrown errors |
276
-
277
- ---
278
-
279
- ### `createTests.withImplementation(f, opts)`
280
-
281
- Same as `createTests` but replaces the implementation with a `vi.fn()` mock
282
- before the test suite runs.
283
-
284
- ```typescript
285
- const { acceptation, success } = createTests.withImplementation(myFn, {
286
- name: 'myFn',
287
- instanciation: async () => realImpl,
288
- });
289
- ```
290
-
291
- **`opts` properties**
292
-
293
- | Property | Type | Description |
294
- | --------------- | --------------------------- | -------------------------------------------------------- |
295
- | `instanciation` | `() => Promise<F> \| F` | Factory called in `beforeAll` to set mock implementation |
296
- | `name` | `string` | Display name used in acceptation tests |
297
- | `transform` | `NextFn<F> \| undefined` | Optional return-value transformer |
298
- | `toError` | `ToError_F<F> \| undefined` | Optional error deriver |
299
-
300
- ---
301
-
302
- ### `doneTest(invite, fn, options?)`
303
-
304
- Wraps a callback-style (done-based) test into a Vitest `test`. The test
305
- passes only when `done()` is called within the timeout. Supports both sync
306
- and async test functions.
307
-
308
- ```typescript
309
- import { doneTest } from '@bemedev/dev-utils/vitest-extended';
310
-
311
- // Async example with await
312
- doneTest('async callback', async done => {
313
- await service.start();
314
- await service.send('event');
315
- });
316
-
317
- // Sync example
318
- doneTest('fires callback', done => {
319
- emitter.once('event', done);
320
- emitter.emit('event');
321
- });
322
- ```
323
-
324
- **Parameters**
325
-
326
- | Name | Type | Default | Description |
327
- | --------- | --------------------------------------------- | ------- | ------------------------------------------ |
328
- | `invite` | `string` | — | Test description |
329
- | `fn` | `(done: () => void) => void \| Promise<void>` | — | Test body (sync or async, receives `done`) |
330
- | `options` | `number \| TestOptions` | `100` | Timeout in ms or Vitest `TestOptions` |
331
-
332
- **Variants**
333
-
334
- | Variant | Description |
335
- | ------------------------------------------- | -------------------------- |
336
- | `doneTest.fails(invite, fn, options?)` | Expects the test to fail |
337
- | `doneTest.concurrent(invite, fn, options?)` | Runs the test concurrently |
338
-
339
- ---
340
-
341
- ### `createFakeWaiter(vi)`
342
-
343
- Creates a fake-timer-aware async waiter. If fake timers are active it
344
- advances them; otherwise it uses a real `sleep`.
345
-
346
- ```typescript
347
- import { createFakeWaiter } from '@bemedev/dev-utils/vitest-extended';
348
-
349
- const wait = createFakeWaiter(vi);
350
-
351
- test('advances time', async () => {
352
- vi.useFakeTimers();
353
- await wait(500); // advances fake timers by 500 ms
354
- });
355
- ```
356
-
357
- **Parameters**
358
-
359
- | Name | Type | Description |
360
- | ---- | ------------- | ------------------ |
361
- | `vi` | `VitestUtils` | Vitest `vi` object |
362
-
363
- **Returns** `(ms?: number, times?: number) => Promise<void>`
364
-
365
- **Variants**
366
-
367
- | Variant | Signature | Description |
368
- | -------------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------------- |
369
- | `createFakeWaiter.withDefaultDelay(vi, ms?)` | `(index, times?) => [string, () => Promise<void>]` | Returns a labelled waiter with a fixed delay |
370
- | `createFakeWaiter.all(vi)` | `(index, ms?, times?) => [string, () => Promise<void>]` | Returns a labelled waiter with configurable delay and repetitions |
371
-
372
- ---
373
-
374
- ### `useEach(func, transform?)`
375
-
376
- A typed wrapper around `test.concurrent.each` for synchronous functions.
377
-
378
- ```typescript
379
- import { useEach } from '@bemedev/dev-utils/vitest-extended';
380
-
381
- const run = useEach(add);
382
-
383
- run(['1+2', [1, 2], 3], ['0+0', [0, 0], 0]);
384
- ```
385
-
386
- **Parameters**
387
-
388
- | Name | Type | Description |
389
- | ----------- | ------------------------ | --------------------------------- |
390
- | `func` | `Fn` | Function under test |
391
- | `transform` | `NextFn<F> \| undefined` | Optional return-value transformer |
392
-
393
- **Returns** `(...cases: TestArgs2<F>) => void`
394
-
395
- ---
396
-
397
- ### `useEachAsync(func, transform?)`
398
-
399
- Same as `useEach` but awaits the function result.
400
-
401
- ---
402
-
403
- ### `useErrorAsyncEach(func, transform?, toError?)`
404
-
405
- Runs async error cases using `expect(fn).rejects.toThrowError(error)`.
406
-
407
- ```typescript
408
- const runErrors = vitestExtended.useErrorAsyncEach(
409
- divide,
410
- undefined,
411
- ([_, b]) => (b === 0 ? 'Division by zero' : undefined),
412
- );
413
-
414
- runErrors(['divide by 0', [1, 0], undefined]);
415
- ```
416
-
417
- ---
418
-
419
- ### `useTestFunctionAcceptation(f, name?)` / `useTFA`
420
-
421
- Runs two acceptation checks: the function is defined and is actually a
422
- function.
423
-
424
- ```typescript
425
- vitestExtended.useTFA(myFunction, 'myFunction');
426
- ```
427
-
428
- ---
429
-
430
- ### Utility helpers
431
-
432
- | Export | Signature | Description |
433
- | ---------------------------------- | ----------------------------------- | ------------------------------------------------- |
434
- | `isDefined(value?)` | `(value?: T \| null) => value is T` | Type guard — not `undefined` or `null` |
435
- | `isFunction(arg)` | `(arg: any) => boolean` | Type guard — checks if arg is a callable function |
436
- | `identity(value)` | `<T>(value: T) => T` | Returns the value unchanged |
437
- | `defaultEquality(value, expected)` | `(a, b) => void` | Strict equality; sorts arrays before comparing |
438
-
439
- ---
440
-
441
- ## `rolldownConfig`
442
-
443
- Rolldown bundler configuration factory with built-in plugins for TypeScript
444
- declarations, path aliasing, circular dependency detection, and
445
- tree-shaking externals.
446
-
447
- ### `defineConfig(additionals?)`
448
-
449
- Shorthand for `defineConfig.default`.
450
-
451
- ### `defineConfig.default(params?)`
452
-
453
- Produces a full Rolldown config with the default plugin pipeline:
454
-
455
- 1. **alias** — resolves tsconfig path aliases (`rollup-plugin-tsc-alias`)
456
- 2. **tsPaths** — resolves tsconfig path imports at bundle time
457
- (`rollup-plugin-tsconfig-paths`)
458
- 3. **circulars** — warns on circular dependencies
459
- (`rollup-plugin-circular-dependency`)
460
- 4. **externals** — marks `dependencies` and `peerDependencies` as external
461
- (`rollup-plugin-node-externals`)
462
- 5. **typescript** — emits `.d.ts` declarations via the TypeScript compiler
463
- API
464
- 6. **clean** — removes JS outputs for files that produce empty chunks
465
-
466
- ```typescript
467
- // rolldown.config.ts
468
- import { defineConfig } from '@bemedev/dev-utils/rolldown';
469
-
470
- export default defineConfig.default({
471
- dir: 'lib',
472
- sourcemap: true,
473
- excludesTS: ['src/fixtures/**/*.ts'],
474
- });
475
- ```
476
-
477
- **`Params` properties**
478
-
479
- | Property | Type | Default | Description |
480
- | ---------------- | --------------------------------------- | ------------- | ------------------------------------------------------- |
481
- | `dir` | `string` | `'lib'` | Output directory |
482
- | `sourcemap` | `boolean` | `false` | Emit sourcemaps |
483
- | `declarationMap` | `boolean` | `undefined` | Emit declaration maps |
484
- | `excludesTS` | `string \| string[]` | `[]` | Extra TS files to exclude from declaration emit |
485
- | `circularDeps` | `string \| string[]` | `[]` | Extra patterns exempt from circular-dep warnings |
486
- | `ignoresJS` | `string \| string[]` | `[]` | Patterns whose empty-bundle warnings are suppressed |
487
- | `externals` | `string \| string[]` | `[]` | Additional packages to mark as external |
488
- | `plugins` | `(RolldownPluginOption \| PluginKey)[]` | default order | Custom plugin list; string keys select built-in plugins |
489
-
490
- **Default excluded files** (always applied):
491
-
492
- ```
493
- **/node_modules/**/*
494
- **/__tests__/**/*
495
- **/*.test.ts / **/*.test-d.ts
496
- **/*.fixtures.ts / **/fixtures.ts
497
- src/fixtures/**/*.ts
498
- ```
499
-
500
- **Output format:** both `esm` (`.js`) and `cjs` (`.cjs`), with
501
- `preserveModules: true`.
502
-
503
- ---
504
-
505
- ### `defineConfig.bemedev(params?)`
506
-
507
- Opinionated preset that extends `defineConfig.default` with:
508
-
509
- - Sourcemaps **enabled by default**
510
- - `DEFAULT_CIRCULAR_DEPS` merged into `circularDeps` (`**/types.ts`,
511
- `**/*.types.ts`, …)
512
- - `DEFAULT_EXCLUDE` merged into `excludesTS`
513
- - `DEFAULT_CIRCULAR_DEPS` merged into `ignoresJS`
514
-
515
- ```typescript
516
- export default defineConfig.bemedev({
517
- excludesTS: ['src/my-fixtures/**'],
518
- });
519
- ```
520
-
521
- ---
522
-
523
- ### Plugin builders (`PLUGIN_BUILDERS`)
524
-
525
- Individual plugin factories are available for custom pipeline assembly:
526
-
527
- | Key | Function | Wraps |
528
- | ------------ | ---------------------- | ------------------------------------- |
529
- | `alias` | `alias(options?)` | `rollup-plugin-tsc-alias` |
530
- | `tsPaths` | `tsPaths(options?)` | `rollup-plugin-tsconfig-paths` |
531
- | `circulars` | `circulars(options?)` | `rollup-plugin-circular-dependency` |
532
- | `externals` | `externals(options?)` | `rollup-plugin-node-externals` |
533
- | `typescript` | `typescript(options?)` | TypeScript compiler API + `tsc-alias` |
534
- | `clean` | `clean(options?)` | Custom post-build JS cleanup |
535
-
536
- Pass plugin keys as strings in the `plugins` array to reorder or subset
537
- them:
538
-
539
- ```typescript
540
- defineConfig.default({
541
- plugins: ['alias', 'tsPaths', 'externals', 'typescript'],
542
- });
543
- ```
544
-
545
- ---
546
-
547
- ## `buildTests`
548
-
549
- CLI tooling that packs your built library as a local tarball, installs it
550
- under the alias `this-gen-1`, runs your test suite against the real
551
- distributable, then tears down.
552
-
553
- Available as a sub-path export:
554
-
555
- ```typescript
556
- import {
557
- addTarball,
558
- cleanup,
559
- customImport,
560
- THIS1,
561
- } from '@bemedev/dev-utils/build-tests';
562
- ```
563
-
564
- ### CLI usage
565
-
566
- The binary is `build-tests`. It exposes three subcommands:
567
-
568
- ```bash
569
- # Install the tarball (pre-test hook)
570
- build-tests pre
571
-
572
- # Run tests with pre/post lifecycle
573
- build-tests test [--pretest] [--posttest]
574
-
575
- # Clean up tarball + uninstall (post-test hook)
576
- build-tests post
577
- ```
578
-
579
- `package.json` integration (auto-configured):
580
-
581
- ```json
582
- {
583
- "scripts": {
584
- "pretest": "build && build-tests pre",
585
- "posttest": "fmt && build-tests post"
586
- }
587
- }
588
- ```
589
-
590
- ---
591
-
592
- ### `addTarball()`
593
-
594
- Programmatic API for the `pre` step:
595
-
596
- 1. Builds the `package.json` for the `outDir` (strips `scripts`,
597
- `devDependencies`, `files`; fixes paths)
598
- 2. Runs `pnpm pack` into `.pack/`
599
- 3. Installs the resulting `.tgz` as `this-gen-1` in `devDependencies`
600
-
601
- ```typescript
602
- import { addTarball } from '@bemedev/dev-utils/build-tests';
603
-
604
- await addTarball();
605
- ```
606
-
607
- ---
608
-
609
- ### `cleanup()`
610
-
611
- Programmatic API for the `post` step:
612
-
613
- 1. Removes the `.pack/` folder
614
- 2. Runs `pnpm remove this-gen-1`
615
-
616
- ```typescript
617
- import { cleanup } from '@bemedev/dev-utils/build-tests';
618
-
619
- cleanup();
620
- ```
621
-
622
- ---
623
-
624
- ### `customImport(fn?)`
625
-
626
- Dynamically imports the installed package (`this-gen-1`) and optionally
627
- transforms its exports via a mapper function.
628
-
629
- ```typescript
630
- import { customImport } from '@bemedev/dev-utils/build-tests';
631
-
632
- // Import the default export as-is
633
- const out = await customImport();
634
-
635
- // Import and pick a specific export
636
- const myFn = await customImport(mod => mod.myFn);
637
- ```
638
-
639
- **Parameters**
640
-
641
- | Name | Type | Default | Description |
642
- | ---- | ------------------------- | ---------- | -------------------------------------------------------- |
643
- | `fn` | `(out: IndexImport) => T` | `identity` | Mapper applied to the imported module; defaults to no-op |
644
-
645
- **Returns** `Promise<T>` — the mapped module output.
646
-
647
- ---
648
-
649
- ### `THIS1`
650
-
651
- Constant string `'this-gen-1'` — the package alias used by `addTarball` and
652
- `cleanup` when installing/removing the local tarball.
653
-
654
- ```typescript
655
- import { THIS1 } from '@bemedev/dev-utils/build-tests';
656
-
657
- console.log(THIS1); // 'this-gen-1'
658
- ```
659
-
660
- ---
661
-
662
- ### Types
663
-
664
- | Name | Description |
665
- | ------------- | --------------------------------------------------------------------- |
666
- | `IndexImport` | Type of the module returned by a dynamic `import(THIS1)` call (`any`) |
667
-
668
- ---
669
-
670
- <br/>
671
-
672
- ## Licence
673
-
674
- MIT
675
-
676
- ## CHANGELOG
677
-
678
- Read [CHANGELOG.md](CHANGELOG.md) for details about all changes and
679
- versions.
680
-
681
- <br/>
682
-
683
- ## Author
684
-
685
- chlbri (bri_lvi@icloud.com)
686
-
687
- [My github](https://github.com/chlbri?tab=repositories)
688
-
689
- [<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>](https://github.com/chlbri?tab=repositories)
690
-
691
- <br/>
692
-
693
- ## Links
694
-
695
- - [GitHub Repository](https://github.com/chlbri/node-dev-utils)
696
- - [Website](https://bemedev.vercel.app)
@@ -1,4 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_vitest_alias_vitest = require("./vitest.cjs");
3
- exports.aliasTs = require_vitest_alias_vitest.aliasTs;
4
- exports.createAlias = require_vitest_alias_vitest.createAlias;
@@ -1 +0,0 @@
1
- export * from './vitest';
@@ -1,2 +0,0 @@
1
- import { aliasTs, createAlias } from "./vitest.js";
2
- export { aliasTs, createAlias };