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

feat: Include/exclude entrypoints based on target browser #115

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/guide/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default defineBackground({
persistent: undefined | true | false,
type: undefined | 'module',

// Set include/exclude if the background should be removed from some builds
include: undefined | string[],
exclude: undefined | string[],

// Executed when background is loaded
main() {
// ...
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/bookmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/content-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default defineContentScript({
matchOriginAsFallback: undefined | true | false,
world: undefined | 'ISOLATED' | 'MAIN',

// Set include/exclude if the background should be removed from some builds
include: undefined | string[],
exclude: undefined | string[],

main() {
// Executed when content script is loaded
},
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Plain old HTML file.
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/newtab.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<meta name="manifest.open_in_tab" content="true|false" />
<meta name="manifest.chrome_style" content="true|false" />
<meta name="manifest.browser_style" content="true|false" />
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
3 changes: 3 additions & 0 deletions docs/guide/popup.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
}"
/>
<meta name="manifest.type" content="page_action|browser_action" />
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Firefox does not support sandboxed pages.

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/sidepanel.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Firefox does not support sidepanel pages.

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/unlisted-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ console.log(url); // "chrome-extension://<id>/<name>.html"

## Definition

Plain old HTML file.

```html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<!-- Set include/exclude if the page should be removed from some builds -->
<meta name="manifest.include" content="['chrome', ...]" />
<meta name="manifest.exclude" content="['chrome', ...]" />
</head>
<body>
<!-- ... -->
Expand Down
40 changes: 40 additions & 0 deletions e2e/tests/output-structure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,44 @@ describe('Output Directory Structure', () => {
{\\"manifest_version\\":3,\\"name\\":\\"E2E Extension\\",\\"description\\":\\"Example description\\",\\"version\\":\\"0.0.0\\",\\"version_name\\":\\"0.0.0-test\\",\\"content_scripts\\":[{\\"matches\\":[\\"*://*/*\\"],\\"js\\":[\\"content-scripts/overlay-one.js\\"]}]}"
`);
});

it('should not include an entrypoint if the target browser is not in the list of included targets', async () => {
const project = new TestProject();
project.addFile('entrypoints/options.html', '<html></html>');
project.addFile(
'entrypoints/background.ts',
`
export default defineBackground({
include: ["chrome"],
main() {},
})
`,
);

await project.build({ browser: 'firefox' });

expect(await project.fileExists('.output/firefox-mv2/background.js')).toBe(
false,
);
});

it('should not include an entrypoint if the target browser is in the list of excluded targets', async () => {
const project = new TestProject();
project.addFile('entrypoints/options.html', '<html></html>');
project.addFile(
'entrypoints/background.ts',
`
export default defineBackground({
exclude: ["chrome"],
main() {},
})
`,
);

await project.build({ browser: 'chrome' });

expect(await project.fileExists('.output/firefox-mv2/background.js')).toBe(
false,
);
});
});
Loading