Skip to content

fix(@schematics/angular): Allow empty string in the type option #17040

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 1 commit into from
Feb 26, 2020

Conversation

sacgrover
Copy link
Contributor

Currently, Component and Class have the options to add custom type. In the case of class, It's already working fine with an empty string in type but in the case of component When setting the type to an empty string the file names generated will contain an extra period (.) which breaks the flow.

With this PR, It will generate the files without an extra period (.)

Reference #16811 and #16891

@sacgrover
Copy link
Contributor Author

@alan-agius4 / @clydin
Any advice on ci/circleci: build-bazel & ci/circleci: test-win FAIL?

@@ -22,6 +22,7 @@ export * from './rules/random';
export * from './rules/schematic';
export * from './rules/template';
export * from './rules/url';
export * from './rules/rename';
Copy link
Member

Choose a reason for hiding this comment

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

This change adds an element to the public API surface. This should be avoided if possible since each addition adds to the long term sustainment cost.

This is also why the bazel build CI is failing. It has a public API check. New public API baselines need to be accepted before the check passes. This helps ensure that new additions were not accidental.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of rename now I used forEach that was already available in public api

@@ -49,15 +50,15 @@ function addDeclarationToNgModule(options: ComponentOptions): Rule {
return host;
}

options.type = !!options.type ? options.type : 'Component';
options.type = options.type != null ? options.type : 'Component';

const modulePath = options.module;
const source = readIntoSourceFile(host, modulePath);

const componentPath = `/${options.path}/`
Copy link
Member

Choose a reason for hiding this comment

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

Since this line is already calculating the file name base, I think we should consider splitting this into two pieces and using them on the templates. “componentPath” can be the first two parts of the current. And “componentFile” can be the remainder as the filename part. This second part can then be used has the base for all file elements in the templates.
This would remove the need to fix the broken file names with a rename as well as optimize the name creation so that it doesn’t have to happen in multiple places as it does currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This componentPath we are using to add component in appModule. We are not using it for template currently.

Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

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

Can you change the commit message type to a fix? This is really something that should have worked initially.

@clydin clydin added the target: patch This PR is targeted for the next patch release label Feb 26, 2020
Currently, Component and Class have the options to add custom type. In the case of class, It's already working fine with  an empty string in type but in the case  of component When setting the type to an empty string the file names generated will contain an extra period (.) which breaks the flow.

With this PR, It will generate the files without an extra period (.)

Reference angular#16811 and angular#16891
@sacgrover
Copy link
Contributor Author

Commit message changed.

@clydin clydin changed the title feat(@schematics/angular): Allow empty string in the type option fix(@schematics/angular): Allow empty string in the type option Feb 26, 2020
@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Feb 26, 2020
@dgp1130 dgp1130 merged commit 1c1f1cd into angular:master Feb 26, 2020
@dgp1130
Copy link
Collaborator

dgp1130 commented Feb 26, 2020

Also merged to 9.0.x patch branch.

Fixed a minor merge conflict with the styles property due to the lack of d6fa2bd in the release branch.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants