-
-
Notifications
You must be signed in to change notification settings - Fork 414
refactor: cleanup esm #1950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor: cleanup esm #1950
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
lishaduck marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| }, | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
||
lishaduck marked this conversation as resolved.
Show resolved
Hide resolved
|
| 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_; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
| const fromModule = viteConfig(env) ?? {}; | ||
| return vite.mergeConfig(fromModule, fromUser); | ||
| }; | ||
|
|
@@ -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); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.