| 99 | |
| 100 | // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging |
| 101 | export class ScopedTree implements Tree { |
| 102 | readonly _root: ScopedDirEntry; |
| 103 | |
| 104 | constructor( |
| 105 | private _base: Tree, |
| 106 | scope: string, |
| 107 | ) { |
| 108 | this[TreeSymbol] = () => this; |
| 109 | const normalizedScope = normalize('/' + scope); |
| 110 | this._root = new ScopedDirEntry(this._base.getDir(normalizedScope), normalizedScope); |
| 111 | } |
| 112 | |
| 113 | get root(): DirEntry { |
| 114 | return this._root; |
| 115 | } |
| 116 | |
| 117 | branch(): Tree { |
| 118 | return new ScopedTree(this._base.branch(), this._root.scope); |
| 119 | } |
| 120 | merge(other: Tree, strategy?: MergeStrategy): void { |
| 121 | // eslint-disable-next-line @typescript-eslint/no-this-alias |
| 122 | const self = this; |
| 123 | const delegate = new (class extends DelegateTree { |
| 124 | override get actions(): Action[] { |
| 125 | return other.actions.map((action) => self._fullPathAction(action)); |
| 126 | } |
| 127 | })(other); |
| 128 | |
| 129 | this._base.merge(delegate, strategy); |
| 130 | } |
| 131 | |
| 132 | // Readonly. |
| 133 | read(path: string): Buffer | null { |
| 134 | return this._base.read(this._fullPath(path)); |
| 135 | } |
| 136 | readText(path: string): string { |
| 137 | return this._base.readText(this._fullPath(path)); |
| 138 | } |
| 139 | readJson(path: string): JsonValue { |
| 140 | return this._base.readJson(this._fullPath(path)); |
| 141 | } |
| 142 | exists(path: string): boolean { |
| 143 | return this._base.exists(this._fullPath(path)); |
| 144 | } |
| 145 | get(path: string): FileEntry | null { |
| 146 | const entry = this._base.get(this._fullPath(path)); |
| 147 | |
| 148 | return entry && new ScopedFileEntry(entry, this._root.scope); |
| 149 | } |
| 150 | getDir(path: string): DirEntry { |
| 151 | const entry = this._base.getDir(this._fullPath(path)); |
| 152 | |
| 153 | return entry && new ScopedDirEntry(entry, this._root.scope); |
| 154 | } |
| 155 | visit(visitor: FileVisitor): void { |
| 156 | return this._root.visit(visitor); |
| 157 | } |
| 158 |
nothing calls this directly
no outgoing calls
no test coverage detected