-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
hydrateRuntimeState.ts
66 lines (52 loc) Β· 2.58 KB
/
hydrateRuntimeState.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {PortablePath, npath, ppath} from '@yarnpkg/fslib';
import {PackageInformation, PackageLocator, PackageStore, RuntimeState, SerializedState} from '../types';
export type HydrateRuntimeStateOptions = {
basePath: string,
};
export function hydrateRuntimeState(data: SerializedState, {basePath}: HydrateRuntimeStateOptions): RuntimeState {
const portablePath = npath.toPortablePath(basePath);
const ignorePattern = data.ignorePatternData !== null
? new RegExp(data.ignorePatternData)
: null;
const packageRegistry = new Map(data.packageRegistryData.map(([packageName, packageStoreData]) => {
return [packageName, new Map(packageStoreData.map(([packageReference, packageInformationData]) => {
return [packageReference, {
packageLocation: ppath.resolve(portablePath, packageInformationData.packageLocation),
packageDependencies: new Map(packageInformationData.packageDependencies),
linkType: packageInformationData.linkType,
}] as [string | null, PackageInformation<PortablePath>];
}))] as [string | null, PackageStore];
}));
const packageLocatorsByLocations = new Map();
for (const [packageName, storeData] of data.packageRegistryData) {
for (const [packageReference, packageInformationData] of storeData) {
if ((packageName === null) !== (packageReference === null))
throw new Error(`Assertion failed: The name and reference should be null, or neither should`);
// @ts-ignore: TypeScript isn't smart enough to understand the type assertion
const packageLocator: PackageLocator = {name: packageName, reference: packageReference};
packageLocatorsByLocations.set(packageInformationData.packageLocation, packageLocator);
}
}
for (const location of data.locationBlacklistData)
packageLocatorsByLocations.set(location, null);
const fallbackExclusionList = new Map(data.fallbackExclusionList.map(([packageName, packageReferences]) => {
return [packageName, new Set(packageReferences)] as [string, Set<string>];
}));
const virtualRoots = data.virtualRoots.map(virtualRoot => {
return ppath.resolve(portablePath, virtualRoot);
});
const dependencyTreeRoots = data.dependencyTreeRoots;
const enableTopLevelFallback = data.enableTopLevelFallback;
const packageLocationLengths = data.locationLengthData;
return {
basePath: portablePath,
dependencyTreeRoots,
enableTopLevelFallback,
fallbackExclusionList,
ignorePattern,
packageLocationLengths,
packageLocatorsByLocations,
packageRegistry,
virtualRoots,
};
}