Skip to content

Commit 23ef101

Browse files
authored
chore: Refactor findEntrypoints to return all entrypoints with skipped set properly (#1244)
1 parent c2f5efb commit 23ef101

File tree

6 files changed

+167
-80
lines changed

6 files changed

+167
-80
lines changed

Diff for: docs/guide/essentials/target-different-browsers.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ Here are some examples:
7575
</body>
7676
</html>
7777
```
78+
79+
Alternatively, you can use the [`filterEntrypoints` config](/api/reference/wxt/interfaces/InlineConfig#filterentrypoints) to list all the entrypoints you want to build.

Diff for: packages/wxt/src/core/utils/building/__tests__/find-entrypoints.test.ts

+90-24
Original file line numberDiff line numberDiff line change
@@ -701,29 +701,39 @@ describe('findEntrypoints', () => {
701701
});
702702

703703
describe('include option', () => {
704-
it("should filter out the background when include doesn't contain the target browser", async () => {
704+
it("should mark the background as skipped when include doesn't contain the target browser", async () => {
705705
globMock.mockResolvedValueOnce(['background.ts']);
706706
importEntrypointMock.mockResolvedValue({
707707
include: ['not' + config.browser],
708708
});
709709

710710
const entrypoints = await findEntrypoints();
711711

712-
expect(entrypoints).toEqual([]);
712+
expect(entrypoints).toEqual([
713+
expect.objectContaining({
714+
name: 'background',
715+
skipped: true,
716+
}),
717+
]);
713718
});
714719

715-
it("should filter out content scripts when include doesn't contain the target browser", async () => {
720+
it("should mark content scripts as skipped when include doesn't contain the target browser", async () => {
716721
globMock.mockResolvedValueOnce(['example.content.ts']);
717722
importEntrypointMock.mockResolvedValue({
718723
include: ['not' + config.browser],
719724
});
720725

721726
const entrypoints = await findEntrypoints();
722727

723-
expect(entrypoints).toEqual([]);
728+
expect(entrypoints).toEqual([
729+
expect.objectContaining({
730+
name: 'example',
731+
skipped: true,
732+
}),
733+
]);
724734
});
725735

726-
it("should filter out the popup when include doesn't contain the target browser", async () => {
736+
it("should mark the popup as skipped when include doesn't contain the target browser", async () => {
727737
globMock.mockResolvedValueOnce(['popup.html']);
728738
readFileMock.mockResolvedValueOnce(
729739
`<html>
@@ -737,10 +747,15 @@ describe('findEntrypoints', () => {
737747

738748
const entrypoints = await findEntrypoints();
739749

740-
expect(entrypoints).toEqual([]);
750+
expect(entrypoints).toEqual([
751+
expect.objectContaining({
752+
name: 'popup',
753+
skipped: true,
754+
}),
755+
]);
741756
});
742757

743-
it("should filter out the options page when include doesn't contain the target browser", async () => {
758+
it("should mark the options page as skipped when include doesn't contain the target browser", async () => {
744759
globMock.mockResolvedValueOnce(['options.html']);
745760
readFileMock.mockResolvedValueOnce(
746761
`<html>
@@ -754,10 +769,15 @@ describe('findEntrypoints', () => {
754769

755770
const entrypoints = await findEntrypoints();
756771

757-
expect(entrypoints).toEqual([]);
772+
expect(entrypoints).toEqual([
773+
expect.objectContaining({
774+
name: 'options',
775+
skipped: true,
776+
}),
777+
]);
758778
});
759779

760-
it("should filter out an unlisted page when include doesn't contain the target browser", async () => {
780+
it("should mark unlisted pages as skipped when include doesn't contain the target browser", async () => {
761781
globMock.mockResolvedValueOnce(['unlisted.html']);
762782
readFileMock.mockResolvedValueOnce(
763783
`<html>
@@ -771,34 +791,49 @@ describe('findEntrypoints', () => {
771791

772792
const entrypoints = await findEntrypoints();
773793

774-
expect(entrypoints).toEqual([]);
794+
expect(entrypoints).toEqual([
795+
expect.objectContaining({
796+
name: 'unlisted',
797+
skipped: true,
798+
}),
799+
]);
775800
});
776801
});
777802

778803
describe('exclude option', () => {
779-
it('should filter out the background when exclude contains the target browser', async () => {
804+
it('should mark the background as skipped when exclude contains the target browser', async () => {
780805
globMock.mockResolvedValueOnce(['background.ts']);
781806
importEntrypointMock.mockResolvedValue({
782807
exclude: [config.browser],
783808
});
784809

785810
const entrypoints = await findEntrypoints();
786811

787-
expect(entrypoints).toEqual([]);
812+
expect(entrypoints).toEqual([
813+
expect.objectContaining({
814+
name: 'background',
815+
skipped: true,
816+
}),
817+
]);
788818
});
789819

790-
it('should filter out content scripts when exclude contains the target browser', async () => {
820+
it('should mark content scripts as skipped when exclude contains the target browser', async () => {
791821
globMock.mockResolvedValueOnce(['example.content.ts']);
792822
importEntrypointMock.mockResolvedValue({
793823
exclude: [config.browser],
794824
});
795825

796826
const entrypoints = await findEntrypoints();
797827

798-
expect(entrypoints).toEqual([]);
828+
expect(entrypoints).toEqual([
829+
expect.objectContaining({
830+
name: 'example',
831+
skipped: true,
832+
}),
833+
]);
799834
});
800835

801-
it('should filter out the popup when exclude contains the target browser', async () => {
836+
it('should mark the popup as skipped when exclude contains the target browser', async () => {
802837
globMock.mockResolvedValueOnce(['popup.html']);
803838
readFileMock.mockResolvedValueOnce(
804839
`<html>
@@ -810,10 +845,15 @@ describe('findEntrypoints', () => {
810845

811846
const entrypoints = await findEntrypoints();
812847

813-
expect(entrypoints).toEqual([]);
848+
expect(entrypoints).toEqual([
849+
expect.objectContaining({
850+
name: 'popup',
851+
skipped: true,
852+
}),
853+
]);
814854
});
815855

816-
it('should filter out the options page when exclude contains the target browser', async () => {
856+
it('should mark the options page as skipped when exclude contains the target browser', async () => {
817857
globMock.mockResolvedValueOnce(['options.html']);
818858
readFileMock.mockResolvedValueOnce(
819859
`<html>
@@ -825,10 +865,15 @@ describe('findEntrypoints', () => {
825865

826866
const entrypoints = await findEntrypoints();
827867

828-
expect(entrypoints).toEqual([]);
868+
expect(entrypoints).toEqual([
869+
expect.objectContaining({
870+
name: 'options',
871+
skipped: true,
872+
}),
873+
]);
829874
});
830875

831-
it('should filter out an unlisted page when exclude contains the target browser', async () => {
876+
it('should mark unlisted pages as skipped when exclude contains the target browser', async () => {
832877
globMock.mockResolvedValueOnce(['unlisted.html']);
833878
readFileMock.mockResolvedValueOnce(
834879
`<html>
@@ -840,12 +885,17 @@ describe('findEntrypoints', () => {
840885

841886
const entrypoints = await findEntrypoints();
842887

843-
expect(entrypoints).toEqual([]);
888+
expect(entrypoints).toEqual([
889+
expect.objectContaining({
890+
name: 'unlisted',
891+
skipped: true,
892+
}),
893+
]);
844894
});
845895
});
846896

847897
describe('filterEntrypoints option', () => {
848-
it('should control entrypoints accessible', async () => {
898+
it('should override include/exclude of individual entrypoint options', async () => {
849899
globMock.mockResolvedValue([
850900
'options/index.html',
851901
'popup/index.html',
@@ -867,9 +917,25 @@ describe('findEntrypoints', () => {
867917
importEntrypointMock.mockResolvedValue({});
868918

869919
const entrypoints = await findEntrypoints();
870-
const names = entrypoints.map((item) => item.name);
871-
expect(names).toHaveLength(2);
872-
expect(names).toEqual(filterEntrypoints);
920+
921+
expect(entrypoints).toEqual([
922+
expect.objectContaining({
923+
name: 'injected',
924+
skipped: true,
925+
}),
926+
expect.objectContaining({
927+
name: 'options',
928+
skipped: true,
929+
}),
930+
expect.objectContaining({
931+
name: 'popup',
932+
skipped: false,
933+
}),
934+
expect.objectContaining({
935+
name: 'ui',
936+
skipped: false,
937+
}),
938+
]);
873939
});
874940
});
875941
});

Diff for: packages/wxt/src/core/utils/building/__tests__/group-entrypoints.test.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,39 @@ describe('groupEntrypoints', () => {
152152
options: {
153153
type: 'module',
154154
},
155+
skipped: false,
156+
});
157+
const popup = fakePopupEntrypoint({
158+
skipped: false,
155159
});
156-
const popup = fakePopupEntrypoint();
157160
const sandbox = fakeGenericEntrypoint({
158161
inputPath: '/entrypoints/sandbox.html',
159162
name: 'sandbox',
160163
type: 'sandbox',
164+
skipped: false,
161165
});
162166

163167
const actual = groupEntrypoints([background, popup, sandbox]);
164168

165169
expect(actual).toEqual([[background, popup], [sandbox]]);
166170
});
167171

172+
it('should exclude skipped entrypoints from the groups to build', () => {
173+
const background = fakeBackgroundEntrypoint({
174+
options: {
175+
type: 'module',
176+
},
177+
skipped: false,
178+
});
179+
const popup = fakePopupEntrypoint({
180+
skipped: true,
181+
});
182+
183+
const actual = groupEntrypoints([background, popup]);
184+
185+
expect(actual).toEqual([[background]]);
186+
});
187+
168188
it.todo(
169189
'should group ESM compatible sandbox scripts with sandbox pages',
170190
() => {

0 commit comments

Comments
 (0)