@cenk1cenk2/oclif-common 3.1.0-beta.3 → 3.1.0-beta.6

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