Skip to content

Commit

Permalink
refactor(resolve): remove environmentsOptions parameter (#18590)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 6, 2024
1 parent dd25c1a commit 3ef0bf1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
21 changes: 9 additions & 12 deletions packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,15 @@ export async function resolvePlugins(
modulePreload !== false && modulePreload.polyfill
? modulePreloadPolyfillPlugin(config)
: null,
resolvePlugin(
{
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
},
config.environments,
),
resolvePlugin({
root: config.root,
isProduction: config.isProduction,
isBuild,
packageCache: config.packageCache,
asSrc: true,
optimizeDeps: true,
externalize: true,
}),
htmlInlineProxyPlugin(config),
cssPlugin(config),
config.esbuild !== false ? esbuildPlugin(config) : null,
Expand Down
23 changes: 4 additions & 19 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
safeRealpathSync,
tryStatSync,
} from '../utils'
import type { ResolvedEnvironmentOptions } from '../config'
import { optimizedDepInfoFromFile, optimizedDepInfoFromId } from '../optimizer'
import type { DepsOptimizer } from '../optimizer'
import type { SSROptions } from '..'
Expand Down Expand Up @@ -181,13 +180,6 @@ export interface ResolvePluginOptionsWithOverrides

export function resolvePlugin(
resolveOptions: ResolvePluginOptionsWithOverrides,
/**
* @internal
* config.createResolver creates a pluginContainer before environments are created.
* The resolve plugin is especial as it works without environments to enable this use case.
* It only needs access to the resolve options.
*/
environmentsOptions?: Record<string, ResolvedEnvironmentOptions>,
): Plugin {
const { root, isProduction, asSrc, preferRelative = false } = resolveOptions

Expand Down Expand Up @@ -228,18 +220,11 @@ export function resolvePlugin(
const isRequire: boolean =
resolveOpts?.custom?.['node-resolve']?.isRequire ?? false

const environmentName = this.environment.name ?? (ssr ? 'ssr' : 'client')
const currentEnvironmentOptions =
this.environment.config || environmentsOptions?.[environmentName]
const environmentResolveOptions = currentEnvironmentOptions?.resolve
if (!environmentResolveOptions) {
throw new Error(
`Missing ResolveOptions for ${environmentName} environment`,
)
}
const currentEnvironmentOptions = this.environment.config

const options: InternalResolveOptions = {
isRequire,
...environmentResolveOptions,
...currentEnvironmentOptions.resolve,
...resolveOptions, // plugin options + resolve options overrides
scan: resolveOpts?.scan ?? resolveOptions.scan,
}
Expand Down Expand Up @@ -456,7 +441,7 @@ export function resolvePlugin(
importer,
)}"`
}
message += `. Consider disabling environments.${environmentName}.noExternal or remove the built-in dependency.`
message += `. Consider disabling environments.${this.environment.name}.noExternal or remove the built-in dependency.`
this.error(message)
}

Expand Down

0 comments on commit 3ef0bf1

Please sign in to comment.