@lark-project/cli
Version:
飞书项目插件开发工具
32 lines (31 loc) • 1.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyCwdOption = void 0;
const path_1 = __importDefault(require("path"));
const fs_extra_1 = require("fs-extra");
const logger_1 = require("./logger");
/**
* Apply the global `--cwd <dir>` option: resolve it to an absolute path and
* `process.chdir()` into it, so every downstream `process.cwd()` read anchors to
* the plugin project root — both inline command resolution (e.g. `--from`) and
* the dispatcher child process, which inherits the parent's cwd at spawn time.
*
* This lets callers run `lpm --cwd <projectRoot> <command>` from anywhere
* (a parent dir, another repo) without a brittle `cd`. Only directory existence
* is validated here; plugin-root checks stay where they belong downstream
* (`assertPluginRoot` for .lpm-cache writes, `getLocalPluginConfig` for reads).
*/
function applyCwdOption(cwd) {
if (!cwd)
return;
const abs = path_1.default.resolve(cwd);
if (!(0, fs_extra_1.existsSync)(abs) || !(0, fs_extra_1.statSync)(abs).isDirectory()) {
logger_1.logger.error(`--cwd: "${cwd}" is not an existing directory (resolved to ${abs}).`);
process.exit(1);
}
process.chdir(abs);
}
exports.applyCwdOption = applyCwdOption;