Skip to content

Commit

Permalink
feat(@schematics/angular): add option to export component as default
Browse files Browse the repository at this point in the history
Introduces option `--export-default` to control whether the generated component uses a default export instead of a named export.

Closes: angular#25023
  • Loading branch information
aparzi committed Aug 23, 2024
1 parent 5ba0b07 commit c35d200
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,20 @@ describe('Component Schematic', () => {
await expectAsync(schematicRunner.runSchematic('component', options, appTree)).toBeRejected();
});
});

it('should export the component as default when exportDefault is true', async () => {
const options = { ...defaultOptions, exportDefault: true };

const tree = await schematicRunner.runSchematic('component', options, appTree);
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(tsContent).toContain('export default class FooComponent');
});

it('should export the component as a named export when exportDefault is false', async () => {
const options = { ...defaultOptions, exportDefault: false };

const tree = await schematicRunner.runSchematic('component', options, appTree);
const tsContent = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(tsContent).toContain('export class FooComponent');
});
});
5 changes: 5 additions & 0 deletions packages/schematics/angular/component/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
"type": "boolean",
"default": false,
"description": "The declaring NgModule exports this component."
},
"exportDefault": {
"type": "boolean",
"default": false,
"description": "Use default export for the component instead of a named export."
}
},
"required": ["name", "project"]
Expand Down

0 comments on commit c35d200

Please sign in to comment.