+
Skip to content

fix(vite-plugin-angular): remove check for Vitest command in watch mode #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pnpm-lock.yaml
*.analog
/.nx/workspace-data
/packages/create-analog/template-*
.vite-inspect
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": "*.md",
Expand Down
2 changes: 1 addition & 1 deletion apps/analog-app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
37 changes: 18 additions & 19 deletions apps/analog-app/src/app/pages/newsletter.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@ type FormErrors =
<h3>Newsletter Signup</h3>

@if (!signedUp()) {
<form
method="post"
(onSuccess)="onSuccess()"
(onError)="onError($any($event))"
(onStateChange)="errors.set(undefined)"
>
<div>
<label for="email"> Email </label>
<input type="email" name="email" />
</div>

<button class="button" type="submit">Submit</button>
</form>

@if (errors()?.email) {
<p>{{ errors()?.email }}</p>
}
} @else {
<div>Thanks for signing up!</div>
<form
method="post"
(onSuccess)="onSuccess()"
(onError)="onError($any($event))"
(onStateChange)="errors.set(undefined)"
>
<div>
<label for="email"> Email </label>
<input type="email" name="email" />
</div>

<button class="button" type="submit">Submit</button>
</form>

@if (errors()?.email) {
<p>{{ errors()?.email }}</p>
} } @else {
<div>Thanks for signing up!</div>
}
`,
})
Expand Down
2 changes: 1 addition & 1 deletion apps/analog-app/src/app/pages/search.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { load } from './search.server';
</form>

@if (searchTerm()) {
<p>Search Term: {{ searchTerm() }}</p>
<p>Search Term: {{ searchTerm() }}</p>
}
`,
})
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
39 changes: 19 additions & 20 deletions apps/docs-app/docs/guides/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,24 @@ type FormErrors =
<h3>Newsletter Signup</h3>

@if (!signedUp()) {
<form
method="post"
(onSuccess)="onSuccess()"
(onError)="onError($any($event))"
(onStateChange)="errors.set(undefined)"
>
<div>
<label for="email"> Email </label>
<input type="email" name="email" />
</div>

<button class="button" type="submit">Submit</button>
</form>

@if (errors()?.email) {
<p>{{ errors()?.email }}</p>
}
} @else {
<div>Thanks for signing up!</div>
<form
method="post"
(onSuccess)="onSuccess()"
(onError)="onError($any($event))"
(onStateChange)="errors.set(undefined)"
>
<div>
<label for="email"> Email </label>
<input type="email" name="email" />
</div>

<button class="button" type="submit">Submit</button>
</form>

@if (errors()?.email) {
<p>{{ errors()?.email }}</p>
} } @else {
<div>Thanks for signing up!</div>
}
`,
})
Expand Down Expand Up @@ -179,7 +178,7 @@ import type { load } from './search.server';
</form>

@if (searchTerm()) {
<p>Search Term: {{ searchTerm() }}</p>
<p>Search Term: {{ searchTerm() }}</p>
}
`,
})
Expand Down
2 changes: 1 addition & 1 deletion apps/ng-app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
2 changes: 1 addition & 1 deletion apps/trpc-app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html class="dark h-full" lang="en">
<head>
<meta charset="utf-8" />
Expand Down
2 changes: 1 addition & 1 deletion libs/card/src/lib/autocomplete/autocomplete.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/>
<mat-autocomplete #autocomplete="matAutocomplete" autoActiveFirstOption>
@for (option of filteredOptions(); track option) {
<mat-option [value]="option.value">{{ option.label }}</mat-option>
<mat-option [value]="option.value">{{ option.label }}</mat-option>
}
</mat-autocomplete>
</mat-form-field>
20 changes: 9 additions & 11 deletions packages/router/src/lib/debug/debug.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ type CollectedRoute = {
<div class="header-cell">Type</div>
</div>
<div class="table-body">
@for (
collectedRoute of collectedRoutes;
track collectedRoute.filename
@for ( collectedRoute of collectedRoutes; track collectedRoute.filename
) {
<div class="table-row">
<div class="table-cell">{{ collectedRoute.path }}</div>
<div class="table-cell" [title]="collectedRoute.filename">
{{ collectedRoute.file }}
</div>
<div class="table-cell">
{{ collectedRoute.isLayout ? 'Layout' : 'Page' }}
</div>
<div class="table-row">
<div class="table-cell">{{ collectedRoute.path }}</div>
<div class="table-cell" [title]="collectedRoute.filename">
{{ collectedRoute.file }}
</div>
<div class="table-cell">
{{ collectedRoute.isLayout ? 'Layout' : 'Page' }}
</div>
</div>
}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/lib/server.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ServerOnly {
};
}
return throwError(
() => ({}) as { html: string; outputs: ServerOutputs },
() => ({} as { html: string; outputs: ServerOutputs }),
);
}),
catchError((error: unknown) => {
Expand Down
44 changes: 22 additions & 22 deletions packages/trpc/src/lib/client/shared-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ export type CreateTRPCClientBaseOptions<TRouter extends AnyRouter> =
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;
};
12 changes: 6 additions & 6 deletions packages/trpc/src/lib/client/trpc-rxjs-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ type DecorateProcedure<
query: Resolver<TProcedure>;
}
: TProcedure extends AnyMutationProcedure
? {
mutate: Resolver<TProcedure>;
}
: never;
? {
mutate: Resolver<TProcedure>;
}
: never;

// Removed subscription and using new type
type DecoratedProcedureRecord<
Expand All @@ -66,8 +66,8 @@ type DecoratedProcedureRecord<
TProcedures[TKey]
>
: TProcedures[TKey] extends AnyProcedure
? DecorateProcedure<TProcedures[TKey], TRouter>
: never;
? DecorateProcedure<TProcedures[TKey], TRouter>
: never;
};

// Removed subscription and using new type
Expand Down
20 changes: 7 additions & 13 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
32 changes: 12 additions & 20 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-angular/src/lib/authoring/analog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/vite-plugin-angular/src/lib/component-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-nitro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async function render(_url: string, document: string) {
const html = ReactDOMServer.renderToString(
<React.StrictMode>
<App />
</React.StrictMode>
</React.StrictMode>,
);
return document.replace('<!--app-html-->', html);
}
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载