Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async fetchFromDisk(locator: Locator, opts: FetchOptions) {
const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PROTOCOL});
// If the file 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 = ppath.isAbsolute(path)
? {packageFs: new NodeFS(), prefixPath: PortablePath.root, localPath: PortablePath.root}
: await opts.fetcher.fetch(parentLocator, opts);
// If the package fs publicized its "original location" (for example like
// in the case of "file:" packages), we use it to derive the real location.
const effectiveParentFetch = parentFetch.localPath
? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
: parentFetch;
// Discard the parent fs unless we really need it to access the files
if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
parentFetch.releaseFs();
const sourceFs = effectiveParentFetch.packageFs;
const sourcePath = ppath.resolve(effectiveParentFetch.prefixPath, path);
async fetch(locator: Locator, opts: FetchOptions) {
const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: RAW_LINK_PROTOCOL});
// If the link 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 = ppath.isAbsolute(path)
? {packageFs: new NodeFS(), prefixPath: PortablePath.root, localPath: PortablePath.root}
: await opts.fetcher.fetch(parentLocator, opts);
// If the package fs publicized its "original location" (for example like
// in the case of "file:" packages), we use it to derive the real location.
const effectiveParentFetch = parentFetch.localPath
? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
: parentFetch;
// Discard the parent fs unless we really need it to access the files
if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
parentFetch.releaseFs();
const sourceFs = effectiveParentFetch.packageFs;
const sourcePath = ppath.resolve(effectiveParentFetch.prefixPath, path);
return null;
// We allow disabling the pnp resolution for some subpaths.
// This is because some projects, often legacy, contain multiple
// levels of dependencies (ie. a yarn.lock inside a subfolder of
// a yarn.lock). This is typically solved using workspaces, but
// not all of them have been converted already.
if (issuer && isPathIgnored(issuer)) {
// Absolute paths that seem to belong to a PnP tree are still
// handled by our runtime even if the issuer isn't. This is
// because the native Node resolution uses a special version
// of the `stat` syscall which would otherwise bypass the
// filesystem layer we require to access the files.
if (!ppath.isAbsolute(request) || findPackageLocator(request) === null) {
const result = callNativeResolution(request, issuer);
if (result === false) {
throw makeError(
ErrorCode.BUILTIN_NODE_RESOLUTION_FAILED,
`The builtin node resolution algorithm was unable to resolve the requested module (it didn't go through the pnp resolver because the issuer was explicitely ignored by the regexp)\n\nRequire request: "${request}"\nRequired by: ${issuer}\n`,
{request, issuer},
);
}
return npath.toPortablePath(result);
}
}
let unqualifiedPath: PortablePath;
private async fetchFromDisk(locator: Locator, opts: FetchOptions) {
const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PROTOCOL});
// If the file 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 = ppath.isAbsolute(path)
? {packageFs: new NodeFS(), prefixPath: PortablePath.root, localPath: PortablePath.root}
: await opts.fetcher.fetch(parentLocator, opts);
// If the package fs publicized its "original location" (for example like
// in the case of "file:" packages), we use it to derive the real location.
const effectiveParentFetch = parentFetch.localPath
? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
: parentFetch;
// Discard the parent fs unless we really need it to access the files
if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
parentFetch.releaseFs();
const generatorFs = effectiveParentFetch.packageFs;
const generatorPath = ppath.resolve(ppath.resolve(generatorFs.getRealPath(), effectiveParentFetch.prefixPath), path);
getLocalPath(locator: Locator, opts: FetchOptions) {
const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: RAW_LINK_PROTOCOL});
if (ppath.isAbsolute(path))
return path;
const parentLocalPath = opts.fetcher.getLocalPath(parentLocator, opts);
if (parentLocalPath === null)
return null;
return ppath.resolve(parentLocalPath, path);
}
for (const [propKey, propDefinition] of Object.entries(definition.properties))
result.set(propKey, getDefaultValue(configuration, propDefinition));
return result;
} break;
case SettingsType.MAP: {
return new Map();
} break;
case SettingsType.ABSOLUTE_PATH: {
if (definition.default === null)
return null;
if (configuration.projectCwd === null) {
if (ppath.isAbsolute(definition.default)) {
return ppath.normalize(definition.default);
} else if (definition.isNullable || definition.default === null) {
return null;
}
} else {
if (Array.isArray(definition.default)) {
return definition.default.map((entry: string) => ppath.resolve(configuration.projectCwd!, entry as PortablePath));
} else {
return ppath.resolve(configuration.projectCwd, definition.default);
}
}
} break;
default: {
return definition.default;
} break;
getLocalPath(locator: Locator, opts: FetchOptions) {
const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PROTOCOL});
if (ppath.isAbsolute(path))
return path;
const parentLocalPath = opts.fetcher.getLocalPath(parentLocator, opts);
if (parentLocalPath === null)
return null;
return ppath.resolve(parentLocalPath, path);
}
tryWorkspaceByCwd(workspaceCwd: PortablePath) {
if (!ppath.isAbsolute(workspaceCwd))
workspaceCwd = ppath.resolve(this.cwd, workspaceCwd);
const workspace = this.workspacesByCwd.get(workspaceCwd);
if (!workspace)
return null;
return workspace;
}