Skip to content
Open
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
// Additional guidelines for Copilot
"github.copilot.chat.codeGeneration.instructions": [
{ "file": "CONTRIBUTING.md" }
]
],
"oxc.enable": true
}
10 changes: 9 additions & 1 deletion packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
"vite-node": "^2.1.4 || ^3.1.2",
"web-ext-run": "^0.2.4"
},
"peerDependencies": {
"eslint": "^8.57.0 || ^9.0.0"
},
"peerDependenciesMeta": {
"eslint": {
"optional": true
}
},
"devDependencies": {
"@aklinker1/check": "^2.1.0",
"@faker-js/faker": "^10.0.0",
Expand All @@ -70,6 +78,7 @@
"@types/node": "^20.17.6",
"@types/normalize-path": "^3.0.2",
"@types/prompts": "^2.4.9",
"eslint": "^9.38.0",
"extract-zip": "^2.0.1",
"happy-dom": "^18.0.1",
"lodash.merge": "^4.6.2",
Expand All @@ -80,7 +89,6 @@
"vitest": "^3.2.4",
"vitest-plugin-random-seed": "^1.1.1"
},
"peerDependenciesMeta": {},
"repository": {
"type": "git",
"url": "git+https://github.com/wxt-dev/wxt.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Plugin } from 'vite';
import { ResolvedConfig, WxtDevServer } from '../../../../types';
import type { Plugin } from 'vite';
import type { ResolvedConfig, WxtDevServer } from '../../../../types';

/**
* Defines global constants about the dev server. Helps scripts connect to the server's web socket.
Expand Down
4 changes: 2 additions & 2 deletions packages/wxt/src/core/builders/vite/plugins/download.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Plugin } from 'vite';
import { ResolvedConfig } from '../../../../types';
import type { Plugin } from 'vite';
import type { ResolvedConfig } from '../../../../types';
import { fetchCached } from '../../../utils/network';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'vite';
import type { Plugin } from 'vite';
import { VIRTUAL_NOOP_BACKGROUND_MODULE_ID } from '../../../utils/constants';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ResolvedConfig } from '../../../../types';
import * as vite from 'vite';
import type * as vite from 'vite';
import { normalizePath } from '../../../utils/paths';
import { removeMainFunctionCode } from '../../../utils/transform';
import { resolve } from 'node:path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'vite';
import type { Plugin } from 'vite';
import { ResolvedConfig } from '../../../../types';
import { normalizePath } from '../../../utils/paths';
import {
Expand Down
13 changes: 3 additions & 10 deletions packages/wxt/src/core/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,10 @@ async function getUnimportEslintOptions(
* Returns the path to `node_modules/wxt`.
*/
function resolveWxtModuleDir() {
// TODO: Drop the __filename expression once we're fully running in ESM
// (see https://github.com/wxt-dev/wxt/issues/277)
const importer =
typeof __filename === 'string'
? pathToFileURL(__filename).href
: import.meta.url;

// TODO: Switch to import.meta.resolve() once the parent argument is unflagged
// (e.g. --experimental-import-meta-resolve) and all Node.js versions we support
// have it.
const url = esmResolve('wxt', importer);
const url = esmResolve('wxt', import.meta.url);

// esmResolve() returns the "wxt/dist/index.mjs" file, not the package's root
// directory, which we want to return from this function.
Expand Down Expand Up @@ -584,8 +577,8 @@ export async function mergeBuilderConfig(
if (vite) {
return {
vite: async (env) => {
const resolvedInlineConfig = (await inlineConfig.vite?.(env)) ?? {};
const resolvedUserConfig = (await userConfig.vite?.(env)) ?? {};
const [resolvedInlineConfig = {}, resolvedUserConfig = {}] =
await Promise.all([inlineConfig.vite?.(env), userConfig.vite?.(env)]);
Comment on lines +580 to +581
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could potentially be a race condition if someone is doing something stupid in their config file. Probably fine.

return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
},
};
Expand Down
12 changes: 6 additions & 6 deletions packages/wxt/src/core/runners/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ExtensionRunner } from '../../types';
import { createWslRunner } from './wsl';
import { createWebExtRunner } from './web-ext';
import { createSafariRunner } from './safari';
import { createManualRunner } from './manual';
import type { ExtensionRunner } from '../../types';
import { isWsl } from '../utils/wsl';
import { wxt } from '../wxt';
import { createManualRunner } from './manual';
import { createSafariRunner } from './safari';
import { createWebExtRunner } from './web-ext';
import { createWslRunner } from './wsl';

export async function createExtensionRunner(): Promise<ExtensionRunner> {
if (wxt.config.browser === 'safari') return createSafariRunner();

if (await isWsl()) return createWslRunner();
if (isWsl()) return createWslRunner();
if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();

return createWebExtRunner();
Expand Down
5 changes: 1 addition & 4 deletions packages/wxt/src/core/utils/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export async function getEslintVersion(): Promise<string[]> {
try {
const require = (await import('node:module')).default.createRequire(
import.meta.url,
);
const { ESLint } = require('eslint');
const { ESLint } = await import('eslint');
return ESLint.version?.split('.') ?? [];
} catch {
// Return an empty version when there's an error importing ESLint
Expand Down
4 changes: 2 additions & 2 deletions packages/wxt/src/core/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ function discoverIcons(
/^icon@([0-9]+)w\.png$/, // [email protected]
/^icon@([0-9]+)h\.png$/, // [email protected]
/^icon@([0-9]+)\.png$/, // [email protected]
/^icons?[/\\]([0-9]+)\.png$/, // icon/16.png | icons/16.png
/^icons?[/\\]([0-9]+)x[0-9]+\.png$/, // icon/16x16.png | icons/16x16.png
/^icons?[/\\]([0-9]+)\.png$/, // icon/16.png | icons/16.png
/^icons?[/\\]([0-9]+)x[0-9]+\.png$/, // icon/16x16.png | icons/16x16.png
];
// #endregion snippet

Expand Down
8 changes: 5 additions & 3 deletions packages/wxt/src/core/utils/wsl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// TODO: Someone smarter than me should just mock this module instead.
import isWsl_ from 'is-wsl';

/**
* Returns true when running on WSL or WSL2.
*/
export async function isWsl(): Promise<boolean> {
const { default: isWsl } = await import('is-wsl'); // ESM only, requires dynamic import
return isWsl;
export function isWsl(): boolean {
return isWsl_;
}
6 changes: 4 additions & 2 deletions packages/wxt/src/core/wxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export async function registerWxt(

const hooks = createHooks<WxtHooks>();
const config = await resolveConfig(inlineConfig, command);
const builder = await createViteBuilder(config, hooks, () => wxt.server);
const pm = await createWxtPackageManager(config.root);
const [builder, pm] = await Promise.all([
createViteBuilder(config, hooks, () => wxt.server),
createWxtPackageManager(config.root),
]);
Comment on lines +29 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We own these, should be fine, but could potentially call something user created and cause a new race condition... yeah this is ridiculous.


wxt = {
config,
Expand Down
9 changes: 6 additions & 3 deletions packages/wxt/src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
WxtModuleOptions,
WxtModuleSetup,
} from './types';
import * as vite from 'vite';
import type * as vite from 'vite';
import glob from 'fast-glob';
import { resolve } from 'node:path';
import type { UnimportOptions } from 'unimport';
Expand Down Expand Up @@ -109,7 +109,10 @@ export function addViteConfig(
wxt.hooks.hook('config:resolved', (wxt) => {
const userVite = wxt.config.vite;
wxt.config.vite = async (env) => {
const fromUser = await userVite(env);
const [vite, fromUser] = await Promise.all([
import('vite'),
userVite(env),
]);
Comment on lines +112 to +115
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto

const fromModule = viteConfig(env) ?? {};
return vite.mergeConfig(fromModule, fromUser);
};
Expand Down Expand Up @@ -171,7 +174,7 @@ export function addImportPreset(
if (!wxt.config.imports) return;

wxt.config.imports.presets ??= [];
// De-dupelicate built-in named presets
// De-duplicate built-in named presets
if (wxt.config.imports.presets.includes(preset)) return;

wxt.config.imports.presets.push(preset);
Expand Down
Loading