Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findPackageLocator(location: PortablePath): PackageLocator | null {
let relativeLocation = normalizePath(ppath.relative(runtimeState.basePath, location));
if (!relativeLocation.match(isStrictRegExp))
relativeLocation = `./${relativeLocation}` as PortablePath;
if (location.match(isDirRegExp) && !relativeLocation.endsWith(`/`))
relativeLocation = `${relativeLocation}/` as PortablePath;
let from = 0;
// If someone wants to use a binary search to go from O(n) to O(log n), be my guest
while (from < packageLocationLengths.length && packageLocationLengths[from] > relativeLocation.length)
from += 1;
for (let t = from; t < packageLocationLengths.length; ++t) {
const locator = packageLocatorsByLocations.get(relativeLocation.substr(0, packageLocationLengths[t]) as PortablePath);
if (typeof locator === `undefined`)
maybeRejectPath(configuration.get(`bstatePath`));
maybeRejectPath(configuration.get(`cacheFolder`));
maybeRejectPath(configuration.get(`globalFolder`));
maybeRejectPath(configuration.get(`virtualFolder`));
maybeRejectPath(configuration.get(`yarnPath`));
await configuration.triggerHook((hooks: StageHooks) => {
return hooks.populateYarnPaths;
}, project, (path: PortablePath | null) => {
maybeRejectPath(path);
});
// All child workspaces are ignored
for (const otherWorkspace of project.workspaces) {
const rel = ppath.relative(workspace.cwd, otherWorkspace.cwd);
if (rel !== `` && !rel.match(/^(\.\.)?\//)) {
globalList.reject.push(`/${rel}`);
}
}
const ignoreList: IgnoreList = {
accept: [],
reject: [],
};
if (workspace.manifest.publishConfig && workspace.manifest.publishConfig.main)
ignoreList.accept.push(ppath.resolve(PortablePath.root, workspace.manifest.publishConfig.main));
else if (workspace.manifest.main)
ignoreList.accept.push(ppath.resolve(PortablePath.root, workspace.manifest.main));
if (workspace.manifest.publishConfig && workspace.manifest.publishConfig.module)
private normalizeDirectoryPath(folder: PortablePath) {
let relativeFolder = ppath.relative(this.opts.project.cwd, folder);
if (!relativeFolder.match(/^\.{0,2}\//))
// Don't use ppath.join here, it ignores the `.`
relativeFolder = `./${relativeFolder}` as PortablePath;
return relativeFolder.replace(/\/?$/, '/') as PortablePath;
}
}
async setup() {
// @ts-ignore: It's ok to initialize it now
this.manifest = xfs.existsSync(ppath.join(this.cwd, Manifest.fileName))
? await Manifest.find(this.cwd)
: new Manifest();
// We use ppath.relative to guarantee that the default hash will be consistent even if the project is installed on different OS / path
// @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
this.relativeCwd = ppath.relative(this.project.cwd, this.cwd) || PortablePath.dot;
const ident = this.manifest.name ? this.manifest.name : structUtils.makeIdent(null, `${this.computeCandidateName()}-${hashUtils.makeHash(this.relativeCwd).substr(0, 6)}`);
const reference = this.manifest.version ? this.manifest.version : `0.0.0`;
// @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
this.locator = structUtils.makeLocator(ident, reference);
// @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
this.anchoredDescriptor = structUtils.makeDescriptor(this.locator, `${WorkspaceResolver.protocol}${this.relativeCwd}`);
// @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
this.anchoredLocator = structUtils.makeLocator(this.locator, `${WorkspaceResolver.protocol}${this.relativeCwd}`);
for (const definition of this.manifest.workspaceDefinitions) {
const relativeCwds = await globby(definition.pattern, {
absolute: true,
private normalizeDirectoryPath(folder: PortablePath) {
let relativeFolder = ppath.relative(this.opts.project.cwd, folder);
if (!relativeFolder.match(/^\.{0,2}\//))
// Don't use ppath.join here, it ignores the `.`
relativeFolder = `./${relativeFolder}` as PortablePath;
return relativeFolder.replace(/\/?$/, '/') as PortablePath;
}
async function fetchPreviousNonce(workspace: Workspace, {root, base}: {root: PortablePath, base: string}) {
const {code, stdout} = await execUtils.execvp(`git`, [`show`, `${base}:${fromPortablePath(ppath.relative(root, ppath.join(workspace.cwd, `package.json` as Filename)))}`], {cwd: workspace.cwd});
if (code === 0) {
return getNonce(Manifest.fromText(stdout));
} else {
return null;
}
}
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)))});
};