From 744ed1fcf8f2f3228177698fc81fc64d1648110e Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Mon, 10 Feb 2025 12:06:10 -0600 Subject: [PATCH] fix(vite-plugin-angular): remove check for Vitest command in watch mode (#1606) --- .prettierignore | 1 + .prettierrc | 1 + apps/analog-app/index.html | 2 +- .../src/app/pages/newsletter.page.ts | 37 ++++++++-------- apps/analog-app/src/app/pages/search.page.ts | 2 +- apps/blog-app/index.html | 2 +- apps/docs-app/docs/guides/forms.md | 39 ++++++++-------- apps/ng-app/index.html | 2 +- apps/trpc-app/index.html | 2 +- .../autocomplete/autocomplete.component.html | 2 +- packages/router/src/lib/debug/debug.page.ts | 20 ++++----- packages/router/src/lib/server.component.ts | 2 +- .../trpc/src/lib/client/shared-internal.ts | 44 +++++++++---------- .../trpc/src/lib/client/trpc-rxjs-proxy.ts | 12 ++--- .../src/lib/angular-vite-plugin.spec.ts | 20 +++------ .../src/lib/angular-vite-plugin.ts | 32 +++++--------- .../src/lib/authoring/analog.ts | 4 +- .../src/lib/component-resolvers.ts | 4 +- packages/vite-plugin-nitro/README.md | 2 +- 19 files changed, 108 insertions(+), 122 deletions(-) diff --git a/.prettierignore b/.prettierignore index 00b299c77..580b071c0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,3 +10,4 @@ pnpm-lock.yaml *.analog /.nx/workspace-data /packages/create-analog/template-* +.vite-inspect diff --git a/.prettierrc b/.prettierrc index 042d8c697..1865627ce 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "singleQuote": true, + "trailingComma": "all", "overrides": [ { "files": "*.md", diff --git a/apps/analog-app/index.html b/apps/analog-app/index.html index 4a59929ee..b8fdf5588 100644 --- a/apps/analog-app/index.html +++ b/apps/analog-app/index.html @@ -1,4 +1,4 @@ - + diff --git a/apps/analog-app/src/app/pages/newsletter.page.ts b/apps/analog-app/src/app/pages/newsletter.page.ts index 41741de09..c04ae4fdb 100644 --- a/apps/analog-app/src/app/pages/newsletter.page.ts +++ b/apps/analog-app/src/app/pages/newsletter.page.ts @@ -16,25 +16,24 @@ type FormErrors =

Newsletter Signup

@if (!signedUp()) { -
-
- - -
- - -
- - @if (errors()?.email) { -

{{ errors()?.email }}

- } - } @else { -
Thanks for signing up!
+
+
+ + +
+ + +
+ + @if (errors()?.email) { +

{{ errors()?.email }}

+ } } @else { +
Thanks for signing up!
} `, }) diff --git a/apps/analog-app/src/app/pages/search.page.ts b/apps/analog-app/src/app/pages/search.page.ts index 82a00e45a..d3fd19cc2 100644 --- a/apps/analog-app/src/app/pages/search.page.ts +++ b/apps/analog-app/src/app/pages/search.page.ts @@ -20,7 +20,7 @@ import type { load } from './search.server'; @if (searchTerm()) { -

Search Term: {{ searchTerm() }}

+

Search Term: {{ searchTerm() }}

} `, }) diff --git a/apps/blog-app/index.html b/apps/blog-app/index.html index 54bde8e01..8d653adc9 100644 --- a/apps/blog-app/index.html +++ b/apps/blog-app/index.html @@ -1,4 +1,4 @@ - + diff --git a/apps/docs-app/docs/guides/forms.md b/apps/docs-app/docs/guides/forms.md index 8c29fb86d..6d0e3611d 100644 --- a/apps/docs-app/docs/guides/forms.md +++ b/apps/docs-app/docs/guides/forms.md @@ -44,25 +44,24 @@ type FormErrors =

Newsletter Signup

