Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// that's part of the Yarn installation
if (path === cwd || path.startsWith(`${cwd}/`))
resolved.push(path);
let stat;
try {
stat = xfs.statSync(path);
} catch (error) {
// ignore errors
break;
}
// If it's a symbolic link then we also need to also consider its target as
// part of the Yarn installation (unless it's outside of the repo)
if (stat.isSymbolicLink()) {
path = ppath.resolve(ppath.dirname(path), xfs.readlinkSync(path));
} else {
break;
}
}
return resolved;
}
if (!dependencyNameMatch) {
if (ppath.isAbsolute(request)) {
unqualifiedPath = ppath.normalize(request);
} else {
if (!issuer) {
throw makeError(
ErrorCode.API_ERROR,
`The resolveToUnqualified function must be called with a valid issuer when the path isn't a builtin nor absolute`,
{request, issuer},
);
}
if (issuer.match(isDirRegExp)) {
unqualifiedPath = ppath.normalize(ppath.resolve(issuer, request));
} else {
unqualifiedPath = ppath.normalize(ppath.resolve(ppath.dirname(issuer), request));
}
}
// No need to use the return value; we just want to check the blacklist status
findPackageLocator(unqualifiedPath);
}
// 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
else {
if (!issuer) {
throw makeError(
ErrorCode.API_ERROR,
`The resolveToUnqualified function must be called with a valid issuer when the path isn't a builtin nor absolute`,
{request, issuer},
async function fetchRoot(initialCwd: PortablePath) {
// Note: We can't just use `git rev-parse --show-toplevel`, because on Windows
// it may return long paths even when the cwd uses short paths, and we have no
// way to detect it from Node (not even realpath).
let match: PortablePath | null = null;
let cwd: PortablePath;
let nextCwd = initialCwd;
do {
cwd = nextCwd;
if (await xfs.existsPromise(ppath.join(cwd, `.git` as Filename)))
match = cwd;
nextCwd = ppath.dirname(cwd);
} while (match === null && nextCwd !== cwd);
if (match === null)
throw new UsageError(`This command can only be run from within a Git repository`);
return match;
}
export const generateEslintWrapper = async (projectRoot: PortablePath, target: PortablePath) => {
const eslint = ppath.join(target, `eslint` as PortablePath);
const manifest = ppath.join(eslint, `package.json` as PortablePath);
const api = ppath.join(eslint, `lib/api.js` as PortablePath);
const relPnpApiPath = ppath.relative(ppath.dirname(api), ppath.join(projectRoot, `.pnp.js` as Filename));
await xfs.mkdirpPromise(ppath.dirname(api));
await xfs.writeFilePromise(manifest, JSON.stringify({name: 'eslint', version: `${dynamicRequire('eslint/package.json').version}-pnpify`, main: 'lib/api.js'}, null, 2));
await xfs.writeFilePromise(api, TEMPLATE(relPnpApiPath, "eslint", {usePnpify: false}));
await addVSCodeWorkspaceSettings(projectRoot, {'eslint.nodePath': npath.fromPortablePath(ppath.relative(projectRoot, ppath.dirname(eslint)))});
};
const generateTypescriptWrapper = async (projectRoot: PortablePath, target: PortablePath) => {
const typescript = ppath.join(target, `typescript` as PortablePath);
const manifest = ppath.join(typescript, `package.json` as PortablePath);
const tsserver = ppath.join(typescript, `lib/tsserver.js` as PortablePath);
const relPnpApiPath = ppath.relative(ppath.dirname(tsserver), ppath.join(projectRoot, `.pnp.js` as Filename));
await xfs.mkdirpPromise(ppath.dirname(tsserver));
await xfs.writeFilePromise(manifest, JSON.stringify({name: 'typescript', version: `${dynamicRequire('typescript/package.json').version}-pnpify`}, null, 2));
await xfs.writeFilePromise(tsserver, TEMPLATE(relPnpApiPath, "typescript/lib/tsserver", {usePnpify: true}));
await addVSCodeWorkspaceSettings(projectRoot, {'typescript.tsdk': npath.fromPortablePath(ppath.relative(projectRoot, ppath.dirname(tsserver)))});
};
targetFs.mkdirSync(mappedPath);
targetFs.chmodSync(mappedPath, mode);
targetFs.utimesSync(mappedPath, defaultTime, defaultTime);
} break;
case `OldFile`:
case `File`: {
targetFs.mkdirpSync(ppath.dirname(mappedPath), {chmod: 0o755, utimes: [defaultTime, defaultTime]});
targetFs.writeFileSync(mappedPath, Buffer.concat(chunks));
targetFs.chmodSync(mappedPath, mode);
targetFs.utimesSync(mappedPath, defaultTime, defaultTime);
} break;
case `SymbolicLink`: {
targetFs.mkdirpSync(ppath.dirname(mappedPath), {chmod: 0o755, utimes: [defaultTime, defaultTime]});
targetFs.symlinkSync(entry.linkpath, mappedPath);
targetFs.lutimesSync!(mappedPath, defaultTime, defaultTime);
} break;
}
});
});
throw new Error(`Trying to delete file that doesn't exist: ${eff.path}`);
}
} else {
await preserveTime(baseFs, ppath.dirname(eff.path), async () => {
await baseFs.unlinkPromise(eff.path);
});
}
} break;
case `rename`: {
if (dryRun) {
if (!baseFs.existsSync(eff.fromPath)) {
throw new Error(`Trying to move file that doesn't exist: ${eff.fromPath}`);
}
} else {
await preserveTime(baseFs, ppath.dirname(eff.fromPath), async () => {
await preserveTime(baseFs, ppath.dirname(eff.toPath), async () => {
await preserveTime(baseFs, eff.fromPath, async () => {
await baseFs.movePromise(eff.fromPath, eff.toPath);
return eff.toPath;
});
});
});
}
} break;
case `file creation`: {
if (dryRun) {
if (baseFs.existsSync(eff.path)) {
throw new Error(`Trying to create file that already exists: ${eff.path}`);
}
} else {
export async function applyPatchFile(effects: ParsedPatchFile, {baseFs = new NodeFS(), dryRun = false}: {baseFs?: FakeFS, dryRun?: boolean} = {}) {
for (const eff of effects) {
switch (eff.type) {
case `file deletion`: {
if (dryRun) {
if (!baseFs.existsSync(eff.path)) {
throw new Error(`Trying to delete file that doesn't exist: ${eff.path}`);
}
} else {
await preserveTime(baseFs, ppath.dirname(eff.path), async () => {
await baseFs.unlinkPromise(eff.path);
});
}
} break;
case `rename`: {
if (dryRun) {
if (!baseFs.existsSync(eff.fromPath)) {
throw new Error(`Trying to move file that doesn't exist: ${eff.fromPath}`);
}
} else {
await preserveTime(baseFs, ppath.dirname(eff.fromPath), async () => {
await preserveTime(baseFs, ppath.dirname(eff.toPath), async () => {
await preserveTime(baseFs, eff.fromPath, async () => {
await baseFs.movePromise(eff.fromPath, eff.toPath);
return eff.toPath;
function findApiPathFor(modulePath: NativePath) {
let curr: PortablePath;
let next = npath.toPortablePath(modulePath);
do {
curr = next;
const candidate = ppath.join(curr, `.pnp.js` as Filename);
if (xfs.existsSync(candidate) && xfs.statSync(candidate).isFile())
return candidate;
next = ppath.dirname(curr);
} while (curr !== PortablePath.root);
return null;
}