fix(angular): add missing skipImport option to the component generator (#10167)
This commit is contained in:
parent
7da1913812
commit
5c94d6222f
@ -319,6 +319,11 @@
|
||||
"description": "Create the new files at the top level of the current project.",
|
||||
"default": false
|
||||
},
|
||||
"skipImport": {
|
||||
"type": "boolean",
|
||||
"description": "Do not import this component into the owning NgModule.",
|
||||
"default": false
|
||||
},
|
||||
"selector": {
|
||||
"type": "string",
|
||||
"format": "html-selector",
|
||||
|
||||
@ -100,6 +100,25 @@ export class ExampleComponent implements OnInit {
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`component Generator should create the component correctly and not export it when "--skip-import=true" 1`] = `
|
||||
"import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'example',
|
||||
templateUrl: './example.component.html',
|
||||
styleUrls: ['./example.component.css']
|
||||
})
|
||||
export class ExampleComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`component Generator should create the component correctly but not export it when no entry point exists 1`] = `
|
||||
"import { Component, OnInit } from '@angular/core';
|
||||
|
||||
|
||||
@ -83,6 +83,47 @@ describe('component Generator', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should create the component correctly and not export it when "--skip-import=true"', async () => {
|
||||
// ARRANGE
|
||||
const tree = createTreeWithEmptyWorkspace(2);
|
||||
addProjectConfiguration(tree, 'lib1', {
|
||||
projectType: 'library',
|
||||
sourceRoot: 'libs/lib1/src',
|
||||
root: 'libs/lib1',
|
||||
});
|
||||
tree.write(
|
||||
'libs/lib1/src/lib/lib.module.ts',
|
||||
`
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
exports: []
|
||||
})
|
||||
export class LibModule {}`
|
||||
);
|
||||
tree.write('libs/lib1/src/index.ts', '');
|
||||
|
||||
// ACT
|
||||
await componentGenerator(tree, {
|
||||
name: 'example',
|
||||
project: 'lib1',
|
||||
skipImport: true,
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
const componentSource = tree.read(
|
||||
'libs/lib1/src/lib/example/example.component.ts',
|
||||
'utf-8'
|
||||
);
|
||||
expect(componentSource).toMatchSnapshot();
|
||||
|
||||
const indexSource = tree.read('libs/lib1/src/index.ts', 'utf-8');
|
||||
expect(indexSource).not.toContain(
|
||||
`export * from "./lib/example/example.component"`
|
||||
);
|
||||
});
|
||||
|
||||
it('should create the component correctly but not export it when no entry point exists', async () => {
|
||||
// ARRANGE
|
||||
const tree = createTreeWithEmptyWorkspace(2);
|
||||
|
||||
@ -47,7 +47,7 @@ function checkPathUnderProjectRoot(tree: Tree, schema: Partial<Schema>) {
|
||||
}
|
||||
|
||||
function exportComponent(tree: Tree, schema: Schema) {
|
||||
if (!schema.export) {
|
||||
if (!schema.export || schema.skipImport) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ export interface Schema {
|
||||
skipTests?: boolean;
|
||||
type?: string;
|
||||
flat?: boolean;
|
||||
skipImport?: boolean;
|
||||
selector?: string;
|
||||
module?: string;
|
||||
skipSelector?: boolean;
|
||||
|
||||
@ -81,6 +81,11 @@
|
||||
"description": "Create the new files at the top level of the current project.",
|
||||
"default": false
|
||||
},
|
||||
"skipImport": {
|
||||
"type": "boolean",
|
||||
"description": "Do not import this component into the owning NgModule.",
|
||||
"default": false
|
||||
},
|
||||
"selector": {
|
||||
"type": "string",
|
||||
"format": "html-selector",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user