Compare commits

...

6 Commits

Author SHA1 Message Date
Aaron Klinker 4ac87bef44 Bump to alpha2 2023-12-17 11:31:17 -06:00
Aaron Klinker 4caaa1bc4d Update test snapshots 2023-12-17 11:31:11 -06:00
Aaron Klinker e46920b6a0 Fix sandbox exports 2023-12-17 11:28:33 -06:00
Aaron Klinker 6d4dae59c6 Update readme 2023-12-17 11:25:06 -06:00
Aaron Klinker 1f3616b056 Better organize and type the virtual modules to ensure PNP works 2023-12-17 11:18:35 -06:00
Aaron Klinker 78a146b1ca Remove NPMRC from init 2023-12-17 10:06:12 -06:00
23 changed files with 63 additions and 53 deletions
+2
View File
@@ -17,6 +17,8 @@ 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']
+4 -2
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.12.2-alpha1",
"version": "0.12.2-alpha2",
"description": "Next gen framework for developing web extensions",
"engines": {
"node": ">=18",
@@ -86,7 +86,9 @@
"lint": "run-p -c -s lint:*",
"lint:eslint": "echo 'ESLint: TODO'",
"lint:package": "publint",
"compile": "tsc --noEmit",
"compile": "run-s -c compile:*",
"compile:wxt": "tsc --noEmit",
"compile:virtual": "tsc --noEmit",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"prepare": "simple-git-hooks",
+3 -2
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: tsup.Options = {
const preset = {
dts: true,
silent: true,
sourcemap: false,
@@ -26,7 +26,7 @@ const preset: tsup.Options = {
'virtual:user-content-script-main-world',
'virtual:user-background',
],
};
} satisfies tsup.Options;
function spinnerPMap(configs: tsup.Options[]) {
let completed = 0;
@@ -88,6 +88,7 @@ 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 '~/client/utils/logger';
import { logger } from '~/sandbox/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 '~/client/utils/logger';
import { logger } from '~/sandbox/utils/logger';
import { ContentScriptContext } from './content-script-context';
import {
ContentScriptAnchoredOptions,
-8
View File
@@ -150,14 +150,6 @@ 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 './match-patterns';
export * from '@webext-core/match-patterns';
-1
View File
@@ -1 +0,0 @@
export * from '@webext-core/match-patterns';
@@ -1,3 +1,5 @@
/// <reference types="vite/client" />
function print(method: (...args: any[]) => void, ...args: any[]) {
if (import.meta.env.MODE === 'production') return;
+7
View File
@@ -0,0 +1,7 @@
// 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
@@ -0,0 +1,11 @@
# 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 '~/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';
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';
if (__COMMAND__ === 'serve') {
try {
@@ -1,6 +1,6 @@
import definition from 'virtual:user-content-script-isolated-world';
import { logger } from '~/client/utils/logger';
import { ContentScriptContext } from '~/client/content-scripts/content-script-context';
import { logger } from '../sandbox/utils/logger';
import { ContentScriptContext } from 'wxt/client';
(async () => {
try {
@@ -1,5 +1,5 @@
import definition from 'virtual:user-content-script-main-world';
import { logger } from '~/client/utils/logger';
import { logger } from '../sandbox/utils/logger';
(async () => {
try {
+1 -1
View File
@@ -1,3 +1,3 @@
import { fakeBrowser as mockBrowser } from '~/testing';
import { fakeBrowser as mockBrowser } from 'wxt/testing';
export default mockBrowser;
+2 -4
View File
@@ -1,7 +1,5 @@
/// <reference types="vite/client" />
import { logger } from '~/client/utils/logger';
import { setupWebSocket } from '~/client/utils/setup-web-socket';
import { logger } from '../sandbox/utils/logger';
import { setupWebSocket } from './utils/setup-web-socket';
if (__COMMAND__ === 'serve') {
try {
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["vite/client", "../types/globals.d.ts"],
"paths": {
"wxt/*": ["../*"]
}
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
import definition from 'virtual:user-unlisted-script';
import { logger } from '~/client/utils/logger';
import { logger } from '../sandbox/utils/logger';
(async () => {
try {
@@ -1,4 +1,4 @@
import { browser } from '~/browser';
import { browser } from 'wxt/browser';
/**
* https://developer.chrome.com/blog/longer-esw-lifetimes/
@@ -1,6 +1,6 @@
import { browser, Manifest } from '~/browser';
import { logger } from './logger';
import { MatchPattern } from '~/sandbox';
import { browser, Manifest } from 'wxt/browser';
import { logger } from '../../sandbox/utils/logger';
import { MatchPattern } from 'wxt/sandbox';
export function reloadContentScript(contentScript: Manifest.ContentScript) {
const manifest = browser.runtime.getManifest();
@@ -1,4 +1,4 @@
import { logger } from './logger';
import { logger } from '../../sandbox/utils/logger';
interface WebSocketMessage {
type: string;
+4 -17
View File
@@ -1,34 +1,21 @@
// Types required to make the virtual modules happy.
declare module '*?raw' {
const content: any;
export default content;
}
declare module 'virtual:user-background' {
const definition: import('~/types').BackgroundDefinition;
const definition: import('wxt/types').BackgroundDefinition;
export default definition;
}
declare module 'virtual:user-content-script-isolated-world' {
const definition: import('~/types').ContentScriptIsolatedWorldDefinition;
const definition: import('wxt/types').ContentScriptIsolatedWorldDefinition;
export default definition;
}
declare module 'virtual:user-content-script-main-world' {
const definition: import('~/types').ContentScriptMainWorldDefinition;
const definition: import('wxt/types').ContentScriptMainWorldDefinition;
export default definition;
}
declare module 'virtual:user-unlisted-script' {
const definition: import('~/types').UnlistedScriptDefinition;
const definition: import('wxt/types').UnlistedScriptDefinition;
export default definition;
}
// 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"]
"exclude": ["dist", "demo", "e2e/dist", "templates", "src/virtual"]
}