Skip to content

Commit 8e81c6a

Browse files
muradmmgechev
authored andcommitted
feat(@angular/cli): Support XDG Base Directory Specfication
Explained here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html Current change affects reading of global config from `.angular-config.json`. By default it will be created in user's home directory. If user moves it manually to `$HOME/.config/angular/.angular-config.json`, it will be subsequently read from new location.
1 parent 0152c13 commit 8e81c6a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/angular/cli/utilities/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export const workspaceSchemaPath = getSchemaLocation();
3131
const configNames = [ 'angular.json', '.angular.json' ];
3232
const globalFileName = '.angular-config.json';
3333

34+
function xdgConfigHome(home: string, configFile?: string): string {
35+
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
36+
const p = process.env['XDG_CONFIG_HOME'] || path.join(home, '.config', 'angular');
37+
38+
return configFile ? path.join(p, configFile) : p;
39+
}
40+
3441
function projectFilePath(projectPath?: string): string | null {
3542
// Find the configuration, either where specified, in the Angular CLI project
3643
// (if it's in node_modules) or from the current process.
@@ -45,6 +52,15 @@ function globalFilePath(): string | null {
4552
return null;
4653
}
4754

55+
// follow XDG Base Directory spec
56+
// note that createGlobalSettings() will continue creating
57+
// global file in home directory, with this user will have
58+
// choice to move change its location to meet XDG convention
59+
const xdgConfig = xdgConfigHome(home, globalFileName);
60+
if (existsSync(xdgConfig)) {
61+
return xdgConfig;
62+
}
63+
4864
const p = path.join(home, globalFileName);
4965
if (existsSync(p)) {
5066
return p;

0 commit comments

Comments
 (0)