@rushstack/webpack-workspace-resolve-plugin 0.3.17 → 0.3.19
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/CHANGELOG.json +32 -0
- package/CHANGELOG.md +13 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/KnownPackageDependenciesPlugin.d.ts.map +1 -1
- package/lib/KnownPackageDependenciesPlugin.js +5 -1
- package/lib/KnownPackageDependenciesPlugin.js.map +1 -1
- package/lib/WorkspaceLayoutCache.d.ts.map +1 -1
- package/lib/WorkspaceLayoutCache.js +7 -7
- package/lib/WorkspaceLayoutCache.js.map +1 -1
- package/lib/WorkspaceResolvePlugin.d.ts.map +1 -1
- package/lib/WorkspaceResolvePlugin.js +6 -6
- package/lib/WorkspaceResolvePlugin.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack-workspace-resolve-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.19",
|
|
6
|
+
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.3.19",
|
|
7
|
+
"date": "Tue, 07 Jan 2025 22:17:32 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"dependency": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Updating dependency \"@rushstack/lookup-by-path\" to `0.5.1`"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.68.12`"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"version": "0.3.18",
|
|
21
|
+
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.3.18",
|
|
22
|
+
"date": "Wed, 18 Dec 2024 01:11:33 GMT",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"comment": "Fix a bug with path handling on Windows. Tap hooks earlier to ensure that these plugins run before builtin behavior."
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"dependency": [
|
|
30
|
+
{
|
|
31
|
+
"comment": "Updating dependency \"@rushstack/lookup-by-path\" to `0.5.0`"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
4
36
|
{
|
|
5
37
|
"version": "0.3.17",
|
|
6
38
|
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.3.17",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @rushstack/webpack-workspace-resolve-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 07 Jan 2025 22:17:32 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.19
|
|
6
|
+
Tue, 07 Jan 2025 22:17:32 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 0.3.18
|
|
11
|
+
Wed, 18 Dec 2024 01:11:33 GMT
|
|
12
|
+
|
|
13
|
+
### Patches
|
|
14
|
+
|
|
15
|
+
- Fix a bug with path handling on Windows. Tap hooks earlier to ensure that these plugins run before builtin behavior.
|
|
4
16
|
|
|
5
17
|
## 0.3.17
|
|
6
18
|
Sat, 14 Dec 2024 01:11:07 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnownPackageDependenciesPlugin.d.ts","sourceRoot":"","sources":["../src/KnownPackageDependenciesPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAIpF;;;;;GAKG;AACH,qBAAa,8BAA8B;IACzC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C;;;;;OAKG;gBACgB,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMvE,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"KnownPackageDependenciesPlugin.d.ts","sourceRoot":"","sources":["../src/KnownPackageDependenciesPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAIpF;;;;;GAKG;AACH,qBAAa,8BAA8B;IACzC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAE9C;;;;;OAKG;gBACgB,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMvE,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAgEvC"}
|
|
@@ -41,7 +41,11 @@ class KnownPackageDependenciesPlugin {
|
|
|
41
41
|
const cache = this._cache;
|
|
42
42
|
let scope = cache.contextForPackage.get(descriptionFileData);
|
|
43
43
|
if (!scope) {
|
|
44
|
-
|
|
44
|
+
scope = cache.contextLookup.findLongestPrefixMatch(path);
|
|
45
|
+
if (!scope) {
|
|
46
|
+
return callback(new Error(`Expected context for ${request.descriptionFileRoot}`));
|
|
47
|
+
}
|
|
48
|
+
cache.contextForPackage.set(descriptionFileData, scope);
|
|
45
49
|
}
|
|
46
50
|
let dependency;
|
|
47
51
|
while (scope && !dependency) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnownPackageDependenciesPlugin.js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EAAE,SAAS;gBAC9B,mBAAmB,EAAE,GAAG,mBAAmB,GAAG,KAAK,CAAC,qBAAqB,cAAc;gBAEvF,YAAY,EAAE,YAAY;gBAC1B,OAAO,EAAE,YAAY;gBACrB,cAAc;gBACd,MAAM,EAAE,KAAK;aACd,CAAC;YACF,kDAAkD;YAClD,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAlFD,wEAkFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { Resolver } from 'webpack';\nimport type { IPrefixMatch } from '@rushstack/lookup-by-path';\nimport type { IResolveContext, WorkspaceLayoutCache } from './WorkspaceLayoutCache';\n\ntype ResolveRequest = Parameters<Resolver['hooks']['resolveStep']['call']>[1];\n\n/**\n * A resolver plugin that optimizes resolving installed dependencies for the current package.\n * Enforces strict resolution.\n *\n * @internal\n */\nexport class KnownPackageDependenciesPlugin {\n public readonly source: string;\n public readonly target: string;\n\n private readonly _cache: WorkspaceLayoutCache;\n\n /**\n * Constructs a new instance of `KnownPackageDependenciesPlugin`.\n * @param cache - The workspace layout cache\n * @param source - The resolve step to hook into\n * @param target - The resolve step to delegate to\n */\n public constructor(cache: WorkspaceLayoutCache, source: string, target: string) {\n this.source = source;\n this.target = target;\n this._cache = cache;\n }\n\n public apply(resolver: Resolver): void {\n const target: ReturnType<Resolver['ensureHook']> = resolver.ensureHook(this.target);\n\n resolver\n .getHook(this.source)\n .tapAsync(KnownPackageDependenciesPlugin.name, (request, resolveContext, callback) => {\n const { path, request: rawRequest } = request;\n if (!path) {\n return callback();\n }\n\n if (!rawRequest) {\n return callback();\n }\n\n const { descriptionFileData } = request;\n if (!descriptionFileData) {\n return callback(new Error(`Expected descriptionFileData for ${path}`));\n }\n\n const cache: WorkspaceLayoutCache = this._cache;\n\n let scope: IPrefixMatch<IResolveContext> | undefined =\n cache.contextForPackage.get(descriptionFileData);\n if (!scope) {\n scope = cache.contextLookup.findLongestPrefixMatch(path);\n if (!scope) {\n return callback(new Error(`Expected context for ${request.descriptionFileRoot}`));\n }\n cache.contextForPackage.set(descriptionFileData, scope);\n }\n\n let dependency: IPrefixMatch<IResolveContext> | undefined;\n while (scope && !dependency) {\n dependency = scope.value.findDependency(rawRequest);\n scope = scope.lastMatch;\n }\n\n if (!dependency) {\n return callback();\n }\n\n const isPackageRoot: boolean = dependency.index === rawRequest.length;\n const fullySpecified: boolean | undefined = isPackageRoot ? false : request.fullySpecified;\n const remainingPath: string = isPackageRoot ? '.' : `.${rawRequest.slice(dependency.index)}`;\n const relativePath: string =\n (remainingPath.length > 1 && cache.normalizeToSlash?.(remainingPath)) || remainingPath;\n const { descriptionFileRoot } = dependency.value;\n const obj: ResolveRequest = {\n ...request,\n path: descriptionFileRoot,\n descriptionFileRoot,\n descriptionFileData: undefined,\n descriptionFilePath: `${descriptionFileRoot}${cache.resolverPathSeparator}package.json`,\n\n relativePath: relativePath,\n request: relativePath,\n fullySpecified,\n module: false\n };\n // eslint-disable-next-line @rushstack/no-new-null\n resolver.doResolve(target, obj, null, resolveContext, callback);\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceLayoutCache.d.ts","sourceRoot":"","sources":["../src/WorkspaceLayoutCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE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
|
|
43
43
|
if (!this._descriptionFileRoot) {
|
|
44
|
-
|
|
44
|
+
const merged = `${basePath}${this._serialized.root}`;
|
|
45
|
+
this._descriptionFileRoot = (_a = normalizeToPlatform === null || normalizeToPlatform === void 0 ? void 0 : normalizeToPlatform(merged)) !== null && _a !== void 0 ? _a : merged;
|
|
45
46
|
}
|
|
46
47
|
return this._descriptionFileRoot;
|
|
47
48
|
}
|
|
@@ -66,17 +67,16 @@ class WorkspaceLayoutCache {
|
|
|
66
67
|
for (const serialized of cacheData.contexts) {
|
|
67
68
|
const resolveContext = new ResolveContext(serialized);
|
|
68
69
|
resolveContexts.push(resolveContext);
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
contextLookup.setItemFromSegments(concat(
|
|
71
|
+
// All paths in the cache file are platform-agnostic
|
|
72
|
+
lookup_by_path_1.LookupByPath.iteratePathSegments(basePath, '/'), lookup_by_path_1.LookupByPath.iteratePathSegments(serialized.root, '/')), resolveContext);
|
|
71
73
|
// Handle nested package.json files. These may modify some properties, but the dependency resolution
|
|
72
74
|
// will match the original package root. Typically these are used to set the `type` field to `module`.
|
|
73
75
|
if (serialized.dirInfoFiles) {
|
|
74
76
|
for (const file of serialized.dirInfoFiles) {
|
|
75
77
|
contextLookup.setItemFromSegments(concat(
|
|
76
|
-
//
|
|
77
|
-
lookup_by_path_1.LookupByPath.iteratePathSegments(
|
|
78
|
-
// Subpaths are platform-agnostic
|
|
79
|
-
lookup_by_path_1.LookupByPath.iteratePathSegments(file, '/')), resolveContext);
|
|
78
|
+
// All paths in the cache file are platform-agnostic
|
|
79
|
+
concat(lookup_by_path_1.LookupByPath.iteratePathSegments(basePath, '/'), lookup_by_path_1.LookupByPath.iteratePathSegments(serialized.root, '/')), lookup_by_path_1.LookupByPath.iteratePathSegments(file, '/')), resolveContext);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceLayoutCache.js","sourceR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C;SACF;QAED,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC5C,MAAM,cAAc,GAAmB,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC;YACtE,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAErC,MAAM,mBAAmB,GAAW,cAAc,CAAC,mBAAmB,CAAC;YACvE,aAAa,CAAC,OAAO,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;YAE3D,oGAAoG;YACpG,sGAAsG;YACtG,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;gBAC5B,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;oBAC3C,aAAa,CAAC,mBAAmB,CAC/B,MAAM;oBACJ,yCAAyC;oBACzC,6BAAY,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;oBAC5E,iCAAiC;oBACjC,6BAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,GAAG,CAAC,CAC5C,EACD,cAAc,CACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAxGD,oDAwGC;AAED,QAAQ,CAAC,CAAC,MAAM,CAAI,CAAc,EAAE,CAAc;IAChD,KAAK,CAAC,CAAC,CAAC,CAAC;IACT,KAAK,CAAC,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { sep as directorySeparator } from 'node:path';\n\nimport { LookupByPath, type IPrefixMatch } from '@rushstack/lookup-by-path';\n\n/**\n * Information about a local or installed npm package.\n * @beta\n */\nexport interface ISerializedResolveContext {\n /**\n * The path to the root folder of this context.\n * This path is normalized to use `/` as the separator and should not end with a trailing `/`.\n */\n root: string;\n /**\n * The name of this package. Used to inject a self-reference into the dependency map.\n */\n name: string;\n /**\n * Map of declared dependencies (if any) to the ordinal of the corresponding context.\n */\n deps?: Record<string, number>;\n /**\n * Set of relative paths to nested `package.json` files within this context.\n * These paths are normalized to use `/` as the separator and should not begin with a leading `./`.\n */\n dirInfoFiles?: string[];\n}\n\n/**\n * The serialized form of the cache file. This file is expected to be generated by a separate tool from\n * information known to the package manager. Namely, the dependency relationships between packages, and\n * all the `package.json` files in the workspace (installed or local).\n * @beta\n */\nexport interface IResolverCacheFile {\n /**\n * The base path. All paths in context entries are prefixed by this path.\n */\n basePath: string;\n /**\n * The ordered list of all contexts in the cache\n */\n contexts: ISerializedResolveContext[];\n}\n\n/**\n * A context for resolving dependencies in a workspace.\n * @beta\n */\nexport interface IResolveContext {\n /**\n * The absolute path to the root folder of this context\n */\n descriptionFileRoot: string;\n /**\n * Find the context that corresponds to a module specifier, when requested in the current context.\n * @param request - The module specifier to resolve\n */\n findDependency(request: string): IPrefixMatch<IResolveContext> | undefined;\n}\n\n/**\n * Options for creating a `WorkspaceLayoutCache`.\n * @beta\n */\nexport interface IWorkspaceLayoutCacheOptions {\n /**\n * The parsed cache data. File reading is left as an exercise for the caller.\n */\n cacheData: IResolverCacheFile;\n /**\n * The directory separator used in the `path` field of the resolver inputs.\n * Will usually be `path.sep`.\n */\n resolverPathSeparator?: '/' | '\\\\';\n}\n\n/**\n * A function that normalizes a path to a platform-specific format (if needed).\n * Will be undefined if the platform uses `/` as the path separator.\n *\n * @beta\n */\nexport type IPathNormalizationFunction = ((input: string) => string) | undefined;\n\nfunction backslashToSlash(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\nfunction slashToBackslash(path: string): string {\n return path.replace(/\\//g, '\\\\');\n}\n\n/**\n * A cache of workspace layout information.\n * @beta\n */\nexport class WorkspaceLayoutCache {\n /**\n * A lookup of context roots to their corresponding context objects\n */\n public readonly contextLookup: LookupByPath<IResolveContext>;\n /**\n * A weak map of package JSON contents to their corresponding context objects\n */\n public readonly contextForPackage: WeakMap<object, IPrefixMatch<IResolveContext>>;\n\n public readonly resolverPathSeparator: string;\n public readonly normalizeToSlash: IPathNormalizationFunction;\n public readonly normalizeToPlatform: IPathNormalizationFunction;\n\n public constructor(options: IWorkspaceLayoutCacheOptions) {\n const { cacheData, resolverPathSeparator = directorySeparator } = options;\n\n if (resolverPathSeparator !== '/' && resolverPathSeparator !== '\\\\') {\n throw new Error(`Unsupported directory separator: ${resolverPathSeparator}`);\n }\n\n const { basePath } = cacheData;\n const resolveContexts: ResolveContext[] = [];\n const contextLookup: LookupByPath<IResolveContext> = new LookupByPath(undefined, resolverPathSeparator);\n\n this.contextLookup = contextLookup;\n this.contextForPackage = new WeakMap<object, IPrefixMatch<IResolveContext>>();\n\n const normalizeToSlash: IPathNormalizationFunction =\n resolverPathSeparator === '\\\\' ? backslashToSlash : undefined;\n const normalizeToPlatform: IPathNormalizationFunction =\n resolverPathSeparator === '\\\\' ? slashToBackslash : undefined;\n\n this.resolverPathSeparator = resolverPathSeparator;\n this.normalizeToSlash = normalizeToSlash;\n this.normalizeToPlatform = normalizeToPlatform;\n\n // Internal class due to coupling to `resolveContexts`\n class ResolveContext implements IResolveContext {\n private readonly _serialized: ISerializedResolveContext;\n private _descriptionFileRoot: string | undefined;\n private _dependencies: LookupByPath<IResolveContext> | undefined;\n\n public constructor(serialized: ISerializedResolveContext) {\n this._serialized = serialized;\n this._descriptionFileRoot = undefined;\n this._dependencies = undefined;\n }\n\n public get descriptionFileRoot(): string {\n if (!this._descriptionFileRoot) {\n this._descriptionFileRoot = `${basePath}${\n normalizeToPlatform?.(this._serialized.root) ?? this._serialized.root\n }`;\n }\n return this._descriptionFileRoot;\n }\n\n public findDependency(request: string): IPrefixMatch<IResolveContext> | undefined {\n if (!this._dependencies) {\n // Lazy initialize this object since most packages won't be requested.\n const dependencies: LookupByPath<IResolveContext> = new LookupByPath(undefined, '/');\n\n const { name, deps } = this._serialized;\n\n // Handle the self-reference scenario\n dependencies.setItem(name, this);\n if (deps) {\n for (const [key, ordinal] of Object.entries(deps)) {\n // This calls into the array of instances that is owned by WorkpaceLayoutCache\n dependencies.setItem(key, resolveContexts[ordinal]);\n }\n }\n this._dependencies = dependencies;\n }\n\n return this._dependencies.findLongestPrefixMatch(request);\n }\n }\n\n for (const serialized of cacheData.contexts) {\n const resolveContext: ResolveContext = new ResolveContext(serialized);\n resolveContexts.push(resolveContext);\n\n const descriptionFileRoot: string = resolveContext.descriptionFileRoot;\n contextLookup.setItem(descriptionFileRoot, resolveContext);\n\n // Handle nested package.json files. These may modify some properties, but the dependency resolution\n // will match the original package root. Typically these are used to set the `type` field to `module`.\n if (serialized.dirInfoFiles) {\n for (const file of serialized.dirInfoFiles) {\n contextLookup.setItemFromSegments(\n concat<string>(\n // Root is normalized to platform slashes\n LookupByPath.iteratePathSegments(descriptionFileRoot, resolverPathSeparator),\n // Subpaths are platform-agnostic\n LookupByPath.iteratePathSegments(file, '/')\n ),\n resolveContext\n );\n }\n }\n }\n }\n}\n\nfunction* concat<T>(a: Iterable<T>, b: Iterable<T>): IterableIterator<T> {\n yield* a;\n yield* b;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WorkspaceLayoutCache.js","sourceRoot":"","sources":["../src/WorkspaceLayoutCache.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,yCAAsD;AAEtD,8DAA4E;AAoF5E,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAa,oBAAoB;IAc/B,YAAmB,OAAqC;QACtD,MAAM,EAAE,SAAS,EAAE,qBAAqB,GAAG,eAAkB,EAAE,GAAG,OAAO,CAAC;QAE1E,IAAI,qBAAqB,KAAK,GAAG,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,o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CAC/B,MAAM;oBACJ,oDAAoD;oBACpD,MAAM,CACJ,6BAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,GAAG,CAAC,EAC/C,6BAAY,CAAC,mBAAmB,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CACvD,EACD,6BAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,GAAG,CAAC,CAC5C,EACD,cAAc,CACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA/GD,oDA+GC;AAED,QAAQ,CAAC,CAAC,MAAM,CAAI,CAAc,EAAE,CAAc;IAChD,KAAK,CAAC,CAAC,CAAC,CAAC;IACT,KAAK,CAAC,CAAC,CAAC,CAAC;AACX,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { sep as directorySeparator } from 'node:path';\n\nimport { LookupByPath, type IPrefixMatch } from '@rushstack/lookup-by-path';\n\n/**\n * Information about a local or installed npm package.\n * @beta\n */\nexport interface ISerializedResolveContext {\n /**\n * The path to the root folder of this context.\n * This path is normalized to use `/` as the separator and should not end with a trailing `/`.\n */\n root: string;\n /**\n * The name of this package. Used to inject a self-reference into the dependency map.\n */\n name: string;\n /**\n * Map of declared dependencies (if any) to the ordinal of the corresponding context.\n */\n deps?: Record<string, number>;\n /**\n * Set of relative paths to nested `package.json` files within this context.\n * These paths are normalized to use `/` as the separator and should not begin with a leading `./`.\n */\n dirInfoFiles?: string[];\n}\n\n/**\n * The serialized form of the cache file. This file is expected to be generated by a separate tool from\n * information known to the package manager. Namely, the dependency relationships between packages, and\n * all the `package.json` files in the workspace (installed or local).\n * @beta\n */\nexport interface IResolverCacheFile {\n /**\n * The base path. All paths in context entries are prefixed by this path.\n */\n basePath: string;\n /**\n * The ordered list of all contexts in the cache\n */\n contexts: ISerializedResolveContext[];\n}\n\n/**\n * A context for resolving dependencies in a workspace.\n * @beta\n */\nexport interface IResolveContext {\n /**\n * The absolute path to the root folder of this context\n */\n descriptionFileRoot: string;\n /**\n * Find the context that corresponds to a module specifier, when requested in the current context.\n * @param request - The module specifier to resolve\n */\n findDependency(request: string): IPrefixMatch<IResolveContext> | undefined;\n}\n\n/**\n * Options for creating a `WorkspaceLayoutCache`.\n * @beta\n */\nexport interface IWorkspaceLayoutCacheOptions {\n /**\n * The parsed cache data. File reading is left as an exercise for the caller.\n */\n cacheData: IResolverCacheFile;\n /**\n * The directory separator used in the `path` field of the resolver inputs.\n * Will usually be `path.sep`.\n */\n resolverPathSeparator?: '/' | '\\\\';\n}\n\n/**\n * A function that normalizes a path to a platform-specific format (if needed).\n * Will be undefined if the platform uses `/` as the path separator.\n *\n * @beta\n */\nexport type IPathNormalizationFunction = ((input: string) => string) | undefined;\n\nfunction backslashToSlash(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\nfunction slashToBackslash(path: string): string {\n return path.replace(/\\//g, '\\\\');\n}\n\n/**\n * A cache of workspace layout information.\n * @beta\n */\nexport class WorkspaceLayoutCache {\n /**\n * A lookup of context roots to their corresponding context objects\n */\n public readonly contextLookup: LookupByPath<IResolveContext>;\n /**\n * A weak map of package JSON contents to their corresponding context objects\n */\n public readonly contextForPackage: WeakMap<object, IPrefixMatch<IResolveContext>>;\n\n public readonly resolverPathSeparator: string;\n public readonly normalizeToSlash: IPathNormalizationFunction;\n public readonly normalizeToPlatform: IPathNormalizationFunction;\n\n public constructor(options: IWorkspaceLayoutCacheOptions) {\n const { cacheData, resolverPathSeparator = directorySeparator } = options;\n\n if (resolverPathSeparator !== '/' && resolverPathSeparator !== '\\\\') {\n throw new Error(`Unsupported directory separator: ${resolverPathSeparator}`);\n }\n\n const { basePath } = cacheData;\n const resolveContexts: ResolveContext[] = [];\n const contextLookup: LookupByPath<IResolveContext> = new LookupByPath(undefined, resolverPathSeparator);\n\n this.contextLookup = contextLookup;\n this.contextForPackage = new WeakMap<object, IPrefixMatch<IResolveContext>>();\n\n const normalizeToSlash: IPathNormalizationFunction =\n resolverPathSeparator === '\\\\' ? backslashToSlash : undefined;\n const normalizeToPlatform: IPathNormalizationFunction =\n resolverPathSeparator === '\\\\' ? slashToBackslash : undefined;\n\n this.resolverPathSeparator = resolverPathSeparator;\n this.normalizeToSlash = normalizeToSlash;\n this.normalizeToPlatform = normalizeToPlatform;\n\n // Internal class due to coupling to `resolveContexts`\n class ResolveContext implements IResolveContext {\n private readonly _serialized: ISerializedResolveContext;\n private _descriptionFileRoot: string | undefined;\n private _dependencies: LookupByPath<IResolveContext> | undefined;\n\n public constructor(serialized: ISerializedResolveContext) {\n this._serialized = serialized;\n this._descriptionFileRoot = undefined;\n this._dependencies = undefined;\n }\n\n public get descriptionFileRoot(): string {\n if (!this._descriptionFileRoot) {\n const merged: string = `${basePath}${this._serialized.root}`;\n this._descriptionFileRoot = normalizeToPlatform?.(merged) ?? merged;\n }\n return this._descriptionFileRoot;\n }\n\n public findDependency(request: string): IPrefixMatch<IResolveContext> | undefined {\n if (!this._dependencies) {\n // Lazy initialize this object since most packages won't be requested.\n const dependencies: LookupByPath<IResolveContext> = new LookupByPath(undefined, '/');\n\n const { name, deps } = this._serialized;\n\n // Handle the self-reference scenario\n dependencies.setItem(name, this);\n if (deps) {\n for (const [key, ordinal] of Object.entries(deps)) {\n // This calls into the array of instances that is owned by WorkpaceLayoutCache\n dependencies.setItem(key, resolveContexts[ordinal]);\n }\n }\n this._dependencies = dependencies;\n }\n\n return this._dependencies.findLongestPrefixMatch(request);\n }\n }\n\n for (const serialized of cacheData.contexts) {\n const resolveContext: ResolveContext = new ResolveContext(serialized);\n resolveContexts.push(resolveContext);\n\n contextLookup.setItemFromSegments(\n concat<string>(\n // All paths in the cache file are platform-agnostic\n LookupByPath.iteratePathSegments(basePath, '/'),\n LookupByPath.iteratePathSegments(serialized.root, '/')\n ),\n resolveContext\n );\n\n // Handle nested package.json files. These may modify some properties, but the dependency resolution\n // will match the original package root. Typically these are used to set the `type` field to `module`.\n if (serialized.dirInfoFiles) {\n for (const file of serialized.dirInfoFiles) {\n contextLookup.setItemFromSegments(\n concat<string>(\n // All paths in the cache file are platform-agnostic\n concat<string>(\n LookupByPath.iteratePathSegments(basePath, '/'),\n LookupByPath.iteratePathSegments(serialized.root, '/')\n ),\n LookupByPath.iteratePathSegments(file, '/')\n ),\n resolveContext\n );\n }\n }\n }\n }\n}\n\nfunction* concat<T>(a: Iterable<T>, b: Iterable<T>): IterableIterator<T> {\n yield* a;\n yield* b;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceResolvePlugin.d.ts","sourceRoot":"","sources":["../src/WorkspaceResolvePlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAInE;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,KAAK,EAAE,oBAAoB,CAAC;CAC7B;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAE3B,KAAK,EAAE,oBAAoB;IAIvC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"WorkspaceResolvePlugin.d.ts","sourceRoot":"","sources":["../src/WorkspaceResolvePlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAInE;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,KAAK,EAAE,oBAAoB,CAAC;CAC7B;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAE3B,KAAK,EAAE,oBAAoB;IAIvC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAuCvC"}
|
|
@@ -32,17 +32,17 @@ class WorkspaceResolvePlugin {
|
|
|
32
32
|
(_a = resolveOptions.plugins) !== null && _a !== void 0 ? _a : (resolveOptions.plugins = []);
|
|
33
33
|
resolveOptions.plugins.push(
|
|
34
34
|
// Optimize identifying the package.json file for the issuer
|
|
35
|
-
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'parsed-resolve', 'described-resolve'),
|
|
35
|
+
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'before-parsed-resolve', 'described-resolve'),
|
|
36
36
|
// Optimize locating the installed dependencies of the current package
|
|
37
|
-
new KnownPackageDependenciesPlugin_1.KnownPackageDependenciesPlugin(cache, 'raw-module', 'resolve-as-module'),
|
|
37
|
+
new KnownPackageDependenciesPlugin_1.KnownPackageDependenciesPlugin(cache, 'before-raw-module', 'resolve-as-module'),
|
|
38
38
|
// Optimize loading the package.json file for the destination package (bare specifier)
|
|
39
|
-
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'resolve-as-module', 'resolve-in-package'),
|
|
39
|
+
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'before-resolve-as-module', 'resolve-in-package'),
|
|
40
40
|
// Optimize loading the package.json file for the destination package (relative path)
|
|
41
|
-
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'relative', 'described-relative'),
|
|
41
|
+
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'before-relative', 'described-relative'),
|
|
42
42
|
// Optimize locating and loading nested package.json for a directory
|
|
43
|
-
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'undescribed-existing-directory', 'existing-directory', true),
|
|
43
|
+
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'before-undescribed-existing-directory', 'existing-directory', true),
|
|
44
44
|
// Optimize locating and loading nested package.json for a file
|
|
45
|
-
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'undescribed-raw-file', 'raw-file'));
|
|
45
|
+
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'before-undescribed-raw-file', 'raw-file'));
|
|
46
46
|
return resolveOptions;
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceResolvePlugin.js","sourceRoot":"","sources":["../src/WorkspaceResolvePlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAK3D,6EAA0E;AAC1E,qFAAkF;AAclF;;;;GAIG;AACH,MAAa,sBAAsB;IAGjC,YAAmB,KAA2B;QAC5C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAEM,KAAK,CAAC,QAAkB;QAC7B,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc;aAC1C,GAAG,CAAC,QAAQ,CAAC;aACb,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,cAAc,EAAE,EAAE;;YACnD,8BAA8B;YAC9B,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;gBAC3B,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,UAAkB,EAAE,EAAE;oBAC5E,OAAO,UAAU,KAAK,cAAc,CAAC;gBACvC,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,OAAO,GAAG,EAAE,CAAC;YAC9B,CAAC;YAED,MAAM,KAAK,GAAyB,IAAI,CAAC,MAAM,CAAC;YAEhD,MAAA,cAAc,CAAC,OAAO,oCAAtB,cAAc,CAAC,OAAO,GAAK,EAAE,EAAC;YAC9B,cAAc,CAAC,OAAO,CAAC,IAAI;YACzB,4DAA4D;YAC5D,IAAI,uDAA0B,C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EAAE,oBAAoB,CAAC;YAC9E,oEAAoE;YACpE,IAAI,uDAA0B,CAC5B,KAAK,EACL,uCAAuC,EACvC,oBAAoB,EACpB,IAAI,CACL;YACD,+DAA+D;YAC/D,IAAI,uDAA0B,CAAC,KAAK,EAAE,6BAA6B,EAAE,UAAU,CAAC,CACjF,CAAC;YAEF,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AA9CD,wDA8CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { WebpackPluginInstance, Compiler } from 'webpack';\n\nimport type { WorkspaceLayoutCache } from './WorkspaceLayoutCache';\nimport { KnownDescriptionFilePlugin } from './KnownDescriptionFilePlugin';\nimport { KnownPackageDependenciesPlugin } from './KnownPackageDependenciesPlugin';\n\n/**\n * Options for constructing a `WorkspaceResolvePlugin`.\n *\n * @beta\n */\nexport interface IWorkspaceResolvePluginOptions {\n /**\n * The cache of workspace layout information.\n */\n cache: WorkspaceLayoutCache;\n}\n\n/**\n * A Webpack plugin that optimizes package.json lookups and resolution of bare specifiers in a monorepo.\n *\n * @beta\n */\nexport class WorkspaceResolvePlugin implements WebpackPluginInstance {\n private readonly _cache: WorkspaceLayoutCache;\n\n public constructor(cache: WorkspaceLayoutCache) {\n this._cache = cache;\n }\n\n public apply(compiler: Compiler): void {\n compiler.resolverFactory.hooks.resolveOptions\n .for('normal')\n .tap(WorkspaceResolvePlugin.name, (resolveOptions) => {\n // Omit default `node_modules`\n if (resolveOptions.modules) {\n resolveOptions.modules = resolveOptions.modules.filter((modulePath: string) => {\n return modulePath !== 'node_modules';\n });\n } else {\n resolveOptions.modules = [];\n }\n\n const cache: WorkspaceLayoutCache = this._cache;\n\n resolveOptions.plugins ??= [];\n resolveOptions.plugins.push(\n // Optimize identifying the package.json file for the issuer\n new KnownDescriptionFilePlugin(cache, 'before-parsed-resolve', 'described-resolve'),\n // Optimize locating the installed dependencies of the current package\n new KnownPackageDependenciesPlugin(cache, 'before-raw-module', 'resolve-as-module'),\n // Optimize loading the package.json file for the destination package (bare specifier)\n new KnownDescriptionFilePlugin(cache, 'before-resolve-as-module', 'resolve-in-package'),\n // Optimize loading the package.json file for the destination package (relative path)\n new KnownDescriptionFilePlugin(cache, 'before-relative', 'described-relative'),\n // Optimize locating and loading nested package.json for a directory\n new KnownDescriptionFilePlugin(\n cache,\n 'before-undescribed-existing-directory',\n 'existing-directory',\n true\n ),\n // Optimize locating and loading nested package.json for a file\n new KnownDescriptionFilePlugin(cache, 'before-undescribed-raw-file', 'raw-file')\n );\n\n return resolveOptions;\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack-workspace-resolve-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"description": "This plugin leverages workspace-level metadata to greatly accelerate module resolution.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/webpack-workspace-resolve-plugin.d.ts",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"@types/node": "*"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rushstack/lookup-by-path": "0.
|
|
21
|
+
"@rushstack/lookup-by-path": "0.5.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"memfs": "4.12.0",
|
|
25
25
|
"webpack": "~5.95.0",
|
|
26
|
-
"@rushstack/heft": "0.68.
|
|
26
|
+
"@rushstack/heft": "0.68.12",
|
|
27
27
|
"local-node-rig": "1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"sideEffects": false,
|