CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
1'use strict';2 3const fs = require('fs');4const micromatch = require('micromatch');5const path = require('path');6 7module.exports = findWorkspaceRoot;8 9/**10 * Adapted from:11 * https://github.com/yarnpkg/yarn/blob/ddf2f9ade211195372236c2f39a75b00fa18d4de/src/config.js#L61212 * @param {string} [initial]13 * @return {string|null}14 */15function findWorkspaceRoot(initial) {16  if (!initial) {17    initial = process.cwd();18  }19  let previous = null;20  let current = path.normalize(initial);21 22  do {23    const manifest = readPackageJSON(current);24    const workspaces = extractWorkspaces(manifest);25 26    if (workspaces) {27      const relativePath = path.relative(current, initial);28      if (relativePath === '' || micromatch([relativePath], workspaces).length > 0) {29        return current;30      } else {31        return null;32      }33    }34 35    previous = current;36    current = path.dirname(current);37  } while (current !== previous);38 39  return null;40}41 42function extractWorkspaces(manifest) {43  const workspaces = (manifest || {}).workspaces;44  return (workspaces && workspaces.packages) || (Array.isArray(workspaces) ? workspaces : null);45}46 47function readPackageJSON(dir) {48  const file = path.join(dir, 'package.json');49  if (fs.existsSync(file)) {50    return JSON.parse(fs.readFileSync(file, 'utf8'));51  }52  return null;53}54 
basant307/AI_Governance_Project · CoolFace