guardia-messenger/node_modules/find-yarn-workspace-root/index.js
DESKTOP-TKLFCPRython f29f525c77 refactor: 101.79.17.164 → zioinfo.co.kr 전체 도메인 변환 + Manager UI 배포
- 37개 파일 IP → zioinfo.co.kr 치환 (소스/매뉴얼/설정/하네스)
- Manager DrConsole/NetworkConsole/CsapConsole 빌드 + /var/www/manager/ 배포
- 테스트: Manager HTTP 200, ITSM 신규 API 7개 전체 200

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 10:09:17 +09:00

54 lines
1.3 KiB
JavaScript

'use strict';
const fs = require('fs');
const micromatch = require('micromatch');
const path = require('path');
module.exports = findWorkspaceRoot;
/**
* Adapted from:
* https://github.com/yarnpkg/yarn/blob/ddf2f9ade211195372236c2f39a75b00fa18d4de/src/config.js#L612
* @param {string} [initial]
* @return {string|null}
*/
function findWorkspaceRoot(initial) {
if (!initial) {
initial = process.cwd();
}
let previous = null;
let current = path.normalize(initial);
do {
const manifest = readPackageJSON(current);
const workspaces = extractWorkspaces(manifest);
if (workspaces) {
const relativePath = path.relative(current, initial);
if (relativePath === '' || micromatch([relativePath], workspaces).length > 0) {
return current;
} else {
return null;
}
}
previous = current;
current = path.dirname(current);
} while (current !== previous);
return null;
}
function extractWorkspaces(manifest) {
const workspaces = (manifest || {}).workspaces;
return (workspaces && workspaces.packages) || (Array.isArray(workspaces) ? workspaces : null);
}
function readPackageJSON(dir) {
const file = path.join(dir, 'package.json');
if (fs.existsSync(file)) {
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
return null;
}