-
Notifications
You must be signed in to change notification settings - Fork 202
Bundle extension files using ESBuild #1799
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
Conversation
6b2c56e
to
dbe94c1
Compare
c12e6ba
to
c08dd39
Compare
I think this PR is now ready for review. All tests are passing. I haven't run through the full test plan, so we should still do that before merging this. I've also created #1911 which uses Webpack instead of ESBuild. See the internal linked issue for some more information about the differences. |
Great work @koesie10! Agree we should run a thorough test of the various features (ideally also ones that aren't covered by our test plan yet). Perhaps we can ask for some help from others. One thing that isn't working for me yet is the ability to debug the extension e.g. put a breakpoint and execute some code that would hit the breakpoint. At the minute, the breakpoints don't bind. |
This bundles the extension files using esbuild, as recommended by VSCode. This reduces the size of the extension from 34MB to less than 5MB. Gulp will still run TypeScript to check types, but will not use the TypeScript compiler output in the bundle. Tests are now run separately, outside of Gulp, so their data doesn't need to be copied anymore. See: https://code.visualstudio.com/api/working-with-extensions/bundling-extension
This will copy the WASM file from source-map to the output directory. This makes the source-map package work. See the comment in the code for more details.
c08dd39
to
08549c7
Compare
08549c7
to
6bf19eb
Compare
VSCode was not able to find the original source of the bundled extension because it was looking for the source in the `out` directory. By setting the `sourceRoot` to the `extensions/ql-vscode` directory which is located at `..` from the `out` directory, VSCode is able to find the original source and breakpoints are hit.
Can you please try again? There was a missing setting in the ESBuild config which caused VSCode not to be able to map the sourcemap to the actual source code. That should have been fixed now and I'm able to hit breakpoints. |
Thanks, I can hit breakpoints now! |
Can you explain why we're removing fs mocking e.g. in |
ESBuild uses a slightly different method of importing dependencies which doesn't allow redefining exported methods, so you get errors like I think in terms of speed it shouldn't matter whether we're mocking or writing the actual files, but I think writing the files to disk will make the tests slightly better at spotting errors. We're also not just overwriting an |
I also prefer not mocking fs, but I wanted to understand why this change was relevant to bundling. Thanks for explaining! |
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.
Thanks for getting this sorted and dealing with all the merge conflicts etc.!
The PR looks good to me, and the extension seems to work okay with the changes, but I've not done any extensive testing.
It would be great to also get a review from @aeisenberg or someone else if possible.
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.
Nice work! Looks generally good to me. I have one question, and after that's addressed, 🚢.
"watch:extension": "tsc --watch", | ||
"watch:webpack": "gulp watchView", | ||
"watch:files": "gulp watchTestData", | ||
"watch": "gulp watch", |
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.
Nice, but just want to be clear that this is still all you need to do for watching things. In particular, it looks like watchTestData
is not being used any more. Is it still working as expected?
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 tests are now run from their source code directly, so we don't need to copy the test data to out
anymore. I believe we could also have combined all these different invocations of gulp
to a single invocation to gulp watch
in the previous setup, but now that we don't have a separate tsc --watch
step anymore, it makes even more sense.
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.
Thanks. This makes sense. Nice improvement.
Does debugging integration tests still work for you @koesie10? |
Yes, debugging the integration tests using Jest Runner still seems to work after I uncomment the settings in |
Sorry which settings are those? So far I've been able to just click the Debug button |
Those are these settings: diff --git a/.vscode/settings.json b/.vscode/settings.json
index 984ccf8c..c70a42f0 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -44,12 +44,12 @@
},
"jestrunner.debugOptions": {
// Uncomment to debug integration tests
- // "attachSimplePort": 9223,
+ "attachSimplePort": 9223,
"env": {
"LANG": "en-US",
"TZ": "UTC",
// Uncomment to debug integration tests
- // "VSCODE_WAIT_FOR_DEBUGGER": "true",
+ "VSCODE_WAIT_FOR_DEBUGGER": "true",
}
},
"terminal.integrated.env.linux": { This is also mentioned in the CONTRIBUTING file, although it's not explicitly called out, only mentioned. |
Weird, I never had to do that before. Works with that change though, thanks! |
FWIW I tested out a few things:
|
Hmmmm...I'm having trouble debugging the cli integration tests. Here is my "jestrunner.debugOptions": {
// Uncomment to debug integration tests
"attachSimplePort": 9223,
"env": {
"LANG": "en-US",
"TZ": "UTC",
// Uncomment to debug integration tests
"VSCODE_WAIT_FOR_DEBUGGER": "true",
}
}, I am clicking on the debug code lens in Shell output from jest run$ cd /Users/andrew.eisenberg/Eclipse/git-repos/github/vscode-codeql/extensions/ql-vscode ; /usr/bin/env LANG=en-US TZ=UTC VSCODE_WAIT_FOR_DEBUGGER=true 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/var/folders/41/kxmfbgxj40dd2l_x63x9fw7c0000gn/T/node-cdp.52486-8.sock","deferredMode":false,"waitForDebugger":"","execPath":"/Users/andrew.eisenberg/.nvm/versions/node/v16.18.1/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/var/folders/41/kxmfbgxj40dd2l_x63x9fw7c0000gn/T/node-debug-callback-6ce3e3fe600e3372"}' /Users/andrew.eisenberg/.nvm/versions/node/v16.18.1/bin/node node_modules/.bin/jest /Users/andrew.eisenberg/Eclipse/git-repos/github/vscode-codeql/extensions/ql-vscode/test/vscode-tests/cli-integration/remote-queries/variant-analysis-manager.test.ts -c /Users/andrew.eisenberg/Eclipse/git-repos/github/vscode-codeql/extensions/ql-vscode/test/vscode-tests/cli-integration/jest.config.ts -t Variant\ Analysis\ Manager\ runVariantAnalysis\ should\ run\ a\ remote\ query\ that\ is\ nested\ inside\ a\ qlpack --runInBand Found existing install in /Users/andrew.eisenberg/Eclipse/git-repos/github/vscode-codeql/extensions/ql-vscode/.vscode-test/vscode-darwin-1.74.3. Skipping download Installing required extensions for /Users/andrew.eisenberg/Eclipse/git-repos/github/vscode-codeql/extensions/ql-vscode/.vscode-test/vscode-darwin-1.74.3/Visual Studio Code.app/Contents/MacOS/Electron Installing extensions... Some other things I noticed:
I'm pretty sure I get the same behaviour when running on main (so it's not this PR, but rather the changes to jest that introduced this weirdness). It's also highly possible there is something strange with my setup if no one else is seeing it. |
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.
Given that the difficulties running and debugging tests are already in main, I think this is fine to go through. But, maybe we can pair at some point to look into debugging some more?
I also tried building the extension and installing it into my vscode. Works perfectly. |
Thanks for the reviews @charisk and @aeisenberg! I've tested the extension myself as well and haven't found any features which aren't working. Since you both also haven't found anything that isn't working, I'll go ahead and merge this.
Sure! I don't actually use the debugging features that much, so that's probably why I missed that these things are not working. |
This bundles the extension files using esbuild, as recommended by VSCode. This reduces the size of the extension from 34MB to less than 5MB.
Gulp will still run TypeScript to check types, but will not use the TypeScript compiler output in the bundle.
Tests are now run separately, outside of Gulp, so their data doesn't need to be copied anymore.
See: https://code.visualstudio.com/api/working-with-extensions/bundling-extension
Checklist
ready-for-doc-review
label there.