-
-
Notifications
You must be signed in to change notification settings - Fork 499
fix: file reloading mechanism and add profile watch ignores #2112
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
ZerGo0
wants to merge
12
commits into
wxt-dev:main
Choose a base branch
from
ZerGo0:fix/dev-watch-missed-reloads
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
12 commits
Select commit
Hold shift + click to select a range
7354e74
fix: file reloading mechanism and add profile watch ignores
ZerGo0 0cf79bb
fix: file change detection and reloading logic
ZerGo0 41b2084
fix: keep createFileReloader out of the public API
ZerGo0 8767b01
fix: file reloading mechanism and add profile watch ignores
ZerGo0 4d0062d
fix: file change detection and reloading logic
ZerGo0 9e4d40d
fix: keep createFileReloader out of the public API
ZerGo0 d3c877f
Merge branch 'fix/dev-watch-missed-reloads' of github.com:ZerGo0/wxt …
ZerGo0 64889ee
fix: rebuild new entrypoints during dev reloads
ZerGo0 c5be896
Merge upstream/main into fix/dev-watch-missed-reloads
ZerGo0 1fb1d26
Merge remote-tracking branch 'upstream/main' into fix/dev-watch-misse…
ZerGo0 d9550bf
chore: address file reloader review comments
ZerGo0 cd5c7cf
fix: avoid redundant no-change reload condition
ZerGo0 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
145 changes: 145 additions & 0 deletions
145
packages/wxt/src/core/utils/__tests__/create-file-reloader.test.ts
|
aklinker1 marked this conversation as resolved.
|
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,145 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { createFileReloader } from '../create-file-reloader'; | ||
| import { findEntrypoints, rebuild } from '../building'; | ||
| import { | ||
| fakeBackgroundEntrypoint, | ||
| fakeBuildOutput, | ||
| fakeDevServer, | ||
| fakeOutputChunk, | ||
| fakePopupEntrypoint, | ||
| setFakeWxt, | ||
| } from '../testing/fake-objects'; | ||
|
|
||
| vi.mock('../building', async () => { | ||
| const actual = | ||
| await vi.importActual<typeof import('../building')>('../building'); | ||
| return { | ||
| ...actual, | ||
| findEntrypoints: vi.fn(), | ||
| rebuild: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| describe('createFileReloader', () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| setFakeWxt({ | ||
| config: { | ||
| root: '/root', | ||
| entrypointsDir: '/root/src/entrypoints', | ||
| dev: { | ||
| server: { | ||
| watchDebounce: 100, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| vi.mocked(findEntrypoints).mockResolvedValue([]); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it('should detect relevant file changes even when noisy file events happen first', async () => { | ||
| const relevantFile = '/root/src/entrypoints/background.ts'; | ||
| const noisyProfileFile = | ||
| '/root/private/.dev-profile/Default/Cache/Cache_Data/d573fa6484e43cf9_0'; | ||
| const backgroundEntrypoint = fakeBackgroundEntrypoint({ | ||
| inputPath: relevantFile, | ||
| skipped: false, | ||
| }); | ||
| const currentOutput = fakeBuildOutput({ | ||
| steps: [ | ||
| { | ||
| entrypoints: backgroundEntrypoint, | ||
| chunks: [fakeOutputChunk({ moduleIds: [relevantFile] })], | ||
| }, | ||
| ], | ||
| publicAssets: [], | ||
| }); | ||
| const server = fakeDevServer({ | ||
| currentOutput, | ||
| reloadExtension: vi.fn(), | ||
| }); | ||
|
|
||
| vi.mocked(rebuild).mockResolvedValue({ | ||
| output: currentOutput, | ||
| manifest: currentOutput.manifest, | ||
| warnings: [], | ||
| }); | ||
| vi.mocked(findEntrypoints).mockResolvedValue([backgroundEntrypoint]); | ||
|
|
||
| const reloadOnChange = createFileReloader(server); | ||
|
|
||
| const fixedFirst = reloadOnChange('change', noisyProfileFile); | ||
| await vi.advanceTimersByTimeAsync(50); | ||
| const fixedSecond = reloadOnChange('change', relevantFile); | ||
| await vi.advanceTimersByTimeAsync(500); | ||
| await Promise.all([fixedFirst, fixedSecond]); | ||
|
|
||
| expect(rebuild).toBeCalledTimes(1); | ||
| const [allEntrypoints, rebuiltGroups] = vi.mocked(rebuild).mock.calls[0]; | ||
| expect( | ||
| allEntrypoints.some((entry) => entry.inputPath === relevantFile), | ||
| ).toBe(true); | ||
| expect( | ||
| rebuiltGroups.flat().some((entry) => entry.inputPath === relevantFile), | ||
| ).toBe(true); | ||
| expect(server.reloadExtension).toBeCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should rebuild and reload extension when a new entrypoint is added', async () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed you resolved that TODO, thanks! |
||
| const backgroundFile = '/root/src/entrypoints/background.ts'; | ||
| const newEntrypointFile = '/root/src/entrypoints/popup.html'; | ||
| const backgroundEntrypoint = fakeBackgroundEntrypoint({ | ||
| inputPath: backgroundFile, | ||
| skipped: false, | ||
| }); | ||
| const popupEntrypoint = fakePopupEntrypoint({ | ||
| inputPath: newEntrypointFile, | ||
| skipped: false, | ||
| }); | ||
| const currentOutput = fakeBuildOutput({ | ||
| steps: [ | ||
| { | ||
| entrypoints: backgroundEntrypoint, | ||
| chunks: [fakeOutputChunk({ moduleIds: [backgroundFile] })], | ||
| }, | ||
| ], | ||
| publicAssets: [], | ||
| }); | ||
| const server = fakeDevServer({ | ||
| currentOutput, | ||
| reloadExtension: vi.fn(), | ||
| }); | ||
|
|
||
| vi.mocked(findEntrypoints).mockResolvedValue([ | ||
| backgroundEntrypoint, | ||
| popupEntrypoint, | ||
| ]); | ||
| vi.mocked(rebuild).mockResolvedValue({ | ||
| output: currentOutput, | ||
| manifest: currentOutput.manifest, | ||
| warnings: [], | ||
| }); | ||
|
|
||
| const reloadOnChange = createFileReloader(server); | ||
| const trigger = reloadOnChange('add', newEntrypointFile); | ||
| await vi.advanceTimersByTimeAsync(500); | ||
| await trigger; | ||
|
|
||
| expect(rebuild).toBeCalledTimes(1); | ||
| const [allEntrypoints, rebuiltGroups, cachedOutput] = | ||
| vi.mocked(rebuild).mock.calls[0]; | ||
| expect(allEntrypoints).toEqual([backgroundEntrypoint, popupEntrypoint]); | ||
| expect( | ||
| rebuiltGroups | ||
| .flat() | ||
| .some((entry) => entry.inputPath === newEntrypointFile), | ||
| ).toBe(true); | ||
| expect(cachedOutput).toEqual(currentOutput); | ||
| expect(server.reloadExtension).toBeCalledTimes(1); | ||
| }); | ||
| }); | ||
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.
Hmm, I'm working on adding an alternative runner in the next major version and hardcoding access to one of the runner's config will prevent me from abstracting it.
It works for now like this, but we'll likely have to add a hook for this in the future...
Just thinking out loud, no changes here.