@cenk1cenk2/oclif-common 3.1.0-beta.2 → 3.1.0-beta.5

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -653,7 +653,7 @@ var ConfigService = class {
653
653
  extras.push(await iter(value["__element" /* ELEMENT */], [...location, "__element" /* ELEMENT */]));
654
654
  }
655
655
  if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
656
- return [
656
+ const variable = [
657
657
  {
658
658
  key: location,
659
659
  env: value["__name" /* NAME */],
@@ -661,6 +661,7 @@ var ConfigService = class {
661
661
  },
662
662
  ...extras
663
663
  ];
664
+ return variable;
664
665
  } else {
665
666
  return iter(value, location);
666
667
  }
@@ -670,21 +671,24 @@ var ConfigService = class {
670
671
  return data.flatMap((d) => d);
671
672
  }, "iter");
672
673
  const parsed = await iter(env);
674
+ const cb = /* @__PURE__ */ __name(async (variable, data) => {
675
+ if (variable.parser) {
676
+ try {
677
+ variable = await this.parser.parse(variable.parser, data);
678
+ } catch (e) {
679
+ this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
680
+ throw e;
681
+ }
682
+ }
683
+ return import_object_path_immutable.default.update(config, variable.key, () => {
684
+ this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
685
+ return variable;
686
+ });
687
+ }, "cb");
673
688
  await Promise.all(
674
689
  parsed.map(async (variable) => {
675
- let data = process.env[variable.env];
676
- if (!data) {
677
- return;
678
- }
679
- if (variable.parser) {
680
- try {
681
- data = await this.parser.parse(variable.parser, data);
682
- } catch (e) {
683
- this.logger.trace("Can not parse environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
684
- throw e;
685
- }
686
- }
687
- if (variable.key.includes("__element" /* ELEMENT */)) {
690
+ let data;
691
+ if (variable.key.length && variable.key.includes("__element" /* ELEMENT */)) {
688
692
  const timeout = 6e4;
689
693
  const startedAt = Date.now();
690
694
  for (let i = 0; i < Infinity; i++) {
@@ -692,23 +696,23 @@ var ConfigService = class {
692
696
  throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
693
697
  }
694
698
  const clone = JSON.parse(JSON.stringify(variable));
695
- data = process.env[clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString())];
699
+ clone.env = clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString());
700
+ this.logger.trace("Looking for environment variable element: %o", clone);
701
+ data = process.env[clone.env];
696
702
  if (!data) {
697
703
  this.logger.trace("No more variable available: %s -> %d", variable.env, i);
698
704
  break;
699
705
  }
700
706
  clone.key[clone.key.findIndex((value) => value === "__element" /* ELEMENT */)] = i;
701
- config = import_object_path_immutable.default.update(config, clone.key, () => {
702
- this.logger.trace("Overwriting config with element environment variable: %s -> %s", clone.key.join("."), variable.env);
703
- return data;
704
- });
707
+ config = await cb(clone, data);
705
708
  }
706
- } else {
707
- config = import_object_path_immutable.default.update(config, variable.key, () => {
708
- this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
709
- return data;
710
- });
709
+ return;
710
+ }
711
+ data = process.env[variable.env];
712
+ if (!data) {
713
+ return;
711
714
  }
715
+ config = await cb(variable, data);
712
716
  })
713
717
  );
714
718
  return config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.1.0-beta.2",
3
+ "version": "3.1.0-beta.5",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {