Skip to content
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
239 changes: 0 additions & 239 deletions packages/wxt/e2e/tests/runners.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/wxt/src/core/builders/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function createViteBuilder(
hooks: Hookable<WxtHooks>,
getWxtDevServer?: () => WxtDevServer | undefined,
): Promise<WxtBuilder> {
// TODO: This doesn't need to be async. Convert to class like other overridable services as well.
const vite = await import('vite');

/**
Expand Down
12 changes: 6 additions & 6 deletions packages/wxt/src/core/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function createServerInternal(): Promise<WxtDevServer> {
async stop() {
wasStopped = true;
keyboardShortcuts.stop();
await wxt.config.runner.closeBrowser?.();
await wxt.runner.closeBrowser?.();
await builderServer.close();
await wxt.hooks.callHook('server:closed', wxt, server);

Expand All @@ -118,14 +118,14 @@ async function createServerInternal(): Promise<WxtDevServer> {
server.ws.send('wxt:reload-extension');
},
async restartBrowser() {
await wxt.config.runner.closeBrowser?.();
await wxt.runner.closeBrowser?.();
keyboardShortcuts.stop();
await wxt.reloadConfig();
await wxt.config.runner.openBrowser();
await wxt.runner.openBrowser();
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.webExt.config.disabled && !!wxt.config.runner.canOpen?.(),
!wxt.config.webExt.config.disabled && !!wxt.runner.canOpen?.(),
});
},
};
Expand Down Expand Up @@ -164,11 +164,11 @@ async function createServerInternal(): Promise<WxtDevServer> {
}

// Open browser after everything is ready to go.
await wxt.config.runner.openBrowser();
await wxt.runner.openBrowser();
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.webExt.config.disabled && !!wxt.config.runner.canOpen?.(),
!wxt.config.webExt.config.disabled && !!wxt.runner.canOpen?.(),
});
};

Expand Down
108 changes: 108 additions & 0 deletions packages/wxt/src/core/entrypoint-finders/flat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import type {
Entrypoint,
EntrypointFinder,
EntrypointInfo,
ResolvedConfig,
} from '../../types';
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from '../utils/constants';
import { CSS_EXTENSIONS_PATTERN } from '../utils/paths';
import picomatch from 'picomatch';
import { glob } from 'tinyglobby';
import { getEntrypointName } from '../utils/entrypoints';
import { resolve } from 'node:path';

const PATH_GLOB_TO_TYPE_MAP: Record<string, Entrypoint['type']> = {
'sandbox.html': 'sandbox',
'sandbox/index.html': 'sandbox',
'*.sandbox.html': 'sandbox',
'*.sandbox/index.html': 'sandbox',

'bookmarks.html': 'bookmarks',
'bookmarks/index.html': 'bookmarks',

'history.html': 'history',
'history/index.html': 'history',

'newtab.html': 'newtab',
'newtab/index.html': 'newtab',

'sidepanel.html': 'sidepanel',
'sidepanel/index.html': 'sidepanel',
'*.sidepanel.html': 'sidepanel',
'*.sidepanel/index.html': 'sidepanel',

'devtools.html': 'devtools',
'devtools/index.html': 'devtools',

'background.[jt]s': 'background',
'background/index.[jt]s': 'background',
[VIRTUAL_NOOP_BACKGROUND_MODULE_ID]: 'background',

'content.[jt]s?(x)': 'content-script',
'content/index.[jt]s?(x)': 'content-script',
'*.content.[jt]s?(x)': 'content-script',
'*.content/index.[jt]s?(x)': 'content-script',
[`content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`*.content.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',
[`*.content/index.${CSS_EXTENSIONS_PATTERN}`]: 'content-script-style',

'popup.html': 'popup',
'popup/index.html': 'popup',

'options.html': 'options',
'options/index.html': 'options',

'*.html': 'unlisted-page',
'*/index.html': 'unlisted-page',
'*.[jt]s?(x)': 'unlisted-script',
'*/index.[jt]s?(x)': 'unlisted-script',
[`*.${CSS_EXTENSIONS_PATTERN}`]: 'unlisted-style',
[`*/index.${CSS_EXTENSIONS_PATTERN}`]: 'unlisted-style',
};
Comment on lines +14 to +62

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-pasted with no changes


/**
* WXT's default entrypoint finder. It looks up entrypoints using a flat folder
* structure inside the `entrypoints.` directory, as described in the docs:
* https://wxt.dev/guide/essentials/entrypoints.html
*/
export class FlatEntrypointFinder implements EntrypointFinder {
constructor(public config: ResolvedConfig) {}

async findEntrypoints(): Promise<EntrypointInfo[]> {
const relativePaths = await glob(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
cwd: this.config.entrypointsDir,
expandDirectories: false,
});
// Ensure consistent output
relativePaths.sort();

const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
return relativePaths
.reduce<EntrypointInfo[]>((results, relativePath) => {
const inputPath = resolve(this.config.entrypointsDir, relativePath);
const name = getEntrypointName(this.config.entrypointsDir, inputPath);
const matchingGlob = pathGlobs.find((glob) =>
picomatch(glob)(relativePath),
);
if (matchingGlob) {
const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
results.push({ name, inputPath, type });
}
return results;
}, [])
.filter(({ name, inputPath }, _, entrypointInfos) => {
// Remove <name>/index.* if <name>/index.html exists
if (inputPath.endsWith('.html')) return true;
const isIndexFile = /index\..+$/.test(inputPath);
if (!isIndexFile) return true;

const hasIndexHtml = entrypointInfos.some(
(entry) =>
entry.name === name && entry.inputPath.endsWith('index.html'),
);

return !hasIndexHtml;
});
Comment on lines +73 to +106

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-pasted with no changes

}
}
Loading
Loading