ttsc
Version:
General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.
26 lines • 1.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertSafeExplicitCacheDirectory = assertSafeExplicitCacheDirectory;
const node_path_1 = __importDefault(require("node:path"));
/**
* Refuse an explicit cache directory whose wholesale removal could delete the
* project or an entire filesystem volume.
*/
function assertSafeExplicitCacheDirectory(projectRoot, cacheDirectory) {
const project = node_path_1.default.resolve(projectRoot);
const cache = node_path_1.default.resolve(cacheDirectory);
if (cache === node_path_1.default.parse(cache).root) {
throw new Error(`ttsc: refusing to clean cache directory ${JSON.stringify(cache)} because filesystem roots are never valid cache directories`);
}
const relative = node_path_1.default.relative(cache, project);
if (relative === "" ||
(relative !== ".." &&
!relative.startsWith(`..${node_path_1.default.sep}`) &&
!node_path_1.default.isAbsolute(relative))) {
throw new Error(`ttsc: refusing to clean cache directory ${JSON.stringify(cache)} because it equals or contains project root ${JSON.stringify(project)}; choose a dedicated cache directory`);
}
}
//# sourceMappingURL=assertSafeExplicitCacheDirectory.js.map