@bemedev/dev-utils 1.3.0 → 1.4.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 +62 -83
- package/lib/build-tests/buildPackageJson.cjs.map +1 -1
- package/lib/build-tests/buildPackageJson.js.map +1 -1
- package/lib/build-tests/cli/test.cjs.map +1 -1
- package/lib/build-tests/cli/test.js.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.cjs.map +1 -1
- package/lib/build-tests/getTypescriptOutdir.js.map +1 -1
- package/lib/build-tests/imports/create.cjs.map +1 -1
- package/lib/build-tests/imports/create.js.map +1 -1
- package/lib/build-tests/imports/helper.cjs.map +1 -1
- package/lib/build-tests/imports/helper.js.map +1 -1
- package/lib/plugins/hmr.cjs +14 -26
- package/lib/plugins/hmr.cjs.map +1 -1
- package/lib/plugins/hmr.d.ts +5 -15
- package/lib/plugins/hmr.js +14 -26
- package/lib/plugins/hmr.js.map +1 -1
- package/lib/plugins/suppressWarnings.cjs.map +1 -1
- package/lib/plugins/suppressWarnings.js.map +1 -1
- package/lib/rolldown-config/config.cjs.map +1 -1
- package/lib/rolldown-config/config.js.map +1 -1
- package/lib/rolldown-config/helpers.cjs.map +1 -1
- package/lib/rolldown-config/helpers.js.map +1 -1
- package/lib/rolldown-config/input.cjs.map +1 -1
- package/lib/rolldown-config/input.js.map +1 -1
- package/lib/rolldown-config/plugins/circulars.cjs.map +1 -1
- package/lib/rolldown-config/plugins/circulars.js.map +1 -1
- package/lib/rolldown-config/plugins/clean.cjs.map +1 -1
- package/lib/rolldown-config/plugins/clean.js.map +1 -1
- package/lib/rolldown-config/plugins/externals.cjs.map +1 -1
- package/lib/rolldown-config/plugins/externals.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.config.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.fast.cjs.map +1 -1
- package/lib/rolldown-config/plugins/typescript.fast.js.map +1 -1
- package/lib/rolldown-config/plugins/typescript.js.map +1 -1
- package/lib/utils/bemedev/globals/utils/expandFn.cjs.map +1 -1
- package/lib/utils/bemedev/globals/utils/expandFn.js.map +1 -1
- package/lib/vitest-exclude/vitest.cjs.map +1 -1
- package/lib/vitest-exclude/vitest.js.map +1 -1
- package/lib/vitest-extended/createTests.cjs.map +1 -1
- package/lib/vitest-extended/createTests.js.map +1 -1
- package/lib/vitest-extended/done.cjs.map +1 -1
- package/lib/vitest-extended/done.js.map +1 -1
- package/lib/vitest-extended/each/error.cjs.map +1 -1
- package/lib/vitest-extended/each/error.js.map +1 -1
- package/lib/vitest-extended/each/pass.cjs.map +1 -1
- package/lib/vitest-extended/each/pass.js.map +1 -1
- package/lib/vitest-extended/fakeWaiter.cjs.map +1 -1
- package/lib/vitest-extended/fakeWaiter.js.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.cjs.map +1 -1
- package/lib/vitest-extended/fixtures/partialCall.js.map +1 -1
- package/lib/vitest-extended/isFunction.cjs.map +1 -1
- package/lib/vitest-extended/isFunction.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# @bemedev/dev-utils
|
|
2
2
|
|
|
3
|
-
A collection of utilities for Node.js development, including build tools,
|
|
4
|
-
|
|
3
|
+
A collection of utilities for Node.js development, including build tools, testing
|
|
4
|
+
utilities, and configuration management.
|
|
5
5
|
|
|
6
6
|
## HOTFIX fix for version 1.0.*
|
|
7
7
|
|
|
8
|
-
> It doesn't type declarations well, if you're not put directly the output
|
|
9
|
-
> type
|
|
8
|
+
> It doesn't type declarations well, if you're not put directly the output type
|
|
10
9
|
|
|
11
10
|
## Modules
|
|
12
11
|
|
|
@@ -19,11 +18,11 @@ testing utilities, and configuration management.
|
|
|
19
18
|
| [`plugins`](#plugins) | Vite development helper plugins |
|
|
20
19
|
| [`utils`](#utils) | Utility functions and helpers |
|
|
21
20
|
|
|
22
|
-
> **Note (v0.8.1):** The `./vitest-alias` export has been removed. Path
|
|
23
|
-
>
|
|
24
|
-
> `vite-tsconfig-paths` or the built-in `resolve.tsConfigPaths` option.
|
|
25
|
-
>
|
|
26
|
-
>
|
|
21
|
+
> **Note (v0.8.1):** The `./vitest-alias` export has been removed. Path alias
|
|
22
|
+
> resolution is now handled natively by Vite via `resolve.alias` with
|
|
23
|
+
> `vite-tsconfig-paths` or the built-in `resolve.tsConfigPaths` option. Remove any
|
|
24
|
+
> `aliasTs()` / `createAlias()` usage and configure aliases directly in your `vite` /
|
|
25
|
+
> `vitest` config.
|
|
27
26
|
|
|
28
27
|
<br/>
|
|
29
28
|
|
|
@@ -43,15 +42,12 @@ yarn add @bemedev/dev-utils
|
|
|
43
42
|
|
|
44
43
|
## Usage
|
|
45
44
|
|
|
46
|
-
Each module is available as a dedicated sub-path export — there is no root
|
|
47
|
-
|
|
45
|
+
Each module is available as a dedicated sub-path export — there is no root barrel
|
|
46
|
+
export:
|
|
48
47
|
|
|
49
48
|
```typescript
|
|
50
49
|
import { exclude } from '@bemedev/dev-utils/vitest-exclude';
|
|
51
|
-
import {
|
|
52
|
-
createTests,
|
|
53
|
-
createFakeWaiter,
|
|
54
|
-
} from '@bemedev/dev-utils/vitest-extended';
|
|
50
|
+
import { createTests, createFakeWaiter } from '@bemedev/dev-utils/vitest-extended';
|
|
55
51
|
import { defineConfig } from '@bemedev/dev-utils/rolldown';
|
|
56
52
|
import { addTarball, cleanup } from '@bemedev/dev-utils/build-tests';
|
|
57
53
|
import { suppressWarnings, hmr } from '@bemedev/dev-utils/plugins';
|
|
@@ -62,14 +58,13 @@ import { clamp, toArray, identity, sleep } from '@bemedev/dev-utils/utils';
|
|
|
62
58
|
|
|
63
59
|
## `vitestExclude`
|
|
64
60
|
|
|
65
|
-
Vitest plugin that uses glob patterns to dynamically build `test.include`
|
|
66
|
-
|
|
61
|
+
Vitest plugin that uses glob patterns to dynamically build `test.include` and
|
|
62
|
+
`coverage.include` lists — no need to maintain `test.exclude` manually.
|
|
67
63
|
|
|
68
64
|
### `exclude(args?)`
|
|
69
65
|
|
|
70
66
|
Uses default patterns (`src/**/*.ts` for coverage,
|
|
71
|
-
`src/**/*.{test,spec}.{ts,js,tsx,jsx}` for tests) and applies optional
|
|
72
|
-
ignore lists.
|
|
67
|
+
`src/**/*.{test,spec}.{ts,js,tsx,jsx}` for tests) and applies optional ignore lists.
|
|
73
68
|
|
|
74
69
|
```typescript
|
|
75
70
|
import { exclude } from '@bemedev/dev-utils/vitest-exclude';
|
|
@@ -98,8 +93,7 @@ export default defineConfig({
|
|
|
98
93
|
|
|
99
94
|
### `exclude.withPattern(patterns, args)`
|
|
100
95
|
|
|
101
|
-
Same as `exclude`, but lets you provide custom glob patterns instead of the
|
|
102
|
-
defaults.
|
|
96
|
+
Same as `exclude`, but lets you provide custom glob patterns instead of the defaults.
|
|
103
97
|
|
|
104
98
|
```typescript
|
|
105
99
|
exclude.withPattern(
|
|
@@ -147,8 +141,8 @@ const { files, coverage } = await create({
|
|
|
147
141
|
|
|
148
142
|
### `create.withPattern(patterns, args)`
|
|
149
143
|
|
|
150
|
-
Same as `create`, but accepts custom glob patterns for both test and
|
|
151
|
-
|
|
144
|
+
Same as `create`, but accepts custom glob patterns for both test and coverage
|
|
145
|
+
discovery.
|
|
152
146
|
|
|
153
147
|
```typescript
|
|
154
148
|
import { create } from '@bemedev/dev-utils/vitest-exclude';
|
|
@@ -177,8 +171,8 @@ Extended helpers for writing structured, type-safe Vitest tests.
|
|
|
177
171
|
|
|
178
172
|
### `createTests(func, args?)`
|
|
179
173
|
|
|
180
|
-
Creates a reusable test suite for a function with `acceptation`, `success`,
|
|
181
|
-
|
|
174
|
+
Creates a reusable test suite for a function with `acceptation`, `success`, and
|
|
175
|
+
`fails` runners.
|
|
182
176
|
|
|
183
177
|
```typescript
|
|
184
178
|
import { createTests } from '@bemedev/dev-utils/vitest-extended';
|
|
@@ -225,8 +219,8 @@ describe('add', () => {
|
|
|
225
219
|
|
|
226
220
|
### `createTests.withImplementation(f, opts)`
|
|
227
221
|
|
|
228
|
-
Same as `createTests` but replaces the implementation with a `vi.fn()` mock
|
|
229
|
-
|
|
222
|
+
Same as `createTests` but replaces the implementation with a `vi.fn()` mock before
|
|
223
|
+
the test suite runs.
|
|
230
224
|
|
|
231
225
|
```typescript
|
|
232
226
|
const { acceptation, success } = createTests.withImplementation(myFn, {
|
|
@@ -248,9 +242,9 @@ const { acceptation, success } = createTests.withImplementation(myFn, {
|
|
|
248
242
|
|
|
249
243
|
### `doneTest(invite, fn, options?)`
|
|
250
244
|
|
|
251
|
-
Wraps a callback-style (done-based) test into a Vitest `test`. The test
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
Wraps a callback-style (done-based) test into a Vitest `test`. The test passes only
|
|
246
|
+
when `done()` is called within the timeout. Supports both sync and async test
|
|
247
|
+
functions.
|
|
254
248
|
|
|
255
249
|
```typescript
|
|
256
250
|
import { doneTest } from '@bemedev/dev-utils/vitest-extended';
|
|
@@ -287,8 +281,8 @@ doneTest('fires callback', done => {
|
|
|
287
281
|
|
|
288
282
|
### `createFakeWaiter(vi)`
|
|
289
283
|
|
|
290
|
-
Creates a fake-timer-aware async waiter. If fake timers are active it
|
|
291
|
-
|
|
284
|
+
Creates a fake-timer-aware async waiter. If fake timers are active it advances them;
|
|
285
|
+
otherwise it uses a real `sleep`.
|
|
292
286
|
|
|
293
287
|
```typescript
|
|
294
288
|
import { createFakeWaiter } from '@bemedev/dev-utils/vitest-extended';
|
|
@@ -352,10 +346,8 @@ Same as `useEach` but awaits the function result.
|
|
|
352
346
|
Runs async error cases using `expect(fn).rejects.toThrowError(error)`.
|
|
353
347
|
|
|
354
348
|
```typescript
|
|
355
|
-
const runErrors = vitestExtended.useErrorAsyncEach(
|
|
356
|
-
|
|
357
|
-
undefined,
|
|
358
|
-
([_, b]) => (b === 0 ? 'Division by zero' : undefined),
|
|
349
|
+
const runErrors = vitestExtended.useErrorAsyncEach(divide, undefined, ([_, b]) =>
|
|
350
|
+
b === 0 ? 'Division by zero' : undefined,
|
|
359
351
|
);
|
|
360
352
|
|
|
361
353
|
runErrors(['divide by 0', [1, 0], undefined]);
|
|
@@ -365,8 +357,7 @@ runErrors(['divide by 0', [1, 0], undefined]);
|
|
|
365
357
|
|
|
366
358
|
### `useTestFunctionAcceptation(f, name?)` / `useTFA`
|
|
367
359
|
|
|
368
|
-
Runs two acceptation checks: the function is defined and is actually a
|
|
369
|
-
function.
|
|
360
|
+
Runs two acceptation checks: the function is defined and is actually a function.
|
|
370
361
|
|
|
371
362
|
```typescript
|
|
372
363
|
vitestExtended.useTFA(myFunction, 'myFunction');
|
|
@@ -376,14 +367,13 @@ vitestExtended.useTFA(myFunction, 'myFunction');
|
|
|
376
367
|
|
|
377
368
|
### `defineProject(config)`
|
|
378
369
|
|
|
379
|
-
A wrapper around Vitest's `defineProject` / `defineConfig` that injects
|
|
380
|
-
|
|
370
|
+
A wrapper around Vitest's `defineProject` / `defineConfig` that injects default
|
|
371
|
+
configurations.
|
|
381
372
|
|
|
382
|
-
> [!IMPORTANT] **HOT FIX**: Use this instead of standard `defineProject`
|
|
383
|
-
>
|
|
384
|
-
> `
|
|
385
|
-
>
|
|
386
|
-
> `'test'` by default.
|
|
373
|
+
> [!IMPORTANT] **HOT FIX**: Use this instead of standard `defineProject` from
|
|
374
|
+
> `vitest/config` to automatically resolve path aliases (via `tsconfigPaths: true`),
|
|
375
|
+
> set `globals: true`, configure `logHeapUsage: false`, and set the `NODE_ENV`
|
|
376
|
+
> environment variable to `'test'` by default.
|
|
387
377
|
|
|
388
378
|
```typescript
|
|
389
379
|
import { defineProject } from '@bemedev/dev-utils/vitest-extended';
|
|
@@ -425,8 +415,7 @@ Produces a full Rolldown config with the default plugin pipeline:
|
|
|
425
415
|
(`rollup-plugin-circular-dependency`)
|
|
426
416
|
2. **externals** — marks `dependencies` and `peerDependencies` as external
|
|
427
417
|
(`rollup-plugin-node-externals`)
|
|
428
|
-
3. **typescript** — emits `.d.ts` declarations via the TypeScript compiler
|
|
429
|
-
API
|
|
418
|
+
3. **typescript** — emits `.d.ts` declarations via the TypeScript compiler API
|
|
430
419
|
4. **clean** — removes JS outputs for files that produce empty chunks
|
|
431
420
|
|
|
432
421
|
```typescript
|
|
@@ -473,31 +462,28 @@ src/fixtures/**/*.ts
|
|
|
473
462
|
Opinionated preset that extends `defineConfig.default` with:
|
|
474
463
|
|
|
475
464
|
- Sourcemaps **enabled by default**
|
|
476
|
-
- `DEFAULT_CIRCULAR_DEPS` merged into `circularDeps` (`**/types.ts`,
|
|
477
|
-
|
|
465
|
+
- `DEFAULT_CIRCULAR_DEPS` merged into `circularDeps` (`**/types.ts`, `**/*.types.ts`,
|
|
466
|
+
…)
|
|
478
467
|
- `DEFAULT_EXCLUDE` merged into `excludesTS`
|
|
479
468
|
- `DEFAULT_CIRCULAR_DEPS` merged into `ignoresJS`
|
|
480
469
|
|
|
481
470
|
```typescript
|
|
482
|
-
export default defineConfig.bemedev({
|
|
483
|
-
excludesTS: ['src/my-fixtures/**'],
|
|
484
|
-
});
|
|
471
|
+
export default defineConfig.bemedev({ excludesTS: ['src/my-fixtures/**'] });
|
|
485
472
|
```
|
|
486
473
|
|
|
487
474
|
---
|
|
488
475
|
|
|
489
476
|
### `defineConfig.fast(params?)`
|
|
490
477
|
|
|
491
|
-
A fast build configuration preset that optimizes TypeScript declaration
|
|
492
|
-
|
|
493
|
-
|
|
478
|
+
A fast build configuration preset that optimizes TypeScript declaration emitting. It
|
|
479
|
+
uses the `fast` (`typescriptFast`) plugin wrapping `oxc-transform` instead of the
|
|
480
|
+
standard compiler API.
|
|
494
481
|
|
|
495
482
|
It runs the following plugin pipeline:
|
|
496
483
|
|
|
497
484
|
1. **circulars** — warns on circular dependencies
|
|
498
485
|
2. **externals** — marks `dependencies` and `peerDependencies` as external
|
|
499
|
-
3. **esm** — injects ESM external require helpers
|
|
500
|
-
(`esmExternalRequirePlugin`)
|
|
486
|
+
3. **esm** — injects ESM external require helpers (`esmExternalRequirePlugin`)
|
|
501
487
|
4. **fast** — generates `.d.ts` files quickly using `oxc-transform`
|
|
502
488
|
5. **clean** — removes empty JS chunks
|
|
503
489
|
|
|
@@ -520,8 +506,7 @@ Individual plugin factories are available for custom pipeline assembly:
|
|
|
520
506
|
| `fast` | `fast(options?)` | `oxc-transform` + `tsc-alias`, for ONLY compilerOptions.isolatedDeclarations set to `true` |
|
|
521
507
|
| `clean` | `clean(options?)` | Custom post-build JS cleanup |
|
|
522
508
|
|
|
523
|
-
Pass plugin keys as strings in the `plugins` array to reorder or subset
|
|
524
|
-
them:
|
|
509
|
+
Pass plugin keys as strings in the `plugins` array to reorder or subset them:
|
|
525
510
|
|
|
526
511
|
```typescript
|
|
527
512
|
defineConfig.default({ plugins: ['externals', 'typescript'] });
|
|
@@ -531,9 +516,9 @@ defineConfig.default({ plugins: ['externals', 'typescript'] });
|
|
|
531
516
|
|
|
532
517
|
## `buildTests`
|
|
533
518
|
|
|
534
|
-
CLI tooling that packs your built library as a local tarball, installs it
|
|
535
|
-
|
|
536
|
-
|
|
519
|
+
CLI tooling that packs your built library as a local tarball, installs it under the
|
|
520
|
+
alias `this-gen-1`, runs your test suite against the real distributable, then tears
|
|
521
|
+
down.
|
|
537
522
|
|
|
538
523
|
Available as a sub-path export:
|
|
539
524
|
|
|
@@ -578,8 +563,8 @@ build-tests post
|
|
|
578
563
|
|
|
579
564
|
Programmatic API for the `pre` step:
|
|
580
565
|
|
|
581
|
-
1. Builds the `package.json` for the `outDir` (strips `scripts`,
|
|
582
|
-
`
|
|
566
|
+
1. Builds the `package.json` for the `outDir` (strips `scripts`, `devDependencies`,
|
|
567
|
+
`files`; fixes paths)
|
|
583
568
|
2. Runs `pnpm pack` into `.pack/`
|
|
584
569
|
3. Installs the resulting `.tgz` as `this-gen-1` in `devDependencies`
|
|
585
570
|
|
|
@@ -608,8 +593,8 @@ cleanup();
|
|
|
608
593
|
|
|
609
594
|
### `customImport(fn?)`
|
|
610
595
|
|
|
611
|
-
Dynamically imports the installed package (`this-gen-1`) and optionally
|
|
612
|
-
|
|
596
|
+
Dynamically imports the installed package (`this-gen-1`) and optionally transforms
|
|
597
|
+
its exports via a mapper function.
|
|
613
598
|
|
|
614
599
|
```typescript
|
|
615
600
|
import { customImport } from '@bemedev/dev-utils/build-tests';
|
|
@@ -633,8 +618,8 @@ const myFn = await customImport(mod => mod.myFn);
|
|
|
633
618
|
|
|
634
619
|
### `THIS1`
|
|
635
620
|
|
|
636
|
-
Constant string `'this-gen-1'` — the package alias used by `addTarball` and
|
|
637
|
-
|
|
621
|
+
Constant string `'this-gen-1'` — the package alias used by `addTarball` and `cleanup`
|
|
622
|
+
when installing/removing the local tarball.
|
|
638
623
|
|
|
639
624
|
```typescript
|
|
640
625
|
import { THIS1 } from '@bemedev/dev-utils/build-tests';
|
|
@@ -658,18 +643,16 @@ Vite plugins for development and test workflows.
|
|
|
658
643
|
|
|
659
644
|
### `suppressWarnings(...patterns)`
|
|
660
645
|
|
|
661
|
-
Vite plugin that intercepts and suppresses noisy terminal stderr output
|
|
662
|
-
|
|
663
|
-
|
|
646
|
+
Vite plugin that intercepts and suppresses noisy terminal stderr output (e.g., from
|
|
647
|
+
Nitro, SSR workers, or third-party dependencies) matching specific strings or regular
|
|
648
|
+
expressions during dev (`apply: 'serve'`).
|
|
664
649
|
|
|
665
650
|
```typescript
|
|
666
651
|
import { suppressWarnings } from '@bemedev/dev-utils/plugins';
|
|
667
652
|
import { defineConfig } from 'vite';
|
|
668
653
|
|
|
669
654
|
export default defineConfig({
|
|
670
|
-
plugins: [
|
|
671
|
-
suppressWarnings('ExperimentalWarning', /punycode/, '[Vue warn]'),
|
|
672
|
-
],
|
|
655
|
+
plugins: [suppressWarnings('ExperimentalWarning', /punycode/, '[Vue warn]')],
|
|
673
656
|
});
|
|
674
657
|
```
|
|
675
658
|
|
|
@@ -679,16 +662,14 @@ export default defineConfig({
|
|
|
679
662
|
| ------------- | ------------------------- | --------------------------------------------------------------------- |
|
|
680
663
|
| `...patterns` | `Array<string \| RegExp>` | Strings or RegExp patterns to match against stderr chunks to suppress |
|
|
681
664
|
|
|
682
|
-
**Returns** a Vite `Plugin`
|
|
683
|
-
(`{ name: 'suppress-logs-plugin', apply: 'serve' }`).
|
|
665
|
+
**Returns** a Vite `Plugin` (`{ name: 'suppress-logs-plugin', apply: 'serve' }`).
|
|
684
666
|
|
|
685
667
|
---
|
|
686
668
|
|
|
687
669
|
### `hmr(props?)`
|
|
688
670
|
|
|
689
|
-
Vite plugin providing Hot Module Reloading (HMR) capabilities for external
|
|
690
|
-
|
|
691
|
-
detected.
|
|
671
|
+
Vite plugin providing Hot Module Reloading (HMR) capabilities for external file paths
|
|
672
|
+
by watching files and executing build scripts when changes are detected.
|
|
692
673
|
|
|
693
674
|
```typescript
|
|
694
675
|
import { hmr } from '@bemedev/dev-utils/plugins';
|
|
@@ -719,8 +700,7 @@ export default defineConfig({
|
|
|
719
700
|
|
|
720
701
|
## `utils`
|
|
721
702
|
|
|
722
|
-
General development utility helpers available via the `./utils` sub-path
|
|
723
|
-
export.
|
|
703
|
+
General development utility helpers available via the `./utils` sub-path export.
|
|
724
704
|
|
|
725
705
|
### `clamp(value, min, max)`
|
|
726
706
|
|
|
@@ -777,8 +757,7 @@ MIT
|
|
|
777
757
|
|
|
778
758
|
## CHANGELOG
|
|
779
759
|
|
|
780
|
-
Read [CHANGELOG.md](CHANGELOG.md) for details about all changes and
|
|
781
|
-
versions.
|
|
760
|
+
Read [CHANGELOG.md](CHANGELOG.md) for details about all changes and versions.
|
|
782
761
|
|
|
783
762
|
<br/>
|
|
784
763
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPackageJson.cjs","names":["editJsonFile","getTypescriptOutdir","EXPORT_KEY","sortKeys"],"sources":["../../src/build-tests/buildPackageJson.ts"],"sourcesContent":["import editJsonFile from 'edit-json-file';\nimport sortKeys from 'sort-keys';\n\nimport type { Fn } from '#utils';\n\nimport { BIN_KEY, EXPORT_KEY, EXPORT_KEYS } from './constants';\nimport { getTypescriptOutdir } from './getTypescriptOutdir';\n\ntype BuldPackageJson_F = Fn<[], { packageJson: object; outDir: string }>;\n\n/**\n * Transforms `package.json` for packed distribution by adjusting paths and removing internal fields.\n *\n * @returns Object containing the modified `packageJson` and resolved `outDir`.\n */\nexport const buildPackageJson: BuldPackageJson_F = () => {\n const file = editJsonFile('./package.json');\n const outDir = getTypescriptOutdir();\n const lib = `${outDir}/`;\n const replaceLib = (str: string) => str.replace(lib, '');\n\n // #region Set export values\n EXPORT_KEYS.forEach(key => {\n const value = file.get(key);\n if (value) {\n const transformed = replaceLib(value);\n file.set(key, transformed);\n }\n });\n // #endregion\n\n // #region Set Export key\n const valueExports = file.get(EXPORT_KEY);\n\n if (valueExports) {\n const transformedExports = Object.entries(valueExports).reduce(\n (acc, [key, value]) => {\n const entries = Object.entries(value as any);\n const _value = entries.reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value as any);\n return acc;\n }, {} as any);\n acc[key] = key.includes('package.json') ? value : _value;\n return acc;\n },\n {} as any,\n );\n\n file.set(EXPORT_KEY, transformedExports);\n }\n // #endregion\n\n // #region Set bin\n const bin1 = file.get(BIN_KEY) as
|
|
1
|
+
{"version":3,"file":"buildPackageJson.cjs","names":["editJsonFile","getTypescriptOutdir","EXPORT_KEY","sortKeys"],"sources":["../../src/build-tests/buildPackageJson.ts"],"sourcesContent":["import editJsonFile from 'edit-json-file';\nimport sortKeys from 'sort-keys';\n\nimport type { Fn } from '#utils';\n\nimport { BIN_KEY, EXPORT_KEY, EXPORT_KEYS } from './constants';\nimport { getTypescriptOutdir } from './getTypescriptOutdir';\n\ntype BuldPackageJson_F = Fn<[], { packageJson: object; outDir: string }>;\n\n/**\n * Transforms `package.json` for packed distribution by adjusting paths and removing internal fields.\n *\n * @returns Object containing the modified `packageJson` and resolved `outDir`.\n */\nexport const buildPackageJson: BuldPackageJson_F = () => {\n const file = editJsonFile('./package.json');\n const outDir = getTypescriptOutdir();\n const lib = `${outDir}/`;\n const replaceLib = (str: string) => str.replace(lib, '');\n\n // #region Set export values\n EXPORT_KEYS.forEach(key => {\n const value = file.get(key);\n if (value) {\n const transformed = replaceLib(value);\n file.set(key, transformed);\n }\n });\n // #endregion\n\n // #region Set Export key\n const valueExports = file.get(EXPORT_KEY);\n\n if (valueExports) {\n const transformedExports = Object.entries(valueExports).reduce(\n (acc, [key, value]) => {\n const entries = Object.entries(value as any);\n const _value = entries.reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value as any);\n return acc;\n }, {} as any);\n acc[key] = key.includes('package.json') ? value : _value;\n return acc;\n },\n {} as any,\n );\n\n file.set(EXPORT_KEY, transformedExports);\n }\n // #endregion\n\n // #region Set bin\n const bin1 = file.get(BIN_KEY) as Record<string, string> | undefined | string;\n\n if (bin1) {\n if (typeof bin1 === 'string') {\n const bin2 = replaceLib(bin1);\n file.set(BIN_KEY, bin2);\n } else {\n const bin2 = Object.entries(bin1).reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value);\n return acc;\n }, {} as any);\n\n const bin3 = sortKeys(bin2);\n file.set(BIN_KEY, bin3);\n }\n }\n // #endregion\n\n // #region Unset some props\n file.unset('files');\n file.unset('scripts');\n file.unset('devDependencies');\n // #endregion\n\n const packageJson = file.get();\n return { packageJson, outDir };\n};\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,yBAA4C;CACvD,MAAM,QAAA,GAAOA,eAAAA,QAAAA,CAAa,gBAAgB;CAC1C,MAAM,SAASC,wCAAAA,oBAAoB;CACnC,MAAM,MAAM,GAAG,OAAO;CACtB,MAAM,cAAc,QAAgB,IAAI,QAAQ,KAAK,EAAE;CAGvD,8BAAA,YAAY,SAAQ,QAAO;EACzB,MAAM,QAAQ,KAAK,IAAI,GAAG;EAC1B,IAAI,OAAO;GACT,MAAM,cAAc,WAAW,KAAK;GACpC,KAAK,IAAI,KAAK,WAAW;EAC3B;CACF,CAAC;CAID,MAAM,eAAe,KAAK,IAAIC,8BAAAA,UAAU;CAExC,IAAI,cAAc;EAChB,MAAM,qBAAqB,OAAO,QAAQ,YAAY,CAAC,CAAC,QACrD,KAAK,CAAC,KAAK,WAAW;GAErB,MAAM,SADU,OAAO,QAAQ,KACV,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;IACnD,IAAI,OAAO,WAAW,KAAY;IAClC,OAAO;GACT,GAAG,CAAC,CAAQ;GACZ,IAAI,OAAO,IAAI,SAAS,cAAc,IAAI,QAAQ;GAClD,OAAO;EACT,GACA,CAAC,CACH;EAEA,KAAK,IAAIA,8BAAAA,YAAY,kBAAkB;CACzC;CAIA,MAAM,OAAO,KAAK,IAAA,KAAW;CAE7B,IAAI,MAAM;EACR,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,OAAO,WAAW,IAAI;GAC5B,KAAK,IAAA,OAAa,IAAI;EACxB,OAAO;GACL,MAAM,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;IAC9D,IAAI,OAAO,WAAW,KAAK;IAC3B,OAAO;GACT,GAAG,CAAC,CAAQ;GAEZ,MAAM,QAAA,GAAOC,UAAAA,QAAAA,CAAS,IAAI;GAC1B,KAAK,IAAA,OAAa,IAAI;EACxB;CACF;CAIA,KAAK,MAAM,OAAO;CAClB,KAAK,MAAM,SAAS;CACpB,KAAK,MAAM,iBAAiB;CAI5B,OAAO;EAAE,aADW,KAAK,IACN;EAAG;CAAO;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildPackageJson.js","names":[],"sources":["../../src/build-tests/buildPackageJson.ts"],"sourcesContent":["import editJsonFile from 'edit-json-file';\nimport sortKeys from 'sort-keys';\n\nimport type { Fn } from '#utils';\n\nimport { BIN_KEY, EXPORT_KEY, EXPORT_KEYS } from './constants';\nimport { getTypescriptOutdir } from './getTypescriptOutdir';\n\ntype BuldPackageJson_F = Fn<[], { packageJson: object; outDir: string }>;\n\n/**\n * Transforms `package.json` for packed distribution by adjusting paths and removing internal fields.\n *\n * @returns Object containing the modified `packageJson` and resolved `outDir`.\n */\nexport const buildPackageJson: BuldPackageJson_F = () => {\n const file = editJsonFile('./package.json');\n const outDir = getTypescriptOutdir();\n const lib = `${outDir}/`;\n const replaceLib = (str: string) => str.replace(lib, '');\n\n // #region Set export values\n EXPORT_KEYS.forEach(key => {\n const value = file.get(key);\n if (value) {\n const transformed = replaceLib(value);\n file.set(key, transformed);\n }\n });\n // #endregion\n\n // #region Set Export key\n const valueExports = file.get(EXPORT_KEY);\n\n if (valueExports) {\n const transformedExports = Object.entries(valueExports).reduce(\n (acc, [key, value]) => {\n const entries = Object.entries(value as any);\n const _value = entries.reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value as any);\n return acc;\n }, {} as any);\n acc[key] = key.includes('package.json') ? value : _value;\n return acc;\n },\n {} as any,\n );\n\n file.set(EXPORT_KEY, transformedExports);\n }\n // #endregion\n\n // #region Set bin\n const bin1 = file.get(BIN_KEY) as
|
|
1
|
+
{"version":3,"file":"buildPackageJson.js","names":[],"sources":["../../src/build-tests/buildPackageJson.ts"],"sourcesContent":["import editJsonFile from 'edit-json-file';\nimport sortKeys from 'sort-keys';\n\nimport type { Fn } from '#utils';\n\nimport { BIN_KEY, EXPORT_KEY, EXPORT_KEYS } from './constants';\nimport { getTypescriptOutdir } from './getTypescriptOutdir';\n\ntype BuldPackageJson_F = Fn<[], { packageJson: object; outDir: string }>;\n\n/**\n * Transforms `package.json` for packed distribution by adjusting paths and removing internal fields.\n *\n * @returns Object containing the modified `packageJson` and resolved `outDir`.\n */\nexport const buildPackageJson: BuldPackageJson_F = () => {\n const file = editJsonFile('./package.json');\n const outDir = getTypescriptOutdir();\n const lib = `${outDir}/`;\n const replaceLib = (str: string) => str.replace(lib, '');\n\n // #region Set export values\n EXPORT_KEYS.forEach(key => {\n const value = file.get(key);\n if (value) {\n const transformed = replaceLib(value);\n file.set(key, transformed);\n }\n });\n // #endregion\n\n // #region Set Export key\n const valueExports = file.get(EXPORT_KEY);\n\n if (valueExports) {\n const transformedExports = Object.entries(valueExports).reduce(\n (acc, [key, value]) => {\n const entries = Object.entries(value as any);\n const _value = entries.reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value as any);\n return acc;\n }, {} as any);\n acc[key] = key.includes('package.json') ? value : _value;\n return acc;\n },\n {} as any,\n );\n\n file.set(EXPORT_KEY, transformedExports);\n }\n // #endregion\n\n // #region Set bin\n const bin1 = file.get(BIN_KEY) as Record<string, string> | undefined | string;\n\n if (bin1) {\n if (typeof bin1 === 'string') {\n const bin2 = replaceLib(bin1);\n file.set(BIN_KEY, bin2);\n } else {\n const bin2 = Object.entries(bin1).reduce((acc, [key, value]) => {\n acc[key] = replaceLib(value);\n return acc;\n }, {} as any);\n\n const bin3 = sortKeys(bin2);\n file.set(BIN_KEY, bin3);\n }\n }\n // #endregion\n\n // #region Unset some props\n file.unset('files');\n file.unset('scripts');\n file.unset('devDependencies');\n // #endregion\n\n const packageJson = file.get();\n return { packageJson, outDir };\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,yBAA4C;CACvD,MAAM,OAAO,aAAa,gBAAgB;CAC1C,MAAM,SAAS,oBAAoB;CACnC,MAAM,MAAM,GAAG,OAAO;CACtB,MAAM,cAAc,QAAgB,IAAI,QAAQ,KAAK,EAAE;CAGvD,YAAY,SAAQ,QAAO;EACzB,MAAM,QAAQ,KAAK,IAAI,GAAG;EAC1B,IAAI,OAAO;GACT,MAAM,cAAc,WAAW,KAAK;GACpC,KAAK,IAAI,KAAK,WAAW;EAC3B;CACF,CAAC;CAID,MAAM,eAAe,KAAK,IAAI,UAAU;CAExC,IAAI,cAAc;EAChB,MAAM,qBAAqB,OAAO,QAAQ,YAAY,CAAC,CAAC,QACrD,KAAK,CAAC,KAAK,WAAW;GAErB,MAAM,SADU,OAAO,QAAQ,KACV,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;IACnD,IAAI,OAAO,WAAW,KAAY;IAClC,OAAO;GACT,GAAG,CAAC,CAAQ;GACZ,IAAI,OAAO,IAAI,SAAS,cAAc,IAAI,QAAQ;GAClD,OAAO;EACT,GACA,CAAC,CACH;EAEA,KAAK,IAAI,YAAY,kBAAkB;CACzC;CAIA,MAAM,OAAO,KAAK,IAAA,KAAW;CAE7B,IAAI,MAAM;EACR,IAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,OAAO,WAAW,IAAI;GAC5B,KAAK,IAAA,OAAa,IAAI;EACxB,OAAO;GACL,MAAM,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,WAAW;IAC9D,IAAI,OAAO,WAAW,KAAK;IAC3B,OAAO;GACT,GAAG,CAAC,CAAQ;GAEZ,MAAM,OAAO,SAAS,IAAI;GAC1B,KAAK,IAAA,OAAa,IAAI;EACxB;CACF;CAIA,KAAK,MAAM,OAAO;CAClB,KAAK,MAAM,SAAS;CACpB,KAAK,MAAM,iBAAiB;CAI5B,OAAO;EAAE,aADW,KAAK,IACN;EAAG;CAAO;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.cjs","names":["command","flag","addTarball","sh"],"sources":["../../../src/build-tests/cli/test.ts"],"sourcesContent":["import { command, flag } from 'cmd-ts';\nimport sh from 'shelljs';\n\nimport { addTarball } from '../addTarball';\nimport { cleanup } from '../cleanup';\n\n/**\n * CLI command to execute tests with optional lifecycle hooks (pre/post).\n */\nexport const test = command({\n name: 'test',\n\n args: {\n pretest: flag({
|
|
1
|
+
{"version":3,"file":"test.cjs","names":["command","flag","addTarball","sh"],"sources":["../../../src/build-tests/cli/test.ts"],"sourcesContent":["import { command, flag } from 'cmd-ts';\nimport sh from 'shelljs';\n\nimport { addTarball } from '../addTarball';\nimport { cleanup } from '../cleanup';\n\n/**\n * CLI command to execute tests with optional lifecycle hooks (pre/post).\n */\nexport const test = command({\n name: 'test',\n\n args: {\n pretest: flag({ description: 'The hook pretest', short: 'b', long: 'pretest' }),\n\n posttest: flag({\n description: 'The hook posttest',\n short: 'a',\n long: 'posttest',\n }),\n\n pre: flag({ description: 'The hook pretest', long: 'pre' }),\n\n post: flag({ description: 'The hook posttest', long: 'post' }),\n },\n\n // Ignores coverage because of recursivity\n /* v8 ignore next 11 */\n handler: async ({ pretest, posttest, pre, post }) => {\n if (pretest || pre) await addTarball();\n\n // #region Test\n const { stderr } = sh.exec('pnpm run test');\n if (!!stderr && stderr.trim() !== '') console.warn(stderr);\n // #endregion\n\n if (posttest || post) cleanup();\n },\n});\n"],"mappings":";;;;;;;;;;;AASA,MAAa,QAAA,GAAOA,OAAAA,QAAAA,CAAQ;CAC1B,MAAM;CAEN,MAAM;EACJ,UAAA,GAASC,OAAAA,KAAAA,CAAK;GAAE,aAAa;GAAoB,OAAO;GAAK,MAAM;EAAU,CAAC;EAE9E,WAAA,GAAUA,OAAAA,KAAAA,CAAK;GACb,aAAa;GACb,OAAO;GACP,MAAM;EACR,CAAC;EAED,MAAA,GAAKA,OAAAA,KAAAA,CAAK;GAAE,aAAa;GAAoB,MAAM;EAAM,CAAC;EAE1D,OAAA,GAAMA,OAAAA,KAAAA,CAAK;GAAE,aAAa;GAAqB,MAAM;EAAO,CAAC;CAC/D;;CAIA,SAAS,OAAO,EAAE,SAAS,UAAU,KAAK,WAAW;EACnD,IAAI,WAAW,KAAK,MAAMC,+BAAAA,WAAW;EAGrC,MAAM,EAAE,WAAWC,QAAAA,QAAG,KAAK,eAAe;EAC1C,IAAI,CAAC,CAAC,UAAU,OAAO,KAAK,MAAM,IAAI,QAAQ,KAAK,MAAM;EAGzD,IAAI,YAAY,MAAM,4BAAA,QAAQ;CAChC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","names":[],"sources":["../../../src/build-tests/cli/test.ts"],"sourcesContent":["import { command, flag } from 'cmd-ts';\nimport sh from 'shelljs';\n\nimport { addTarball } from '../addTarball';\nimport { cleanup } from '../cleanup';\n\n/**\n * CLI command to execute tests with optional lifecycle hooks (pre/post).\n */\nexport const test = command({\n name: 'test',\n\n args: {\n pretest: flag({
|
|
1
|
+
{"version":3,"file":"test.js","names":[],"sources":["../../../src/build-tests/cli/test.ts"],"sourcesContent":["import { command, flag } from 'cmd-ts';\nimport sh from 'shelljs';\n\nimport { addTarball } from '../addTarball';\nimport { cleanup } from '../cleanup';\n\n/**\n * CLI command to execute tests with optional lifecycle hooks (pre/post).\n */\nexport const test = command({\n name: 'test',\n\n args: {\n pretest: flag({ description: 'The hook pretest', short: 'b', long: 'pretest' }),\n\n posttest: flag({\n description: 'The hook posttest',\n short: 'a',\n long: 'posttest',\n }),\n\n pre: flag({ description: 'The hook pretest', long: 'pre' }),\n\n post: flag({ description: 'The hook posttest', long: 'post' }),\n },\n\n // Ignores coverage because of recursivity\n /* v8 ignore next 11 */\n handler: async ({ pretest, posttest, pre, post }) => {\n if (pretest || pre) await addTarball();\n\n // #region Test\n const { stderr } = sh.exec('pnpm run test');\n if (!!stderr && stderr.trim() !== '') console.warn(stderr);\n // #endregion\n\n if (posttest || post) cleanup();\n },\n});\n"],"mappings":";;;;;;;;AASA,MAAa,OAAO,QAAQ;CAC1B,MAAM;CAEN,MAAM;EACJ,SAAS,KAAK;GAAE,aAAa;GAAoB,OAAO;GAAK,MAAM;EAAU,CAAC;EAE9E,UAAU,KAAK;GACb,aAAa;GACb,OAAO;GACP,MAAM;EACR,CAAC;EAED,KAAK,KAAK;GAAE,aAAa;GAAoB,MAAM;EAAM,CAAC;EAE1D,MAAM,KAAK;GAAE,aAAa;GAAqB,MAAM;EAAO,CAAC;CAC/D;;CAIA,SAAS,OAAO,EAAE,SAAS,UAAU,KAAK,WAAW;EACnD,IAAI,WAAW,KAAK,MAAM,WAAW;EAGrC,MAAM,EAAE,WAAW,GAAG,KAAK,eAAe;EAC1C,IAAI,CAAC,CAAC,UAAU,OAAO,KAAK,MAAM,IAAI,QAAQ,KAAK,MAAM;EAGzD,IAAI,YAAY,MAAM,QAAQ;CAChC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTypescriptOutdir.cjs","names":["editJsonFile","resolve","TS_PATH"],"sources":["../../src/build-tests/getTypescriptOutdir.ts"],"sourcesContent":["import { resolve } from 'path';\n\nimport editJsonFile, { type JsonEditor } from 'edit-json-file';\n\nimport type { Fn } from '#utils/types';\n\nimport { DEFAULT_OUT_DIR, DOT, PATH_OUT_DIR, TS_PATH } from './constants';\n\ntype Fn1 = Fn<[], string>;\n\n/**\n * Resolves the TypeScript output directory specified in `tsconfig.json`.\n *\n * @returns Output directory path string without leading `./`.\n */\nexport const getTypescriptOutdir: Fn1 = () => {\n let file: JsonEditor | undefined = editJsonFile(
|
|
1
|
+
{"version":3,"file":"getTypescriptOutdir.cjs","names":["editJsonFile","resolve","TS_PATH"],"sources":["../../src/build-tests/getTypescriptOutdir.ts"],"sourcesContent":["import { resolve } from 'path';\n\nimport editJsonFile, { type JsonEditor } from 'edit-json-file';\n\nimport type { Fn } from '#utils/types';\n\nimport { DEFAULT_OUT_DIR, DOT, PATH_OUT_DIR, TS_PATH } from './constants';\n\ntype Fn1 = Fn<[], string>;\n\n/**\n * Resolves the TypeScript output directory specified in `tsconfig.json`.\n *\n * @returns Output directory path string without leading `./`.\n */\nexport const getTypescriptOutdir: Fn1 = () => {\n let file: JsonEditor | undefined = editJsonFile(resolve(process.cwd(), TS_PATH));\n\n const outDir1 = file.get(PATH_OUT_DIR) ?? DEFAULT_OUT_DIR;\n /* v8 ignore next 3 */\n const outDir2 = outDir1.startsWith(DOT) ? outDir1.replace(DOT, '') : outDir1;\n\n file = undefined;\n return outDir2;\n};\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,4BAAiC;CAC5C,IAAI,QAAA,GAA+BA,eAAAA,QAAAA,EAAAA,GAAaC,KAAAA,QAAAA,CAAQ,QAAQ,IAAI,GAAGC,8BAAAA,OAAO,CAAC;CAE/E,MAAM,UAAU,KAAK,IAAA,wBAAgB,KAAA;;CAErC,MAAM,UAAU,QAAQ,WAAA,IAAc,IAAI,QAAQ,QAAA,MAAa,EAAE,IAAI;CAErE,OAAO,KAAA;CACP,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTypescriptOutdir.js","names":[],"sources":["../../src/build-tests/getTypescriptOutdir.ts"],"sourcesContent":["import { resolve } from 'path';\n\nimport editJsonFile, { type JsonEditor } from 'edit-json-file';\n\nimport type { Fn } from '#utils/types';\n\nimport { DEFAULT_OUT_DIR, DOT, PATH_OUT_DIR, TS_PATH } from './constants';\n\ntype Fn1 = Fn<[], string>;\n\n/**\n * Resolves the TypeScript output directory specified in `tsconfig.json`.\n *\n * @returns Output directory path string without leading `./`.\n */\nexport const getTypescriptOutdir: Fn1 = () => {\n let file: JsonEditor | undefined = editJsonFile(
|
|
1
|
+
{"version":3,"file":"getTypescriptOutdir.js","names":[],"sources":["../../src/build-tests/getTypescriptOutdir.ts"],"sourcesContent":["import { resolve } from 'path';\n\nimport editJsonFile, { type JsonEditor } from 'edit-json-file';\n\nimport type { Fn } from '#utils/types';\n\nimport { DEFAULT_OUT_DIR, DOT, PATH_OUT_DIR, TS_PATH } from './constants';\n\ntype Fn1 = Fn<[], string>;\n\n/**\n * Resolves the TypeScript output directory specified in `tsconfig.json`.\n *\n * @returns Output directory path string without leading `./`.\n */\nexport const getTypescriptOutdir: Fn1 = () => {\n let file: JsonEditor | undefined = editJsonFile(resolve(process.cwd(), TS_PATH));\n\n const outDir1 = file.get(PATH_OUT_DIR) ?? DEFAULT_OUT_DIR;\n /* v8 ignore next 3 */\n const outDir2 = outDir1.startsWith(DOT) ? outDir1.replace(DOT, '') : outDir1;\n\n file = undefined;\n return outDir2;\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,4BAAiC;CAC5C,IAAI,OAA+B,aAAa,QAAQ,QAAQ,IAAI,GAAG,OAAO,CAAC;CAE/E,MAAM,UAAU,KAAK,IAAA,wBAAgB,KAAA;;CAErC,MAAM,UAAU,QAAQ,WAAA,IAAc,IAAI,QAAQ,QAAA,MAAa,EAAE,IAAI;CAErE,OAAO,KAAA;CACP,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.cjs","names":["helperFn","toStringFlat"],"sources":["../../../src/build-tests/imports/create.ts"],"sourcesContent":["import { describe, test } from 'vitest';\n\nimport { toStringFlat } from '../../vitest-extended/toStringFlat';\nimport { helperFn } from './helper';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type ImportArgs = {
|
|
1
|
+
{"version":3,"file":"create.cjs","names":["helperFn","toStringFlat"],"sources":["../../../src/build-tests/imports/create.ts"],"sourcesContent":["import { describe, test } from 'vitest';\n\nimport { toStringFlat } from '../../vitest-extended/toStringFlat';\nimport { helperFn } from './helper';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type ImportArgs = { path?: string; FAILS?: string[]; SUCCESS: string[] };\n\n/**\n * Function type creating import test suites.\n */\nexport type CreateImportTest_F = (args: ImportArgs) => readonly [string, () => void];\n\n/**\n * Creates Vitest test suites verifying that symbols are properly exported from a module.\n *\n * @param args - Import test arguments of type {@linkcode ImportArgs}.\n *\n * @returns Tuple of test description and test runner function.\n */\nexport const createImportFnTests: CreateImportTest_F = args => {\n const path = args.path;\n const invite = `Importing from ${path ?? 'index'}`;\n const testFn = (fn: string) => helperFn({ path, fn });\n\n const fn = () => {\n describe.skipIf(args.SUCCESS.length < 1)(\n '#01 => Functions are inside the module',\n () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.SUCCESS.length);\n };\n\n args.SUCCESS.forEach((fn, index) => {\n test(`#${_index(index)} => should succeed with function ${fn}`, () => {\n return testFn(fn);\n });\n });\n },\n );\n\n if (!args.FAILS || args.FAILS.length < 1) return;\n\n describe('#02 => Functions are not inside the module', () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.FAILS!.length);\n };\n\n args.FAILS!.forEach((fn, index) => {\n test.fails(`#${_index(index)} => should fail with function ${fn}`, () => {\n return testFn(fn);\n });\n });\n });\n };\n\n return [invite, fn] as const;\n};\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAa,uBAA0C,SAAQ;CAC7D,MAAM,OAAO,KAAK;CAClB,MAAM,SAAS,kBAAkB,QAAQ;CACzC,MAAM,UAAU,OAAeA,mCAAAA,SAAS;EAAE;EAAM;CAAG,CAAC;CAEpD,MAAM,WAAW;EACf,OAAA,SAAS,OAAO,KAAK,QAAQ,SAAS,CAAC,CAAC,CACtC,gDACM;GACJ,MAAM,UAAU,UAAkB;IAChC,OAAOC,qCAAAA,aAAa,QAAQ,GAAG,KAAK,QAAQ,MAAM;GACpD;GAEA,KAAK,QAAQ,SAAS,IAAI,UAAU;IAClC,CAAA,GAAA,OAAA,KAAA,CAAK,IAAI,OAAO,KAAK,EAAE,mCAAmC,YAAY;KACpE,OAAO,OAAO,EAAE;IAClB,CAAC;GACH,CAAC;EACH,CACF;EAEA,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,SAAS,GAAG;EAE1C,CAAA,GAAA,OAAA,SAAA,CAAS,oDAAoD;GAC3D,MAAM,UAAU,UAAkB;IAChC,OAAOA,qCAAAA,aAAa,QAAQ,GAAG,KAAK,MAAO,MAAM;GACnD;GAEA,KAAK,MAAO,SAAS,IAAI,UAAU;IACjC,OAAA,KAAK,MAAM,IAAI,OAAO,KAAK,EAAE,gCAAgC,YAAY;KACvE,OAAO,OAAO,EAAE;IAClB,CAAC;GACH,CAAC;EACH,CAAC;CACH;CAEA,OAAO,CAAC,QAAQ,EAAE;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","names":[],"sources":["../../../src/build-tests/imports/create.ts"],"sourcesContent":["import { describe, test } from 'vitest';\n\nimport { toStringFlat } from '../../vitest-extended/toStringFlat';\nimport { helperFn } from './helper';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type ImportArgs = {
|
|
1
|
+
{"version":3,"file":"create.js","names":[],"sources":["../../../src/build-tests/imports/create.ts"],"sourcesContent":["import { describe, test } from 'vitest';\n\nimport { toStringFlat } from '../../vitest-extended/toStringFlat';\nimport { helperFn } from './helper';\n\n/**\n * Options defining expected exported and non-exported symbols.\n */\nexport type ImportArgs = { path?: string; FAILS?: string[]; SUCCESS: string[] };\n\n/**\n * Function type creating import test suites.\n */\nexport type CreateImportTest_F = (args: ImportArgs) => readonly [string, () => void];\n\n/**\n * Creates Vitest test suites verifying that symbols are properly exported from a module.\n *\n * @param args - Import test arguments of type {@linkcode ImportArgs}.\n *\n * @returns Tuple of test description and test runner function.\n */\nexport const createImportFnTests: CreateImportTest_F = args => {\n const path = args.path;\n const invite = `Importing from ${path ?? 'index'}`;\n const testFn = (fn: string) => helperFn({ path, fn });\n\n const fn = () => {\n describe.skipIf(args.SUCCESS.length < 1)(\n '#01 => Functions are inside the module',\n () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.SUCCESS.length);\n };\n\n args.SUCCESS.forEach((fn, index) => {\n test(`#${_index(index)} => should succeed with function ${fn}`, () => {\n return testFn(fn);\n });\n });\n },\n );\n\n if (!args.FAILS || args.FAILS.length < 1) return;\n\n describe('#02 => Functions are not inside the module', () => {\n const _index = (index: number) => {\n return toStringFlat(index + 1, args.FAILS!.length);\n };\n\n args.FAILS!.forEach((fn, index) => {\n test.fails(`#${_index(index)} => should fail with function ${fn}`, () => {\n return testFn(fn);\n });\n });\n });\n };\n\n return [invite, fn] as const;\n};\n"],"mappings":";;;;;;;;;;;AAsBA,MAAa,uBAA0C,SAAQ;CAC7D,MAAM,OAAO,KAAK;CAClB,MAAM,SAAS,kBAAkB,QAAQ;CACzC,MAAM,UAAU,OAAe,SAAS;EAAE;EAAM;CAAG,CAAC;CAEpD,MAAM,WAAW;EACf,SAAS,OAAO,KAAK,QAAQ,SAAS,CAAC,CAAC,CACtC,gDACM;GACJ,MAAM,UAAU,UAAkB;IAChC,OAAO,aAAa,QAAQ,GAAG,KAAK,QAAQ,MAAM;GACpD;GAEA,KAAK,QAAQ,SAAS,IAAI,UAAU;IAClC,KAAK,IAAI,OAAO,KAAK,EAAE,mCAAmC,YAAY;KACpE,OAAO,OAAO,EAAE;IAClB,CAAC;GACH,CAAC;EACH,CACF;EAEA,IAAI,CAAC,KAAK,SAAS,KAAK,MAAM,SAAS,GAAG;EAE1C,SAAS,oDAAoD;GAC3D,MAAM,UAAU,UAAkB;IAChC,OAAO,aAAa,QAAQ,GAAG,KAAK,MAAO,MAAM;GACnD;GAEA,KAAK,MAAO,SAAS,IAAI,UAAU;IACjC,KAAK,MAAM,IAAI,OAAO,KAAK,EAAE,gCAAgC,YAAY;KACvE,OAAO,OAAO,EAAE;IAClB,CAAC;GACH,CAAC;EACH,CAAC;CACH;CAEA,OAAO,CAAC,QAAQ,EAAE;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.cjs","names":["customImport"],"sources":["../../../src/build-tests/imports/helper.ts"],"sourcesContent":["import { expect } from 'vitest';\n\nimport type { Fn } from '../../utils/bemedev/globals/types';\nimport { customImport } from '../import';\n\n/**\n * Helper function type for verifying exported functions.\n */\nexport type Helper_F = (args: {
|
|
1
|
+
{"version":3,"file":"helper.cjs","names":["customImport"],"sources":["../../../src/build-tests/imports/helper.ts"],"sourcesContent":["import { expect } from 'vitest';\n\nimport type { Fn } from '../../utils/bemedev/globals/types';\nimport { customImport } from '../import';\n\n/**\n * Helper function type for verifying exported functions.\n */\nexport type Helper_F = (args: { path?: string; fn: string }) => Promise<void>;\n\n/**\n * Asserts that a specified function is defined and exported from a module.\n *\n * @template | {@linkcode Fn} `T` - Expected function type.\n *\n * @param args - Options object.\n * @param args.path - Submodule path to import from.\n * @param args.fn - Named export function name.\n */\nexport const helperFn = async <T extends Fn = Fn>({\n path,\n fn,\n}: {\n path?: string;\n fn: string;\n}) => {\n const _fn = await customImport<T>({ path, fn: m => m[fn] });\n expect(_fn).toBeDefined();\n expect(_fn).toBeTypeOf('function');\n};\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAa,WAAW,OAA0B,EAChD,MACA,SAII;CACJ,MAAM,MAAM,MAAMA,2BAAAA,aAAgB;EAAE;EAAM,KAAI,MAAK,EAAE;CAAI,CAAC;CAC1D,CAAA,GAAA,OAAA,OAAA,CAAO,GAAG,CAAC,CAAC,YAAY;CACxB,CAAA,GAAA,OAAA,OAAA,CAAO,GAAG,CAAC,CAAC,WAAW,UAAU;AACnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","names":[],"sources":["../../../src/build-tests/imports/helper.ts"],"sourcesContent":["import { expect } from 'vitest';\n\nimport type { Fn } from '../../utils/bemedev/globals/types';\nimport { customImport } from '../import';\n\n/**\n * Helper function type for verifying exported functions.\n */\nexport type Helper_F = (args: {
|
|
1
|
+
{"version":3,"file":"helper.js","names":[],"sources":["../../../src/build-tests/imports/helper.ts"],"sourcesContent":["import { expect } from 'vitest';\n\nimport type { Fn } from '../../utils/bemedev/globals/types';\nimport { customImport } from '../import';\n\n/**\n * Helper function type for verifying exported functions.\n */\nexport type Helper_F = (args: { path?: string; fn: string }) => Promise<void>;\n\n/**\n * Asserts that a specified function is defined and exported from a module.\n *\n * @template | {@linkcode Fn} `T` - Expected function type.\n *\n * @param args - Options object.\n * @param args.path - Submodule path to import from.\n * @param args.fn - Named export function name.\n */\nexport const helperFn = async <T extends Fn = Fn>({\n path,\n fn,\n}: {\n path?: string;\n fn: string;\n}) => {\n const _fn = await customImport<T>({ path, fn: m => m[fn] });\n expect(_fn).toBeDefined();\n expect(_fn).toBeTypeOf('function');\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,WAAW,OAA0B,EAChD,MACA,SAII;CACJ,MAAM,MAAM,MAAM,aAAgB;EAAE;EAAM,KAAI,MAAK,EAAE;CAAI,CAAC;CAC1D,OAAO,GAAG,CAAC,CAAC,YAAY;CACxB,OAAO,GAAG,CAAC,CAAC,WAAW,UAAU;AACnC"}
|
package/lib/plugins/hmr.cjs
CHANGED
|
@@ -4,54 +4,42 @@ const require_utils_array = require("../utils/array.cjs");
|
|
|
4
4
|
let path = require("path");
|
|
5
5
|
let child_process = require("child_process");
|
|
6
6
|
//#region src/plugins/hmr.ts
|
|
7
|
-
/**
|
|
8
|
-
* Normalizes backslashes in a file path to forward slashes.
|
|
9
|
-
*
|
|
10
|
-
* @param path - File path to normalize.
|
|
11
|
-
*
|
|
12
|
-
* @returns Normalized path string.
|
|
13
|
-
*/
|
|
14
7
|
const normalizePath = (path$1) => path$1.replace(/\\/g, "/");
|
|
15
|
-
/**
|
|
16
|
-
* Vite plugin providing Hot Module Reloading (HMR) capabilities for external
|
|
17
|
-
* file paths by watching files and executing build scripts on changes.
|
|
18
|
-
*
|
|
19
|
-
* @param props - Configuration properties of type {@linkcode HmrPluginProps}.
|
|
20
|
-
*
|
|
21
|
-
* @returns A Vite plugin object of type {@linkcode Plugin}.
|
|
22
|
-
*/
|
|
23
8
|
const hmr = (props) => {
|
|
24
9
|
let isBuilding = false;
|
|
25
10
|
const debounce = require_utils_clamp.clamp(props?.debounce ?? 500, 500, 1e4);
|
|
26
|
-
const
|
|
11
|
+
const pathMap = /* @__PURE__ */ new Map();
|
|
27
12
|
let isDev = false;
|
|
28
13
|
return {
|
|
29
14
|
name: "hmr-add-on",
|
|
30
15
|
configResolved(config) {
|
|
31
16
|
isDev = !config.isProduction;
|
|
32
17
|
if (!isDev) return;
|
|
33
|
-
|
|
34
|
-
paths
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
pathMap.clear();
|
|
19
|
+
const rawPaths = props?.paths ?? {};
|
|
20
|
+
Object.entries(rawPaths).forEach(([pathKey, rawScripts]) => {
|
|
21
|
+
const resolved = (0, path.isAbsolute)(pathKey) ? pathKey : (0, path.resolve)(config.root, pathKey);
|
|
22
|
+
const normalized = normalizePath(resolved);
|
|
23
|
+
const scripts = require_utils_array.toArray(rawScripts);
|
|
24
|
+
pathMap.set(normalized, scripts);
|
|
25
|
+
});
|
|
38
26
|
},
|
|
39
27
|
configureServer(server) {
|
|
40
28
|
if (!isDev) return;
|
|
41
|
-
server.watcher.add(
|
|
29
|
+
server.watcher.add(Array.from(pathMap.keys()));
|
|
42
30
|
},
|
|
43
31
|
handleHotUpdate(ctx) {
|
|
44
32
|
if (!isDev) return;
|
|
45
33
|
if (isBuilding) return ctx.modules;
|
|
46
34
|
const normalizedFile = normalizePath(ctx.file);
|
|
47
|
-
|
|
35
|
+
const matchingScripts = /* @__PURE__ */ new Set();
|
|
36
|
+
for (const [watchedPath, scripts] of pathMap.entries()) if (normalizedFile.includes(watchedPath)) scripts.forEach(matchingScripts.add);
|
|
37
|
+
if (matchingScripts.size > 0) {
|
|
48
38
|
console.log(`\n⚡ External file modified: ${ctx.file}. Starting build...`);
|
|
49
39
|
try {
|
|
50
40
|
isBuilding = true;
|
|
51
|
-
require_utils_array.toArray(props?.scripts).forEach((script) => {
|
|
52
|
-
(0, child_process.execSync)(script, { stdio: "inherit" });
|
|
53
|
-
});
|
|
54
41
|
ctx.server.moduleGraph.invalidateAll();
|
|
42
|
+
matchingScripts.forEach((script) => (0, child_process.execSync)(script, { stdio: "inherit" }));
|
|
55
43
|
ctx.server.ws.send({ type: "full-reload" });
|
|
56
44
|
} catch (error) {
|
|
57
45
|
console.error("❌ Command execution failed during HMR:", error);
|
package/lib/plugins/hmr.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.cjs","names":["path","clamp","
|
|
1
|
+
{"version":3,"file":"hmr.cjs","names":["path","clamp","isAbsolute","resolve","toArray","execSync"],"sources":["../../src/plugins/hmr.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport { isAbsolute, resolve } from 'path';\n\nimport { type Plugin } from 'vitest/config';\n\nimport { toArray } from '#utils/array';\nimport { clamp } from '#utils/clamp';\nimport type { SoA } from '#utils/types';\n\nexport type HmrPluginProps = {\n /**\n * Map of watched file/directory paths to one or many shell commands to execute\n * when changes are detected.\n */\n paths?: Record<string, SoA<string>>;\n\n /** Optional interval in milliseconds to wait before allowing another build. */\n debounce?: number;\n};\n\nconst normalizePath = (path: string) => path.replace(/\\\\/g, '/');\n\nexport const hmr = (props?: HmrPluginProps): Plugin => {\n // Lock variable to prevent infinite build loops\n let isBuilding = false;\n const debounce = clamp(props?.debounce ?? 500, 500, 10_000);\n const pathMap = new Map<string, string[]>();\n let isDev = false;\n\n return {\n name: 'hmr-add-on',\n\n configResolved(config) {\n isDev = !config.isProduction;\n if (!isDev) return;\n\n pathMap.clear();\n const rawPaths = props?.paths ?? {};\n\n Object.entries(rawPaths).forEach(([pathKey, rawScripts]) => {\n const resolved = isAbsolute(pathKey)\n ? pathKey\n : resolve(config.root, pathKey);\n\n const normalized = normalizePath(resolved);\n const scripts = toArray(rawScripts);\n pathMap.set(normalized, scripts);\n });\n },\n\n configureServer(server) {\n if (!isDev) return;\n\n server.watcher.add(Array.from(pathMap.keys()));\n },\n\n handleHotUpdate(ctx) {\n if (!isDev) return;\n\n // 1. If a build is already in progress, ignore ALL changes (prevents loops)\n if (isBuilding) return ctx.modules;\n const normalizedFile = normalizePath(ctx.file);\n\n // Find all matching path entries for the changed file\n const matchingScripts = new Set<string>();\n for (const [watchedPath, scripts] of pathMap.entries()) {\n if (normalizedFile.includes(watchedPath)) {\n scripts.forEach(matchingScripts.add);\n }\n }\n\n if (matchingScripts.size > 0) {\n console.log(`\\n⚡ External file modified: ${ctx.file}. Starting build...`);\n\n try {\n // 2. Acquire lock before starting the build\n isBuilding = true;\n\n // Invalidate module graph so Vite reads fresh built files from disk\n ctx.server.moduleGraph.invalidateAll();\n matchingScripts.forEach(script => execSync(script, { stdio: 'inherit' }));\n ctx.server.ws.send({ type: 'full-reload' });\n } catch (error) {\n console.error('❌ Command execution failed during HMR:', error);\n } finally {\n // 3. Once build is complete, wait for the debounce period to allow\n // Vite to ignore generated build files, then release the lock.\n setTimeout(() => {\n isBuilding = false;\n console.log('✅ Build completed. Ready for subsequent changes.');\n }, debounce);\n }\n }\n\n return ctx.modules;\n },\n };\n};\n"],"mappings":";;;;;;AAoBA,MAAM,iBAAiB,WAAiBA,OAAK,QAAQ,OAAO,GAAG;AAE/D,MAAa,OAAO,UAAmC;CAErD,IAAI,aAAa;CACjB,MAAM,WAAWC,oBAAAA,MAAM,OAAO,YAAY,KAAK,KAAK,GAAM;CAC1D,MAAM,0BAAU,IAAI,IAAsB;CAC1C,IAAI,QAAQ;CAEZ,OAAO;EACL,MAAM;EAEN,eAAe,QAAQ;GACrB,QAAQ,CAAC,OAAO;GAChB,IAAI,CAAC,OAAO;GAEZ,QAAQ,MAAM;GACd,MAAM,WAAW,OAAO,SAAS,CAAC;GAElC,OAAO,QAAQ,QAAQ,CAAC,CAAC,SAAS,CAAC,SAAS,gBAAgB;IAC1D,MAAM,YAAA,GAAWC,KAAAA,WAAAA,CAAW,OAAO,IAC/B,WAAA,GACAC,KAAAA,QAAAA,CAAQ,OAAO,MAAM,OAAO;IAEhC,MAAM,aAAa,cAAc,QAAQ;IACzC,MAAM,UAAUC,oBAAAA,QAAQ,UAAU;IAClC,QAAQ,IAAI,YAAY,OAAO;GACjC,CAAC;EACH;EAEA,gBAAgB,QAAQ;GACtB,IAAI,CAAC,OAAO;GAEZ,OAAO,QAAQ,IAAI,MAAM,KAAK,QAAQ,KAAK,CAAC,CAAC;EAC/C;EAEA,gBAAgB,KAAK;GACnB,IAAI,CAAC,OAAO;GAGZ,IAAI,YAAY,OAAO,IAAI;GAC3B,MAAM,iBAAiB,cAAc,IAAI,IAAI;GAG7C,MAAM,kCAAkB,IAAI,IAAY;GACxC,KAAK,MAAM,CAAC,aAAa,YAAY,QAAQ,QAAQ,GACnD,IAAI,eAAe,SAAS,WAAW,GACrC,QAAQ,QAAQ,gBAAgB,GAAG;GAIvC,IAAI,gBAAgB,OAAO,GAAG;IAC5B,QAAQ,IAAI,+BAA+B,IAAI,KAAK,oBAAoB;IAExE,IAAI;KAEF,aAAa;KAGb,IAAI,OAAO,YAAY,cAAc;KACrC,gBAAgB,SAAQ,YAAA,GAAUC,cAAAA,SAAAA,CAAS,QAAQ,EAAE,OAAO,UAAU,CAAC,CAAC;KACxE,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;IAC5C,SAAS,OAAO;KACd,QAAQ,MAAM,0CAA0C,KAAK;IAC/D,UAAU;KAGR,iBAAiB;MACf,aAAa;MACb,QAAQ,IAAI,kDAAkD;KAChE,GAAG,QAAQ;IACb;GACF;GAEA,OAAO,IAAI;EACb;CACF;AACF"}
|
package/lib/plugins/hmr.d.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { type Plugin } from 'vitest/config';
|
|
2
2
|
import type { SoA } from '../utils/types';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for the HMR add-on plugin.
|
|
5
|
-
*/
|
|
6
3
|
export type HmrPluginProps = {
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Map of watched file/directory paths to one or many shell commands to execute
|
|
6
|
+
* when changes are detected.
|
|
7
|
+
*/
|
|
8
|
+
paths?: Record<string, SoA<string>>;
|
|
11
9
|
/** Optional interval in milliseconds to wait before allowing another build. */
|
|
12
10
|
debounce?: number;
|
|
13
11
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Vite plugin providing Hot Module Reloading (HMR) capabilities for external
|
|
16
|
-
* file paths by watching files and executing build scripts on changes.
|
|
17
|
-
*
|
|
18
|
-
* @param props - Configuration properties of type {@linkcode HmrPluginProps}.
|
|
19
|
-
*
|
|
20
|
-
* @returns A Vite plugin object of type {@linkcode Plugin}.
|
|
21
|
-
*/
|
|
22
12
|
export declare const hmr: (props?: HmrPluginProps) => Plugin;
|