deps-conflict-resolver 1.3.0 → 1.4.1

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/README.en.md CHANGED
@@ -167,6 +167,23 @@ console.log(resolver.explainResolution('vue', '/absolute/path/to/legacy-lib/inde
167
167
 
168
168
  Diagnostics expose stable codes. A failed strict initialization throws the exported `ResolutionError`, which includes `diagnostics`.
169
169
 
170
+ ## Vite Server-Side Rendering
171
+
172
+ The Vite plugin supports esbuild pre-bundling in Vite 4–7 and native Rolldown in Vite 8. Set `ssr: 'auto'` to include affected packages and active aliases in SSR builds and development pre-bundling:
173
+
174
+ ```typescript
175
+ depsConflictResolverVitePlugin({
176
+ dependencies: ['legacy-lib'],
177
+ ssr: 'auto',
178
+ });
179
+ ```
180
+
181
+ The default is `ssr: 'manual'`. Explicit `ssr.external` entries and SSR optimization exclusions retain Vite's precedence; avoid excluding packages that require redirection. When `projectRoot` is omitted, the plugin uses the final configured Vite `root`.
182
+
183
+ ## Webpack Watch and Linked Dependencies
184
+
185
+ Webpack watch tracks package manifests consulted during analysis and re-resolves affected modules when redirects change, while retaining unrelated module caches. Redirects from linked and workspace packages resolve from the host while preserving package `exports` and `import`/`require` conditions.
186
+
170
187
  ## How It Works
171
188
 
172
189
  ### 1. Dependency Analysis
package/README.md CHANGED
@@ -167,6 +167,23 @@ console.log(resolver.explainResolution('vue', '/absolute/path/to/legacy-lib/inde
167
167
 
168
168
  诊断包含稳定的错误代码;严格模式初始化失败时可捕获导出的 `ResolutionError` 并读取其 `diagnostics`。
169
169
 
170
+ ## Vite 服务端渲染
171
+
172
+ Vite 插件支持 Vite 4–7 的 esbuild 预构建和 Vite 8 的原生 Rolldown。设置 `ssr: 'auto'` 可将需要重定向的包和有效别名加入 SSR 构建及开发预构建:
173
+
174
+ ```typescript
175
+ depsConflictResolverVitePlugin({
176
+ dependencies: ['legacy-lib'],
177
+ ssr: 'auto',
178
+ });
179
+ ```
180
+
181
+ 默认值为 `ssr: 'manual'`。显式 `ssr.external` 和 SSR 优化排除项仍遵循 Vite 的优先级;需要重定向的包不应同时被排除。未指定 `projectRoot` 时,插件使用最终 Vite 配置的 `root`。
182
+
183
+ ## Webpack watch 与链接依赖
184
+
185
+ Webpack watch 会跟踪分析涉及的包清单,在重定向发生变化时重新解析受影响的模块,同时保留无关模块的缓存。链接或 workspace 包的重定向从宿主工程解析,并保留包的 `exports` 及 `import`/`require` 条件。
186
+
170
187
  ## 工作原理
171
188
 
172
189
  ### 1. 依赖分析
package/dist/vite.cjs CHANGED
@@ -12,6 +12,7 @@ var child_process = require('child_process');
12
12
  var crypto = require('crypto');
13
13
  var os = require('os');
14
14
  var perf_hooks = require('perf_hooks');
15
+ var vite = require('vite');
15
16
 
16
17
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
18
 
@@ -4269,110 +4270,354 @@ function escapeRegex(str) {
4269
4270
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4270
4271
  }
4271
4272
 
4272
- // src/plugins/vite/index.ts
4273
- var logger9 = createLogger("vite-plugin");
4274
- var PLUGIN_NAME = "deps-conflict-resolver";
4275
- function createViteAliases(mappings) {
4276
- const aliases = [];
4277
- for (const mapping of mappings) {
4278
- aliases.push({
4279
- find: new RegExp(`^${escapeRegex(mapping.aliasName)}$`),
4280
- replacement: mapping.path
4281
- });
4282
- }
4283
- return aliases;
4273
+ // src/plugins/vite/optimizer.ts
4274
+ async function externalId(policy, source, importer, isRequire) {
4275
+ if (!/^[\w@]/.test(source) || source.includes(":")) return null;
4276
+ const request = source.split(/[?#]/, 1)[0] ?? "";
4277
+ const parts = request.split("/");
4278
+ const packageName = request.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
4279
+ if (!policy.isExternal(packageName)) return null;
4280
+ return await policy.resolve(source, importer, isRequire) ?? null;
4281
+ }
4282
+ function esbuildExternalPlugin(policy) {
4283
+ return {
4284
+ name: "deps-conflict-resolver-ssr-external",
4285
+ setup(build) {
4286
+ build.onResolve({ filter: /^[\w@]/ }, async (args) => {
4287
+ if (!args.importer || args.kind === "entry-point") return null;
4288
+ const id = await externalId(
4289
+ policy,
4290
+ args.path,
4291
+ args.importer,
4292
+ args.kind.startsWith("require")
4293
+ );
4294
+ return id ? { path: id, external: true } : null;
4295
+ });
4296
+ }
4297
+ };
4298
+ }
4299
+ function rolldownExternalPlugin(policy) {
4300
+ return {
4301
+ name: "deps-conflict-resolver-ssr-external",
4302
+ async resolveId(source, importer, options) {
4303
+ if (!importer || options.isEntry) return null;
4304
+ const kind = options.kind;
4305
+ const isRequire = kind?.startsWith("require") ?? options.custom?.["node-resolve"]?.isRequire === true;
4306
+ const id = await externalId(policy, source, importer, isRequire);
4307
+ return id ? { id, external: true } : null;
4308
+ }
4309
+ };
4284
4310
  }
4285
- function createEsbuildAliasPlugin(resolver, projectRoot) {
4311
+ function esbuildPlugin(resolver, projectRoot) {
4286
4312
  return {
4287
4313
  name: "deps-conflict-resolver-esbuild",
4288
4314
  setup(build) {
4289
- const activeMappings = resolver.getAliasPathMappings();
4290
- if (activeMappings.length === 0) {
4291
- return;
4292
- }
4293
- const originalNames = Array.from(new Set(activeMappings.map((m) => m.originalName)));
4294
- const filter = new RegExp(`^(${originalNames.map(escapeRegex).join("|")})(?:/.*)?$`);
4295
- const hasResolveApi = typeof build.resolve === "function";
4315
+ const originals = [
4316
+ ...new Set(resolver.getAliasPathMappings().map((mapping) => mapping.originalName))
4317
+ ];
4318
+ if (originals.length === 0) return;
4319
+ const filter = new RegExp("^(" + originals.map(escapeRegex).join("|") + ")(?:[/?#].*)?$");
4296
4320
  build.onResolve({ filter }, async (args) => {
4297
- if (!args.importer) {
4298
- return null;
4299
- }
4300
- const resolved = resolver.resolveModule(args.path, args.importer);
4301
- if (!resolved) {
4302
- return null;
4303
- }
4304
- logger9.debug(`[esbuild] Redirecting ${args.path} -> ${resolved} (from ${args.importer})`);
4305
- if (hasResolveApi) {
4306
- const result = await build.resolve(resolved, {
4321
+ if (!args.importer) return null;
4322
+ const redirected = resolver.resolveModule(args.path, args.importer);
4323
+ if (!redirected) return null;
4324
+ if (typeof build.resolve === "function") {
4325
+ return build.resolve(redirected, {
4307
4326
  kind: args.kind,
4308
4327
  resolveDir: projectRoot,
4309
4328
  importer: args.importer
4310
4329
  });
4311
- if (result.errors.length > 0) {
4312
- return { errors: result.errors };
4313
- }
4314
- return { path: result.path };
4315
4330
  }
4316
- return {
4317
- path: resolved,
4318
- resolveDir: projectRoot
4319
- };
4331
+ try {
4332
+ return { path: module$1.createRequire(path.join(projectRoot, "package.json")).resolve(redirected) };
4333
+ } catch (error) {
4334
+ return {
4335
+ errors: [{ text: "Cannot resolve alias " + redirected + ": " + String(error) }]
4336
+ };
4337
+ }
4338
+ });
4339
+ }
4340
+ };
4341
+ }
4342
+ function rolldownPlugin(resolver, projectRoot) {
4343
+ return {
4344
+ name: "deps-conflict-resolver-rolldown",
4345
+ async resolveId(source, importer, resolveOptions) {
4346
+ if (!importer) return null;
4347
+ const redirected = resolver.resolveModule(source, importer);
4348
+ if (!redirected) return null;
4349
+ const resolved = await this.resolve(redirected, path.join(projectRoot, "package.json"), {
4350
+ ...resolveOptions,
4351
+ skipSelf: true
4320
4352
  });
4353
+ if (!resolved) throw new Error("Cannot resolve active alias: " + redirected);
4354
+ return resolved;
4355
+ }
4356
+ };
4357
+ }
4358
+ function createOptimizerOptions(resolver, projectRoot, viteVersion2, ssrExternal) {
4359
+ const include = [...new Set(resolver.getAliasPathMappings().map((mapping) => mapping.aliasName))];
4360
+ return Number.parseInt(viteVersion2, 10) >= 8 ? {
4361
+ include,
4362
+ rolldownOptions: {
4363
+ plugins: [
4364
+ rolldownPlugin(resolver, projectRoot),
4365
+ ...ssrExternal ? [rolldownExternalPlugin(ssrExternal)] : []
4366
+ ]
4367
+ }
4368
+ } : {
4369
+ include,
4370
+ esbuildOptions: {
4371
+ plugins: [
4372
+ esbuildPlugin(resolver, projectRoot),
4373
+ ...ssrExternal ? [esbuildExternalPlugin(ssrExternal)] : []
4374
+ ]
4321
4375
  }
4322
4376
  };
4323
4377
  }
4378
+ function createSsrExternalPolicy(config, projectRoot, isExternal) {
4379
+ const conditions = config.environments?.ssr?.resolve.externalConditions ?? config.ssr?.resolve?.externalConditions ?? ["node"];
4380
+ const importResolver = config.createResolver({
4381
+ asSrc: false,
4382
+ scan: true,
4383
+ mainFields: [],
4384
+ conditions,
4385
+ isRequire: false
4386
+ });
4387
+ const requireResolver = config.createResolver({
4388
+ asSrc: false,
4389
+ scan: true,
4390
+ mainFields: [],
4391
+ conditions,
4392
+ isRequire: true
4393
+ });
4394
+ const specifiers = new LruCache({ maxEntries: 1e3 });
4395
+ return {
4396
+ isExternal,
4397
+ async resolve(source, importer, isRequire) {
4398
+ const resolved = await (isRequire ? requireResolver : importResolver)(
4399
+ source,
4400
+ importer,
4401
+ false,
4402
+ true
4403
+ );
4404
+ if (!resolved || !path.isAbsolute(resolved)) return void 0;
4405
+ const extension = path.extname(resolved);
4406
+ if (extension && ![".js", ".mjs", ".cjs"].includes(extension)) return void 0;
4407
+ if (isRequire) return resolved;
4408
+ const key = source + "\0" + resolved;
4409
+ const cached = specifiers.get(key);
4410
+ if (cached) return cached;
4411
+ const request = source.split(/[?#]/, 1)[0] ?? "";
4412
+ const packageName = request.startsWith("@") ? request.split("/").slice(0, 2).join("/") : request.split("/")[0];
4413
+ const host = findPackagePath(packageName, projectRoot);
4414
+ if (host) {
4415
+ const directory = fs.realpathSync(host).replace(/\\/g, "/");
4416
+ if (resolved.replace(/\\/g, "/").startsWith(directory + "/")) {
4417
+ specifiers.set(key, source);
4418
+ return source;
4419
+ }
4420
+ }
4421
+ const url$1 = JSON.stringify(url.pathToFileURL(resolved).href);
4422
+ const code = `export function then(resolve,reject){import(${url$1}).then(resolve,reject)}`;
4423
+ const specifier = "data:text/javascript;base64," + Buffer.from(code).toString("base64");
4424
+ specifiers.set(key, specifier);
4425
+ return specifier;
4426
+ }
4427
+ };
4428
+ }
4429
+ var logger9 = createLogger("vite-plugin");
4430
+ var PLUGIN_NAME = "deps-conflict-resolver";
4431
+ function createViteAliases(mappings, projectRoot) {
4432
+ const aliases = [];
4433
+ for (const mapping of mappings) {
4434
+ aliases.push({
4435
+ find: new RegExp(`^${escapeRegex(mapping.aliasName)}$`),
4436
+ replacement: mapping.path,
4437
+ ...projectRoot ? {
4438
+ customResolver: function(_source, _importer, options) {
4439
+ return this.resolve(mapping.aliasName, path.join(projectRoot, "package.json"), {
4440
+ ...options,
4441
+ skipSelf: true
4442
+ });
4443
+ }
4444
+ } : {}
4445
+ });
4446
+ }
4447
+ return aliases;
4448
+ }
4449
+ function mergeOptimizer(target, addition) {
4450
+ const merged = vite.mergeConfig(target, addition);
4451
+ for (const key of Object.keys(addition)) Reflect.set(target, key, Reflect.get(merged, key));
4452
+ if (target.include) target.include = [...new Set(target.include)];
4453
+ if (target.exclude) target.exclude = [...new Set(target.exclude)];
4454
+ }
4324
4455
  function depsConflictResolverVitePlugin(options) {
4325
4456
  let resolver = null;
4326
4457
  let isEnabled = true;
4327
- const { enableInDev = true, enableInBuild = true, hooks, ...resolverOptions } = options;
4458
+ let resolveSsrExternal;
4459
+ let ssrExternalEnabled = false;
4460
+ let isSsrExternal;
4461
+ const {
4462
+ enableInDev = true,
4463
+ enableInBuild = true,
4464
+ ssr = "manual",
4465
+ hooks,
4466
+ ...resolverOptions
4467
+ } = options;
4328
4468
  if (options.debug) {
4329
- logger9.setLevel(1 /* DEBUG */);
4469
+ logger9.setLevel(15 /* ALL */);
4470
+ }
4471
+ function runtimeConfig(config, activeResolver) {
4472
+ const command = config.command;
4473
+ const analysisResult = activeResolver.getAnalysisResult();
4474
+ if (!analysisResult || analysisResult.aliasMappings.length === 0) {
4475
+ if (activeResolver.getDiagnostics().some((diagnostic) => diagnostic.severity === "error")) {
4476
+ logger9.warn(
4477
+ "No alias mappings available; inspect resolver diagnostics for unresolved conditions"
4478
+ );
4479
+ } else {
4480
+ logger9.info("No aliases needed");
4481
+ }
4482
+ return void 0;
4483
+ }
4484
+ const aliasPathMappings = activeResolver.getAliasPathMappings();
4485
+ if (aliasPathMappings.length === 0) {
4486
+ logger9.info("No active aliases available");
4487
+ return void 0;
4488
+ }
4489
+ const projectRoot = activeResolver.getOptions().projectRoot;
4490
+ logger9.info(`Configured ${aliasPathMappings.length} alias redirections`);
4491
+ const aliasPackages = Array.from(new Set(aliasPathMappings.map((m) => m.aliasName)));
4492
+ const activeNames = new Set(aliasPackages);
4493
+ const ssrPackages = new Set(aliasPackages);
4494
+ const ssrOptimizerPackages = new Set(aliasPackages);
4495
+ for (const mapping of analysisResult.aliasMappings) {
4496
+ if (!activeNames.has(mapping.aliasName)) continue;
4497
+ const excluded = new Set(resolverOptions.excludeRedirects?.[mapping.originalName] ?? []);
4498
+ for (const name of [
4499
+ ...mapping.allDependents,
4500
+ ...mapping.usedBy.map((path) => path.split(">")[0]),
4501
+ ...resolverOptions.includeRedirects?.[mapping.originalName] ?? []
4502
+ ]) {
4503
+ if (!excluded.has(name)) ssrPackages.add(name);
4504
+ }
4505
+ for (const name of [
4506
+ ...mapping.usedBy.map((path) => path.split(">")[0]),
4507
+ ...resolverOptions.includeRedirects?.[mapping.originalName] ?? []
4508
+ ]) {
4509
+ if (!excluded.has(name)) ssrOptimizerPackages.add(name);
4510
+ }
4511
+ }
4512
+ const ssrEnvironment = config.environments?.ssr;
4513
+ const ssrResolve = vite.mergeConfig(
4514
+ { resolve: { external: config.ssr?.external, noExternal: config.ssr?.noExternal } },
4515
+ { resolve: ssrEnvironment?.resolve ?? {} }
4516
+ ).resolve;
4517
+ const ssrOptimizer = vite.mergeConfig(
4518
+ config.ssr?.optimizeDeps ?? {},
4519
+ ssrEnvironment?.optimizeDeps ?? {}
4520
+ );
4521
+ const external = ssrResolve.external;
4522
+ const ssrExternal = Array.isArray(external) ? external : [];
4523
+ const ssrExcluded = [...ssrExternal, ...ssrOptimizer.exclude ?? []];
4524
+ const manualNoExternal = ssrResolve.noExternal;
4525
+ const keepsInternal = manualNoExternal === true ? () => true : manualNoExternal && (!Array.isArray(manualNoExternal) || manualNoExternal.length > 0) ? vite.createFilter(manualNoExternal, void 0, { resolve: false }) : () => false;
4526
+ const allowsSsrOptimization = (name) => (external !== true || keepsInternal(name)) && !ssrExcluded.some((excluded) => name === excluded || name.startsWith(excluded + "/"));
4527
+ logger9.debug(`Alias packages to include: ${aliasPackages.join(", ")}`);
4528
+ const optimizeDeps = createOptimizerOptions(activeResolver, projectRoot, vite.version);
4529
+ ssrExternalEnabled = ssr === "auto" && command === "serve" && external === true && manualNoExternal !== true;
4530
+ isSsrExternal = (packageName) => !keepsInternal(packageName);
4531
+ const ssrOptimizeDeps = ssrExternalEnabled ? createOptimizerOptions(activeResolver, projectRoot, vite.version, {
4532
+ isExternal: (packageName) => !keepsInternal(packageName),
4533
+ resolve: (source, importer, isRequire) => {
4534
+ if (!resolveSsrExternal) throw new Error("SSR external resolver is not initialized");
4535
+ return resolveSsrExternal(source, importer, isRequire);
4536
+ }
4537
+ }) : optimizeDeps;
4538
+ return {
4539
+ ...ssr === "auto" ? {
4540
+ ssr: {
4541
+ noExternal: ssrResolve.noExternal === true ? true : [...ssrPackages].filter(allowsSsrOptimization),
4542
+ ...command === "serve" ? {
4543
+ optimizeDeps: {
4544
+ ...ssrOptimizeDeps,
4545
+ include: [...ssrOptimizerPackages].filter(allowsSsrOptimization),
4546
+ // Vite's SSR optimizer is a separate bundler; forward
4547
+ // explicit externals so nested imports stay external too.
4548
+ exclude: ssrExternal
4549
+ }
4550
+ } : {}
4551
+ }
4552
+ } : {},
4553
+ optimizeDeps
4554
+ };
4330
4555
  }
4331
- return {
4556
+ const plugin = {
4332
4557
  name: PLUGIN_NAME,
4333
- // 确保在 vite:resolve 之前运行
4558
+ // Module resolution still runs before Vite's resolver. Preparation waits
4559
+ // for all config hooks, including framework plugins that choose the root.
4334
4560
  enforce: "pre",
4335
- /**
4336
- * 配置阶段 - 修改 Vite 配置
4337
- */
4338
- async config(_config, { command }) {
4339
- isEnabled = command === "serve" && enableInDev || command === "build" && enableInBuild;
4340
- if (!isEnabled) {
4341
- logger9.info(`Plugin disabled for ${command} mode`);
4342
- return;
4343
- }
4344
- logger9.info("Initializing dependencies resolver...");
4345
- resolver = new DepsConflictResolver(resolverOptions, hooks);
4346
- await resolver.initialize();
4347
- const analysisResult = resolver.getAnalysisResult();
4348
- if (!analysisResult || analysisResult.aliasMappings.length === 0) {
4349
- logger9.info("No aliases needed");
4350
- return;
4561
+ config(config, { command }) {
4562
+ const enabled = command === "serve" && enableInDev || command === "build" && enableInBuild;
4563
+ const [major, minor] = vite.version.split(".").map(Number);
4564
+ if (enabled && ssr === "auto" && command === "serve" && (major < 5 || major === 5 && minor === 0) && config.ssr?.optimizeDeps?.disabled === void 0) {
4565
+ return { ssr: { optimizeDeps: { disabled: false } } };
4351
4566
  }
4352
- const aliasPathMappings = resolver.getAliasPathMappings();
4353
- if (aliasPathMappings.length === 0) {
4354
- logger9.info("No active aliases available");
4355
- return;
4356
- }
4357
- const aliases = createViteAliases(aliasPathMappings);
4358
- logger9.info(`Configured ${aliasPathMappings.length} alias redirections`);
4359
- const aliasPackages = Array.from(new Set(aliasPathMappings.map((m) => m.aliasName)));
4360
- logger9.debug(`Alias packages to include: ${aliasPackages.join(", ")}`);
4361
- const projectRoot = resolver.getOptions().projectRoot;
4362
- const esbuildAliasPlugin = createEsbuildAliasPlugin(resolver, projectRoot);
4363
- return {
4364
- resolve: {
4365
- alias: aliases
4567
+ return void 0;
4568
+ },
4569
+ async configResolved(config) {
4570
+ const mainConfig = config.mainConfig;
4571
+ if (config.isWorker && mainConfig?.plugins.includes(plugin)) return;
4572
+ isEnabled = config.command === "serve" && enableInDev || config.command === "build" && enableInBuild;
4573
+ resolver = null;
4574
+ ssrExternalEnabled = false;
4575
+ resolveSsrExternal = void 0;
4576
+ isSsrExternal = void 0;
4577
+ if (!isEnabled) return;
4578
+ resolver = new DepsConflictResolver(
4579
+ {
4580
+ ...resolverOptions,
4581
+ projectRoot: resolverOptions.projectRoot ?? config.root
4366
4582
  },
4367
- optimizeDeps: {
4368
- // 确保别名包被预构建
4369
- include: aliasPackages,
4370
- // 在 esbuild 预构建时也应用别名
4371
- esbuildOptions: {
4372
- plugins: [esbuildAliasPlugin]
4373
- }
4583
+ hooks
4584
+ );
4585
+ await resolver.initialize();
4586
+ if (config.isWorker) return;
4587
+ const addition = runtimeConfig(config, resolver);
4588
+ if (!addition) return;
4589
+ const clientOptimizer = addition.optimizeDeps;
4590
+ if (clientOptimizer) {
4591
+ mergeOptimizer(config.optimizeDeps, clientOptimizer);
4592
+ const environment = config.environments?.client;
4593
+ if (environment && environment.optimizeDeps !== config.optimizeDeps)
4594
+ mergeOptimizer(environment.optimizeDeps ??= {}, clientOptimizer);
4595
+ }
4596
+ if (addition.ssr) {
4597
+ config.ssr.noExternal = vite.mergeConfig(
4598
+ { ssr: { noExternal: config.ssr.noExternal } },
4599
+ { ssr: { noExternal: addition.ssr.noExternal } }
4600
+ ).ssr.noExternal;
4601
+ const environment = config.environments?.ssr;
4602
+ if (environment)
4603
+ (environment.resolve ??= {}).noExternal = vite.mergeConfig(
4604
+ { ssr: { noExternal: environment.resolve.noExternal } },
4605
+ { ssr: { noExternal: addition.ssr.noExternal } }
4606
+ ).ssr.noExternal;
4607
+ const ssrOptimizer = addition.ssr.optimizeDeps;
4608
+ if (ssrOptimizer) {
4609
+ config.ssr.optimizeDeps ??= {};
4610
+ mergeOptimizer(config.ssr.optimizeDeps, ssrOptimizer);
4611
+ if (environment && environment.optimizeDeps !== config.ssr.optimizeDeps)
4612
+ mergeOptimizer(environment.optimizeDeps ??= {}, ssrOptimizer);
4374
4613
  }
4375
- };
4614
+ }
4615
+ if (ssrExternalEnabled)
4616
+ resolveSsrExternal = createSsrExternalPolicy(
4617
+ config,
4618
+ resolver.getOptions().projectRoot,
4619
+ isSsrExternal
4620
+ ).resolve;
4376
4621
  },
4377
4622
  /**
4378
4623
  * 解析模块 ID
@@ -4390,14 +4635,18 @@ function depsConflictResolverVitePlugin(options) {
4390
4635
  const resolved = resolver.resolveModule(source, importer);
4391
4636
  if (resolved) {
4392
4637
  logger9.debug(`Redirecting ${source} -> ${resolved} (from ${importer ?? "entry"})`);
4393
- return this.resolve?.(resolved, importer, {
4394
- skipSelf: true,
4395
- ...resolveOptions
4638
+ return this.resolve(resolved, path.join(resolver.getOptions().projectRoot, "package.json"), {
4639
+ ...resolveOptions,
4640
+ skipSelf: true
4641
+ }).then((result) => {
4642
+ if (!result) throw new Error("Cannot resolve active alias: " + resolved);
4643
+ return result;
4396
4644
  });
4397
4645
  }
4398
4646
  return null;
4399
4647
  }
4400
4648
  };
4649
+ return plugin;
4401
4650
  }
4402
4651
  var vite_default = depsConflictResolverVitePlugin;
4403
4652