Bug 225009 - Web Inspector: Default Audits script are minified in release builds
Summary: Web Inspector: Default Audits script are minified in release builds
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Patrick Angle
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-23 16:37 PDT by Patrick Angle
Modified: 2021-04-27 16:53 PDT (History)
5 users (show)

See Also:


Attachments
Patch v1.0 (105.18 KB, patch)
2021-04-23 16:55 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
Patch v1.1 - Added test, review notes (106.11 KB, patch)
2021-04-27 10:06 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
Patch v1.2 - Review note (106.10 KB, patch)
2021-04-27 15:24 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Angle 2021-04-23 16:37:40 PDT
This means that when entering Edit mode in the Audit tab all of the default audits, many meant to server as examples while writing audits, are a block of minified code instead of in their original, non-minified form.

<rdar://76778007>
Comment 1 Patrick Angle 2021-04-23 16:55:40 PDT
Created attachment 426966 [details]
Patch v1.0
Comment 2 Devin Rousso 2021-04-23 17:12:54 PDT
Comment on attachment 426966 [details]
Patch v1.0

View in context: https://bugs.webkit.org/attachment.cgi?id=426966&action=review

> Source/WebInspectorUI/Scripts/combine-resources.pl:131
> +    concatenateIncludedFilesMatchingPattern($outputStylesheetName, "<link rel=\"stylesheet\" href=\"($inputDirectoryPattern)\">", defined $skipConcatenateTag ? "" : "<link rel=\"stylesheet\" href=\"$outputStylesheetName\">") if defined $outputStylesheetName;
> +    concatenateIncludedFilesMatchingPattern($outputScriptName, "<script src=\"($inputDirectoryPattern)\"><\/script>", defined $skipConcatenateTag ? "" : "<script src=\"$outputScriptName\"></script>") if defined $outputScriptName;

Why is `$skipConcatenateTag` actually needed?  Wouldn't any files we want to concatenate get skipped anyway because of `$inputDirectoryPattern`?

> Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl:357
> +       '--output-script-name', 'NonMinified.js',

Does this eventually get deleted after it's appended?

> Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js:349
> +                    new WI.AuditTestCase("level-pass", removeWhitespace(WI.DefaultAudits.levelPass), {description: WI.UIString("This is what the result of a passing test with no data looks like.")}),

we should either `console.assert(WI.DefaultAudits)` or even just bail if it's not there, just in case :)

