Compare commits

..

10 Commits

Author SHA1 Message Date
Aaron Klinker 8447f9aa7c Release version for testing 2023-12-17 09:53:27 -06:00
Aaron Klinker ee768f84bb Remove wxt/client inline for vitest 2023-12-17 09:49:38 -06:00
Aaron Klinker cfd4979a7a Fix docs 2023-12-17 09:41:43 -06:00
Aaron Klinker de5b4e16cd cleanup 2023-12-17 09:32:55 -06:00
Aaron Klinker 5c696da6e2 Fix build 2023-12-17 09:30:28 -06:00
Aaron Klinker 2363144bb6 Cleanup 2023-12-17 09:15:05 -06:00
Aaron Klinker 9e2d11d8db List imports by hand 2023-12-16 12:37:13 -06:00
Aaron Klinker f2523c778f Only export types for polyfill 2023-12-16 12:29:15 -06:00
Aaron Klinker 04a51581fc Fix tests, don't auto-import WebextensionPolyfill namespace 2023-12-16 12:28:25 -06:00
Aaron Klinker bb40db78e3 Import all dependencies from WXT 2023-12-16 12:20:15 -06:00
25 changed files with 59 additions and 96 deletions
-8
View File
@@ -1,13 +1,5 @@
# Changelog
## v0.12.2
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.12.1...v0.12.2)
### 🚀 Enhancements
- Support PNPM without hoisting dependencies ([#291](https://github.com/wxt-dev/wxt/pull/291))
## v0.12.1
[compare changes](https://github.com/wxt-dev/wxt/compare/v0.12.0...v0.12.1)
-2
View File
@@ -17,8 +17,6 @@ describe('Auto Imports', () => {
export {}
declare global {
const ContentScriptContext: typeof import('wxt/client')['ContentScriptContext']
const InvalidMatchPattern: typeof import('wxt/sandbox')['InvalidMatchPattern']
const MatchPattern: typeof import('wxt/sandbox')['MatchPattern']
const browser: typeof import('wxt/browser')['browser']
const builtinDrivers: typeof import('wxt/storage')['builtinDrivers']
const createContentScriptIframe: typeof import('wxt/client')['createContentScriptIframe']
+2 -4
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.12.2",
"version": "0.12.2-alpha1",
"description": "Next gen framework for developing web extensions",
"engines": {
"node": ">=18",
@@ -86,9 +86,7 @@
"lint": "run-p -c -s lint:*",
"lint:eslint": "echo 'ESLint: TODO'",
"lint:package": "publint",
"compile": "run-s -c compile:*",
"compile:wxt": "tsc --noEmit",
"compile:virtual": "tsc --noEmit -p src/virtual",
"compile": "tsc --noEmit",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"prepare": "simple-git-hooks",
+2 -3
View File
@@ -16,7 +16,7 @@ const startTime = Date.now();
const outDir = 'dist';
await fs.rm(path.join(outDir, '*'), { recursive: true, force: true });
const preset = {
const preset: tsup.Options = {
dts: true,
silent: true,
sourcemap: false,
@@ -26,7 +26,7 @@ const preset = {
'virtual:user-content-script-main-world',
'virtual:user-background',
],
} satisfies tsup.Options;
};
function spinnerPMap(configs: tsup.Options[]) {
let completed = 0;
@@ -88,7 +88,6 @@ const config: tsup.Options[] = [
format: ['esm'],
splitting: false,
dts: false,
external: [...preset.external, 'wxt'],
},
// CJS-only
{
@@ -1,6 +1,6 @@
import { ContentScriptDefinition } from '~/types';
import { browser } from '~/browser';
import { logger } from '~/sandbox/utils/logger';
import { logger } from '~/client/utils/logger';
import { WxtLocationChangeEvent, getUniqueEventName } from './custom-events';
import { createLocationWatcher } from './location-watcher';
@@ -1,6 +1,6 @@
import { createIsolatedElement } from '@webext-core/isolated-element';
import { browser } from '~/browser';
import { logger } from '~/sandbox/utils/logger';
import { logger } from '~/client/utils/logger';
import { ContentScriptContext } from './content-script-context';
import {
ContentScriptAnchoredOptions,
@@ -1,4 +1,4 @@
import { browser } from 'wxt/browser';
import { browser } from '~/browser';
/**
* https://developer.chrome.com/blog/longer-esw-lifetimes/
@@ -1,5 +1,3 @@
/// <reference types="vite/client" />
function print(method: (...args: any[]) => void, ...args: any[]) {
if (import.meta.env.MODE === 'production') return;
@@ -1,14 +1,8 @@
import { browser } from 'wxt/browser';
import { logger } from '../../sandbox/utils/logger';
import { MatchPattern } from 'wxt/sandbox';
import { browser, Manifest } from '~/browser';
import { logger } from './logger';
import { MatchPattern } from '~/sandbox';
interface ContentScript {
matches: string[];
js?: string[];
css?: string[];
}
export function reloadContentScript(contentScript: ContentScript) {
export function reloadContentScript(contentScript: Manifest.ContentScript) {
const manifest = browser.runtime.getManifest();
if (manifest.manifest_version == 2) {
void reloadContentScriptMv2(contentScript);
@@ -17,7 +11,9 @@ export function reloadContentScript(contentScript: ContentScript) {
}
}
export async function reloadContentScriptMv3(contentScript: ContentScript) {
export async function reloadContentScriptMv3(
contentScript: Manifest.ContentScript,
) {
const id = `wxt:${contentScript.js![0]}`;
logger.log('Reloading content script:', contentScript);
const registered = await browser.scripting.getRegisteredContentScripts();
@@ -45,6 +41,8 @@ export async function reloadContentScriptMv3(contentScript: ContentScript) {
await Promise.all(matchingTabs.map((tab) => browser.tabs.reload(tab.id)));
}
export async function reloadContentScriptMv2(contentScript: ContentScript) {
export async function reloadContentScriptMv2(
contentScript: Manifest.ContentScript,
) {
throw Error('TODO: reloadContentScriptMv2');
}
@@ -1,4 +1,4 @@
import { logger } from '../../sandbox/utils/logger';
import { logger } from './logger';
interface WebSocketMessage {
type: string;
+8
View File
@@ -150,6 +150,14 @@ async function cloneProject({
consola.warn('Failed to move _gitignore to .gitignore:', err),
);
// 3. Add .npmrc for pnpm
if (packageManager === 'pnpm') {
await fs.writeFile(
path.join(directory, '.npmrc'),
'shamefully-hoist=true\n',
);
}
spinner.succeed();
} catch (err) {
spinner.fail();
+1 -1
View File
@@ -6,4 +6,4 @@
export * from './define-unlisted-script';
export * from './define-background';
export * from './define-content-script';
export * from '@webext-core/match-patterns';
export * from './match-patterns';
+1
View File
@@ -0,0 +1 @@
export * from '@webext-core/match-patterns';
-7
View File
@@ -1,7 +0,0 @@
// Globals defined by the vite-plugins/devServerGlobals.ts and utils/globals.ts
declare const __COMMAND__: 'build' | 'serve';
declare const __DEV_SERVER_PROTOCOL__: string;
declare const __DEV_SERVER_HOSTNAME__: string;
declare const __DEV_SERVER_PORT__: string;
declare const __MANIFEST_VERSION__: 2 | 3;
declare const __ENTRYPOINT__: string;
-11
View File
@@ -1,11 +0,0 @@
# WXT Virtual Entrypoints
This folder contains scripts that are either loaded as entrypoints to JS files or included in HTML files, just like a project using WXT might load their own scripts.
While they are bundled and shipped inside WXT, Vite considers them apart of your project's source code, not WXT's. This means they cannot import 3rd party modules directly, otherwise `pnpm i --shamefully-hoist=false` and Yarn PnP will fail.
For this reason, the virtual entrypoints get their own TS project to isolate them from the rest of the project. They can only import from `wxt/*` or utils that don't have any imports from node_modules, like the logger.
When bundling WXT for publishing to NPM, all the `wxt/*` imports are marked as external and resolved when building your application. Other imports are added inline.
See https://github.com/wxt-dev/wxt/issues/286#issuecomment-1858888390 for more details.
+5 -5
View File
@@ -1,9 +1,9 @@
import definition from 'virtual:user-background';
import { setupWebSocket } from './utils/setup-web-socket';
import { logger } from '../sandbox/utils/logger';
import { browser } from 'wxt/browser';
import { keepServiceWorkerAlive } from './utils/keep-service-worker-alive';
import { reloadContentScript } from './utils/reload-content-scripts';
import { setupWebSocket } from '~/client/utils/setup-web-socket';
import { logger } from '~/client/utils/logger';
import { browser } from '~/browser';
import { keepServiceWorkerAlive } from '~/client/utils/keep-service-worker-alive';
import { reloadContentScript } from '~/client/utils/reload-content-scripts';
if (__COMMAND__ === 'serve') {
try {
@@ -1,6 +1,6 @@
import definition from 'virtual:user-content-script-isolated-world';
import { logger } from '../sandbox/utils/logger';
import { ContentScriptContext } from 'wxt/client';
import { logger } from '~/client/utils/logger';
import { ContentScriptContext } from '~/client/content-scripts/content-script-context';
(async () => {
try {
@@ -1,5 +1,5 @@
import definition from 'virtual:user-content-script-main-world';
import { logger } from '../sandbox/utils/logger';
import { logger } from '~/client/utils/logger';
(async () => {
try {
+1 -1
View File
@@ -1,3 +1,3 @@
import { fakeBrowser as mockBrowser } from 'wxt/testing';
import { fakeBrowser as mockBrowser } from '~/testing';
export default mockBrowser;
+4 -2
View File
@@ -1,5 +1,7 @@
import { logger } from '../sandbox/utils/logger';
import { setupWebSocket } from './utils/setup-web-socket';
/// <reference types="vite/client" />
import { logger } from '~/client/utils/logger';
import { setupWebSocket } from '~/client/utils/setup-web-socket';
if (__COMMAND__ === 'serve') {
try {
-7
View File
@@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["vite/client", "../types/globals.d.ts"]
},
"include": ["./*"]
}
+1 -1
View File
@@ -1,5 +1,5 @@
import definition from 'virtual:user-unlisted-script';
import { logger } from '../sandbox/utils/logger';
import { logger } from '~/client/utils/logger';
(async () => {
try {
+16 -21
View File
@@ -1,39 +1,34 @@
// Types required to make the virtual modules happy.
declare module '*?raw' {
const content: any;
export default content;
}
declare module 'virtual:user-background' {
const definition: { main: () => void };
const definition: import('~/types').BackgroundDefinition;
export default definition;
}
declare module 'virtual:user-content-script-isolated-world' {
const definition: {
main: (
ctx: import('wxt/client').ContentScriptContext,
) => void | Promise<void>;
};
const definition: import('~/types').ContentScriptIsolatedWorldDefinition;
export default definition;
}
declare module 'virtual:user-content-script-main-world' {
const definition: { main: () => void | Promise<void> };
const definition: import('~/types').ContentScriptMainWorldDefinition;
export default definition;
}
declare module 'virtual:user-unlisted-script' {
const definition: { main: () => void | Promise<void> };
const definition: import('~/types').UnlistedScriptDefinition;
export default definition;
}
declare module 'wxt/browser' {
export const browser: import('webextension-polyfill').Browser;
}
declare module 'wxt/client' {
export class ContentScriptContext {
constructor(name: string, options: any);
}
}
declare module 'wxt/testing' {
export const fakeBrowser: import('webextension-polyfill').Browser;
}
// Globals defined by the vite-plugins/devServerGlobals.ts and utils/globals.ts
declare const __COMMAND__: 'build' | 'serve';
declare const __DEV_SERVER_PROTOCOL__: string;
declare const __DEV_SERVER_HOSTNAME__: string;
declare const __DEV_SERVER_PORT__: string;
declare const __MANIFEST_VERSION__: 2 | 3;
declare const __ENTRYPOINT__: string;
+1 -1
View File
@@ -5,5 +5,5 @@
"~/*": ["./src/*"]
}
},
"exclude": ["dist", "demo", "e2e/dist", "templates", "src/virtual"]
"exclude": ["dist", "demo", "e2e/dist", "templates"]
}
-1
View File
@@ -20,7 +20,6 @@ const resolve = {
alias: {
'~': path.resolve('src'),
'webextension-polyfill': path.resolve('src/virtual/mock-browser'),
'wxt/testing': path.resolve('src/testing'),
},
};