Skip to content

Commit 67dab8e

Browse files
committed
chore: cleanup esm
As far as I could tell, the original reasons are no longer reproducible.
1 parent 78f8434 commit 67dab8e

File tree

9 files changed

+509
-53
lines changed

9 files changed

+509
-53
lines changed

packages/wxt/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
"vite-node": "^2.1.4 || ^3.1.2",
6363
"web-ext-run": "^0.2.4"
6464
},
65+
"peerDependencies": {
66+
"eslint": "^8.57.0 || ^9.0.0"
67+
},
68+
"peerDependenciesMeta": {
69+
"eslint": {
70+
"optional": true
71+
}
72+
},
6573
"devDependencies": {
6674
"@aklinker1/check": "^2.1.0",
6775
"@faker-js/faker": "^10.0.0",
@@ -70,6 +78,7 @@
7078
"@types/node": "^20.17.6",
7179
"@types/normalize-path": "^3.0.2",
7280
"@types/prompts": "^2.4.9",
81+
"eslint": "^9.38.0",
7382
"extract-zip": "^2.0.1",
7483
"happy-dom": "^18.0.1",
7584
"lodash.merge": "^4.6.2",
@@ -80,7 +89,6 @@
8089
"vitest": "^3.2.4",
8190
"vitest-plugin-random-seed": "^1.1.1"
8291
},
83-
"peerDependenciesMeta": {},
8492
"repository": {
8593
"type": "git",
8694
"url": "git+https://github.com/wxt-dev/wxt.git"

packages/wxt/src/core/builders/vite/plugins/removeEntrypointMainFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ResolvedConfig } from '../../../../types';
2-
import * as vite from 'vite';
2+
import type * as vite from 'vite';
33
import { normalizePath } from '../../../utils/paths';
44
import { removeMainFunctionCode } from '../../../utils/transform';
55
import { resolve } from 'node:path';

packages/wxt/src/core/resolve-config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,10 @@ async function getUnimportEslintOptions(
536536
* Returns the path to `node_modules/wxt`.
537537
*/
538538
function resolveWxtModuleDir() {
539-
// TODO: Drop the __filename expression once we're fully running in ESM
540-
// (see https://github.com/wxt-dev/wxt/issues/277)
541-
const importer =
542-
typeof __filename === 'string'
543-
? pathToFileURL(__filename).href
544-
: import.meta.url;
545-
546539
// TODO: Switch to import.meta.resolve() once the parent argument is unflagged
547540
// (e.g. --experimental-import-meta-resolve) and all Node.js versions we support
548541
// have it.
549-
const url = esmResolve('wxt', importer);
542+
const url = esmResolve('wxt', import.meta.url);
550543

551544
// esmResolve() returns the "wxt/dist/index.mjs" file, not the package's root
552545
// directory, which we want to return from this function.

packages/wxt/src/core/runners/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { ExtensionRunner } from '../../types';
2-
import { createWslRunner } from './wsl';
3-
import { createWebExtRunner } from './web-ext';
4-
import { createSafariRunner } from './safari';
5-
import { createManualRunner } from './manual';
1+
import type { ExtensionRunner } from '../../types';
62
import { isWsl } from '../utils/wsl';
73
import { wxt } from '../wxt';
4+
import { createManualRunner } from './manual';
5+
import { createSafariRunner } from './safari';
6+
import { createWebExtRunner } from './web-ext';
7+
import { createWslRunner } from './wsl';
88

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

12-
if (await isWsl()) return createWslRunner();
12+
if (isWsl()) return createWslRunner();
1313
if (wxt.config.runnerConfig.config?.disabled) return createManualRunner();
1414

1515
return createWebExtRunner();

packages/wxt/src/core/utils/eslint.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
export async function getEslintVersion(): Promise<string[]> {
22
try {
3-
const require = (await import('node:module')).default.createRequire(
4-
import.meta.url,
5-
);
6-
const { ESLint } = require('eslint');
3+
const { ESLint } = await import('eslint');
74
return ESLint.version?.split('.') ?? [];
85
} catch {
96
// Return an empty version when there's an error importing ESLint

packages/wxt/src/core/utils/wsl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// TODO: Someone smarter than me should just mock this module instead.
2+
import isWsl_ from 'is-wsl';
3+
14
/**
25
* Returns true when running on WSL or WSL2.
36
*/
4-
export async function isWsl(): Promise<boolean> {
5-
const { default: isWsl } = await import('is-wsl'); // ESM only, requires dynamic import
6-
return isWsl;
7+
export function isWsl(): boolean {
8+
return isWsl_;
79
}

packages/wxt/src/modules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function addImportPreset(
171171
if (!wxt.config.imports) return;
172172

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

177177
wxt.config.imports.presets.push(preset);

0 commit comments

Comments
 (0)