-
Notifications
You must be signed in to change notification settings - Fork 92
perf(vscode-extension): keep the language server out of the client bundle #1275
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
Open
EvilGenius13
wants to merge
4
commits into
main
Choose a base branch
from
jf/vscode-extension-bundle-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4e4df97
perf(vscode-extension): deep-import LSP types to keep the server out …
EvilGenius13 f3b7ea9
refactor(theme-check-common): expose path and LSP types as public sub…
EvilGenius13 7a6e202
feat(theme-check-common): define public package subpath exports
EvilGenius13 eb0f259
docs(changeset): shorten exports migration notes
EvilGenius13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| '@shopify/theme-language-server-common': major | ||
| '@shopify/theme-check-common': major | ||
| 'theme-check-vscode': patch | ||
| --- | ||
|
|
||
| Define the public entry points with a package `exports` map | ||
|
|
||
| - `@shopify/theme-check-common` exports `.`, `./path`, `./test`, and `./package.json`. | ||
| - `@shopify/theme-language-server-common` exports `.`, `./types`, and `./package.json`. | ||
|
|
||
| Importing a subpath pulls in only that module instead of the whole package. The VS Code extension | ||
| uses this to keep the language server out of the client bundle: `browser/extension.js` is 2.1 MB | ||
| instead of 6.7 MB, and `node/extension.js` is 1.4 MB instead of 6.5 MB. Barrel imports still work | ||
| exactly as before. | ||
|
|
||
| **Breaking:** the `exports` map is now the complete public surface of both packages. Any `src/` or | ||
| `dist/` deep import that is not listed above no longer resolves — Node and bundlers throw | ||
| `ERR_PACKAGE_PATH_NOT_EXPORTED`. | ||
|
|
||
| To migrate: | ||
|
|
||
| - Replace `@shopify/theme-check-common/src/test` or `.../dist/test` with | ||
| `@shopify/theme-check-common/test`. | ||
| - Seven symbols previously reachable only through a retired deep import are now exported from the | ||
| `@shopify/theme-check-common` barrel: `getPosition`, `createDisabledChecksModule`, | ||
| `UNMATCHED_COMMENT_CLOSE_PARSER_ERROR`, `UNMATCHED_RAW_CLOSE_PARSER_ERROR`, | ||
| `hasRubyAcceptedInertCommentBodyCloser`, `hasJavascriptClosingTagAfter`, and | ||
| `hasRubyAcceptedRawTagCloserWithMarkup`. | ||
|
|
||
| Every other symbol those modules exposed is intentionally private. If you depend on one, open an | ||
| issue so it can be promoted deliberately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const requireFromHere = createRequire(__filename); | ||
|
|
||
| function resolutionErrorCode(specifier: string): string | undefined { | ||
| try { | ||
| requireFromHere.resolve(specifier); | ||
| return undefined; | ||
| } catch (error) { | ||
| return (error as NodeJS.ErrnoException).code; | ||
| } | ||
| } | ||
|
|
||
| describe('Module: package exports', () => { | ||
| it.each([ | ||
| ['@shopify/theme-check-common', 'theme-check-common/dist/index.js'], | ||
| ['@shopify/theme-check-common/path', 'theme-check-common/dist/path.js'], | ||
| ['@shopify/theme-check-common/test', 'theme-check-common/dist/test/index.js'], | ||
| ['@shopify/theme-check-common/package.json', 'theme-check-common/package.json'], | ||
| ])('resolves %s', (specifier, suffix) => { | ||
| expect(requireFromHere.resolve(specifier).replace(/\\/g, '/')).toContain(suffix); | ||
| }); | ||
|
|
||
| it.each([ | ||
| '@shopify/theme-check-common/src/index', | ||
| '@shopify/theme-check-common/src/test', | ||
| '@shopify/theme-check-common/dist/index', | ||
| '@shopify/theme-check-common/dist/test', | ||
| '@shopify/theme-check-common/dist/path', | ||
| '@shopify/theme-check-common/dist/utils', | ||
| '@shopify/theme-check-common/dist/disabled-checks', | ||
| '@shopify/theme-check-common/dist/checks/liquid-syntax-error/comment', | ||
| '@shopify/theme-check-common/dist/checks/liquid-syntax-error/javascript', | ||
| '@shopify/theme-check-common/dist/checks/liquid-syntax-error/utils', | ||
| ])('no longer exposes %s', (specifier) => { | ||
| expect(resolutionErrorCode(specifier)).toBe('ERR_PACKAGE_PATH_NOT_EXPORTED'); | ||
| }); | ||
|
|
||
| it('exposes the promoted symbols on the barrel', () => { | ||
| const themeCheckCommon = requireFromHere('@shopify/theme-check-common'); | ||
|
|
||
| for (const name of [ | ||
| 'getPosition', | ||
| 'createDisabledChecksModule', | ||
| 'UNMATCHED_COMMENT_CLOSE_PARSER_ERROR', | ||
| 'UNMATCHED_RAW_CLOSE_PARSER_ERROR', | ||
| 'hasRubyAcceptedInertCommentBodyCloser', | ||
| 'hasJavascriptClosingTagAfter', | ||
| 'hasRubyAcceptedRawTagCloserWithMarkup', | ||
| ]) { | ||
| expect(themeCheckCommon).toHaveProperty(name); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/theme-language-server-common/src/package-exports.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { createRequire } from 'node:module'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const requireFromHere = createRequire(__filename); | ||
|
|
||
| function resolutionErrorCode(specifier: string): string | undefined { | ||
| try { | ||
| requireFromHere.resolve(specifier); | ||
| return undefined; | ||
| } catch (error) { | ||
| return (error as NodeJS.ErrnoException).code; | ||
| } | ||
| } | ||
|
|
||
| describe('Module: package exports', () => { | ||
| it.each([ | ||
| ['@shopify/theme-language-server-common', 'theme-language-server-common/dist/index.js'], | ||
| ['@shopify/theme-language-server-common/types', 'theme-language-server-common/dist/types.js'], | ||
| [ | ||
| '@shopify/theme-language-server-common/package.json', | ||
| 'theme-language-server-common/package.json', | ||
| ], | ||
| ])('resolves %s', (specifier, suffix) => { | ||
| expect(requireFromHere.resolve(specifier).replace(/\\/g, '/')).toContain(suffix); | ||
| }); | ||
|
|
||
| it.each([ | ||
| '@shopify/theme-language-server-common/src/index', | ||
| '@shopify/theme-language-server-common/src/types', | ||
| '@shopify/theme-language-server-common/dist/index', | ||
| '@shopify/theme-language-server-common/dist/types', | ||
| ])('no longer exposes %s', (specifier) => { | ||
| expect(resolutionErrorCode(specifier)).toBe('ERR_PACKAGE_PATH_NOT_EXPORTED'); | ||
| }); | ||
| }); |
2 changes: 1 addition & 1 deletion
2
packages/theme-language-server-common/src/renamed/handlers/AssetRenameHandler.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/theme-language-server-common/src/renamed/handlers/BlockRenameHandler.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/theme-language-server-common/src/renamed/handlers/SectionRenameHandler.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/theme-language-server-common/src/renamed/handlers/SnippetRenameHandler.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/theme-language-server-common/src/server/startServer.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 love the outcome of this PR but not a huge fan of how we're getting there. Reaching into the
distfolder is creating an implicit connection totheme-check-common's build process. I'd rather fix this intheme-check-commonitself by adding some public subpath exports that we intend for consumers to use.Also side note: I don't think the type imports need this? I don't think these are included at runtime.
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 the suggestion Gray.
Type imports - you were totally right so I put it back the way it was.
Instead of reaching into the
distfolder they got moved into the packages themselves and they each have an entry point pointing to the actual file. No more weird connections.I tried the subpath exports but I ran into a couple problems. Our TS setup falls back to the older resolution mode and it ignores exports completely. When I tried setting up the new mode if a path wasn't explicitly listed it stopped resolving. It messed up deep-imports of
MockThemeand MockFileSystem`. My concern is if any user of the libraries has deep links we would probably break for them as well.What do you think about this current method vs the subpath export?