deps-conflict-resolver 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from 'vite';
1
+ import { Alias, Plugin } from 'vite';
2
2
  import { P as PluginConfig, A as AliasPathMapping } from './config.types-CVCkyLb5.cjs';
3
3
 
4
4
  /**
@@ -7,11 +7,12 @@ import { P as PluginConfig, A as AliasPathMapping } from './config.types-CVCkyLb
7
7
  interface ViteAliasEntry {
8
8
  find: string | RegExp;
9
9
  replacement: string;
10
+ customResolver?: Alias['customResolver'];
10
11
  }
11
12
  /**
12
13
  * 基于 AliasPathMapping 生成 Vite 的 resolve.alias 配置
13
14
  */
14
- declare function createViteAliases(mappings: AliasPathMapping[]): ViteAliasEntry[];
15
+ declare function createViteAliases(mappings: AliasPathMapping[], projectRoot?: string): ViteAliasEntry[];
15
16
  /**
16
17
  * Vite 插件配置
17
18
  */
@@ -26,6 +27,8 @@ interface VitePluginOptions extends PluginConfig {
26
27
  * @default true
27
28
  */
28
29
  enableInBuild?: boolean;
30
+ /** Bundle affected packages for SSR builds and pre-bundle them for SSR development. */
31
+ ssr?: 'manual' | 'auto';
29
32
  }
30
33
  /**
31
34
  * 创建 Vite 插件
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from 'vite';
1
+ import { Alias, Plugin } from 'vite';
2
2
  import { P as PluginConfig, A as AliasPathMapping } from './config.types-CVCkyLb5.js';
3
3
 
4
4
  /**
@@ -7,11 +7,12 @@ import { P as PluginConfig, A as AliasPathMapping } from './config.types-CVCkyLb
7
7
  interface ViteAliasEntry {
8
8
  find: string | RegExp;
9
9
  replacement: string;
10
+ customResolver?: Alias['customResolver'];
10
11
  }
11
12
  /**
12
13
  * 基于 AliasPathMapping 生成 Vite 的 resolve.alias 配置
13
14
  */
14
- declare function createViteAliases(mappings: AliasPathMapping[]): ViteAliasEntry[];
15
+ declare function createViteAliases(mappings: AliasPathMapping[], projectRoot?: string): ViteAliasEntry[];
15
16
  /**
16
17
  * Vite 插件配置
17
18
  */
@@ -26,6 +27,8 @@ interface VitePluginOptions extends PluginConfig {
26
27
  * @default true
27
28
  */
28
29
  enableInBuild?: boolean;
30
+ /** Bundle affected packages for SSR builds and pre-bundle them for SSR development. */
31
+ ssr?: 'manual' | 'auto';
29
32
  }
