-
-
Notifications
You must be signed in to change notification settings - Fork 170
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
feat: add the flag for disabling optimizations #1447
Conversation
src/commands/optimize.ts
Outdated
@@ -40,6 +40,7 @@ export default class Optimize extends Command { | |||
optimization: Flags.string({char: 'p', default: Object.values(Optimizations), options: Object.values(Optimizations), multiple: true, description: 'select the type of optimizations that you want to apply.'}), | |||
output: Flags.string({char: 'o', default: Outputs.TERMINAL, options: Object.values(Outputs), description: 'select where you want the output.'}), | |||
'no-tty': Flags.boolean({ description: 'do not use an interactive terminal', default: false }), | |||
disableOptimizationForSchema: Flags.boolean({ description: 'schema should be ignored from the optimization prcoess', default: false }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a shorter and DX friendly flag ?
What about: --omit=schema
in case we want to disable something else in the future we can reuse the same flag
--omit=components...
cc @KhudaDad414
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, even I was thinking that. I just used this since it was suggested here #1432 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. In the original issue, I suggested --ignore
but --omit
also works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for confirmation @Amzani, when you mention other things that can be omitted by changing the flag format, do you mean this, like reuseComponents
, removeComponents
etc can also be enabled or disabled by default?
{
output: 'YAML',
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: false,
},
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KhudaDad414 is the best person to answer this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During all the time I've been working with Optimizer
, I didn't see a need to disable optimization for anything else except schema
, and that was only because schemas were disrupting the view of optimized AsyncAPI Document. So I think if at least one user requests anything else, it would be possible to think about changes to the logic, and for now it can be simply the introduction of one consistent across versions switch disableOptimizationForSchema
and that's it.
@KhudaDad414 wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aeworxet I agree with @helios2003.
I don't think it makes a lot of sense to try to match the command names from optimizer to CLI. they are separate tools and they can evolve separately. purely from the DX point of view having a long command line options like disableOptimizationForSchema
isn't ideal since user has to type it every time.
that's why I think having something like --ignore
or --omit
makes sense here.
optimizer is a library and it is used in other tools, so if we have a long descriptive option names, it doesn't matter since user will only deal with it once in their code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are separate tools and they can evolve separately
I don't have a strong opinion in this case either.
@helios2003, please refer to asyncapi/optimizer#252 in which disableOptimizationFor
was introduced, to see a list of all places where it was used at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@helios2003 @aeworxet tbh I don't have a strong opinion here. one one side
disableOptimizationFor: { schema: false, }
can be used to add more components to ignore in the future. things like:
disableOptimizationFor: { schema: false, message: true }
the question is whether it's a valid case? will someone want this feature? I don't know.
and on the other hand changing the name to
disableOptimizationForSchema
would make a more seemless way of integration between CLI and optimizer.
I am bit confused. So do I need to add additional components to the flags and change it in both the repositories or just do it for schema
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@helios2003 since optimizer currently only supports schemas
I think you can only support schemas here and call it a day.
src/commands/optimize.ts
Outdated
@@ -40,6 +40,7 @@ export default class Optimize extends Command { | |||
optimization: Flags.string({char: 'p', default: Object.values(Optimizations), options: Object.values(Optimizations), multiple: true, description: 'select the type of optimizations that you want to apply.'}), | |||
output: Flags.string({char: 'o', default: Outputs.TERMINAL, options: Object.values(Outputs), description: 'select where you want the output.'}), | |||
'no-tty': Flags.boolean({ description: 'do not use an interactive terminal', default: false }), | |||
disableOptimizationForSchema: Flags.boolean({ description: 'schema should be ignored from the optimization prcoess', default: false }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a typo here :)
disableOptimizationForSchema: Flags.boolean({ description: 'schema should be ignored from the optimization prcoess', default: false }), | |
disableOptimizationForSchema: Flags.boolean({ description: 'schema should be ignored from the optimization process', default: false }), |
src/commands/optimize.ts
Outdated
if (flags['disableOptimizationForSchema'] === true) { | ||
flags.disableOptimizationForSchema = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You basically wrote
if (flags['disableOptimizationForSchema'] === true) {
flags['disableOptimizationForSchema'] = true;
}
cuz just to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried set the flag so it can be used in the optimizedDocument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The very presence of a command line switch in this CLI already means 'true' and its absence - 'false', so you already imported the value of this cmd switch into the JS execution context in lines R106-R108
.
It's done in Bundler
the same way:
https://github.com/asyncapi/cli/blob/master/src/commands/bundle.ts#L44
This makes code in lines R85-R87
redudant and it can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, my bad. I don't know how I missed it. Thank you. I will incorporate all the necessary changes in the future commit to this PR.
Quality Gate passedIssues Measures |
Hey folks, I apologize for the delay as I've been busy over the past week or two. I will address all the comments made by the maintainers on this PR in a few days. Thank you all for your patience and cooperation. |
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
I have made the changes that were talked about in the discussion. The PR can be reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @helios2003,
I tested the result and it works great. there is one issue that I think should be solved before we can merge this one.
If I pass the ignore flag in the getOptimizedDocument
stage, then the report won't reflect it. I mean a component will appear as it's being removed but it will not be removed.
I think this flag should be passed at the (getReport())[https://github.com/asyncapi/optimizer/blob/4fe33fe499d3b1add61f70a27d720f5c8d8e248c/src/Optimizer.ts#L62] stage. but the problem with this approach would be that the user won't see the report to decide if they want to ignore the schemas or not.
I think the best approach would be to accept the flag but also have the option to change it later on with this screen:
this way, if someone is using --no-tty
then they will not sure the Report and it doesn't matter if the report doesn't reflect the ignored schema.
And if someone is going the standard way, then they have an option to change their mind about ignoring schemas mid-way. (or ignore them after seeing the report)
I have tried making the changes as asked, but I am not sure if this is the correct way to implement it. PTAL @KhudaDad414 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested some changes.
src/commands/optimize.ts
Outdated
@@ -178,6 +190,11 @@ export default class Optimize extends Command { | |||
this.showOptimizations(report.reuseComponents); | |||
choices.push({name: 'reuse components', value: Optimizations.REUSE_COMPONENTS}); | |||
} | |||
if (canIgnoreSchema) { | |||
this.log("Do not ignore schema for the components"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings must use single quote.
src/commands/optimize.ts
Outdated
@@ -152,6 +163,7 @@ export default class Optimize extends Command { | |||
const canMoveAll = report.moveAllToComponents?.length; | |||
const canRemove = report.removeComponents?.length; | |||
const canReuse = report.reuseComponents?.length; | |||
const canIgnoreSchema = this.disableOptimizations?.includes(DisableOptimizations.SCHEMA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this. we always show this option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, we allow the user to ignore the schema halfway through even if they didn't put the flag initially and vice versa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included these changes in the last commit.
@@ -178,6 +190,11 @@ export default class Optimize extends Command { | |||
this.showOptimizations(report.reuseComponents); | |||
choices.push({name: 'reuse components', value: Optimizations.REUSE_COMPONENTS}); | |||
} | |||
if (canIgnoreSchema) { | |||
this.log("Do not ignore schema for the components"); | |||
choices.push({name: 'Do not ignore schema', value: DisableOptimizations.SCHEMA}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we use the same option as flag. I mean the name should be Ignore schemas
. Also it should be checked by default if --ignore=schema
is passed.
Hi maintainers, can you please review the PR? It has been pending for quite a while. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
/rtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/rtm |
1 similar comment
/rtm |
/u |
Quality Gate passedIssues Measures |
🎉 This PR is included in version 2.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Now the
disableOptimizationFor
parameter can also be provided in the optimized document.Related issue(s)
Fixes #1432