|
7 | 7 |
|
8 | 8 | /** @typedef {import("./Resolver")} Resolver */ |
9 | 9 | /** @typedef {import("./Resolver").FileSystem} FileSystem */ |
| 10 | +/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ |
10 | 11 | /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * Per-filesystem inode cache. The cache lifetime is tied to the filesystem |
14 | 15 | * object (same invariant as `_pathCacheByFs` in `Resolver.js`): when the |
15 | 16 | * user swaps filesystems the entries become unreachable and get collected. |
16 | | - * @type {WeakMap<FileSystem, Map<string, string>>} |
| 17 | + * @type {WeakMap<FileSystem, Map<string, ResolveRequest>>} |
17 | 18 | */ |
18 | 19 | const _inodeCacheByFs = new WeakMap(); |
19 | 20 |
|
@@ -51,26 +52,19 @@ module.exports = class HardlinkPlugin { |
51 | 52 | if (ino === 0) return callback(); |
52 | 53 |
|
53 | 54 | const key = `${stat.dev}:${ino}`; |
54 | | - const cachedPath = inodeCache.get(key); |
| 55 | + const cached = inodeCache.get(key); |
55 | 56 |
|
56 | | - if (cachedPath !== undefined) { |
57 | | - if (cachedPath !== filePath) { |
58 | | - // Only request.path is updated; description-file |
59 | | - // metadata (descriptionFileRoot, descriptionFilePath, |
60 | | - // descriptionFileData, relativePath) still reflects |
61 | | - // the original path. For the primary use case |
62 | | - // (bundler module identity) only path matters, and |
63 | | - // for pnpm hardlinks the description-file content is |
64 | | - // identical across copies. |
65 | | - request.path = cachedPath; |
| 57 | + if (cached !== undefined) { |
| 58 | + if (cached.path !== filePath) { |
66 | 59 | if (resolveContext.log) { |
67 | 60 | resolveContext.log( |
68 | | - `deduplicated hardlink ${filePath} to ${cachedPath}`, |
| 61 | + `deduplicated hardlink ${filePath} to ${cached.path}`, |
69 | 62 | ); |
70 | 63 | } |
| 64 | + return callback(null, cached); |
71 | 65 | } |
72 | 66 | } else { |
73 | | - inodeCache.set(key, filePath); |
| 67 | + inodeCache.set(key, { ...request }); |
74 | 68 | } |
75 | 69 | callback(); |
76 | 70 | }); |
|
0 commit comments