Skip to content
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

bugfix(schematics): fix for angular 12 and align schematics #437

Closed
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 projects/spectator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"angular testing dumb components"
],
"dependencies": {
"@angular-devkit/core": ">= 10.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn I tried to run this as a linked package it complained that @angular-devkit/core was not found although it was installed in the project.

"@testing-library/dom": "7.26.5",
"jquery": "3.6.0",
"replace-in-file": "^6.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"styl"
]
},
"type": {
"type": "string",
"description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\".",
"default": "Component"
},
"spec": {
"type": "boolean",
"description": "When true (the default), generates a \"spec.ts\" test file for the new component.",
Expand Down
23 changes: 19 additions & 4 deletions projects/spectator/schematics/src/spectator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ComponentOptions, DirectiveOptions, ServiceOptions } from './schema';
export function spectatorComponentSchematic(options: ComponentOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'component', {
...options,
..._omit(options, ['jest', 'withHost', 'withCustomHost']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angular 12 complains about options that are passed but not known

skipTests: true,
spec: false
}),
Expand Down Expand Up @@ -52,7 +52,7 @@ export function spectatorComponentSchematic(options: ComponentOptions): Rule {
export function spectatorServiceSchematic(options: ServiceOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'service', {
...options,
..._omit(options, ['jest']),
skipTests: true,
spec: false
}),
Expand All @@ -79,7 +79,7 @@ export function spectatorServiceSchematic(options: ServiceOptions): Rule {
export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'directive', {
...options,
..._omit(options, ['jest']),
skipTests: true,
spec: false
}),
Expand All @@ -106,7 +106,7 @@ export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule {
export function spectatorPipeSchematic(options: DirectiveOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'pipe', {
...options,
..._omit(options, ['jest']),
skipTests: true,
spec: false
}),
Expand Down Expand Up @@ -147,3 +147,18 @@ async function _ensurePath(tree: Tree, options: any): Promise<void> {
options.name = parsedPath.name;
options.path = parsedPath.path;
}

/**
* create a new object without given keys
* @param raw initial object
* @param keys list of keys to remove from object
*/
function _omit<T extends Record<string, any>>(raw: T, keys: (keyof T)[]): any {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I think this function is doing the opposite of what you want it to!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benelliott is right. Check your filter logic.

return Object.keys(raw)
.filter(key => !keys.includes(key))
.reduce((obj: any, key) => {
obj[key] = raw[key];

return obj;
}, {});
}
4 changes: 4 additions & 0 deletions projects/spectator/schematics/src/spectator/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export class ComponentOptions {
path?: string;
withHost?: boolean;
withCustomHost?: boolean;
/**
* Adds a developer-defined type to the filename, in the format "name.type.ts"
*/
type?: string;
/**
* Specifies the change detection strategy.
*/
Expand Down