delegateas / XrmDefinitelyTyped

Tool to generate TypeScript declaration files for Dynamics 365/CDS client-side coding.
http://delegateas.github.io/Delegate.XrmDefinitelyTyped/
MIT License
133 stars 53 forks source link

Solution checker complains about dg.xrmquery.web.js #292

Open Mihails-Simvulidi opened 1 year ago

Mihails-Simvulidi commented 1 year ago

Describe the bug Power Apps solution checker shows a medium severity issues because:

  1. Deprecated Xrm.Page is used in dg.xrmquery.web.js.
  2. == and != are used for comparison instead of === and !==.

To Reproduce Steps to reproduce the behavior:

  1. Run XrmDefinitelyTyped.exe.
  2. Create a TypeScript script which uses XrmQuery.
  3. Build and run webpack.
  4. Upload the generated JavaScript file to a new solution.
  5. Run the solution checker on this solution.

Expected behavior No solution checker issues. It could be achieved by:

  1. Only including the code which uses Xrm.Page when using Dynamics 365 versions below 9.0 which do not support newer client API.
  2. Replacing == and != with === and !==.

Screenshots

Solution check results

Environment

skovlund commented 8 months ago

Hello @Mihails-Simvulidi

We've made an initial effort towards reducing the warnings produced by the solution checker by enforcing strict comparison in dg.xrmquery.web.js. However, the minified versions (dg.xrmquery.web.min.js and dg.xrmquery.web.promise.min.js) still produce warnings as the minifying process (gulp-uglify and UglifyJS) introduces loose equality comparisons.

Unfortunately I don't see a solution to all of the warnings produced by the solution checker:

  1. We still use Xrm.Page and Xrm.Page.context. These could strictly speaking be removed, as they are only called as a backup solution to getting the client url, when it can't be retrieved through neither global context nor utility. However, removing them is not backwards compatible, and would be breaking for anyone where this backup solution is used (I don't have the overview of where this may be the case). Generally speaking this would just require bumping the major/minor version number, but since this is buried quite deep in XrmQuery, I don't think everyone upgrading would notice this change before it became an issue.
  2. Compiling TypeScript can generate "use strict"; at file level of each JavaScript file but not at function level. I don't believe there are any recommendations for doing this differently. But currently the Solution Checker does not consider this behavior correct. The Solution Checker requires the "use strict;" line at the beginning of each function. Additionally it creates a warning for incorrect usage of "use strict"; which currently includes the line at file level. We could add "use strict"; to functions in TypeScript, but that doesn't improve the code, and I don't believe we can add it to helper functions generated by the TypeScript compiler, e.g. __extends.

I don't currently see a feasible solution for eliminating all Solution Checker warnings. Ideas are welcome and pull requests even more so.

Mihails-Simvulidi commented 8 months ago

Thank you!

Regarding Xrm.Page - I think XrmDefinitelyTyped.exe could generate different dg.xrmquery.web*.js files depending on environment version or setting in XrmDefinitelyTyped.exe.config.

Regarding "use strict;" - maybe it could be reported as a bug to Microsoft?