@rushstack/webpack-workspace-resolve-plugin 0.2.0 → 0.3.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/CHANGELOG.json +24 -0
- package/CHANGELOG.md +15 -1
- package/README.md +8 -0
- package/dist/webpack-workspace-resolve-plugin.d.ts +4 -4
- package/lib/WorkspaceLayoutCache.d.ts +4 -4
- package/lib/WorkspaceLayoutCache.d.ts.map +1 -1
- package/lib/WorkspaceLayoutCache.js +3 -2
- package/lib/WorkspaceLayoutCache.js.map +1 -1
- package/lib/WorkspaceResolvePlugin.d.ts.map +1 -1
- package/lib/WorkspaceResolvePlugin.js +3 -1
- package/lib/WorkspaceResolvePlugin.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack-workspace-resolve-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.1",
|
|
6
|
+
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.3.1",
|
|
7
|
+
"date": "Thu, 29 Aug 2024 00:11:32 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Fix description file resolution after cross-package import."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.3.0",
|
|
18
|
+
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.3.0",
|
|
19
|
+
"date": "Wed, 28 Aug 2024 00:11:41 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"minor": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Expect the base path to be part of the resolver cache file."
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
"version": "0.2.0",
|
|
6
30
|
"tag": "@rushstack/webpack-workspace-resolve-plugin_v0.2.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
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 Thu, 29 Aug 2024 00:11:32 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.1
|
|
6
|
+
Thu, 29 Aug 2024 00:11:32 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Fix description file resolution after cross-package import.
|
|
11
|
+
|
|
12
|
+
## 0.3.0
|
|
13
|
+
Wed, 28 Aug 2024 00:11:41 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Expect the base path to be part of the resolver cache file.
|
|
4
18
|
|
|
5
19
|
## 0.2.0
|
|
6
20
|
Tue, 27 Aug 2024 15:12:33 GMT
|
package/README.md
CHANGED
|
@@ -17,6 +17,14 @@ When using this plugin, the following options should be configured for your reso
|
|
|
17
17
|
- `symlinks: false` - Since the cache knows the symlinks for package dependencies, you can avoid the cost of testing for other symlinks unless you are using additional symlinks.
|
|
18
18
|
- `modules: []` - The cache should contain all information necessary to locate available dependencies for any arbitrary folder. If you need to allow resolution in other roots, you can add those, but omit `'node_modules'`.
|
|
19
19
|
|
|
20
|
+
## Impact
|
|
21
|
+
|
|
22
|
+
This plugin should eliminate file system calls associated with the following operations of NodeJS module resolution in webpack:
|
|
23
|
+
- Find the nearest `package.json` to the calling module
|
|
24
|
+
- Locate a named package from a calling module
|
|
25
|
+
- Identify a `package.json` in a resolved directory
|
|
26
|
+
- Find the nearest `package.json` to a resolved file path
|
|
27
|
+
|
|
20
28
|
## Limitations
|
|
21
29
|
|
|
22
30
|
This plugin depends on the presence of a cache file in the workspace to function. Data in this cache file is assumed not to change while the webpack process is running.
|
|
@@ -34,6 +34,10 @@ export declare interface IResolveContext {
|
|
|
34
34
|
* @beta
|
|
35
35
|
*/
|
|
36
36
|
export declare interface IResolverCacheFile {
|
|
37
|
+
/**
|
|
38
|
+
* The base path. All paths in context entries are prefixed by this path.
|
|
39
|
+
*/
|
|
40
|
+
basePath: string;
|
|
37
41
|
/**
|
|
38
42
|
* The ordered list of all contexts in the cache
|
|
39
43
|
*/
|
|
@@ -70,10 +74,6 @@ export declare interface ISerializedResolveContext {
|
|
|
70
74
|
* @beta
|
|
71
75
|
*/
|
|
72
76
|
export declare interface IWorkspaceLayoutCacheOptions {
|
|
73
|
-
/**
|
|
74
|
-
* The root folder of the workspace. All paths in the cache file are assumed to be relative to this folder.
|
|
75
|
-
*/
|
|
76
|
-
workspaceRoot: string;
|
|
77
77
|
/**
|
|
78
78
|
* The parsed cache data. File reading is left as an exercise for the caller.
|
|
79
79
|
*/
|
|
@@ -30,6 +30,10 @@ export interface ISerializedResolveContext {
|
|
|
30
30
|
* @beta
|
|
31
31
|
*/
|
|
32
32
|
export interface IResolverCacheFile {
|
|
33
|
+
/**
|
|
34
|
+
* The base path. All paths in context entries are prefixed by this path.
|
|
35
|
+
*/
|
|
36
|
+
basePath: string;
|
|
33
37
|
/**
|
|
34
38
|
* The ordered list of all contexts in the cache
|
|
35
39
|
*/
|
|
@@ -55,10 +59,6 @@ export interface IResolveContext {
|
|
|
55
59
|
* @beta
|
|
56
60
|
*/
|
|
57
61
|
export interface IWorkspaceLayoutCacheOptions {
|
|
58
|
-
/**
|
|
59
|
-
* The root folder of the workspace. All paths in the cache file are assumed to be relative to this folder.
|
|
60
|
-
*/
|
|
61
|
-
workspaceRoot: string;
|
|
62
62
|
/**
|
|
63
63
|
* The parsed cache data. File reading is left as an exercise for the caller.
|
|
64
64
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkspaceLayoutCache.d.ts","sourceRoot":"","sources":["../src/WorkspaceLayoutCache.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,K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G;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;CAC5E;AAED;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;IAC9B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;CACpC;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;AAUjF;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B;;OAEG;IACH,SAAgB,aAAa,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC;IAC7D;;OAEG;IACH,SAAgB,iBAAiB,EAAE,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;IAElF,SAAgB,qBAAqB,EAAE,MAAM,CAAC;IAC9C,SAAgB,gBAAgB,EAAE,0BAA0B,CAAC;IAC7D,SAAgB,mBAAmB,EAAE,0BAA0B,CAAC;gBAE7C,OAAO,EAAE,4BAA4B;CA0FzD"}
|
|
@@ -17,10 +17,11 @@ function slashToBackslash(path) {
|
|
|
17
17
|
*/
|
|
18
18
|
class WorkspaceLayoutCache {
|
|
19
19
|
constructor(options) {
|
|
20
|
-
const {
|
|
20
|
+
const { cacheData, resolverPathSeparator = node_path_1.sep } = options;
|
|
21
21
|
if (resolverPathSeparator !== '/' && resolverPathSeparator !== '\\') {
|
|
22
22
|
throw new Error(`Unsupported directory separator: ${resolverPathSeparator}`);
|
|
23
23
|
}
|
|
24
|
+
const { basePath } = cacheData;
|
|
24
25
|
const resolveContexts = [];
|
|
25
26
|
const contextLookup = new lookup_by_path_1.LookupByPath(undefined, resolverPathSeparator);
|
|
26
27
|
this.contextLookup = contextLookup;
|
|
@@ -40,7 +41,7 @@ class WorkspaceLayoutCache {
|
|
|
40
41
|
get descriptionFileRoot() {
|
|
41
42
|
var _a;
|
|
42
43
|
if (!this._descriptionFileRoot) {
|
|
43
|
-
this._descriptionFileRoot = `${
|
|
44
|
+
this._descriptionFileRoot = `${basePath}${(_a = normalizeToPlatform === null || normalizeToPlatform === void 0 ? void 0 : normalizeToPlatform(this._serialized.root)) !== null && _a !== void 0 ? _a : this._serialized.root}`;
|
|
44
45
|
}
|
|
45
46
|
return this._descriptionFileRoot;
|
|
46
47
|
}
|
|
@@ -1 +1 @@
|
|
|
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,aAAa,EAAE,SAAS,EAAE,qBAAqB,GAAG,eAAkB,EAAE,GAAG,OAAO,CAAC;QAEzF,IAAI,qBAAqB,KAAK,GAAG,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,oCAAoC,qBAAqB,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,eAAe,GAAqB,EAAE,CAAC;QAC7C,MAAM,aAAa,GAAkC,IAAI,6BAAY,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;QAExG,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CA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AAC,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 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 root folder of the workspace. All paths in the cache file are assumed to be relative to this folder.\n */\n workspaceRoot: string;\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 { workspaceRoot, cacheData, resolverPathSeparator = directorySeparator } = options;\n\n if (resolverPathSeparator !== '/' && resolverPathSeparator !== '\\\\') {\n throw new Error(`Unsupported directory separator: ${resolverPathSeparator}`);\n }\n\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 = `${workspaceRoot}${resolverPathSeparator}${\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,gBA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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 +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;CAkCvC"}
|
|
@@ -35,7 +35,9 @@ class WorkspaceResolvePlugin {
|
|
|
35
35
|
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'parsed-resolve', 'described-resolve'),
|
|
36
36
|
// Optimize locating the installed dependencies of the current package
|
|
37
37
|
new KnownPackageDependenciesPlugin_1.KnownPackageDependenciesPlugin(cache, 'raw-module', 'resolve-as-module'),
|
|
38
|
-
// Optimize loading the package.json file for the destination package
|
|
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'),
|
|
40
|
+
// Optimize loading the package.json file for the destination package (relative path)
|
|
39
41
|
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'relative', 'described-relative'),
|
|
40
42
|
// Optimize locating and loading nested package.json for a directory
|
|
41
43
|
new KnownDescriptionFilePlugin_1.KnownDescriptionFilePlugin(cache, 'undescribed-existing-directory', 'existing-directory', true),
|
|
@@ -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,Q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E;;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,CAAC,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,CAAC;YAC5E,sEAAsE;YACtE,IAAI,+DAA8B,CAAC,KAAK,EAAE,YAAY,EAAE,mBAAmB,CAAC;YAC5E,sFAAsF;YACtF,IAAI,uDAA0B,CAAC,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,CAAC;YAChF,qFAAqF;YACrF,IAAI,uDAA0B,CAAC,KAAK,EAAE,UAAU,EAAE,oBAAoB,CAAC;YACvE,oEAAoE;YACpE,IAAI,uDAA0B,CAAC,KAAK,EAAE,gCAAgC,EAAE,oBAAoB,EAAE,IAAI,CAAC;YACnG,+DAA+D;YAC/D,IAAI,uDAA0B,CAAC,KAAK,EAAE,sBAAsB,EAAE,UAAU,CAAC,CAC1E,CAAC;YAEF,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAzCD,wDAyCC","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, 'parsed-resolve', 'described-resolve'),\n // Optimize locating the installed dependencies of the current package\n new KnownPackageDependenciesPlugin(cache, 'raw-module', 'resolve-as-module'),\n // Optimize loading the package.json file for the destination package (bare specifier)\n new KnownDescriptionFilePlugin(cache, 'resolve-as-module', 'resolve-in-package'),\n // Optimize loading the package.json file for the destination package (relative path)\n new KnownDescriptionFilePlugin(cache, 'relative', 'described-relative'),\n // Optimize locating and loading nested package.json for a directory\n new KnownDescriptionFilePlugin(cache, 'undescribed-existing-directory', 'existing-directory', true),\n // Optimize locating and loading nested package.json for a file\n new KnownDescriptionFilePlugin(cache, '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
|
+
"version": "0.3.1",
|
|
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",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"memfs": "3.4.3",
|
|
25
25
|
"webpack": "~5.82.1",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"local-node-rig": "1.0.0",
|
|
27
|
+
"@rushstack/heft": "0.67.0"
|
|
28
28
|
},
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"peerDependenciesMeta": {
|