Skip to content

Commit

Permalink
Enhance LookupByPath, Fix win32 paths in webpack-workspace-resolve-pl…
Browse files Browse the repository at this point in the history
…ugin (#5050)

* [lookup-by-path] Add size,entries,get,has,removeItem
Add more support for delimiter overrides per method.
Exclude `undefined` and `null` from allowed values to type parameter <TItem>

* [workspace-resolve] Fix win32 path formatting.
Also tap hooks earlier to avoid sequencing issues.

---------

Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
  • Loading branch information
dmichon-msft and dmichon-msft authored Dec 18, 2024
1 parent fc48c64 commit 970b221
Show file tree
Hide file tree
Showing 9 changed files with 642 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/lookup-by-path",
"comment": "Update all methods to accept optional override delimiters. Add `size`, `entries(), `get()`, `has()`, `removeItem()`. Make class iterable.\nExplicitly exclude `undefined` and `null` from the allowed types for the type parameter `TItem`.",
"type": "minor"
}
],
"packageName": "@rushstack/lookup-by-path"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/webpack-workspace-resolve-plugin",
"comment": "Fix a bug with path handling on Windows. Tap hooks earlier to ensure that these plugins run before builtin behavior.",
"type": "patch"
}
],
"packageName": "@rushstack/webpack-workspace-resolve-plugin"
}
32 changes: 22 additions & 10 deletions common/reviews/api/lookup-by-path.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,43 @@
```ts

// @beta
export interface IPrefixMatch<TItem> {
export interface IPrefixMatch<TItem extends {}> {
index: number;
lastMatch?: IPrefixMatch<TItem>;
value: TItem;
}

// @beta
export interface IReadonlyLookupByPath<TItem> {
findChildPath(childPath: string): TItem | undefined;
export interface IReadonlyLookupByPath<TItem extends {}> extends Iterable<[string, TItem]> {
[Symbol.iterator](query?: string, delimiter?: string): IterableIterator<[string, TItem]>;
entries(query?: string, delimiter?: string): IterableIterator<[string, TItem]>;
findChildPath(childPath: string, delimiter?: string): TItem | undefined;
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;
findLongestPrefixMatch(query: string, delimiter?: string): IPrefixMatch<TItem> | undefined;
get(query: string, delimiter?: string): TItem | undefined;
groupByChild<TInfo>(infoByPath: Map<string, TInfo>, delimiter?: string): Map<TItem, Map<string, TInfo>>;
has(query: string, delimiter?: string): boolean;
get size(): number;
}

// @beta
export class LookupByPath<TItem> implements IReadonlyLookupByPath<TItem> {
export class LookupByPath<TItem extends {}> implements IReadonlyLookupByPath<TItem> {
[Symbol.iterator](query?: string, delimiter?: string): IterableIterator<[string, TItem]>;
constructor(entries?: Iterable<[string, TItem]>, delimiter?: string);
clear(): this;
deleteItem(query: string, delimeter?: string): boolean;
readonly delimiter: string;
findChildPath(childPath: string): TItem | undefined;
entries(query?: string, delimiter?: string): IterableIterator<[string, TItem]>;
findChildPath(childPath: string, delimiter?: string): TItem | undefined;
findChildPathFromSegments(childPathSegments: Iterable<string>): TItem | undefined;
findLongestPrefixMatch(query: string): IPrefixMatch<TItem> | undefined;
groupByChild<TInfo>(infoByPath: Map<string, TInfo>): Map<TItem, Map<string, TInfo>>;
findLongestPrefixMatch(query: string, delimiter?: string): IPrefixMatch<TItem> | undefined;
get(key: string, delimiter?: string): TItem | undefined;
groupByChild<TInfo>(infoByPath: Map<string, TInfo>, delimiter?: string): Map<TItem, Map<string, TInfo>>;
has(key: string, delimiter?: string): boolean;
static iteratePathSegments(serializedPath: string, delimiter?: string): Iterable<string>;
setItem(serializedPath: string, value: TItem): this;
setItem(serializedPath: string, value: TItem, delimiter?: string): this;
setItemFromSegments(pathSegments: Iterable<string>, value: TItem): this;
get size(): number;
}

```
Loading

0 comments on commit 970b221

Please sign in to comment.