30
33
  /**
31
34
  * 创建 Vite 插件
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { realpathSync, existsSync, promises, statSync, readFileSync } from 'fs';
2
- import { resolve, join, dirname, posix, relative, basename, win32 } from 'path';
2
+ import { join, resolve, isAbsolute, extname, dirname, posix, basename, relative, win32 } from 'path';
3
3
  import { createRequire } from 'module';
4
4
  import { pathToFileURL } from 'url';
5
5
  import { parse } from 'yaml';
@@ -8,6 +8,7 @@ import { spawn } from 'child_process';
8
8
  import { createHash, randomUUID } from 'crypto';
9
9
  import { userInfo, tmpdir, hostname } from 'os';
10
10
  import { performance } from 'perf_hooks';
11
+ import { mergeConfig, version, createFilter } from 'vite';
11
12
 
12
13
  // src/constants.ts
13
14
  var DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
@@ -4261,110 +4262,354 @@ function escapeRegex(str) {
4261
4262
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4262
4263
  }
4263
4264
 
4264
- // src/plugins/vite/index.ts
4265
- var logger9 = createLogger("vite-plugin");
4266
- var PLUGIN_NAME = "deps-conflict-resolver";
4267
- function createViteAliases(mappings) {
4268
- const aliases = [];
4269
- for (const mapping of mappings) {
4270
- aliases.push({
4271
- find: new RegExp(`^${escapeRegex(mapping.aliasName)}$`),
4272
- replacement: mapping.path
4273
- });
4274
- }
4275
- return aliases;
4265
+ // src/plugins/vite/optimizer.ts
4266
+ async function externalId(policy, source, importer, isRequire) {
4267
+ if (!/^[\w@]/.test(source) || source.includes(":")) return null;
4268
+ const request = source.split(/[?#]/, 1)[0] ?? "";
4269
+ const parts = request.split("/");
4270
+ const packageName = request.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
4271
+ if (!policy.isExternal(packageName)) return null;
4272
+ return await policy.resolve(source, importer, isRequire) ?? null;
4273
+ }
4274
+ function esbuildExternalPlugin(policy) {
4275
+ return {
4276
+ name: "deps-conflict-resolver-ssr-external",
4277
+ setup(build) {
4278
+ build.onResolve({ filter: /^[\w@]/ }, async (args) => {
4279
+ if (!args.importer || args.kind === "entry-point") return null;
4280
+ const id = await externalId(
4281
+ policy,
4282
+ args.path,
4283
+ args.importer,
4284
+ args.kind.startsWith("require")
4285
+ );
4286
+ return id ? { path: id, external: true } : null;
4287
+ });
4288
+ }
4289
+ };
4290
+ }
4291
+ function rolldownExternalPlugin(policy) {
4292
+ return {
4293
+ name: "deps-conflict-resolver-ssr-external",
4294
+ async resolveId(source, importer, options) {
4295
+ if (!importer || options.isEntry) return null;
4296
+ const kind = options.kind;
4297
+ const isRequire = kind?.startsWith("require") ?? options.custom?.["node-resolve"]?.isRequire === true;
4298
+ const id = await externalId(policy, source, importer, isRequire);
4299
+ return id ? { id, external: true } : null;
4300
+ }
4301
+ };
4276
4302
  }
4277
- function createEsbuildAliasPlugin(resolver, projectRoot) {
4303
+ function esbuildPlugin(resolver, projectRoot) {
4278
4304
  return {
4279
4305
  name: "deps-conflict-resolver-esbuild",
4280
4306
  setup(build) {
4281
- const activeMappings = resolver.getAliasPathMappings();
4282
- if (activeMappings.length === 0) {
4283
- return;
4284
- }
4285
- const originalNames = Array.from(new Set(activeMappings.map((m) => m.originalName)));
4286
- const filter = new RegExp(`^(${originalNames.map(escapeRegex).join("|")})(?:/.*)?$`);
4287
- const hasResolveApi = typeof build.resolve === "function";
4307
+ const originals = [
4308
+ ...new Set(resolver.getAliasPathMappings().map((mapping) => mapping.originalName))
4309
+ ];
4310
+ if (originals.length === 0) return;
4311
+ const filter = new RegExp("^(" + originals.map(escapeRegex).join("|") + ")(?:[/?#].*)?$");
4288
4312
  build.onResolve({ filter }, async (args) => {
4289
- if (!args.importer) {
4290
- return null;
4291
- }
4292
- const resolved = resolver.resolveModule(args.path, args.importer);
4293
- if (!resolved) {
4294
- return null;
4295
- }
4296
- logger9.debug(`[esbuild] Redirecting ${args.path} -> ${resolved} (from ${args.importer})`);
4297
- if (hasResolveApi) {
4298
- const result = await build.resolve(resolved, {
4313
+ if (!args.importer) return null;
4314
+ const redirected = resolver.resolveModule(args.path, args.importer);
4315
+ if (!redirected) return null;
4316
+ if (typeof build.resolve === "function") {
4317
+ return build.resolve(redirected, {
4299
4318
  kind: args.kind,
4300
4319
  resolveDir: projectRoot,
4301
4320
  importer: args.importer
4302
4321
  });
4303
- if (result.errors.length > 0) {
4304
- return { errors: result.errors };
4305
- }
4306
- return { path: result.path };
4307
4322
  }
4308
- return {
4309
- path: resolved,
4310
- resolveDir: projectRoot
4311
- };
4323
+ try {
4324
+ return { path: createRequire(join(projectRoot, "package.json")).resolve(redirected) };
4325
+ } catch (error) {
4326
+ return {
4327
+ errors: [{ text: "Cannot resolve alias " + redirected + ": " + String(error) }]
4328
+ };
4329
+ }
4330
+ });
4331
+ }
4332
+ };
4333
+ }
4334
+ function rolldownPlugin(resolver, projectRoot) {
4335
+ return {
4336
+ name: "deps-conflict-resolver-rolldown",
4337
+ async resolveId(source, importer, resolveOptions) {
4338
+ if (!importer) return null;
4339
+ const redirected = resolver.resolveModule(source, importer);
4340
+ if (!redirected) return null;
4341
+ const resolved = await this.resolve(redirected, join(projectRoot, "package.json"), {
4342
+ ...resolveOptions,
4343
+ skipSelf: true
4312
4344
  });
4345
+ if (!resolved) throw new Error("Cannot resolve active alias: " + redirected);
4346
+ return resolved;
4347
+ }
4348
+ };
4349
+ }
4350
+ function createOptimizerOptions(resolver, projectRoot, viteVersion2, ssrExternal) {
4351
+ const include = [...new Set(resolver.getAliasPathMappings().map((mapping) => mapping.aliasName))];
4352
+ return Number.parseInt(viteVersion2, 10) >= 8 ? {
4353
+ include,
4354
+ rolldownOptions: {
4355
+ plugins: [
4356
+ rolldownPlugin(resolver, projectRoot),
4357
+ ...ssrExternal ? [rolldownExternalPlugin(ssrExternal)] : []
4358
+ ]
4359
+ }
4360
+ } : {
4361
+ include,
4362
+ esbuildOptions: {
4363
+ plugins: [
4364
+ esbuildPlugin(resolver, projectRoot),
4365
+ ...ssrExternal ? [esbuildExternalPlugin(ssrExternal)] : []
4366
+ ]
4313
4367
  }
4314
4368
  };
4315
4369
  }
4370
+ function createSsrExternalPolicy(config, projectRoot, isExternal) {
4371
+ const conditions = config.environments?.ssr?.resolve.externalConditions ?? config.ssr?.resolve?.externalConditions ?? ["node"];
4372
+ const importResolver = config.createResolver({
4373
+ asSrc: false,
4374
+ scan: true,
4375
+ mainFields: [],
4376
+ conditions,
4377
+ isRequire: false
4378
+ });
4379
+ const requireResolver = config.createResolver({
4380
+ asSrc: false,
4381
+ scan: true,
4382
+ mainFields: [],
4383
+ conditions,
4384
+ isRequire: true
4385
+ });
4386
+ const specifiers = new LruCache({ maxEntries: 1e3 });
4387
+ return {
4388
+ isExternal,
4389
+ async resolve(source, importer, isRequire) {
4390
+ const resolved = await (isRequire ? requireResolver : importResolver)(
4391
+ source,
4392
+ importer,
4393
+ false,
4394
+ true
4395
+ );
4396
+ if (!resolved || !isAbsolute(resolved)) return void 0;
4397
+ const extension = extname(resolved);
4398
+ if (extension && ![".js", ".mjs", ".cjs"].includes(extension)) return void 0;
4399
+ if (isRequire) return resolved;
4400
+ const key = source + "\0" + resolved;
4401
+ const cached = specifiers.get(key);
4402
+ if (cached) return cached;
4403
+ const request = source.split(/[?#]/, 1)[0] ?? "";
4404
+ const packageName = request.startsWith("@") ? request.split("/").slice(0, 2).join("/") : request.split("/")[0];
4405
+ const host = findPackagePath(packageName, projectRoot);
4406
+ if (host) {
4407
+ const directory = realpathSync(host).replace(/\\/g, "/");
4408
+ if (resolved.replace(/\\/g, "/").startsWith(directory + "/")) {
4409
+ specifiers.set(key, source);
4410
+ return source;
4411
+ }
4412
+ }
4413
+ const url = JSON.stringify(pathToFileURL(resolved).href);
4414
+ const code = `export function then(resolve,reject){import(${url}).then(resolve,reject)}`;
4415
+ const specifier = "data:text/javascript;base64," + Buffer.from(code).toString("base64");
4416
+ specifiers.set(key, specifier);
4417
+ return specifier;
4418
+ }
4419
+ };
4420
+ }
4421
+ var logger9 = createLogger("vite-plugin");
4422
+ var PLUGIN_NAME = "deps-conflict-resolver";
4423
+ function createViteAliases(mappings, projectRoot) {
4424
+ const aliases = [];
4425
+ for (const mapping of mappings) {
4426
+ aliases.push({
4427
+ find: new RegExp(`^${escapeRegex(mapping.aliasName)}$`),
4428
+ replacement: mapping.path,
4429
+ ...projectRoot ? {
4430
+ customResolver: function(_source, _importer, options) {
4431
+ return this.resolve(mapping.aliasName, join(projectRoot, "package.json"), {
4432
+ ...options,
4433
+ skipSelf: true
4434
+ });
4435
+ }
4436
+ } : {}
4437
+ });
4438
+ }
4439
+ return aliases;
4440
+ }
4441
+ function mergeOptimizer(target, addition) {
4442
+ const merged = mergeConfig(target, addition);
4443
+ for (const key of Object.keys(addition)) Reflect.set(target, key, Reflect.get(merged, key));
4444
+ if (target.include) target.include = [...new Set(target.include)];
4445
+ if (target.exclude) target.exclude = [...new Set(target.exclude)];
4446
+ }
4316
4447
  function depsConflictResolverVitePlugin(options) {
4317
4448
  let resolver = null;
4318
4449
  let isEnabled = true;
4319
- const { enableInDev = true, enableInBuild = true, hooks, ...resolverOptions } = options;
4450
+ let resolveSsrExternal;
4451
+ let ssrExternalEnabled = false;
4452
+ let isSsrExternal;
4453
+ const {
4454
+ enableInDev = true,
4455
+ enableInBuild = true,
4456
+ ssr = "manual",
4457
+ hooks,
4458
+ ...resolverOptions
4459
+ } = options;
4320
4460
  if (options.debug) {
4321
- logger9.setLevel(1 /* DEBUG */);
4461
+ logger9.setLevel(15 /* ALL */);
4462
+ }
4463
+ function runtimeConfig(config, activeResolver) {
4464
+ const command = config.command;
4465
+ const analysisResult = activeResolver.getAnalysisResult();
4466
+ if (!analysisResult || analysisResult.aliasMappings.length === 0) {
4467
+ if (activeResolver.getDiagnostics().some((diagnostic) => diagnostic.severity === "error")) {
4468
+ logger9.warn(
4469
+ "No alias mappings available; inspect resolver diagnostics for unresolved conditions"
4470
+ );
4471
+ } else {
4472
+ logger9.info("No aliases needed");
4473
+ }
4474
+ return void 0;
4475
+ }
4476
+ const aliasPathMappings = activeResolver.getAliasPathMappings();
4477
+ if (aliasPathMappings.length === 0) {
4478
+ logger9.info("No active aliases available");
4479
+ return void 0;
4480
+ }
4481
+ const projectRoot = activeResolver.getOptions().projectRoot;
4482
+ logger9.info(`Configured ${aliasPathMappings.length} alias redirections`);
4483
+ const aliasPackages = Array.from(new Set(aliasPathMappings.map((m) => m.aliasName)));
4484
+ const activeNames = new Set(aliasPackages);
4485
+ const ssrPackages = new Set(aliasPackages);
4486
+ const ssrOptimizerPackages = new Set(aliasPackages);
4487
+ for (const mapping of analysisResult.aliasMappings) {
4488
+ if (!activeNames.has(mapping.aliasName)) continue;
4489
+ const excluded = new Set(resolverOptions.excludeRedirects?.[mapping.originalName] ?? []);
4490
+ for (const name of [
4491
+ ...mapping.allDependents,
4492
+ ...mapping.usedBy.map((path) => path.split(">")[0]),
4493
+ ...resolverOptions.includeRedirects?.[mapping.originalName] ?? []
4494
+ ]) {
4495
+ if (!excluded.has(name)) ssrPackages.add(name);
4496
+ }
4497
+ for (const name of [
4498
+ ...mapping.usedBy.map((path) => path.split(">")[0]),
4499
+ ...resolverOptions.includeRedirects?.[mapping.originalName] ?? []
4500
+ ]) {
4501
+ if (!excluded.has(name)) ssrOptimizerPackages.add(name);
4502
+ }
4503
+ }
4504
+ const ssrEnvironment = config.environments?.ssr;
4505
+ const ssrResolve = mergeConfig(
4506
+ { resolve: { external: config.ssr?.external, noExternal: config.ssr?.noExternal } },
4507
+ { resolve: ssrEnvironment?.resolve ?? {} }
4508
+ ).resolve;
4509
+ const ssrOptimizer = mergeConfig(
4510
+ config.ssr?.optimizeDeps ?? {},
4511
+ ssrEnvironment?.optimizeDeps ?? {}
4512
+ );
4513
+ const external = ssrResolve.external;
4514
+ const ssrExternal = Array.isArray(external) ? external : [];
4515
+ const ssrExcluded = [...ssrExternal, ...ssrOptimizer.exclude ?? []];
4516
+ const manualNoExternal = ssrResolve.noExternal;
4517
+ const keepsInternal = manualNoExternal === true ? () => true : manualNoExternal && (!Array.isArray(manualNoExternal) || manualNoExternal.length > 0) ? createFilter(manualNoExternal, void 0, { resolve: false }) : () => false;
4518
+ const allowsSsrOptimization = (name) => (external !== true || keepsInternal(name)) && !ssrExcluded.some((excluded) => name === excluded || name.startsWith(excluded + "/"));
4519
+ logger9.debug(`Alias packages to include: ${aliasPackages.join(", ")}`);
4520
+ const optimizeDeps = createOptimizerOptions(activeResolver, projectRoot, version);
4521
+ ssrExternalEnabled = ssr === "auto" && command === "serve" && external === true && manualNoExternal !== true;
4522
+ isSsrExternal = (packageName) => !keepsInternal(packageName);
4523
+ const ssrOptimizeDeps = ssrExternalEnabled ? createOptimizerOptions(activeResolver, projectRoot, version, {
4524
+ isExternal: (packageName) => !keepsInternal(packageName),
4525
+ resolve: (source, importer, isRequire) => {
4526
+ if (!resolveSsrExternal) throw new Error("SSR external resolver is not initialized");
4527
+ return resolveSsrExternal(source, importer, isRequire);
4528
+ }
4529
+ }) : optimizeDeps;
4530
+ return {
4531
+ ...ssr === "auto" ? {
4532
+ ssr: {
4533
+ noExternal: ssrResolve.noExternal === true ? true : [...ssrPackages].filter(allowsSsrOptimization),
4534
+ ...command === "serve" ? {
4535
+ optimizeDeps: {
4536
+ ...ssrOptimizeDeps,
4537
+ include: [...ssrOptimizerPackages].filter(allowsSsrOptimization),
4538
+ // Vite's SSR optimizer is a separate bundler; forward
4539
+ // explicit externals so nested imports stay external too.
4540
+ exclude: ssrExternal
4541
+ }
4542
+ } : {}
4543
+ }
4544
+ } : {},
4545
+ optimizeDeps
4546
+ };
4322
4547
  }
