1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { Path } from '../path';
|
---|
9 | import { ResolverHost } from './resolver';
|
---|
10 | /**
|
---|
11 | * A Virtual Host that allow to alias some paths to other paths.
|
---|
12 | *
|
---|
13 | * This does not verify, when setting an alias, that the target or source exist. Neither does it
|
---|
14 | * check whether it's a file or a directory. Please not that directories are also renamed/replaced.
|
---|
15 | *
|
---|
16 | * No recursion is done on the resolution, which means the following is perfectly valid then:
|
---|
17 | *
|
---|
18 | * ```
|
---|
19 | * host.aliases.set(normalize('/file/a'), normalize('/file/b'));
|
---|
20 | * host.aliases.set(normalize('/file/b'), normalize('/file/a'));
|
---|
21 | * ```
|
---|
22 | *
|
---|
23 | * This will result in a proper swap of two files for each others.
|
---|
24 | *
|
---|
25 | * @example
|
---|
26 | * const host = new SimpleMemoryHost();
|
---|
27 | * host.write(normalize('/some/file'), content).subscribe();
|
---|
28 | *
|
---|
29 | * const aHost = new AliasHost(host);
|
---|
30 | * aHost.read(normalize('/some/file'))
|
---|
31 | * .subscribe(x => expect(x).toBe(content));
|
---|
32 | * aHost.aliases.set(normalize('/some/file'), normalize('/other/path');
|
---|
33 | *
|
---|
34 | * // This file will not exist because /other/path does not exist.
|
---|
35 | * aHost.read(normalize('/some/file'))
|
---|
36 | * .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
|
---|
37 | *
|
---|
38 | * @example
|
---|
39 | * const host = new SimpleMemoryHost();
|
---|
40 | * host.write(normalize('/some/folder/file'), content).subscribe();
|
---|
41 | *
|
---|
42 | * const aHost = new AliasHost(host);
|
---|
43 | * aHost.read(normalize('/some/folder/file'))
|
---|
44 | * .subscribe(x => expect(x).toBe(content));
|
---|
45 | * aHost.aliases.set(normalize('/some'), normalize('/other');
|
---|
46 | *
|
---|
47 | * // This file will not exist because /other/path does not exist.
|
---|
48 | * aHost.read(normalize('/some/folder/file'))
|
---|
49 | * .subscribe(undefined, err => expect(err.message).toMatch(/does not exist/));
|
---|
50 | *
|
---|
51 | * // Create the file with new content and verify that this has the new content.
|
---|
52 | * aHost.write(normalize('/other/folder/file'), content2).subscribe();
|
---|
53 | * aHost.read(normalize('/some/folder/file'))
|
---|
54 | * .subscribe(x => expect(x).toBe(content2));
|
---|
55 | */
|
---|
56 | export declare class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
|
---|
57 | protected _aliases: Map<Path, Path>;
|
---|
58 | protected _resolve(path: Path): Path;
|
---|
59 | get aliases(): Map<Path, Path>;
|
---|
60 | }
|
---|