forked from yarnpkg/berry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maël Nison
committed
Feb 18, 2019
1 parent
5dc5bee
commit 96f1608
Showing
13 changed files
with
29,595 additions
and
13,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {miscUtils} from '@berry/core'; | ||
|
||
import {LocationBlacklistData, LocationLengthData, PackageRegistryData} from './types'; | ||
import {PackageStoreData, PnpSettings, SerializedState} from './types'; | ||
|
||
function generatePackageRegistryData(settings: PnpSettings): PackageRegistryData { | ||
const packageRegistryData: PackageRegistryData = []; | ||
|
||
for (const [packageName, packageStore] of miscUtils.sortMap(settings.packageRegistry, ([packageName]) => packageName === null ? `0` : `1${packageName}`)) { | ||
const packageStoreData: PackageStoreData = []; | ||
packageRegistryData.push([packageName, packageStoreData]); | ||
|
||
for (const [packageReference, {packageLocation, packageDependencies}] of miscUtils.sortMap(packageStore, ([packageReference]) => packageReference === null ? `0` : `1${packageReference}`)) { | ||
const normalizedDependencies: Array<[string, string]> = []; | ||
|
||
if (packageName !== null && packageReference !== null && !packageDependencies.has(packageName)) | ||
normalizedDependencies.push([packageName, packageReference]); | ||
|
||
for (const [dependencyName, dependencyReference] of miscUtils.sortMap(packageDependencies.entries(), ([dependencyName]) => dependencyName)) | ||
normalizedDependencies.push([dependencyName, dependencyReference]); | ||
|
||
packageStoreData.push([packageReference, { | ||
packageLocation, | ||
packageDependencies: normalizedDependencies, | ||
}]); | ||
} | ||
} | ||
|
||
return packageRegistryData; | ||
} | ||
|
||
function generateLocationBlacklistData(settings: PnpSettings): LocationBlacklistData { | ||
return miscUtils.sortMap(settings.blacklistedLocations || [], location => location); | ||
} | ||
|
||
function generateLocationLengthData(settings: PnpSettings): LocationLengthData { | ||
const lengths = new Set(); | ||
|
||
for (const packageInformationStore of settings.packageRegistry.values()) | ||
for (const {packageLocation} of packageInformationStore.values()) | ||
if (packageLocation !== null) | ||
lengths.add(packageLocation.length); | ||
|
||
return Array.from(lengths).sort((a, b) => b - a); | ||
} | ||
|
||
export function generateSerializedState(settings: PnpSettings): SerializedState { | ||
const data: any = {}; | ||
|
||
data.__info = [ | ||
`This file is automatically generated. Do not touch it, or risk`, | ||
`your modifications being lost. We also recommend you not to read`, | ||
`it either without using the @berry/pnp package, as the data layout`, | ||
`is entirely unspecified and WILL change from a version to another.`, | ||
]; | ||
|
||
data.packageRegistryData = generatePackageRegistryData(settings); | ||
data.locationBlacklistData = generateLocationBlacklistData(settings); | ||
data.locationLengthData = generateLocationLengthData(settings); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {readFile} from 'fs'; | ||
import {dirname} from 'path'; | ||
import {promisify} from 'util'; | ||
|
||
import {hydrateRuntimeState} from './loader/hydrateRuntimeState'; | ||
import {makeApi} from './loader/makeApi'; | ||
import {SerializedState} from './types'; | ||
|
||
const readFileP = promisify(readFile); | ||
|
||
export async function hydratePnpFile(location: string, {pnpapiResolution}: {pnpapiResolution: string}) { | ||
const source = await readFileP(location, `utf8`); | ||
|
||
return hydratePnpSource(source, { | ||
basePath: dirname(location), | ||
pnpapiResolution, | ||
}); | ||
} | ||
|
||
export function hydratePnpSource(source: string, {basePath, pnpapiResolution}: {basePath: string, pnpapiResolution: string}) { | ||
const data = JSON.parse(source) as SerializedState; | ||
|
||
const runtimeState = hydrateRuntimeState(data, { | ||
basePath, | ||
}); | ||
|
||
return makeApi(runtimeState, { | ||
compatibilityMode: true, | ||
pnpapiResolution, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './types'; | ||
export * from './generatePnpScript'; | ||
export * from './hydratePnpApi'; |
18 changes: 9 additions & 9 deletions
18
...es/berry-pnp/sources/loader/entryPoint.ts → ...s/berry-pnp/sources/loader/_entryPoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.