4323
- return {
4548
+ const plugin = {
4324
4549
  name: PLUGIN_NAME,
4325
- // 确保在 vite:resolve 之前运行
4550
+ // Module resolution still runs before Vite's resolver. Preparation waits
4551
+ // for all config hooks, including framework plugins that choose the root.
4326
4552
  enforce: "pre",
4327
- /**
4328
- * 配置阶段 - 修改 Vite 配置
4329
- */
4330
- async config(_config, { command }) {
4331
- isEnabled = command === "serve" && enableInDev || command === "build" && enableInBuild;
4332
- if (!isEnabled) {
4333
- logger9.info(`Plugin disabled for ${command} mode`);
4334
- return;
4335
- }
4336
- logger9.info("Initializing dependencies resolver...");
4337
- resolver = new DepsConflictResolver(resolverOptions, hooks);
4338
- await resolver.initialize();
4339
- const analysisResult = resolver.getAnalysisResult();
4340
- if (!analysisResult || analysisResult.aliasMappings.length === 0) {
4341
- logger9.info("No aliases needed");
4342
- return;
4553
+ config(config, { command }) {
4554
+ const enabled = command === "serve" && enableInDev || command === "build" && enableInBuild;
4555
+ const [major, minor] = version.split(".").map(Number);
4556
+ if (enabled && ssr === "auto" && command === "serve" && (major < 5 || major === 5 && minor === 0) && config.ssr?.optimizeDeps?.disabled === void 0) {
4557
+ return { ssr: { optimizeDeps: { disabled: false } } };
4343
4558
  }
4344
- const aliasPathMappings = resolver.getAliasPathMappings();
4345
- if (aliasPathMappings.length === 0) {
4346
- logger9.info("No active aliases available");
4347
- return;
4348
- }
4349
- const aliases = createViteAliases(aliasPathMappings);
4350
- logger9.info(`Configured ${aliasPathMappings.length} alias redirections`);
4351
- const aliasPackages = Array.from(new Set(aliasPathMappings.map((m) => m.aliasName)));
4352
- logger9.debug(`Alias packages to include: ${aliasPackages.join(", ")}`);
4353
- const projectRoot = resolver.getOptions().projectRoot;
4354
- const esbuildAliasPlugin = createEsbuildAliasPlugin(resolver, projectRoot);
4355
- return {
4356
- resolve: {
4357
- alias: aliases
4559
+ return void 0;
4560
+ },
4561
+ async configResolved(config) {
4562
+ const mainConfig = config.mainConfig;
4563
+ if (config.isWorker && mainConfig?.plugins.includes(plugin)) return;
4564
+ isEnabled = config.command === "serve" && enableInDev || config.command === "build" && enableInBuild;
4565
+ resolver = null;
4566
+ ssrExternalEnabled = false;
4567
+ resolveSsrExternal = void 0;
4568
+ isSsrExternal = void 0;
4569
+ if (!isEnabled) return;
4570
+ resolver = new DepsConflictResolver(
4571
+ {
4572
+ ...resolverOptions,
4573
+ projectRoot: resolverOptions.projectRoot ?? config.root
4358
4574
  },
4359
- optimizeDeps: {
4360
- // 确保别名包被预构建
4361
- include: aliasPackages,
4362
- // 在 esbuild 预构建时也应用别名
4363
- esbuildOptions: {
4364
- plugins: [esbuildAliasPlugin]
4365
- }
4575
+ hooks
4576
+ );
4577
+ await resolver.initialize();
4578
+ if (config.isWorker) return;
4579
+ const addition = runtimeConfig(config, resolver);
4580
+ if (!addition) return;
4581
+ const clientOptimizer = addition.optimizeDeps;
4582
+ if (clientOptimizer) {
4583
+ mergeOptimizer(config.optimizeDeps, clientOptimizer);
4584
+ const environment = config.environments?.client;
4585
+ if (environment && environment.optimizeDeps !== config.optimizeDeps)
4586
+ mergeOptimizer(environment.optimizeDeps ??= {}, clientOptimizer);
4587
+ }
4588
+ if (addition.ssr) {
4589
+ config.ssr.noExternal = mergeConfig(
4590
+ { ssr: { noExternal: config.ssr.noExternal } },
4591
+ { ssr: { noExternal: addition.ssr.noExternal } }
4592
+ ).ssr.noExternal;
4593
+ const environment = config.environments?.ssr;
4594
+ if (environment)
4595
+ (environment.resolve ??= {}).noExternal = mergeConfig(
4596
+ { ssr: { noExternal: environment.resolve.noExternal } },
4597
+ { ssr: { noExternal: addition.ssr.noExternal } }
4598
+ ).ssr.noExternal;
4599
+ const ssrOptimizer = addition.ssr.optimizeDeps;
4600
+ if (ssrOptimizer) {
4601
+ config.ssr.optimizeDeps ??= {};
4602
+ mergeOptimizer(config.ssr.optimizeDeps, ssrOptimizer);
4603
+ if (environment && environment.optimizeDeps !== config.ssr.optimizeDeps)
4604
+ mergeOptimizer(environment.optimizeDeps ??= {}, ssrOptimizer);
4366
4605
  }
4367
- };
4606
+ }
4607
+ if (ssrExternalEnabled)
4608
+ resolveSsrExternal = createSsrExternalPolicy(
4609
+ config,
4610
+ resolver.getOptions().projectRoot,
4611
+ isSsrExternal
4612
+ ).resolve;
4368
4613
  },
4369
4614
  /**
4370
4615
  * 解析模块 ID
@@ -4382,14 +4627,18 @@ function depsConflictResolverVitePlugin(options) {
4382
4627
  const resolved = resolver.resolveModule(source, importer);
4383
4628
  if (resolved) {
4384
4629
  logger9.debug(`Redirecting ${source} -> ${resolved} (from ${importer ?? "entry"})`);
4385
- return this.resolve?.(resolved, importer, {
4386
- skipSelf: true,
4387
- ...resolveOptions
4630
+ return this.resolve(resolved, join(resolver.getOptions().projectRoot, "package.json"), {
4631
+ ...resolveOptions,
4632
+ skipSelf: true
4633
+ }).then((result) => {
4634
+ if (!result) throw new Error("Cannot resolve active alias: " + resolved);
4635
+ return result;
4388
4636
  });
4389
4637
  }
4390
4638
  return null;
4391
4639
  }
4392
4640
  };
4641
+ return plugin;
4393
4642
  }
4394
4643
  var vite_default = depsConflictResolverVitePlugin;
4395
4644