Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: remove leftovers from when virtuals were symlinks #2524

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions .yarn/versions/8773ddfe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
releases:
"@yarnpkg/core": major
"@yarnpkg/plugin-pnp": major
"@yarnpkg/pnp": major

declined:
- "@yarnpkg/esbuild-plugin-pnp"
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/cli"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ const mte = generatePkgDriver({
[`YARN_ENABLE_TELEMETRY`]: `0`,
// Otherwise snapshots relying on this would break each time it's bumped
[`YARN_CACHE_KEY_OVERRIDE`]: `0`,
// Otherwise the tests would break when C:\tmp is on a different drive than the repo
[`YARN_ENABLE_ABSOLUTE_VIRTUALS`]: `true`,
// Otherwise the output isn't stable between runs
[`YARN_ENABLE_TIMERS`]: `false`,
[`YARN_ENABLE_PROGRESS_BARS`]: `false`,
Expand Down
6 changes: 0 additions & 6 deletions packages/gatsby/static/configuration/yarnrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@
"format": "uri-reference",
"default": "./.yarn/versions"
},
"enableAbsoluteVirtuals": {
"_package": "@yarnpkg/core",
"description": "If true, the virtual symlinks will use absolute (non-portable!) paths if required.",
"type": "boolean",
"default": false
},
"enableColors": {
"_package": "@yarnpkg/core",
"description": "If true (by default detects terminal capabilities), Yarn will format its pretty-print its output by using colors to differentiate important parts of its messages.",
Expand Down
4 changes: 0 additions & 4 deletions packages/plugin-pnp/sources/PnpLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ export class PnpInstaller implements Installer {


async finalizeInstall() {
const blacklistedPaths = new Set<PortablePath>();

for (const {locator, location} of this.virtualTemplates.values()) {
miscUtils.getMapWithDefault(this.packageRegistry, structUtils.stringifyIdent(locator)).set(locator.reference, {
packageLocation: location,
Expand All @@ -222,7 +220,6 @@ export class PnpInstaller implements Installer {

const pnpFallbackMode = this.opts.project.configuration.get(`pnpFallbackMode`);

const blacklistedLocations = blacklistedPaths;
const dependencyTreeRoots = this.opts.project.workspaces.map(({anchoredLocator}) => ({name: structUtils.stringifyIdent(anchoredLocator), reference: anchoredLocator.reference}));
const enableTopLevelFallback = pnpFallbackMode !== `none`;
const fallbackExclusionList = [];
Expand All @@ -237,7 +234,6 @@ export class PnpInstaller implements Installer {
fallbackExclusionList.push({name: structUtils.stringifyIdent(pkg), reference: pkg.reference});

await this.finalizeInstallWithPnp({
blacklistedLocations,
dependencyTreeRoots,
enableTopLevelFallback,
fallbackExclusionList,
Expand Down
6 changes: 0 additions & 6 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
type: SettingsType.BOOLEAN,
default: false,
},
enableAbsoluteVirtuals: {
description: `If true, the virtual symlinks will use absolute paths if required [non portable!!]`,
type: SettingsType.BOOLEAN,
default: false,
},

// Settings related to the output style
enableColors: {
Expand Down Expand Up @@ -501,7 +496,6 @@ export interface ConfigurationValueMap {
immutablePatterns: Array<string>;
rcFilename: Filename;
enableGlobalCache: boolean;
enableAbsoluteVirtuals: boolean;

enableColors: boolean;
enableHyperlinks: boolean;
Expand Down
7 changes: 1 addition & 6 deletions packages/yarnpkg-pnp/sources/generateSerializedState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LocationBlacklistData, PackageRegistryData} from './types';
import {PackageRegistryData} from './types';
import {PackageStoreData, PnpSettings, SerializedState} from './types';

// Keep this function is sync with its implementation in:
Expand Down Expand Up @@ -96,10 +96,6 @@ function generatePackageRegistryData(settings: PnpSettings): PackageRegistryData
return packageRegistryData;
}

function generateLocationBlacklistData(settings: PnpSettings): LocationBlacklistData {
return sortMap(settings.blacklistedLocations || [], location => location);
}

export function generateSerializedState(settings: PnpSettings): SerializedState {
return {
// @eslint-ignore-next-line @typescript-eslint/naming-convention
Expand All @@ -116,7 +112,6 @@ export function generateSerializedState(settings: PnpSettings): SerializedState

fallbackExclusionList: generateFallbackExclusionList(settings),
fallbackPool: generateFallbackPoolData(settings),
locationBlacklistData: generateLocationBlacklistData(settings),
packageRegistryData: generatePackageRegistryData(settings),
};
}
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function hydrateRuntimeState(data: SerializedState, {basePath}: HydrateRu
? new RegExp(data.ignorePatternData)
: null;

const packageLocatorsByLocations = new Map<PortablePath, {locator: PhysicalPackageLocator, discardFromLookup: boolean} | null>();
const packageLocatorsByLocations = new Map<PortablePath, {locator: PhysicalPackageLocator, discardFromLookup: boolean}>();
const packageLocationLengths = new Set<number>();

const packageRegistry = new Map<string | null, PackageStore>(data.packageRegistryData.map(([packageName, packageStoreData]) => {
Expand Down Expand Up @@ -57,9 +57,6 @@ export function hydrateRuntimeState(data: SerializedState, {basePath}: HydrateRu
}))];
}));

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>];
}));
Expand Down
2 changes: 0 additions & 2 deletions packages/yarnpkg-pnp/sources/loader/internalTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Path, npath} from '@yarnpkg/fslib';

export enum ErrorCode {
API_ERROR = `API_ERROR`,
BLACKLISTED = `BLACKLISTED`,
BUILTIN_NODE_RESOLUTION_FAILED = `BUILTIN_NODE_RESOLUTION_FAILED`,
MISSING_DEPENDENCY = `MISSING_DEPENDENCY`,
MISSING_PEER_DEPENDENCY = `MISSING_PEER_DEPENDENCY`,
Expand All @@ -15,7 +14,6 @@ export enum ErrorCode {
// Some errors are exposed as MODULE_NOT_FOUND for compatibility with packages
// that expect this umbrella error when the resolution fails
const MODULE_NOT_FOUND_ERRORS = new Set([
ErrorCode.BLACKLISTED,
ErrorCode.BUILTIN_NODE_RESOLUTION_FAILED,
ErrorCode.MISSING_DEPENDENCY,
ErrorCode.MISSING_PEER_DEPENDENCY,
Expand Down
38 changes: 5 additions & 33 deletions packages/yarnpkg-pnp/sources/loader/makeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,38 +505,13 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp

for (let t = from; t < packageLocationLengths.length; ++t) {
const entry = packageLocatorsByLocations.get(relativeLocation.substr(0, packageLocationLengths[t]) as PortablePath);
if (typeof entry === `undefined`)
continue;

// Ensures that the returned locator isn't a blacklisted one.
//
// Blacklisted packages are packages that cannot be used because their dependencies cannot be deduced. This only
// happens with peer dependencies, which effectively have different sets of dependencies depending on their
// parents.
//
// In order to deambiguate those different sets of dependencies, the Yarn implementation of PnP will generate a
// symlink for each combination of <package name>/<package version>/<dependent package> it will find, and will
// blacklist the target of those symlinks. By doing this, we ensure that files loaded through a specific path
// will always have the same set of dependencies, provided the symlinks are correctly preserved.
//
// Unfortunately, some tools do not preserve them, and when it happens PnP isn't able anymore to deduce the set of
// dependencies based on the path of the file that makes the require calls. But since we've blacklisted those
// paths, we're able to print a more helpful error message that points out that a third-party package is doing
// something incompatible!

if (entry === null) {
const locationForDisplay = getPathForDisplay(location);
throw makeError(
ErrorCode.BLACKLISTED,
`A forbidden path has been used in the package resolution process - this is usually caused by one of your tools calling 'fs.realpath' on the return value of 'require.resolve'. Since we need to use symlinks to simultaneously provide valid filesystem paths and disambiguate peer dependencies, they must be passed untransformed to 'require'.\n\nForbidden path: ${locationForDisplay}`,
{location: locationForDisplay},
);
}

if (entry.discardFromLookup && !includeDiscardFromLookup)
continue;
if (typeof entry !== `undefined`) {
if (entry.discardFromLookup && !includeDiscardFromLookup)
continue;

return entry.locator;
return entry.locator;
}
}

return null;
Expand Down Expand Up @@ -622,9 +597,6 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
unqualifiedPath = ppath.normalize(ppath.join(ppath.dirname(absoluteIssuer), request));
}
}

// No need to use the return value; we just want to check the blacklist status
findPackageLocator(unqualifiedPath);
} else {
// Things are more hairy if it's a package require - we then need to figure out which package is needed, and in
// particular the exact version for the given location on the dependency tree
Expand Down
8 changes: 1 addition & 7 deletions packages/yarnpkg-pnp/sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export type PackageStoreData = Array<[string | null, PackageInformationData<Port
export type PackageRegistry = Map<string | null, PackageStore>;
export type PackageRegistryData = Array<[string | null, PackageStoreData]>;

export type LocationBlacklistData = Array<PortablePath>;
export type LocationLengthData = Array<number>;

// This is what is stored within the .pnp.meta.json file
Expand All @@ -43,7 +42,6 @@ export type SerializedState = {
fallbackExclusionList: Array<[string, Array<string>]>,
fallbackPool: Array<[string, DependencyTarget]>,
ignorePatternData: string | null,
locationBlacklistData: LocationBlacklistData,
packageRegistryData: PackageRegistryData,
dependencyTreeRoots: Array<PhysicalPackageLocator>,
};
Expand All @@ -56,17 +54,13 @@ export type RuntimeState = {
fallbackPool: Map<string, DependencyTarget>,
ignorePattern: RegExp | null,
packageLocationLengths: Array<number>,
packageLocatorsByLocations: Map<PortablePath, {locator: PhysicalPackageLocator, discardFromLookup: boolean} | null>;
packageLocatorsByLocations: Map<PortablePath, {locator: PhysicalPackageLocator, discardFromLookup: boolean}>;
packageRegistry: PackageRegistry,
dependencyTreeRoots: Array<PhysicalPackageLocator>,
};

// This is what the generation functions take as parameter
export type PnpSettings = {
// Some locations that are not allowed to make a require call, period
// (usually the realpath of virtual packages)
blacklistedLocations?: Iterable<PortablePath>,

merceyz marked this conversation as resolved.
Show resolved Hide resolved
// Whether the top-level dependencies should be made available to all the
// dependency tree as a fallback (default is true)
enableTopLevelFallback?: boolean,
Expand Down