@if (!signedUp()) { -
-
- - -
- - -
- - @if (errors()?.email) { -

{{ errors()?.email }}

- } - } @else { -
Thanks for signing up!
+
+
+ + +
+ + +
+ + @if (errors()?.email) { +

{{ errors()?.email }}

+ } } @else { +
Thanks for signing up!
} `, }) @@ -179,7 +178,7 @@ import type { load } from './search.server'; @if (searchTerm()) { -

Search Term: {{ searchTerm() }}

+

Search Term: {{ searchTerm() }}

} `, }) diff --git a/apps/ng-app/index.html b/apps/ng-app/index.html index 9dcb4d185..cec1b2516 100644 --- a/apps/ng-app/index.html +++ b/apps/ng-app/index.html @@ -1,4 +1,4 @@ - + diff --git a/apps/trpc-app/index.html b/apps/trpc-app/index.html index bdf6b6141..aaaa8f4f5 100644 --- a/apps/trpc-app/index.html +++ b/apps/trpc-app/index.html @@ -1,4 +1,4 @@ - + diff --git a/libs/card/src/lib/autocomplete/autocomplete.component.html b/libs/card/src/lib/autocomplete/autocomplete.component.html index e339086e8..98937e4f6 100644 --- a/libs/card/src/lib/autocomplete/autocomplete.component.html +++ b/libs/card/src/lib/autocomplete/autocomplete.component.html @@ -10,7 +10,7 @@ /> @for (option of filteredOptions(); track option) { - {{ option.label }} + {{ option.label }} } diff --git a/packages/router/src/lib/debug/debug.page.ts b/packages/router/src/lib/debug/debug.page.ts index 87e164857..c6945136d 100644 --- a/packages/router/src/lib/debug/debug.page.ts +++ b/packages/router/src/lib/debug/debug.page.ts @@ -22,19 +22,17 @@ type CollectedRoute = {
Type
- @for ( - collectedRoute of collectedRoutes; - track collectedRoute.filename + @for ( collectedRoute of collectedRoutes; track collectedRoute.filename ) { -
-
{{ collectedRoute.path }}
-
- {{ collectedRoute.file }} -
-
- {{ collectedRoute.isLayout ? 'Layout' : 'Page' }} -
+
+
{{ collectedRoute.path }}
+
+ {{ collectedRoute.file }}
+
+ {{ collectedRoute.isLayout ? 'Layout' : 'Page' }} +
+
}
diff --git a/packages/router/src/lib/server.component.ts b/packages/router/src/lib/server.component.ts index 4aef4112f..a64fb0c95 100644 --- a/packages/router/src/lib/server.component.ts +++ b/packages/router/src/lib/server.component.ts @@ -98,7 +98,7 @@ export class ServerOnly { }; } return throwError( - () => ({}) as { html: string; outputs: ServerOutputs }, + () => ({} as { html: string; outputs: ServerOutputs }), ); }), catchError((error: unknown) => { diff --git a/packages/trpc/src/lib/client/shared-internal.ts b/packages/trpc/src/lib/client/shared-internal.ts index 97701120d..ec88784bc 100644 --- a/packages/trpc/src/lib/client/shared-internal.ts +++ b/packages/trpc/src/lib/client/shared-internal.ts @@ -90,25 +90,25 @@ export type CreateTRPCClientBaseOptions = transformer?: 'You must set a transformer on the backend router'; } : TRouter['_def']['_config']['transformer'] extends DataTransformerOptions - ? { - /** - * Data transformer - * - * You must use the same transformer on the backend and frontend - * @link https://trpc.io/docs/data-transformers - **/ - transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer - ? DataTransformerOptions - : TRouter['_def']['_config']['transformer']; - } - : { - /** - * Data transformer - * - * You must use the same transformer on the backend and frontend - * @link https://trpc.io/docs/data-transformers - **/ - transformer?: - | /** @deprecated **/ ClientDataTransformerOptions - | CombinedDataTransformer; - }; + ? { + /** + * Data transformer + * + * You must use the same transformer on the backend and frontend + * @link https://trpc.io/docs/data-transformers + **/ + transformer: TRouter['_def']['_config']['transformer'] extends CombinedDataTransformer + ? DataTransformerOptions + : TRouter['_def']['_config']['transformer']; + } + : { + /** + * Data transformer + * + * You must use the same transformer on the backend and frontend + * @link https://trpc.io/docs/data-transformers + **/ + transformer?: + | /** @deprecated **/ ClientDataTransformerOptions + | CombinedDataTransformer; + }; diff --git a/packages/trpc/src/lib/client/trpc-rxjs-proxy.ts b/packages/trpc/src/lib/client/trpc-rxjs-proxy.ts index 49541567b..fde91f492 100644 --- a/packages/trpc/src/lib/client/trpc-rxjs-proxy.ts +++ b/packages/trpc/src/lib/client/trpc-rxjs-proxy.ts @@ -50,10 +50,10 @@ type DecorateProcedure< query: Resolver; } : TProcedure extends AnyMutationProcedure - ? { - mutate: Resolver; - } - : never; + ? { + mutate: Resolver; + } + : never; // Removed subscription and using new type type DecoratedProcedureRecord< @@ -66,8 +66,8 @@ type DecoratedProcedureRecord< TProcedures[TKey] > : TProcedures[TKey] extends AnyProcedure - ? DecorateProcedure - : never; + ? DecorateProcedure + : never; }; // Removed subscription and using new type diff --git a/packages/vite-plugin-angular/src/lib/angular-vite-plugin.spec.ts b/packages/vite-plugin-angular/src/lib/angular-vite-plugin.spec.ts index 2fd4d7cb2..eb139cfc4 100644 --- a/packages/vite-plugin-angular/src/lib/angular-vite-plugin.spec.ts +++ b/packages/vite-plugin-angular/src/lib/angular-vite-plugin.spec.ts @@ -8,50 +8,44 @@ describe('angularVitePlugin', () => { }); describe('isTestWatchMode', () => { - it('should return false if vitest command not included in the command', () => { - const result = isTestWatchMode('vite'); - - expect(result).toBeFalsy(); - }); - it('should return false for vitest --run', () => { - const result = isTestWatchMode('vitest', ['--run']); + const result = isTestWatchMode(['--run']); expect(result).toBeFalsy(); }); it('should return true for vitest --no-run', () => { - const result = isTestWatchMode('vitest', ['--no-run']); + const result = isTestWatchMode(['--no-run']); expect(result).toBeTruthy(); }); it('should return true for vitest --watch', () => { - const result = isTestWatchMode('vitest', ['--watch']); + const result = isTestWatchMode(['--watch']); expect(result).toBeTruthy(); }); it('should return true for vitest watch', () => { - const result = isTestWatchMode('vitest', ['watch']); + const result = isTestWatchMode(['watch']); expect(result).toBeTruthy(); }); it('should return false for vitest --no-watch', () => { - const result = isTestWatchMode('vitest', ['--no-watch']); + const result = isTestWatchMode(['--no-watch']); expect(result).toBeFalsy(); }); it('should return false for vitest --watch=false', () => { - const result = isTestWatchMode('vitest', ['--watch=false']); + const result = isTestWatchMode(['--watch=false']); expect(result).toBeFalsy(); }); it('should return false for vitest --watch false', () => { - const result = isTestWatchMode('vitest', ['--watch', 'false']); + const result = isTestWatchMode(['--watch', 'false']); expect(result).toBeFalsy(); }); diff --git a/packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts b/packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts index 534591441..205121c98 100644 --- a/packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts +++ b/packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts @@ -237,15 +237,17 @@ export function angular(options?: PluginOptions): Plugin[] { configResolved(config) { resolvedConfig = config; - // set test watch mode - // - vite override from vitest-angular - // - @nx/vite executor set server.watch explicitly to undefined (watch)/null (watch=false) - // - vite config for test.watch variable - // - vitest watch mode detected from the command line - testWatchMode = - !(config.server.watch === null) || - config.test?.watch === true || - testWatchMode; + if (isTest) { + // set test watch mode + // - vite override from vitest-angular + // - @nx/vite executor set server.watch explicitly to undefined (watch)/null (watch=false) + // - vite config for test.watch variable + // - vitest watch mode detected from the command line + testWatchMode = + !(config.server.watch === null) || + config.test?.watch === true || + testWatchMode; + } }, configureServer(server) { viteServer = server; @@ -1046,17 +1048,7 @@ function getFilenameFromPath(id: string): string { * Checks for vitest run from the command line * @returns boolean */ -export function isTestWatchMode( - command = process.env['_'], - args = process.argv, -) { - const isVitestCommand = command?.includes('vitest'); - - // vitest command was not used - if (!isVitestCommand) { - return false; - } - +export function isTestWatchMode(args = process.argv) { // vitest --run const hasRun = args.find((arg) => arg.includes('--run')); if (hasRun) { diff --git a/packages/vite-plugin-angular/src/lib/authoring/analog.ts b/packages/vite-plugin-angular/src/lib/authoring/analog.ts index 7ceef5321..c54d053f0 100644 --- a/packages/vite-plugin-angular/src/lib/authoring/analog.ts +++ b/packages/vite-plugin-angular/src/lib/authoring/analog.ts @@ -504,8 +504,8 @@ function processAnalogScript( scope: hasExportKeyword ? Scope.Protected : isVirtual - ? Scope.Private - : undefined, + ? Scope.Private + : undefined, }); if (name !== ROUTE_META && !isVirtual) { targetConstructor.addStatements((writer) => { diff --git a/packages/vite-plugin-angular/src/lib/component-resolvers.ts b/packages/vite-plugin-angular/src/lib/component-resolvers.ts index 72d427a82..7ce7dee21 100644 --- a/packages/vite-plugin-angular/src/lib/component-resolvers.ts +++ b/packages/vite-plugin-angular/src/lib/component-resolvers.ts @@ -102,7 +102,9 @@ export class TemplateUrlsResolver { const templateUrlPaths = getTemplateUrls(code).map( (url) => - `${url}|${normalizePath(resolve(dirname(id), url).replace(/\\/g, '/'))}`, + `${url}|${normalizePath( + resolve(dirname(id), url).replace(/\\/g, '/'), + )}`, ); this.templateUrlsCache.set(id, { code, templateUrlPaths }); diff --git a/packages/vite-plugin-nitro/README.md b/packages/vite-plugin-nitro/README.md index f9e7dfcbb..cd8a6efd9 100644 --- a/packages/vite-plugin-nitro/README.md +++ b/packages/vite-plugin-nitro/README.md @@ -52,7 +52,7 @@ export default async function render(_url: string, document: string) { const html = ReactDOMServer.renderToString( - + , ); return document.replace('', html); }