@dungarees/bin-audit-dependencies-cli-yargs 0.11.4

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/feature.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { AuditDependenciesBehavior } from '@dungarees/bin-audit-dependencies-domain/behavior.ts';
2
+ import type { AuditDependenciesEvent } from '@dungarees/bin-audit-dependencies-domain/events.ts';
3
+ import type { CliFeature } from '@dungarees/cli/feature.ts';
4
+ export declare const auditDependenciesFeature: ({ auditDependencies, }: {
5
+ auditDependencies: AuditDependenciesBehavior;
6
+ }) => CliFeature<AuditDependenciesEvent>;
package/feature.js ADDED
@@ -0,0 +1,6 @@
1
+ import { auditDependenciesPresenter } from './presenter.js';
2
+ import { auditDependenciesYargsModule } from './yargs-module.js';
3
+ export const auditDependenciesFeature = ({ auditDependencies, }) => ({
4
+ commands: [auditDependenciesYargsModule({ auditDependencies })],
5
+ presenter: auditDependenciesPresenter,
6
+ });
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@dungarees/bin-audit-dependencies-cli-yargs",
3
+ "engines": {
4
+ "node": ">=25.0.0"
5
+ },
6
+ "scripts": {
7
+ "type-check": "tsc --noEmit"
8
+ },
9
+ "type": "module",
10
+ "dependencies": {
11
+ "@dungarees/bin-audit-dependencies-domain": "*",
12
+ "@dungarees/cli": "*"
13
+ },
14
+ "devDependencies": {
15
+ "@dungarees/bin-fake-app-cli-yargs": "*",
16
+ "typescript": "^5.9.3",
17
+ "vitest": "^3.0.2"
18
+ },
19
+ "author": "info@productkind.com",
20
+ "license": "MIT",
21
+ "version": "0.11.4",
22
+ "exports": {
23
+ "./feature.ts": {
24
+ "import": "./feature.js",
25
+ "types": "./feature.d.ts"
26
+ },
27
+ "./presenter.test.ts": {
28
+ "import": "./presenter.test.js",
29
+ "types": "./presenter.test.d.ts"
30
+ },
31
+ "./presenter.ts": {
32
+ "import": "./presenter.js",
33
+ "types": "./presenter.d.ts"
34
+ },
35
+ "./yargs-module.test.ts": {
36
+ "import": "./yargs-module.test.js",
37
+ "types": "./yargs-module.test.d.ts"
38
+ },
39
+ "./yargs-module.ts": {
40
+ "import": "./yargs-module.js",
41
+ "types": "./yargs-module.d.ts"
42
+ }
43
+ }
44
+ }
package/presenter.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { AuditDependenciesEvent } from '@dungarees/bin-audit-dependencies-domain/events.ts';
2
+ import type { Presenter } from '@dungarees/cli/yargs-prompt-app.ts';
3
+ export declare const auditDependenciesPresenter: Presenter<AuditDependenciesEvent>;
package/presenter.js ADDED
@@ -0,0 +1,13 @@
1
+ import { exit, stderr, stdout } from '@dungarees/cli/utils.ts';
2
+ const describeFindings = ({ name, missing, unused, }) => [
3
+ name,
4
+ ...(missing.length === 0 ? [] : [` missing: ${missing.join(', ')}`]),
5
+ ...(unused.length === 0 ? [] : [` unused: ${unused.join(', ')}`]),
6
+ ].join('\n');
7
+ export const auditDependenciesPresenter = {
8
+ 'audit-start': ({ dir }) => stdout(`Auditing dependencies in ${dir}`),
9
+ 'package-findings': (findings) => stderr(describeFindings(findings)),
10
+ 'audit-passed': ({ packageCount }) => stdout(`${packageCount} packages audited, no findings`),
11
+ // Non-zero so the command can gate a build the way the old script did.
12
+ 'audit-failed': () => exit(1),
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { auditDependenciesPresenter } from './presenter.js';
2
+ import { expect, test } from 'vitest';
3
+ test('audit-start maps to an info stdout message', () => {
4
+ expect(auditDependenciesPresenter['audit-start']({ dir: '/repo' })).toEqual({
5
+ type: 'stdout',
6
+ level: 'info',
7
+ message: 'Auditing dependencies in /repo',
8
+ });
9
+ });
10
+ test('package-findings lists both kinds on stderr', () => {
11
+ expect(auditDependenciesPresenter['package-findings']({
12
+ name: '@org/a',
13
+ missing: ['rxjs', 'zod'],
14
+ unused: ['react'],
15
+ })).toEqual({
16
+ type: 'stderr',
17
+ level: 'error',
18
+ message: '@org/a\n missing: rxjs, zod\n unused: react',
19
+ });
20
+ });
21
+ test('package-findings omits a kind that is empty', () => {
22
+ expect(auditDependenciesPresenter['package-findings']({
23
+ name: '@org/a',
24
+ missing: ['rxjs'],
25
+ unused: [],
26
+ })).toEqual({
27
+ type: 'stderr',
28
+ level: 'error',
29
+ message: '@org/a\n missing: rxjs',
30
+ });
31
+ });
32
+ test('audit-passed reports how many packages were checked', () => {
33
+ expect(auditDependenciesPresenter['audit-passed']({ packageCount: 17 })).toEqual({
34
+ type: 'stdout',
35
+ level: 'info',
36
+ message: '17 packages audited, no findings',
37
+ });
38
+ });
39
+ test('audit-failed exits non-zero so the audit can gate a build', () => {
40
+ expect(auditDependenciesPresenter['audit-failed']({ packageCount: 17 })).toEqual({
41
+ type: 'exit',
42
+ code: 1,
43
+ });
44
+ });
@@ -0,0 +1,6 @@
1
+ import type { AuditDependenciesBehavior } from '@dungarees/bin-audit-dependencies-domain/behavior.ts';
2
+ import type { AuditDependenciesEvent } from '@dungarees/bin-audit-dependencies-domain/events.ts';
3
+ import { type CommandFactory } from '@dungarees/cli/yargs-prompt-app.ts';
4
+ export declare const auditDependenciesYargsModule: ({ auditDependencies, }: {
5
+ auditDependencies: AuditDependenciesBehavior;
6
+ }) => CommandFactory<AuditDependenciesEvent>;
@@ -0,0 +1,12 @@
1
+ import { createCommand } from '@dungarees/cli/yargs-prompt-app.ts';
2
+ export const auditDependenciesYargsModule = ({ auditDependencies, }) => (io) => createCommand({
3
+ command: 'audit-dependencies [lib-path]',
4
+ describe: "Compare each package's imports against its declared dependencies",
5
+ builder: (yargs) => yargs.positional('lib-path', {
6
+ type: 'string',
7
+ default: '.',
8
+ }),
9
+ handler: ({ libPath }) => {
10
+ io.registerEvents(auditDependencies.auditDependencies({ dir: libPath }).events$);
11
+ },
12
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { createTestApp } from '@dungarees/bin-fake-app-cli-yargs/test-app.ts';
2
+ import { renderCli } from '@dungarees/cli/test-renderer.ts';
3
+ import { expect, test } from 'vitest';
4
+ test('audit-dependencies reports a clean tree and exits 0', async () => {
5
+ const { app } = createTestApp({
6
+ files: {
7
+ '/repo/src/a/package.json': JSON.stringify({
8
+ name: '@org/a',
9
+ dependencies: { rxjs: '^7.8.1' },
10
+ }),
11
+ '/repo/src/a/index.ts': "import { of } from 'rxjs'\n",
12
+ },
13
+ });
14
+ const { terminal } = renderCli(app, 'dungarees audit-dependencies /repo');
15
+ expect(await terminal.step()).toEqual([
16
+ { type: 'stdout', message: 'Auditing dependencies in /repo', level: 'info' },
17
+ { type: 'stdout', message: '1 packages audited, no findings', level: 'info' },
18
+ { type: 'exit', code: 0 },
19
+ ]);
20
+ });
21
+ test('audit-dependencies reports an undeclared import and exits 1', async () => {
22
+ const { app } = createTestApp({
23
+ files: {
24
+ '/repo/src/a/package.json': JSON.stringify({ name: '@org/a' }),
25
+ '/repo/src/a/index.ts': "import { of } from 'rxjs'\n",
26
+ },
27
+ });
28
+ const { terminal } = renderCli(app, 'dungarees audit-dependencies /repo');
29
+ expect(await terminal.step()).toEqual([
30
+ { type: 'stdout', message: 'Auditing dependencies in /repo', level: 'info' },
31
+ { type: 'stderr', message: '@org/a\n missing: rxjs', level: 'error' },
32
+ { type: 'exit', code: 1 },
33
+ ]);
34
+ });