diff --git a/packages/devtools/src/devframe.ts b/packages/devtools/src/devframe.ts index b2124a4a..ed4387ad 100644 --- a/packages/devtools/src/devframe.ts +++ b/packages/devtools/src/devframe.ts @@ -458,6 +458,8 @@ const pangular = defineDevframe({ name: 'pipe-lint', type: 'query', jsonSerializable: true, + // A source scan like get-pipes, so a static report bakes it in too. + snapshot: true, handler: () => lintPipes(ctx.cwd), }); diff --git a/packages/devtools/src/rpc/__tests__/static-dump.test.ts b/packages/devtools/src/rpc/__tests__/static-dump.test.ts index 6e9b1ab0..b858983f 100644 --- a/packages/devtools/src/rpc/__tests__/static-dump.test.ts +++ b/packages/devtools/src/rpc/__tests__/static-dump.test.ts @@ -1,7 +1,7 @@ -import { writeFileSync } from 'node:fs'; +import { mkdirSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { createHostContext } from 'devframe/node'; -import { collectStaticRpcDump } from 'devframe/rpc/dump'; +import { collectStaticRpcDump, createClientFromDump, dumpFunctions } from 'devframe/rpc/dump'; import { describe, expect, it } from 'vitest'; import pangular from '../../devframe.ts'; import { fixtureDir } from './fixture-dir.ts'; @@ -28,8 +28,33 @@ describe('static report dump', () => { 'get-providers', 'get-pipes', 'get-ngrx-store', + 'pipe-lint', ].map((name) => `pangular:${name}`), ), ); }); + + it('answers the Pipes lint from the report', async () => { + const cwd = fixtureDir('pangular-dump-lint-'); + writeFileSync(join(cwd, 'package.json'), '{}'); + mkdirSync(join(cwd, 'src')); + writeFileSync( + join(cwd, 'src', 'debug.component.ts'), + `@Component({ selector: 'app-debug', template: '{{ user | json }}' })\nexport class Debug {}\n`, + ); + const host = { + mountStatic: () => {}, + resolveOrigin: () => 'http://localhost', + getStorageDir: () => '', + }; + const ctx = await createHostContext({ cwd, mode: 'build', host: host as never }); + await pangular.setup(ctx as never); + const pipes = ['pangular:get-pipes', 'pangular:pipe-lint'].map((name) => + ctx.rpc.definitions.get(name)!, + ); + const store = await dumpFunctions(pipes, ctx); + const client = createClientFromDump(store) as Record Promise>; + const findings = (await client['pangular:pipe-lint']()) as { rule: string }[]; + expect(findings.map((finding) => finding.rule)).toEqual(['json-pipe-in-template']); + }); });