@travetto/config 3.2.3 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/config",
3
- "version": "3.2.3",
3
+ "version": "3.3.1",
4
4
  "description": "Configuration support",
5
5
  "keywords": [
6
6
  "yaml",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/config"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/di": "^3.2.2",
30
- "@travetto/schema": "^3.2.2",
31
- "@travetto/yaml": "^3.2.2"
29
+ "@travetto/di": "^3.3.1",
30
+ "@travetto/schema": "^3.3.1",
31
+ "@travetto/yaml": "^3.3.1"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "Configuration"
@@ -4,6 +4,6 @@ import { ConfigParser } from './types';
4
4
 
5
5
  @Injectable()
6
6
  export class JSONConfigParser implements ConfigParser {
7
- ext = ['json'];
7
+ ext = ['.json'];
8
8
  parse = JSON.parse.bind(JSON);
9
9
  }
@@ -33,7 +33,7 @@ export class PropertiesConfigParser implements ConfigParser {
33
33
  }
34
34
  }
35
35
 
36
- ext = ['properties'];
36
+ ext = ['.properties'];
37
37
 
38
38
  parse(text: string): ConfigData {
39
39
  const out: ConfigData = {};
@@ -41,7 +41,7 @@ export class PropertiesConfigParser implements ConfigParser {
41
41
 
42
42
  for (let i = 0; i < lines.length; i++) {
43
43
  let line = lines[i];
44
- while (i < text.length && line.endsWith('\\')) {
44
+ while (i < lines.length && line.endsWith('\\')) {
45
45
  line = `${line.replace(/\\$/, '')}${lines[i += 1].trimStart()}`;
46
46
  }
47
47
  const entry = PropertiesConfigParser.parseLine(line);
@@ -5,6 +5,6 @@ import { ConfigParser } from './types';
5
5
 
6
6
  @Injectable()
7
7
  export class YAMLConfigParser implements ConfigParser {
8
- ext = ['yaml', 'yml'];
8
+ ext = ['.yaml', '.yml'];
9
9
  parse = YamlUtil.parse;
10
10
  }
@@ -1,3 +1,4 @@
1
+ import { path } from '@travetto/manifest';
1
2
  import { FileQueryProvider } from '@travetto/base';
2
3
  import { DependencyRegistry, InjectableFactory } from '@travetto/di';
3
4
 
@@ -29,22 +30,17 @@ export class FileConfigSource extends FileQueryProvider implements ConfigSource
29
30
  const parsers = await Promise.all(parserClasses.map(x => DependencyRegistry.getInstance<ConfigParser>(x.class, x.qualifier)));
30
31
 
31
32
  // Register parsers
32
- this.parsers = {};
33
- for (const par of parsers) {
34
- for (const ext of par.ext) {
35
- this.parsers[ext] = par;
36
- }
37
- }
33
+ this.parsers = Object.fromEntries(parsers.flatMap(p => p.ext.map(e => [e, p])));
38
34
 
39
- this.extMatch = parsers.length ? new RegExp(`[.](${Object.keys(this.parsers).join('|')})`) : /^$/;
35
+ this.extMatch = parsers.length ? new RegExp(`(${Object.keys(this.parsers).join('|').replaceAll('.', '[.]')})`) : /^$/;
40
36
  }
41
37
 
42
38
  async getValues(profiles: string[]): Promise<ConfigValue[]> {
43
39
  const out: ConfigValue[] = [];
44
40
 
45
41
  for await (const file of this.query(f => this.extMatch.test(f))) {
46
- const ext = file.split('.')[1];
47
- const profile = file.replace(`.${ext}`, '');
42
+ const ext = path.extname(file);
43
+ const profile = path.basename(file, ext);
48
44
  if (!profiles.includes(profile) || !this.parsers[ext]) {
49
45
  continue;
50
46
  }