> Source/WebInspectorUI/UserInterface/NonMinified/DefaultAudits.js:26
> +WI.DefaultAudits = {

Instead of having this all be part of the object literal, could we do something like
```
WI.DefaultAudits = {};

WI.DefaultAudits.levelPass = function() {
    return {level: "pass"};
};

...
```
and then get replace `removeWhitespace` with `.toString()`?

> Source/WebInspectorUI/UserInterface/Test.html:289
> +    <script src="NonMinified/DefaultAudits.js"></script>

Can we add a test that `NonMinified` actually works?  i.e. a test that confirms the presence of `"    "` (four spaces) inside `WI.DefaultAudits.testPass`
Comment 3 Patrick Angle 2021-04-23 17:22:49 PDT
Comment on attachment 426966 [details]
Patch v1.0

View in context: https://bugs.webkit.org/attachment.cgi?id=426966&action=review

>> Source/WebInspectorUI/Scripts/combine-resources.pl:131
>> +    concatenateIncludedFilesMatchingPattern($outputScriptName, "<script src=\"($inputDirectoryPattern)\"><\/script>", defined $skipConcatenateTag ? "" : "<script src=\"$outputScriptName\"></script>") if defined $outputScriptName;
> 
> Why is `$skipConcatenateTag` actually needed?  Wouldn't any files we want to concatenate get skipped anyway because of `$inputDirectoryPattern`?

The default pattern is ignored when an input directory is explicitly provided. This is how we gather the NonMinified sources from Main.html. Later the combined (but non minified) NonMinified.js will be appended to the end of Main.js, so we don't want to add a script tag for it here.

>> Source/WebInspectorUI/Scripts/copy-user-interface-resources.pl:357
>> +       '--output-script-name', 'NonMinified.js',
> 
> Does this eventually get deleted after it's appended?

No, but this is a derived source that doesn't end up in the target directory (e.g. this file will be in `WebKitBuild/WebInspectorUI.build/Release/WebInspectorUI.build/DerivedSources` but not in `WebKitBuild/Release/WebInspectorUI.framework`). It seems helpful for debugging the build that after a build this intermediate file is present along with the rest of the intermediate derived sources.

>> Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js:349
>> +                    new WI.AuditTestCase("level-pass", removeWhitespace(WI.DefaultAudits.levelPass), {description: WI.UIString("This is what the result of a passing test with no data looks like.")}),
> 
> we should either `console.assert(WI.DefaultAudits)` or even just bail if it's not there, just in case :)

👍🏻

>> Source/WebInspectorUI/UserInterface/NonMinified/DefaultAudits.js:26
>> +WI.DefaultAudits = {
> 
> Instead of having this all be part of the object literal, could we do something like
> ```
> WI.DefaultAudits = {};
> 
> WI.DefaultAudits.levelPass = function() {
>     return {level: "pass"};
> };
> 
> ...
> ```
> and then get replace `removeWhitespace` with `.toString()`?

👍🏻

>> Source/WebInspectorUI/UserInterface/Test.html:289
>> +    <script src="NonMinified/DefaultAudits.js"></script>
> 
> Can we add a test that `NonMinified` actually works?  i.e. a test that confirms the presence of `"    "` (four spaces) inside `WI.DefaultAudits.testPass`

Absolutely!
Comment 4 Patrick Angle 2021-04-27 10:04:59 PDT
Comment on attachment 426966 [details]
Patch v1.0

View in context: https://bugs.webkit.org/attachment.cgi?id=426966&action=review

>>> Source/WebInspectorUI/UserInterface/Test.html:289
>>> +    <script src="NonMinified/DefaultAudits.js"></script>
>> 
>> Can we add a test that `NonMinified` actually works?  i.e. a test that confirms the presence of `"    "` (four spaces) inside `WI.DefaultAudits.testPass`
> 
> Absolutely!

I've written a test for this that will be in the next patch I upload. After finishing the test, I realized that such a test would already pass, though, since these files are part of TestCombined.js, which is the combined, but not minified, sum of almost all the included JS in Test.html. However, the test will help to make sure we are including the new file in the `NonMinified` directory, so it still seems worth having.
Comment 5 Patrick Angle 2021-04-27 10:06:44 PDT
Created attachment 427159 [details]
Patch v1.1 - Added test, review notes
Comment 6 BJ Burg 2021-04-27 13:26:38 PDT
Comment on attachment 427159 [details]
Patch v1.1 - Added test, review notes

View in context: https://bugs.webkit.org/attachment.cgi?id=427159&action=review

r=me, this is excellent!

> Source/WebInspectorUI/ChangeLog:14
> +        important to the script. For example, the source for the default audits are visible to the user, and therefor we

Nit: therefore

> Source/WebInspectorUI/UserInterface/Controllers/AuditManager.js:386
> +                new WI.AuditTestCase("testMenuRoleForRequiredChildren", WI.DefaultAudits.testMenuRoleForRequiredChildren.toString(), {description: WI.UIString("Ensure that elements of role \u0022%s\u0022 and \u0022%s\u0022 have required owned elements in accordance with WAI-ARIA.").format(WI.unlocalizedString("menu"), WI.unlocalizedString("menubar")), supports: 1}),

It's rather unfortunate that we have to stringify the functions at every call site.

> LayoutTests/inspector/audit/non-minified-default-audits.html:8
> +    let suite = InspectorTest.createAsyncSuite("Audit.NonMinifiedDefaultAudits");

Nice!
Comment 7 Patrick Angle 2021-04-27 15:24:51 PDT
Created attachment 427203 [details]
Patch v1.2 - Review note
Comment 8 EWS 2021-04-27 16:53:49 PDT
Committed r276680 (237097@main): <https://commits.webkit.org/237097@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 427203 [details].