diff --git a/.yarn/versions/4df7cbc6.yml b/.yarn/versions/4df7cbc6.yml new file mode 100644 index 000000000000..c2df7e33f131 --- /dev/null +++ b/.yarn/versions/4df7cbc6.yml @@ -0,0 +1,6 @@ +releases: + "@yarnpkg/plugin-link": major + +declined: + - "@yarnpkg/cli" + - "@yarnpkg/core" diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d6638970b4c..a987c40e59fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,10 @@ The following changes only affect people writing Yarn plugins: - `versionUtils.{fetchBase,fetchRoot,fetchChangedFiles}` have been moved from `@yarnpkg/plugin-version` to `@yarnpkg/plugin-git`. Use `gitUtils.{fetchBase,fetchRoot,fetchChangedFiles}` instead. +- For consistency reasons: + - `Link{Resolver,Fetcher}` have been renamed to `Portal{Resolver,Fetcher}` + - `RawLink{Resolver,Fetcher}` have been renamed to `Link{Resolver,Fetcher}` + ### Installs - The `pnpm` linker avoids creating symlinks that lead to loops on the file system, by moving them higher up in the directory structure. diff --git a/packages/plugin-link/sources/LinkFetcher.ts b/packages/plugin-link/sources/LinkFetcher.ts index 29e71acee0bd..c44cd16f72f2 100644 --- a/packages/plugin-link/sources/LinkFetcher.ts +++ b/packages/plugin-link/sources/LinkFetcher.ts @@ -52,9 +52,9 @@ export class LinkFetcher implements Fetcher { ); if (parentFetch.localPath) { - return {packageFs: new CwdFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, localPath: sourcePath}; + return {packageFs: new CwdFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, discardFromLookup: true, localPath: sourcePath}; } else { - return {packageFs: new JailFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot}; + return {packageFs: new JailFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, discardFromLookup: true}; } } } diff --git a/packages/plugin-link/sources/LinkResolver.ts b/packages/plugin-link/sources/LinkResolver.ts index a7d5eeb6dd67..ffce1f022394 100644 --- a/packages/plugin-link/sources/LinkResolver.ts +++ b/packages/plugin-link/sources/LinkResolver.ts @@ -1,10 +1,10 @@ -import {Resolver, ResolveOptions, MinimalResolveOptions} from '@yarnpkg/core'; -import {Descriptor, Locator, Manifest, Package} from '@yarnpkg/core'; -import {LinkType} from '@yarnpkg/core'; -import {miscUtils, structUtils} from '@yarnpkg/core'; -import {npath} from '@yarnpkg/fslib'; +import {Resolver, ResolveOptions, MinimalResolveOptions, Package} from '@yarnpkg/core'; +import {Descriptor, Locator} from '@yarnpkg/core'; +import {LinkType} from '@yarnpkg/core'; +import {structUtils} from '@yarnpkg/core'; +import {npath} from '@yarnpkg/fslib'; -import {LINK_PROTOCOL} from './constants'; +import {LINK_PROTOCOL} from './constants'; export class LinkResolver implements Resolver { supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) { @@ -50,33 +50,24 @@ export class LinkResolver implements Resolver { }; } - async resolve(locator: Locator, opts: ResolveOptions): Promise { - if (!opts.fetchOptions) - throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`); - - const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions); - - const manifest = await miscUtils.releaseAfterUseAsync(async () => { - return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs}); - }, packageFetch.releaseFs); - + async resolve(locator: Locator, opts: ResolveOptions) { return { ...locator, - version: manifest.version || `0.0.0`, + version: `0.0.0`, - languageName: manifest.languageName || opts.project.configuration.get(`defaultLanguageName`), + languageName: opts.project.configuration.get(`defaultLanguageName`), linkType: LinkType.SOFT, - conditions: manifest.getConditions(), + conditions: null, - dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies), - peerDependencies: manifest.peerDependencies, + dependencies: new Map(), + peerDependencies: new Map(), - dependenciesMeta: manifest.dependenciesMeta, - peerDependenciesMeta: manifest.peerDependenciesMeta, + dependenciesMeta: new Map(), + peerDependenciesMeta: new Map(), - bin: manifest.bin, + bin: new Map(), }; } } diff --git a/packages/plugin-link/sources/RawLinkFetcher.ts b/packages/plugin-link/sources/PortalFetcher.ts similarity index 83% rename from packages/plugin-link/sources/RawLinkFetcher.ts rename to packages/plugin-link/sources/PortalFetcher.ts index ef9db46a30be..3fec70c52767 100644 --- a/packages/plugin-link/sources/RawLinkFetcher.ts +++ b/packages/plugin-link/sources/PortalFetcher.ts @@ -3,18 +3,18 @@ import {Locator} from '@yarnpkg/ import {structUtils} from '@yarnpkg/core'; import {CwdFS, JailFS, ppath, PortablePath} from '@yarnpkg/fslib'; -import {RAW_LINK_PROTOCOL} from './constants'; +import {PORTAL_PROTOCOL} from './constants'; -export class RawLinkFetcher implements Fetcher { +export class PortalFetcher implements Fetcher { supports(locator: Locator, opts: MinimalFetchOptions) { - if (!locator.reference.startsWith(RAW_LINK_PROTOCOL)) + if (!locator.reference.startsWith(PORTAL_PROTOCOL)) return false; return true; } getLocalPath(locator: Locator, opts: FetchOptions) { - const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: RAW_LINK_PROTOCOL}); + const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PORTAL_PROTOCOL}); if (ppath.isAbsolute(path)) return path; @@ -26,9 +26,9 @@ export class RawLinkFetcher implements Fetcher { } async fetch(locator: Locator, opts: FetchOptions) { - const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: RAW_LINK_PROTOCOL}); + const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PORTAL_PROTOCOL}); - // If the link target is an absolute path we can directly access it via its + // If the portal target is an absolute path we can directly access it via its // location on the disk. Otherwise we must go through the package fs. const parentFetch: FetchResult = ppath.isAbsolute(path) ? {packageFs: new CwdFS(PortablePath.root), prefixPath: PortablePath.dot, localPath: PortablePath.root} @@ -52,9 +52,9 @@ export class RawLinkFetcher implements Fetcher { ); if (parentFetch.localPath) { - return {packageFs: new CwdFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, discardFromLookup: true, localPath: sourcePath}; + return {packageFs: new CwdFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, localPath: sourcePath}; } else { - return {packageFs: new JailFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot, discardFromLookup: true}; + return {packageFs: new JailFS(sourcePath, {baseFs: sourceFs}), releaseFs: effectiveParentFetch.releaseFs, prefixPath: PortablePath.dot}; } } } diff --git a/packages/plugin-link/sources/PortalResolver.ts b/packages/plugin-link/sources/PortalResolver.ts new file mode 100644 index 000000000000..b84dec48089e --- /dev/null +++ b/packages/plugin-link/sources/PortalResolver.ts @@ -0,0 +1,82 @@ +import {Resolver, ResolveOptions, MinimalResolveOptions} from '@yarnpkg/core'; +import {Descriptor, Locator, Manifest, Package} from '@yarnpkg/core'; +import {LinkType} from '@yarnpkg/core'; +import {miscUtils, structUtils} from '@yarnpkg/core'; +import {npath} from '@yarnpkg/fslib'; + +import {PORTAL_PROTOCOL} from './constants'; + +export class PortalResolver implements Resolver { + supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) { + if (!descriptor.range.startsWith(PORTAL_PROTOCOL)) + return false; + + return true; + } + + supportsLocator(locator: Locator, opts: MinimalResolveOptions) { + if (!locator.reference.startsWith(PORTAL_PROTOCOL)) + return false; + + return true; + } + + shouldPersistResolution(locator: Locator, opts: MinimalResolveOptions) { + return false; + } + + bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) { + return structUtils.bindDescriptor(descriptor, { + locator: structUtils.stringifyLocator(fromLocator), + }); + } + + getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) { + return {}; + } + + async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) { + const path = descriptor.range.slice(PORTAL_PROTOCOL.length); + + return [structUtils.makeLocator(descriptor, `${PORTAL_PROTOCOL}${npath.toPortablePath(path)}`)]; + } + + async getSatisfying(descriptor: Descriptor, dependencies: Record, locators: Array, opts: ResolveOptions) { + const [locator] = await this.getCandidates(descriptor, dependencies, opts); + + return { + locators: locators.filter(candidate => candidate.locatorHash === locator.locatorHash), + sorted: false, + }; + } + + async resolve(locator: Locator, opts: ResolveOptions): Promise { + if (!opts.fetchOptions) + throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`); + + const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions); + + const manifest = await miscUtils.releaseAfterUseAsync(async () => { + return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs}); + }, packageFetch.releaseFs); + + return { + ...locator, + + version: manifest.version || `0.0.0`, + + languageName: manifest.languageName || opts.project.configuration.get(`defaultLanguageName`), + linkType: LinkType.SOFT, + + conditions: manifest.getConditions(), + + dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies), + peerDependencies: manifest.peerDependencies, + + dependenciesMeta: manifest.dependenciesMeta, + peerDependenciesMeta: manifest.peerDependenciesMeta, + + bin: manifest.bin, + }; + } +} diff --git a/packages/plugin-link/sources/RawLinkResolver.ts b/packages/plugin-link/sources/RawLinkResolver.ts deleted file mode 100644 index 972dcf4a97fa..000000000000 --- a/packages/plugin-link/sources/RawLinkResolver.ts +++ /dev/null @@ -1,73 +0,0 @@ -import {Resolver, ResolveOptions, MinimalResolveOptions, Package} from '@yarnpkg/core'; -import {Descriptor, Locator} from '@yarnpkg/core'; -import {LinkType} from '@yarnpkg/core'; -import {structUtils} from '@yarnpkg/core'; -import {npath} from '@yarnpkg/fslib'; - -import {RAW_LINK_PROTOCOL} from './constants'; - -export class RawLinkResolver implements Resolver { - supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) { - if (!descriptor.range.startsWith(RAW_LINK_PROTOCOL)) - return false; - - return true; - } - - supportsLocator(locator: Locator, opts: MinimalResolveOptions) { - if (!locator.reference.startsWith(RAW_LINK_PROTOCOL)) - return false; - - return true; - } - - shouldPersistResolution(locator: Locator, opts: MinimalResolveOptions) { - return false; - } - - bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) { - return structUtils.bindDescriptor(descriptor, { - locator: structUtils.stringifyLocator(fromLocator), - }); - } - - getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) { - return {}; - } - - async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) { - const path = descriptor.range.slice(RAW_LINK_PROTOCOL.length); - - return [structUtils.makeLocator(descriptor, `${RAW_LINK_PROTOCOL}${npath.toPortablePath(path)}`)]; - } - - async getSatisfying(descriptor: Descriptor, dependencies: Record, locators: Array, opts: ResolveOptions) { - const [locator] = await this.getCandidates(descriptor, dependencies, opts); - - return { - locators: locators.filter(candidate => candidate.locatorHash === locator.locatorHash), - sorted: false, - }; - } - - async resolve(locator: Locator, opts: ResolveOptions) { - return { - ...locator, - - version: `0.0.0`, - - languageName: opts.project.configuration.get(`defaultLanguageName`), - linkType: LinkType.SOFT, - - conditions: null, - - dependencies: new Map(), - peerDependencies: new Map(), - - dependenciesMeta: new Map(), - peerDependenciesMeta: new Map(), - - bin: new Map(), - }; - } -} diff --git a/packages/plugin-link/sources/constants.ts b/packages/plugin-link/sources/constants.ts index 3fe12ff50e20..8a432ef3a15c 100644 --- a/packages/plugin-link/sources/constants.ts +++ b/packages/plugin-link/sources/constants.ts @@ -1,3 +1,3 @@ -export const LINK_PROTOCOL = `portal:`; +export const PORTAL_PROTOCOL = `portal:`; -export const RAW_LINK_PROTOCOL = `link:`; +export const LINK_PROTOCOL = `link:`; diff --git a/packages/plugin-link/sources/index.ts b/packages/plugin-link/sources/index.ts index a8fe4aa78c14..dd02fe49c2f1 100644 --- a/packages/plugin-link/sources/index.ts +++ b/packages/plugin-link/sources/index.ts @@ -1,23 +1,23 @@ -import {Plugin} from '@yarnpkg/core'; +import {Plugin} from '@yarnpkg/core'; -import {LinkFetcher} from './LinkFetcher'; -import {LinkResolver} from './LinkResolver'; -import {RawLinkFetcher} from './RawLinkFetcher'; -import {RawLinkResolver} from './RawLinkResolver'; +import {LinkFetcher} from './LinkFetcher'; +import {LinkResolver} from './LinkResolver'; +import {PortalFetcher} from './PortalFetcher'; +import {PortalResolver} from './PortalResolver'; +export {PortalFetcher}; +export {PortalResolver}; export {LinkFetcher}; export {LinkResolver}; -export {RawLinkFetcher}; -export {RawLinkResolver}; const plugin: Plugin = { fetchers: [ - RawLinkFetcher, LinkFetcher, + PortalFetcher, ], resolvers: [ - RawLinkResolver, LinkResolver, + PortalResolver, ], };