Compare commits

...

14 Commits

Author SHA1 Message Date
GitHub Actions 12805e9862 chore(release): v0.18.4 2024-05-31 13:27:34 +00:00
hujiulong d889a21465 fix: Properly invalidate content script context (#683) 2024-05-31 08:24:12 -05:00
Aaron 8125d74057 docs: Update contributing guidelines 2024-05-31 01:32:16 -05:00
Aaron c39087a81a Migrate bug report to a GitHub form template 2024-05-31 01:28:45 -05:00
Aaron 7b849b80cb fix: Allow zipping hidden files in sources by listing them explicitly in includeSources (#674) 2024-05-25 16:43:51 -05:00
GitHub Actions b98a5c378e chore(release): v0.18.3 2024-05-24 10:51:34 +00:00
Aaron 215def7e15 fix(security): Upgrade tar to 6.2.1 2024-05-24 05:46:11 -05:00
Aaron 3b954cc6fb chore: Upgrade templates to v0.18 2024-05-24 05:40:07 -05:00
Aaron 20bdd8ad2f fix: Remove import * as imports from entrypoints during build (#671) 2024-05-24 05:38:53 -05:00
Edoan cb9a9c0530 docs: Add YTBlock to homepage (#666) 2024-05-21 12:01:55 -05:00
Aaron 48d8d236c0 fix: Automatically add dev server to sandbox CSP (#663) 2024-05-20 23:41:11 -05:00
Aaron 87d9511b31 chore: Add missing tests for dev mode CSP (#662) 2024-05-20 23:35:21 -05:00
Aaron 5d8efef02f ci: Fix sync-releases workflow trigger 2024-05-08 11:04:58 -05:00
Aaron c9008cd835 Update changelog 2024-05-08 11:03:17 -05:00
22 changed files with 354 additions and 85 deletions
-50
View File
@@ -1,50 +0,0 @@
---
name: Bug report
about: Report an issue with WXT
title: ''
labels: triage
assignees: ''
---
### Describe the bug
A clear and concise description of what the bug is.
### To Reproduce
Share minimal reproduction. Examples of a minimal reproduction:
- PR with a failing test case
- ZIP file containing a minimal WXT project (be sure to include your lockfile!!)
> **_⚠️ If you don't upload a minimal reproduction, your issue will be closed until a reproduction is added._**
>
> Why? https://antfu.me/posts/why-reproductions-are-required
Steps to reproduce the bug using the reproduction:
1. Install dependencies: `pnpm i`
2. Start dev mode: `pnpm dev`
3. Click this...
4. Do that...
5. Etc...
### Expected behavior
A clear and concise description of what you expected to happen.
### Screenshots
If applicable, add screenshots to help explain your problem.
### Environment
<!--- Run `npx envinfo --system --browsers --binaries --npmPackages wxt,vite` and paste the output below -->
```
Paste output here
```
### Additional context
Add any other context about the problem here, otherwise you can delete this section.
+74
View File
@@ -0,0 +1,74 @@
name: "\U0001F41E Bug report"
description: Report an issue with WXT
labels: [pending-triage]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: bug-description
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks!
placeholder: I am doing ... What I expect is ... What actually happening is ...
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: Reproduction
description: |
Please provide a minimal reproduction. This can include:
- A PR with a failing test case
- A link to a github repo
- A ZIP you upload to this issue
A [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) is required ([Why?](https://antfu.me/posts/why-reproductions-are-required)). If a report is vague (e.g. just a generic error message) and has no reproduction or a partial reproduction, it will be closed immediately and labeled with as "needs-reproduction". Once a reproduction is provided, it will be re-opened.
placeholder: Reproduction URL or attach a ZIP
validations:
required: true
- type: textarea
id: reproduction-steps
attributes:
label: Steps to reproduce
description: Please provide any reproduction steps that may need to be described. E.g. if it happens only when running the dev or build script make sure it's clear which one to use.
placeholder: Run `npm install` followed by `npm run dev`
- type: textarea
id: system-info
attributes:
label: System Info
description: Output of `npx envinfo --system --browsers --binaries --npmPackages wxt,vite`
render: shell
placeholder: System, Binaries, Browsers
validations:
required: true
- type: dropdown
id: package-manager
attributes:
label: Used Package Manager
description: Select the used package manager
options:
- npm
- yarn
- pnpm
- bun
validations:
required: true
- type: checkboxes
id: checkboxes
attributes:
label: Validations
description: Before submitting the issue, please make sure you do the following
options:
- label: Read the [Contributing Guidelines](https://github.com/wxt-dev/wxt/blob/main/CONTRIBUTING.md).
required: true
- label: Read the [docs](https://wxt.dev/guide/installation.html).
required: true
- label: Check that there isn't [already an issue](https://github.com/wxt-dev/wxt/issues) that reports the same bug to avoid creating a duplicate.
required: true
- label: Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/wxt-dev/wxt/discussions) or join our [Discord Chat Server](https://discord.gg/ZFsZqGery9).
required: true
- label: The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
required: true
+8
View File
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Discord Chat
url: https://discord.gg/ZFsZqGery9
about: Ask questions and discuss with other WXT users in real time.
- name: Questions & Discussions
url: https://github.com/wxt-dev/wxt/discussions
about: Use GitHub discussions for message-board style questions and discussions.
+1 -1
View File
@@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- CHANGELOG.md
- packages/wxt/CHANGELOG.md
jobs:
sync:
+4 -4
View File
@@ -37,13 +37,13 @@ pnpm build
```sh
# Build WXT package, then build demo extension
cd demo
cd packages/wxt-demo
pnpm build
```
```sh
# Build WXT package, then start the demo extension in dev mode
cd demo
cd packages/wxt-demo
pnpm dev
```
@@ -75,7 +75,7 @@ To run tests for a specific file, add the filename at the end of the test comman
pnpm test manifest-contents
```
Unit and E2E tests are ran together via [Vitest workspaces](https://vitest.dev/guide/#workspaces-support).
All test (unit and E2E) for all packages are ran together via [Vitest workspaces](https://vitest.dev/guide/#workspaces-support).
If you want to manually test a change, you can modify the demo project for your test, but please don't leave those changes committed once you open a PR.
@@ -90,7 +90,7 @@ npm run dev
npm run build
```
Note that templates are hardcoded to a specific version of `wxt` from NPM, they do not use the local version. PR checks will test your changes against the templates, but if you want to manually do it, update the package.json dependency:
Note that templates are hardcoded to a specific version of `wxt` from NPM, they do not use the local version. PR checks will test your PR's changes against the templates, but if you want to manually do it, update the package.json dependency:
```diff
"devDependencies": {
@@ -26,6 +26,7 @@ const chromeExtensionIds = [
'nhclljcpfmmaiojbhhnkpjcfmacfcian', // Facebook Video Controls
'mblkhbaakhbhiimkbcnmeciblfhmafna', // ElemSnap - Quick capture of webpage elements and conversion to images,
'oajalfneblkfiejoadecnmodfpnaeblh', // MS Edge TTS (Text to Speech)
'nedcanggplmbbgmlpcjiafgjcpdimpea', // YTBlock - Block any content from YouTube™
];
const { data, err, isLoading } = useListExtensionDetails(chromeExtensionIds);
+45 -1
View File
@@ -1,5 +1,49 @@
# Changelog
## v0.18.4
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.18.3...v0.18.4)
### 🩹 Fixes
- Allow zipping hidden files in sources by listing them explicitly in `includeSources` ([#674](https://github.com/wxt-dev/wxt/pull/674))
- Properly invalidate content script context ([#683](https://github.com/wxt-dev/wxt/pull/683))
### 📖 Documentation
- Update contributing guidelines ([8125d74](https://github.com/wxt-dev/wxt/commit/8125d74))
### ❤️ Contributors
- Hujiulong ([@hujiulong](http://github.com/hujiulong))
## v0.18.3
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.18.2...v0.18.3)
### 🩹 Fixes
- Automatically add dev server to sandbox CSP ([#663](https://github.com/wxt-dev/wxt/pull/663))
- Remove `import * as` imports from entrypoints during build ([#671](https://github.com/wxt-dev/wxt/pull/671))
- **security:** Upgrade tar to 6.2.1 ([215def7](https://github.com/wxt-dev/wxt/commit/215def7))
### 📖 Documentation
- Add YTBlock to homepage ([#666](https://github.com/wxt-dev/wxt/pull/666))
### 🏡 Chore
- Add missing tests for dev mode CSP ([#662](https://github.com/wxt-dev/wxt/pull/662))
- Upgrade templates to v0.18 ([3b954cc](https://github.com/wxt-dev/wxt/commit/3b954cc))
### 🤖 CI
- Fix sync-releases workflow trigger ([5d8efef](https://github.com/wxt-dev/wxt/commit/5d8efef))
### ❤️ Contributors
- Edoan ([@EdoanR](http://github.com/EdoanR))
## v0.18.2
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.18.1...v0.18.2)
@@ -24,7 +68,7 @@
- Edoan ([@EdoanR](http://github.com/EdoanR))
- Linus Norton ([@linusnorton](http://github.com/linusnorton))
- Jeffrey Zang ([@jeffrey-zang](http://github.com/jeffrey-zang))
- Emmanuel Ferdman <emmanuelferdman@gmail.com>
- Emmanuel Ferdman ([@emmanuel-ferdman](https://github.com/emmanuel-ferdman))
## v0.18.1
+44
View File
@@ -96,4 +96,48 @@ describe('Zipping', () => {
expect(await project.fileExists(artifactZip)).toBe(true);
expect(await project.fileExists(sourcesZip)).toBe(true);
});
it('should not zip hidden files into sources by default', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
});
project.addFile(
'entrypoints/background.ts',
'export default defineBackground(() => {});',
);
project.addFile('.env');
const unzipDir = project.resolvePath('.output/test-1.0.0-sources');
const sourcesZip = project.resolvePath('.output/test-1.0.0-sources.zip');
await project.zip({
browser: 'firefox',
});
await extract(sourcesZip, { dir: unzipDir });
console.log(unzipDir); // TODO: Remove log
expect(await project.fileExists(unzipDir, '.env')).toBe(false);
});
it('should allow zipping hidden files into sources when explicitly listed', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
});
project.addFile(
'entrypoints/background.ts',
'export default defineBackground(() => {});',
);
project.addFile('.env');
const unzipDir = project.resolvePath('.output/test-1.0.0-sources');
const sourcesZip = project.resolvePath('.output/test-1.0.0-sources.zip');
await project.zip({
browser: 'firefox',
zip: {
includeSources: ['.env'],
},
});
await extract(sourcesZip, { dir: unzipDir });
expect(await project.fileExists(unzipDir, '.env')).toBe(true);
});
});
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.18.2",
"version": "0.18.4",
"description": "Next gen framework for developing web extensions",
"repository": {
"type": "git",
@@ -217,7 +217,7 @@ export class ContentScriptContext implements AbortController {
// Use postMessage so it get's sent to all the frames of the page.
window.postMessage(
{
event: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
type: ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
contentScriptName: this.contentScriptName,
},
'*',
@@ -10,6 +10,7 @@ import {
fakeOptionsEntrypoint,
fakePopupEntrypoint,
fakeSidepanelEntrypoint,
fakeWxtDevServer,
setFakeWxt,
} from '../testing/fake-objects';
import { Manifest } from 'webextension-polyfill';
@@ -1496,6 +1497,91 @@ describe('Manifest Utils', () => {
expect(actual.host_permissions).toBeUndefined();
});
});
describe('Dev mode', () => {
it('should not add any code for production builds', async () => {
setFakeWxt({
config: {
command: 'build',
},
server: {
hostname: 'localhost',
port: 3000,
origin: 'http://localhost:3000',
},
});
const output = fakeBuildOutput();
const entrypoints: Entrypoint[] = [];
const { manifest: actual } = await generateManifest(
entrypoints,
output,
);
expect(actual.permissions).toBeUndefined();
expect(actual.content_security_policy).toBeUndefined();
});
it('should add required permissions for dev mode to function for MV2', async () => {
setFakeWxt({
config: {
command: 'serve',
manifestVersion: 2,
},
server: fakeWxtDevServer({
port: 3000,
hostname: 'localhost',
origin: 'http://localhost:3000',
}),
});
const output = fakeBuildOutput();
const entrypoints: Entrypoint[] = [];
const { manifest: actual } = await generateManifest(
entrypoints,
output,
);
expect(actual).toMatchObject({
content_security_policy:
"script-src 'self' http://localhost:3000; object-src 'self';",
permissions: ['http://localhost/*', 'tabs'],
});
});
it('should add required permissions for dev mode to function for MV3', async () => {
setFakeWxt({
config: {
command: 'serve',
manifestVersion: 3,
browser: 'chrome',
},
server: fakeWxtDevServer({
hostname: 'localhost',
port: 3000,
origin: 'http://localhost:3000',
}),
});
const output = fakeBuildOutput();
const entrypoints: Entrypoint[] = [];
const { manifest: actual } = await generateManifest(
entrypoints,
output,
);
expect(actual).toMatchObject({
content_security_policy: {
extension_pages:
"script-src 'self' 'wasm-unsafe-eval' http://localhost:3000; object-src 'self';",
sandbox:
"script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:3000; sandbox allow-scripts allow-forms allow-popups allow-modals; child-src 'self';",
},
host_permissions: ['http://localhost/*'],
permissions: ['tabs', 'scripting'],
});
});
});
});
describe('stripPathFromMatchPattern', () => {
@@ -50,6 +50,7 @@ import "@/utils/github";
import '@/utils/github';
import"@/utils/github"
import'@/utils/github';
import * as abc from "@/utils/github"
`;
expect(removeImportStatements(imports).trim()).toEqual('');
});
+16 -5
View File
@@ -466,23 +466,34 @@ function addDevModeCsp(manifest: Manifest.WebExtensionManifest): void {
addPermission(manifest, permission);
}
const csp = new ContentSecurityPolicy(
const extensionPagesCsp = new ContentSecurityPolicy(
manifest.manifest_version === 3
? // @ts-expect-error: extension_pages is not typed
manifest.content_security_policy?.extension_pages ??
"script-src 'self' 'wasm-unsafe-eval'; object-src 'self';" // default CSP for MV3
"script-src 'self' 'wasm-unsafe-eval'; object-src 'self';" // default extension_pages CSP for MV3
: manifest.content_security_policy ??
"script-src 'self'; object-src 'self';", // default CSP for MV2
);
const sandboxCsp = new ContentSecurityPolicy(
// @ts-expect-error: sandbox is not typed
manifest.content_security_policy?.sandbox ??
"sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';", // default sandbox CSP for MV3
);
if (wxt.server) csp.add('script-src', allowedCsp);
if (wxt.server) {
extensionPagesCsp.add('script-src', allowedCsp);
sandboxCsp.add('script-src', allowedCsp);
}
if (manifest.manifest_version === 3) {
manifest.content_security_policy ??= {};
// @ts-expect-error: extension_pages is not typed
manifest.content_security_policy.extension_pages = csp.toString();
manifest.content_security_policy.extension_pages =
extensionPagesCsp.toString();
// @ts-expect-error: sandbox is not typed
manifest.content_security_policy.sandbox = sandboxCsp.toString();
} else {
manifest.content_security_policy = csp.toString();
manifest.content_security_policy = extensionPagesCsp.toString();
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ export function safeVarName(str: string): string {
*/
export function removeImportStatements(text: string): string {
return text.replace(
/(import\s?[{\w][\s\S]*?from\s?["'][\s\S]*?["'];?|import\s?["'][\s\S]*?["'];?)/gm,
/(import\s?[\s\S]*?from\s?["'][\s\S]*?["'];?|import\s?["'][\s\S]*?["'];?)/gm,
'',
);
}
@@ -311,10 +311,27 @@ export const fakeWxt = fakeObjectCreator<Wxt>(() => ({
logger: mock(),
reloadConfig: vi.fn(),
pm: mock(),
server: faker.helpers.arrayElement([undefined, mock<WxtDevServer>()]),
server: faker.helpers.arrayElement([undefined, fakeWxtDevServer()]),
builder: mock(),
}));
export const fakeWxtDevServer = fakeObjectCreator<WxtDevServer>(() => ({
currentOutput: fakeBuildOutput(),
hostname: 'localhost',
origin: 'http://localhost:3000',
port: 3000,
reloadContentScript: vi.fn(),
reloadExtension: vi.fn(),
reloadPage: vi.fn(),
restart: vi.fn(),
restartBrowser: vi.fn(),
start: vi.fn(),
stop: vi.fn(),
transformHtml: vi.fn(),
watcher: mock(),
ws: mock(),
}));
export function setFakeWxt(overrides?: DeepPartial<Wxt>) {
const wxt = fakeWxt(overrides);
setWxtForTesting(wxt);
+3 -6
View File
@@ -104,15 +104,12 @@ async function zipDir(
// Ignore node_modules, otherwise this glob step takes forever
ignore: ['**/node_modules'],
onlyFiles: true,
dot: true,
})
).filter((relativePath) => {
return (
wxt.config.zip.includeSources.some((pattern) =>
minimatch(relativePath, pattern),
) ||
!wxt.config.zip.excludeSources.some((pattern) =>
minimatch(relativePath, pattern),
)
options?.include?.some((pattern) => minimatch(relativePath, pattern)) ||
!options?.exclude?.some((pattern) => minimatch(relativePath, pattern))
);
});
const filesToZip = [
+45 -9
View File
@@ -1494,7 +1494,7 @@ packages:
vite: ^5.0.0
vue: ^3.2.25
dependencies:
vite: 5.2.8(@types/node@20.10.3)
vite: 5.2.8
vue: 3.4.21(typescript@5.3.3)
dev: true
@@ -2988,7 +2988,7 @@ packages:
mri: 1.2.0
node-fetch-native: 1.6.4
pathe: 1.1.2
tar: 6.2.0
tar: 6.2.1
transitivePeerDependencies:
- supports-color
dev: false
@@ -3004,7 +3004,7 @@ packages:
nypm: 0.3.8
ohash: 1.1.3
pathe: 1.1.2
tar: 6.2.0
tar: 6.2.1
dev: false
/glob-parent@5.1.2:
@@ -5219,8 +5219,8 @@ packages:
resolution: {integrity: sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==}
dev: true
/tar@6.2.0:
resolution: {integrity: sha512-/Wo7DcT0u5HUV486xg675HtjNd3BXZ6xDbzsCUZPt5iw8bTQ63bP0Raut3mvro9u+CUyq7YQd8Cx55fsZXxqLQ==}
/tar@6.2.1:
resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==}
engines: {node: '>=10'}
dependencies:
chownr: 2.0.0
@@ -5563,7 +5563,7 @@ packages:
debug: 4.3.4
pathe: 1.1.2
picocolors: 1.0.0
vite: 5.2.8(@types/node@20.10.3)
vite: 5.2.8
transitivePeerDependencies:
- '@types/node'
- less
@@ -5575,6 +5575,41 @@ packages:
- terser
dev: true
/vite@5.2.8:
resolution: {integrity: sha512-OyZR+c1CE8yeHw5V5t59aXsUPPVTHMDjEZz8MgguLL/Q7NblxhZUlTu9xSPqlsUO/y+X7dlU05jdhvyycD55DA==}
engines: {node: ^18.0.0 || >=20.0.0}
hasBin: true
peerDependencies:
'@types/node': ^18.0.0 || >=20.0.0
less: '*'
lightningcss: ^1.21.0
sass: '*'
stylus: '*'
sugarss: '*'
terser: ^5.4.0
peerDependenciesMeta:
'@types/node':
optional: true
less:
optional: true
lightningcss:
optional: true
sass:
optional: true
stylus:
optional: true
sugarss:
optional: true
terser:
optional: true
dependencies:
esbuild: 0.20.2
postcss: 8.4.38
rollup: 4.14.0
optionalDependencies:
fsevents: 2.3.3
dev: true
/vite@5.2.8(@types/node@20.10.3):
resolution: {integrity: sha512-OyZR+c1CE8yeHw5V5t59aXsUPPVTHMDjEZz8MgguLL/Q7NblxhZUlTu9xSPqlsUO/y+X7dlU05jdhvyycD55DA==}
engines: {node: ^18.0.0 || >=20.0.0}
@@ -5609,6 +5644,7 @@ packages:
rollup: 4.14.0
optionalDependencies:
fsevents: 2.3.3
dev: false
/vitepress@1.0.0-rc.34(typescript@5.3.3):
resolution: {integrity: sha512-TUbTiSdAZFni2XlHlpx61KikgkQ5uG4Wtmw2R0SXhIOG6qGqzDJczAFjkMc4i45I9c3KyatwOYe8oEfCnzVYwQ==}
@@ -5636,7 +5672,7 @@ packages:
shikiji: 0.9.16
shikiji-core: 0.9.16
shikiji-transformers: 0.9.16
vite: 5.2.8(@types/node@20.10.3)
vite: 5.2.8
vue: 3.4.21(typescript@5.3.3)
transitivePeerDependencies:
- '@algolia/client-search'
@@ -5682,7 +5718,7 @@ packages:
peerDependencies:
vite: ^4.0.0 || ^5.0.0
dependencies:
vite: 5.2.8(@types/node@20.10.3)
vite: 5.2.8
dev: true
/vitest@1.5.3:
@@ -5727,7 +5763,7 @@ packages:
strip-literal: 2.1.0
tinybench: 2.5.1
tinypool: 0.8.4
vite: 5.2.8(@types/node@20.10.3)
vite: 5.2.8
vite-node: 1.5.3
why-is-node-running: 2.2.2
transitivePeerDependencies:
+1 -1
View File
@@ -23,6 +23,6 @@
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.3.3",
"wxt": "^0.17.0"
"wxt": "^0.18.0"
}
}
+1 -1
View File
@@ -20,6 +20,6 @@
"devDependencies": {
"typescript": "^5.3.3",
"vite-plugin-solid": "^2.8.0",
"wxt": "^0.17.0"
"wxt": "^0.18.0"
}
}
+1 -1
View File
@@ -20,6 +20,6 @@
"svelte-check": "^3.6.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"wxt": "^0.17.0"
"wxt": "^0.18.0"
}
}
+1 -1
View File
@@ -16,6 +16,6 @@
},
"devDependencies": {
"typescript": "^5.3.3",
"wxt": "^0.17.0"
"wxt": "^0.18.0"
}
}
+1 -1
View File
@@ -21,6 +21,6 @@
"@vitejs/plugin-vue": "^5.0.1",
"typescript": "^5.3.3",
"vue-tsc": "^2.0.6",
"wxt": "^0.17.0"
"wxt": "^0.18.0"
}
}