@argos-ci/core 4.1.1 → 4.1.3

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 +60 -34
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -587,25 +587,43 @@ var mustBeArgosToken = (value) => {
587
587
  throw new Error("Invalid Argos repository token (must be 40 characters)");
588
588
  }
589
589
  };
590
- var minNumber = (value, min) => {
591
- const number = parseInt(value, 10);
592
- if (!Number.isInteger(number)) {
593
- throw new Error("must be a number");
590
+ var minInteger = (min) => (value) => {
591
+ if (!Number.isInteger(value)) {
592
+ throw new Error("must be an integer");
594
593
  }
595
- if (number < min) {
594
+ if (value < min) {
596
595
  throw new Error(`must be at least ${min}`);
597
596
  }
598
597
  };
598
+ var toInt = (value) => {
599
+ if (value === "") {
600
+ return null;
601
+ }
602
+ const num = Number(value);
603
+ if (!Number.isInteger(num) || Number.isNaN(num)) {
604
+ return num;
605
+ }
606
+ return num;
607
+ };
608
+ var toFloat = (value) => parseFloat(value);
609
+ convict.addFormat({
610
+ name: "parallel-total",
611
+ validate: minInteger(-1),
612
+ coerce: toInt
613
+ });
614
+ convict.addFormat({
615
+ name: "parallel-index",
616
+ validate: minInteger(1),
617
+ coerce: toInt
618
+ });
599
619
  convict.addFormat({
600
620
  name: "float-percent",
601
- validate: function(val) {
621
+ validate: (val) => {
602
622
  if (val !== 0 && (!val || val > 1 || val < 0)) {
603
623
  throw new Error("Must be a float between 0 and 1, inclusive.");
604
624
  }
605
625
  },
606
- coerce: function(val) {
607
- return parseFloat(val);
608
- }
626
+ coerce: toFloat
609
627
  });
610
628
  var schema = {
611
629
  apiBaseUrl: {
@@ -671,15 +689,15 @@ var schema = {
671
689
  },
672
690
  parallelIndex: {
673
691
  env: "ARGOS_PARALLEL_INDEX",
692
+ format: "parallel-index",
674
693
  default: null,
675
- nullable: true,
676
- format: (value) => minNumber(value, 1)
694
+ nullable: true
677
695
  },
678
696
  parallelTotal: {
679
697
  env: "ARGOS_PARALLEL_TOTAL",
698
+ format: "parallel-total",
680
699
  default: null,
681
- nullable: true,
682
- format: (value) => minNumber(value, -1)
700
+ nullable: true
683
701
  },
684
702
  referenceBranch: {
685
703
  env: "ARGOS_REFERENCE_BRANCH",
@@ -731,36 +749,44 @@ var schema = {
731
749
  nullable: true
732
750
  }
733
751
  };
734
- var createConfig = () => {
735
- return convict(schema, {
736
- args: []
737
- });
738
- };
752
+ function createConfig() {
753
+ return convict(schema, { args: [], env: {} });
754
+ }
755
+ function getDefaultConfig() {
756
+ return Object.entries(schema).reduce(
757
+ (cfg, [key, entry]) => {
758
+ cfg[key] = "env" in entry && entry.env && process.env[entry.env] ? process.env[entry.env] : entry.default;
759
+ return cfg;
760
+ },
761
+ {}
762
+ );
763
+ }
739
764
  async function readConfig(options = {}) {
740
765
  const config = createConfig();
741
766
  const ciEnv = await getCiEnvironment();
767
+ const defaultConfig = getDefaultConfig();
742
768
  config.load({
743
- apiBaseUrl: options.apiBaseUrl || config.get("apiBaseUrl"),
744
- commit: options.commit || config.get("commit") || ciEnv?.commit || null,
745
- branch: options.branch || config.get("branch") || ciEnv?.branch || null,
746
- token: options.token || config.get("token") || null,
747
- buildName: options.buildName || config.get("buildName") || null,
748
- prNumber: options.prNumber || config.get("prNumber") || ciEnv?.prNumber || null,
749
- prHeadCommit: config.get("prHeadCommit") || ciEnv?.prHeadCommit || null,
750
- prBaseBranch: config.get("prBaseBranch") || ciEnv?.prBaseBranch || null,
751
- referenceBranch: options.referenceBranch || config.get("referenceBranch") || null,
752
- referenceCommit: options.referenceCommit || config.get("referenceCommit") || null,
769
+ apiBaseUrl: options.apiBaseUrl || defaultConfig.apiBaseUrl,
770
+ commit: options.commit || defaultConfig.commit || ciEnv?.commit || null,
771
+ branch: options.branch || defaultConfig.branch || ciEnv?.branch || null,
772
+ token: options.token || defaultConfig.token || null,
773
+ buildName: options.buildName || defaultConfig.buildName || null,
774
+ prNumber: options.prNumber || defaultConfig.prNumber || ciEnv?.prNumber || null,
775
+ prHeadCommit: defaultConfig.prHeadCommit || ciEnv?.prHeadCommit || null,
776
+ prBaseBranch: defaultConfig.prBaseBranch || ciEnv?.prBaseBranch || null,
777
+ referenceBranch: options.referenceBranch || defaultConfig.referenceBranch || null,
778
+ referenceCommit: options.referenceCommit || defaultConfig.referenceCommit || null,
753
779
  repository: ciEnv?.repository || null,
754
780
  jobId: ciEnv?.jobId || null,
755
781
  runId: ciEnv?.runId || null,
756
782
  runAttempt: ciEnv?.runAttempt || null,
757
- parallel: options.parallel ?? config.get("parallel") ?? false,
758
- parallelNonce: options.parallelNonce || config.get("parallelNonce") || ciEnv?.nonce || null,
759
- parallelTotal: options.parallelTotal ?? config.get("parallelTotal") ?? null,
760
- parallelIndex: options.parallelIndex ?? config.get("parallelIndex") ?? null,
761
- mode: options.mode || config.get("mode") || null,
783
+ parallel: options.parallel ?? defaultConfig.parallel ?? false,
784
+ parallelNonce: options.parallelNonce || defaultConfig.parallelNonce || ciEnv?.nonce || null,
785
+ parallelTotal: options.parallelTotal ?? defaultConfig.parallelTotal ?? null,
786
+ parallelIndex: options.parallelIndex ?? defaultConfig.parallelIndex ?? null,
787
+ mode: options.mode || defaultConfig.mode || null,
762
788
  ciProvider: ciEnv?.key || null,
763
- previewBaseUrl: config.get("previewBaseUrl") || null
789
+ previewBaseUrl: defaultConfig.previewBaseUrl || null
764
790
  });
765
791
  config.validate();
766
792
  return config.get();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Node.js SDK for visual testing with Argos.",
4
- "version": "4.1.1",
4
+ "version": "4.1.3",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "exports": {
@@ -64,5 +64,5 @@
64
64
  "lint": "eslint .",
65
65
  "test": "vitest"
66
66
  },
67
- "gitHead": "7cbf27f8eb0415089d827759d9e14deaf891f797"
67
+ "gitHead": "9bda48090685f3215301526c7d979716d485f3ed"
68
68
  }