config.ts — astro Source File
Architecture documentation for config.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65["config.ts"] e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 b326953c_dc9d_ec9e_dc34_4beead549f6e["node:os"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> b326953c_dc9d_ec9e_dc34_4beead549f6e c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 11492406_d927_cd22_cbdd_09d2c1b03ff4["node:process"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> 11492406_d927_cd22_cbdd_09d2c1b03ff4 d9073335_b3f3_9f7a_62f3_5035edaf179b["dlv"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> d9073335_b3f3_9f7a_62f3_5035edaf179b 3c9937a8_1aa7_fe65_44ce_7b303421a398["dset"] 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 --> 3c9937a8_1aa7_fe65_44ce_7b303421a398 style 5b90aac1_20dd_dfa0_03a8_c2a798e9dc65 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';
import dget from 'dlv';
import { dset } from 'dset';
interface ConfigOptions {
name: string;
}
// Adapted from https://github.com/sindresorhus/env-paths
function getConfigDir(name: string) {
const homedir = os.homedir();
const macos = () => path.join(homedir, 'Library', 'Preferences', name);
const win = () => {
const { APPDATA = path.join(homedir, 'AppData', 'Roaming') } = process.env;
return path.join(APPDATA, name, 'Config');
};
const linux = () => {
const { XDG_CONFIG_HOME = path.join(homedir, '.config') } = process.env;
return path.join(XDG_CONFIG_HOME, name);
};
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (process.platform) {
case 'darwin':
return macos();
case 'win32':
return win();
default:
return linux();
}
}
export class GlobalConfig {
private dir: string;
private file: string;
constructor(private project: ConfigOptions) {
this.dir = getConfigDir(this.project.name);
this.file = path.join(this.dir, 'config.json');
}
private _store?: Record<string, any>;
private get store(): Record<string, any> {
if (this._store) return this._store;
this.ensureDir();
if (fs.existsSync(this.file)) {
try {
this._store = JSON.parse(fs.readFileSync(this.file).toString());
} catch {}
}
if (!this._store) {
this._store = {};
this.write();
}
return this._store;
}
private set store(value: Record<string, any>) {
this._store = value;
this.write();
}
private ensureDir() {
fs.mkdirSync(this.dir, { recursive: true });
}
write() {
fs.writeFileSync(this.file, JSON.stringify(this.store, null, '\t'));
}
clear(): void {
this.store = {};
fs.rmSync(this.file, { recursive: true });
}
delete(key: string): boolean {
dset(this.store, key, undefined);
this.write();
return true;
}
get(key: string): any {
return dget(this.store, key);
}
has(key: string): boolean {
return typeof this.get(key) !== 'undefined';
}
set(key: string, value: any): void {
dset(this.store, key, value);
this.write();
}
}
Domain
Subdomains
Functions
Classes
Types
Dependencies
- dlv
- dset
- node:fs
- node:os
- node:path
- node:process
Source
Frequently Asked Questions
What does config.ts do?
config.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in config.ts?
config.ts defines 1 function(s): getConfigDir.
What does config.ts depend on?
config.ts imports 6 module(s): dlv, dset, node:fs, node:os, node:path, node:process.
Where is config.ts in the architecture?
config.ts is located at packages/telemetry/src/config.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/telemetry/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free