Skip to content
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

VSTS-268 Bundle and tree-shake extension task code #365

Merged
merged 2 commits into from
May 28, 2024

Conversation

7PH
Copy link
Member

@7PH 7PH commented May 24, 2024

Using esbuild to inline all dependencies (and drop node_modules from task folders)

We need to to add a workaround for shelljs because we can not bundle it

Size reduction

Size before this PR, on master branch with V1+V4+V5

19M     dist/sonar-scanner-vsts-1.46.0-sonarcloud.vsix
37M     dist/sonar-scanner-vsts-5.20.0-sonarqube.vsix

Size after this PR

3.4M    dist/sonar-scanner-vsts-1.46.0-sonarcloud.vsix
6.8M    dist/sonar-scanner-vsts-5.20.0-sonarqube.vsix

(After rebase with the 2 new versions, V1+V2+V4+V5+V6):

5.0M    ./dist/sonar-scanner-vsts-2.0.0-sonarcloud.vsix
9.1M    ./dist/sonar-scanner-vsts-6.0.0-sonarqube.vsix

Build time

On my machine, before

[12:24:35] Finished 'default' after 34 s

After

[12:20:45] Finished 'default' after 12 s

@7PH 7PH marked this pull request as draft May 24, 2024 08:13
@7PH 7PH force-pushed the task/br/vsts-268-reduce-extension-size branch 3 times, most recently from 98478dc to 9701128 Compare May 24, 2024 13:08
@7PH 7PH marked this pull request as ready for review May 24, 2024 14:00
@7PH 7PH force-pushed the task/br/vsts-268-reduce-extension-size branch 2 times, most recently from e5384bf to c8eaec7 Compare May 27, 2024 09:59
Comment on lines +182 to +189
/**
* Hotfix for shelljs dependency
* @see https://github.com/microsoft/azure-pipelines-task-lib/issues/942#issuecomment-1904939900
*/
const createShellJsDummyFile = gulpFile("index.js", "", { src: true }).pipe(
gulp.dest(path.join(outPath, "node_modules", "shelljs")),
);
streams.push(createShellJsDummyFile);
Copy link
Member Author

@7PH 7PH May 27, 2024

Choose a reason for hiding this comment

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

shelljs doesn't support being bundled through esbuild, but is imported by the azure task lib. Without this fix, we can build but the task execution fails at runtime because the azure task lib always require shelljs, even though we are not using any exported function which uses this dependency.

More explanation in this POC I made to reproduce the behavior, issue and workaround

Copy link
Contributor

Choose a reason for hiding this comment

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

we can also include the real shelljs into node_modules. How can we be sure we aren't using it at all on all systems?

I see it referenced inside the task.ts of the lib
https://github.com/microsoft/azure-pipelines-task-lib/blob/7c0de0dba61afb899068c35d88257017bd3b4736/node/task.ts#L2C8-L2C13

If you're confident it isn't used for any platform, I'm okay with stubbing it like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not used, if we were using at some point, yes it would fail in QA and production (we should spot it in QA),

I considered adding shelljs but it's 1.7MB in each shipped task, so figured, since it's a workaround anyway we can save 2M * 15 tasks by adding this 0B file.

@7PH 7PH force-pushed the task/br/vsts-268-reduce-extension-size branch from c8eaec7 to d4779b1 Compare May 27, 2024 10:22
@7PH 7PH changed the base branch from master to feature/MMF-3703 May 27, 2024 13:57
@7PH 7PH force-pushed the task/br/vsts-268-reduce-extension-size branch 4 times, most recently from 11d74c8 to e6db73b Compare May 27, 2024 14:43
@7PH 7PH force-pushed the task/br/vsts-268-reduce-extension-size branch from e6db73b to 43d4552 Compare May 28, 2024 07:18
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
55 New issues
4 Security Hotspots
0.0% Coverage on New Code (required ≥ 85%)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

@7PH 7PH merged commit cbcdc97 into feature/MMF-3703 May 28, 2024
5 of 8 checks passed
@7PH 7PH deleted the task/br/vsts-268-reduce-extension-size branch May 28, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants