deps-conflict-resolver 1.4.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 +4 -0
- package/README.md +4 -0
- package/dist/webpack.cjs +78 -2
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.cts +2 -0
- package/dist/webpack.d.ts +2 -0
- package/dist/webpack.js +80 -4
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -180,6 +180,10 @@ depsConflictResolverVitePlugin({
|
|
|
180
180
|
|
|
181
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
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
|
+
|
|
183
187
|
## How It Works
|
|
184
188
|
|
|
185
189
|
### 1. Dependency Analysis
|
package/README.md
CHANGED
|
@@ -180,6 +180,10 @@ depsConflictResolverVitePlugin({
|
|
|
180
180
|
|
|
181
181
|
默认值为 `ssr: 'manual'`。显式 `ssr.external` 和 SSR 优化排除项仍遵循 Vite 的优先级;需要重定向的包不应同时被排除。未指定 `projectRoot` 时,插件使用最终 Vite 配置的 `root`。
|
|
182
182
|
|
|
183
|
+
## Webpack watch 与链接依赖
|
|
184
|
+
|
|
185
|
+
Webpack watch 会跟踪分析涉及的包清单,在重定向发生变化时重新解析受影响的模块,同时保留无关模块的缓存。链接或 workspace 包的重定向从宿主工程解析,并保留包的 `exports` 及 `import`/`require` 条件。
|
|
186
|
+
|
|
183
187
|
## 工作原理
|
|
184
188
|
|
|
185
189
|
### 1. 依赖分析
|
package/dist/webpack.cjs
CHANGED
|
@@ -4266,8 +4266,6 @@ var DepsConflictResolver = class {
|
|
|
4266
4266
|
return { ...this.options };
|
|
4267
4267
|
}
|
|
4268
4268
|
};
|
|
4269
|
-
|
|
4270
|
-
// src/plugins/webpack/index.ts
|
|
4271
4269
|
var logger9 = createLogger("webpack-plugin");
|
|
4272
4270
|
var PLUGIN_NAME = "DepsConflictResolverWebpackPlugin";
|
|
4273
4271
|
var DepsConflictResolverWebpackPlugin = class {
|
|
@@ -4277,6 +4275,7 @@ var DepsConflictResolverWebpackPlugin = class {
|
|
|
4277
4275
|
initPromise = null;
|
|
4278
4276
|
initialized = false;
|
|
4279
4277
|
generation = 0;
|
|
4278
|
+
aliasVersions = /* @__PURE__ */ new Map();
|
|
4280
4279
|
constructor(config) {
|
|
4281
4280
|
this.config = config;
|
|
4282
4281
|
if (config.debug) {
|
|
@@ -4322,6 +4321,18 @@ var DepsConflictResolverWebpackPlugin = class {
|
|
|
4322
4321
|
return;
|
|
4323
4322
|
}
|
|
4324
4323
|
this.analysisResult = resolver.getAnalysisResult();
|
|
4324
|
+
this.aliasVersions.clear();
|
|
4325
|
+
for (const mapping of resolver.getAliasPathMappings()) {
|
|
4326
|
+
let path = mapping.path;
|
|
4327
|
+
try {
|
|
4328
|
+
path = fs.realpathSync(path);
|
|
4329
|
+
} catch {
|
|
4330
|
+
}
|
|
4331
|
+
this.aliasVersions.set(
|
|
4332
|
+
mapping.aliasName,
|
|
4333
|
+
crypto.createHash("sha256").update(JSON.stringify([path, readPackageJsonCached(path)])).digest("hex")
|
|
4334
|
+
);
|
|
4335
|
+
}
|
|
4325
4336
|
if (this.analysisResult && this.analysisResult.aliasMappings.length > 0) {
|
|
4326
4337
|
logger9.info(`Planned ${this.analysisResult.aliasMappings.length} alias mappings`);
|
|
4327
4338
|
if (this.config.debug) {
|
|
@@ -4345,6 +4356,7 @@ var DepsConflictResolverWebpackPlugin = class {
|
|
|
4345
4356
|
}
|
|
4346
4357
|
this.analysisResult = null;
|
|
4347
4358
|
this.initialized = false;
|
|
4359
|
+
this.aliasVersions.clear();
|
|
4348
4360
|
logger9.error("Error initializing dependencies resolver:", error);
|
|
4349
4361
|
if (this.config.strict) throw error;
|
|
4350
4362
|
}).finally(() => {
|
|
@@ -4407,6 +4419,37 @@ var DepsConflictResolverWebpackPlugin = class {
|
|
|
4407
4419
|
logger9.debug(`Redirecting ${request} -> ${resolvedModule} (importer: ${importer})`);
|
|
4408
4420
|
}
|
|
4409
4421
|
resolveData.request = resolvedModule;
|
|
4422
|
+
resolveData.context = this.resolver.getOptions().projectRoot;
|
|
4423
|
+
}
|
|
4424
|
+
moduleResolutionVersion(module) {
|
|
4425
|
+
if (!this.initialized || !module.resource || !this.resolver || this.aliasVersions.size === 0)
|
|
4426
|
+
return "";
|
|
4427
|
+
const requests = /* @__PURE__ */ new Set();
|
|
4428
|
+
const versions = [];
|
|
4429
|
+
const blocks = [module];
|
|
4430
|
+
while (blocks.length > 0) {
|
|
4431
|
+
const block = blocks.pop();
|
|
4432
|
+
blocks.push(...block.blocks);
|
|
4433
|
+
for (const dependency of block.dependencies) {
|
|
4434
|
+
if (!("request" in dependency) || typeof dependency.request !== "string") continue;
|
|
4435
|
+
const request = dependency.request;
|
|
4436
|
+
if (requests.has(request) || isPathLikeRequest(request) || isWebpackInternalRequest(request))
|
|
4437
|
+
continue;
|
|
4438
|
+
requests.add(request);
|
|
4439
|
+
const decision = this.resolver.explainResolution(request, module.resource, {
|
|
4440
|
+
skipHook: true
|
|
4441
|
+
});
|
|
4442
|
+
if (!decision.resolved && decision.reason !== "ambiguous") continue;
|
|
4443
|
+
versions.push(
|
|
4444
|
+
JSON.stringify([
|
|
4445
|
+
request,
|
|
4446
|
+
decision.resolved,
|
|
4447
|
+
decision.aliases.map((alias) => this.aliasVersions.get(alias))
|
|
4448
|
+
])
|
|
4449
|
+
);
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
return versions.length > 0 ? JSON.stringify(versions.sort()) : "";
|
|
4410
4453
|
}
|
|
4411
4454
|
apply(compiler) {
|
|
4412
4455
|
this.config = {
|
|
@@ -4421,6 +4464,39 @@ var DepsConflictResolverWebpackPlugin = class {
|
|
|
4421
4464
|
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
|
|
4422
4465
|
await this.initialize(true);
|
|
4423
4466
|
});
|
|
4467
|
+
let legacyCacheHookInstalled = false;
|
|
4468
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
4469
|
+
for (const file of this.analysisResult?.watchFiles ?? [])
|
|
4470
|
+
compilation.fileDependencies.add(file);
|
|
4471
|
+
compilation.fileDependencies.add(path.join(this.config.projectRoot, "package.json"));
|
|
4472
|
+
compilation.hooks.succeedModule.tap(PLUGIN_NAME, (module) => {
|
|
4473
|
+
if ("resource" in module && module.buildInfo)
|
|
4474
|
+
module.buildInfo.depsConflictResolver = this.moduleResolutionVersion(module);
|
|
4475
|
+
});
|
|
4476
|
+
const hooks = compiler.webpack?.NormalModule.getCompilationHooks(compilation);
|
|
4477
|
+
if (hooks?.needBuild) {
|
|
4478
|
+
hooks.needBuild.tapAsync(PLUGIN_NAME, (module, _context, callback) => {
|
|
4479
|
+
const previous = module.buildInfo?.depsConflictResolver ?? "";
|
|
4480
|
+
if (previous !== this.moduleResolutionVersion(module)) return callback(null, true);
|
|
4481
|
+
callback();
|
|
4482
|
+
});
|
|
4483
|
+
} else if (!legacyCacheHookInstalled) {
|
|
4484
|
+
compiler.cache.hooks.get.tap(
|
|
4485
|
+
{ name: PLUGIN_NAME, stage: Number.NEGATIVE_INFINITY },
|
|
4486
|
+
(identifier, _etag, gotHandlers) => {
|
|
4487
|
+
if (!identifier.includes("Compilation/modules|")) return;
|
|
4488
|
+
gotHandlers.push((cached, callback) => {
|
|
4489
|
+
if (cached?.resource && typeof cached.invalidateBuild === "function") {
|
|
4490
|
+
const previous = cached.buildInfo?.depsConflictResolver ?? "";
|
|
4491
|
+
if (previous !== this.moduleResolutionVersion(cached)) cached.invalidateBuild();
|
|
4492
|
+
}
|
|
4493
|
+
callback();
|
|
4494
|
+
});
|
|
4495
|
+
}
|
|
4496
|
+
);
|
|
4497
|
+
legacyCacheHookInstalled = true;
|
|
4498
|
+
}
|
|
4499
|
+
});
|
|
4424
4500
|
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
|
|
4425
4501
|
nmf.hooks.beforeResolve.tapPromise(PLUGIN_NAME, async (resolveData) => {
|
|
4426
4502
|
try {
|