@argos-ci/core 1.5.5 → 2.1.0

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.mjs +30 -32
  2. package/package.json +11 -11
package/dist/index.mjs CHANGED
@@ -181,11 +181,11 @@ const getBranch = ({ env })=>{
181
181
  return null;
182
182
  }
183
183
  const matches = branchRegex.exec(env.GITHUB_REF);
184
- return (matches === null || matches === void 0 ? void 0 : matches[1]) ?? null;
184
+ return matches?.[1] ?? null;
185
185
  };
186
186
  const getRepository$1 = ({ env })=>{
187
187
  if (!env.GITHUB_REPOSITORY) return null;
188
- return env.GITHUB_REPOSITORY.split("/")[1];
188
+ return env.GITHUB_REPOSITORY.split("/")[1] || null;
189
189
  };
190
190
  const readEventPayload = ({ env })=>{
191
191
  if (!env.GITHUB_EVENT_PATH) return null;
@@ -196,7 +196,6 @@ const service$4 = {
196
196
  name: "GitHub Actions",
197
197
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
198
198
  config: async ({ env })=>{
199
- var _payload_pull_request, _payload_pull_request1, _payload_pull_request2;
200
199
  const payload = readEventPayload({
201
200
  env
202
201
  });
@@ -215,7 +214,7 @@ const service$4 = {
215
214
  nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null
216
215
  };
217
216
  // If the job is triggered by from a "deployment" or a "deployment_status"
218
- if (payload === null || payload === void 0 ? void 0 : payload.deployment) {
217
+ if (payload?.deployment) {
219
218
  debug("Deployment event detected");
220
219
  // Try to find a relevant pull request for the sha
221
220
  const pullRequest = await getPullRequestFromHeadSha({
@@ -225,18 +224,18 @@ const service$4 = {
225
224
  ...commonConfig,
226
225
  // If no pull request is found, we fallback to the deployment environment as branch name
227
226
  // Branch name is required to create a build but has no real impact on the build.
228
- branch: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.ref) || payload.deployment.environment || null,
229
- prNumber: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.number) || null,
230
- prHeadCommit: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.sha) || null
227
+ branch: pullRequest?.head.ref || payload.deployment.environment || null,
228
+ prNumber: pullRequest?.number || null,
229
+ prHeadCommit: pullRequest?.head.sha || null
231
230
  };
232
231
  }
233
232
  return {
234
233
  ...commonConfig,
235
- branch: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request = payload.pull_request) === null || _payload_pull_request === void 0 ? void 0 : _payload_pull_request.head.ref) || getBranch({
234
+ branch: payload?.pull_request?.head.ref || getBranch({
236
235
  env
237
236
  }) || null,
238
- prNumber: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request1 = payload.pull_request) === null || _payload_pull_request1 === void 0 ? void 0 : _payload_pull_request1.number) || null,
239
- prHeadCommit: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request2 = payload.pull_request) === null || _payload_pull_request2 === void 0 ? void 0 : _payload_pull_request2.head.sha) ?? null
237
+ prNumber: payload?.pull_request?.number || null,
238
+ prHeadCommit: payload?.pull_request?.head.sha ?? null
240
239
  };
241
240
  }
242
241
  };
@@ -495,21 +494,21 @@ async function readConfig(options = {}) {
495
494
  const ciEnv = await getCiEnvironment();
496
495
  config.load({
497
496
  apiBaseUrl: options.apiBaseUrl || config.get("apiBaseUrl"),
498
- commit: options.commit || config.get("commit") || (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.commit) || null,
499
- branch: options.branch || config.get("branch") || (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.branch) || null,
497
+ commit: options.commit || config.get("commit") || ciEnv?.commit || null,
498
+ branch: options.branch || config.get("branch") || ciEnv?.branch || null,
500
499
  token: options.token || config.get("token") || null,
501
500
  buildName: options.buildName || config.get("buildName") || null,
502
- prNumber: options.prNumber || config.get("prNumber") || (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prNumber) || null,
503
- prHeadCommit: config.get("prHeadCommit") || (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prHeadCommit) || null,
501
+ prNumber: options.prNumber || config.get("prNumber") || ciEnv?.prNumber || null,
502
+ prHeadCommit: config.get("prHeadCommit") || ciEnv?.prHeadCommit || null,
504
503
  referenceBranch: options.referenceBranch || config.get("referenceBranch") || null,
505
504
  referenceCommit: options.referenceCommit || config.get("referenceCommit") || null,
506
- ciService: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.name) || null,
507
- owner: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.owner) || null,
508
- repository: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.repository) || null,
509
- jobId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.jobId) || null,
510
- runId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.runId) || null,
505
+ ciService: ciEnv?.name || null,
506
+ owner: ciEnv?.owner || null,
507
+ repository: ciEnv?.repository || null,
508
+ jobId: ciEnv?.jobId || null,
509
+ runId: ciEnv?.runId || null,
511
510
  parallel: options.parallel ?? config.get("parallel") ?? false,
512
- parallelNonce: options.parallelNonce || config.get("parallelNonce") || (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.nonce) || null,
511
+ parallelNonce: options.parallelNonce || config.get("parallelNonce") || ciEnv?.nonce || null,
513
512
  parallelTotal: options.parallelTotal || config.get("parallelTotal") || null
514
513
  });
515
514
  config.validate();
@@ -612,8 +611,7 @@ const createArgosApiClient = (options)=>{
612
611
  });
613
612
  return response.data;
614
613
  } catch (error) {
615
- var _error_response_data_error, _error_response_data, _error_response;
616
- if (error === null || error === void 0 ? void 0 : (_error_response = error.response) === null || _error_response === void 0 ? void 0 : (_error_response_data = _error_response.data) === null || _error_response_data === void 0 ? void 0 : (_error_response_data_error = _error_response_data.error) === null || _error_response_data_error === void 0 ? void 0 : _error_response_data_error.message) {
614
+ if (error?.response?.data?.error?.message) {
617
615
  // @ts-ignore
618
616
  throw new Error(error.response.data.error.message, {
619
617
  cause: error
@@ -678,7 +676,11 @@ async function uploadFilesToS3(files) {
678
676
  debug(`Uploading chunk ${i + 1}/${chunks.length}`);
679
677
  const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
680
678
  debugTime(timeLabel);
681
- await Promise.all(chunks[i].map(async ({ url, path, contentType })=>{
679
+ const chunk = chunks[i];
680
+ if (!chunk) {
681
+ throw new Error(`Invariant: chunk ${i} is empty`);
682
+ }
683
+ await Promise.all(chunk.map(async ({ url, path, contentType })=>{
682
684
  await upload$1({
683
685
  url,
684
686
  path,
@@ -691,7 +693,6 @@ async function uploadFilesToS3(files) {
691
693
  /**
692
694
  * Upload screenshots to argos-ci.com.
693
695
  */ async function upload(params) {
694
- var _result_pwTraces;
695
696
  debug("Starting upload with params", params);
696
697
  // Read config
697
698
  const config = await getConfigFromOptions(params);
@@ -774,7 +775,7 @@ async function uploadFilesToS3(files) {
774
775
  contentType: "image/png"
775
776
  };
776
777
  }),
777
- ...((_result_pwTraces = result.pwTraces) === null || _result_pwTraces === void 0 ? void 0 : _result_pwTraces.map(({ key, putUrl })=>{
778
+ ...result.pwTraces?.map(({ key, putUrl })=>{
778
779
  const screenshot = screenshots.find((s)=>s.pwTrace && s.pwTrace.hash === key);
779
780
  if (!screenshot || !screenshot.pwTrace) {
780
781
  throw new Error(`Invariant: trace with ${key} not found`);
@@ -784,22 +785,19 @@ async function uploadFilesToS3(files) {
784
785
  path: screenshot.pwTrace.path,
785
786
  contentType: "application/json"
786
787
  };
787
- })) ?? []
788
+ }) ?? []
788
789
  ];
789
790
  await uploadFilesToS3(uploadFiles);
790
791
  // Update build
791
792
  debug("Updating build");
792
793
  await apiClient.updateBuild({
793
794
  buildId: result.build.id,
794
- screenshots: screenshots.map((screenshot)=>{
795
- var _screenshot_pwTrace;
796
- return {
795
+ screenshots: screenshots.map((screenshot)=>({
797
796
  key: screenshot.hash,
798
797
  name: screenshot.name,
799
798
  metadata: screenshot.metadata,
800
- pwTraceKey: ((_screenshot_pwTrace = screenshot.pwTrace) === null || _screenshot_pwTrace === void 0 ? void 0 : _screenshot_pwTrace.hash) ?? null
801
- };
802
- }),
799
+ pwTraceKey: screenshot.pwTrace?.hash ?? null
800
+ })),
803
801
  parallel: config.parallel,
804
802
  parallelTotal: config.parallelTotal
805
803
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
4
- "version": "1.5.5",
4
+ "version": "2.1.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "types": "./dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/argos-ci/argos-javascript/issues"
25
25
  },
26
26
  "engines": {
27
- "node": ">=16.0.0"
27
+ "node": ">=18.0.0"
28
28
  },
29
29
  "license": "MIT",
30
30
  "keywords": [
@@ -40,24 +40,24 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/util": "1.2.1",
44
- "axios": "^1.5.0",
43
+ "@argos-ci/util": "2.0.0",
44
+ "axios": "^1.6.8",
45
45
  "convict": "^6.2.4",
46
46
  "debug": "^4.3.4",
47
- "fast-glob": "^3.3.1",
48
- "sharp": "^0.32.5",
49
- "tmp": "^0.2.1"
47
+ "fast-glob": "^3.3.2",
48
+ "sharp": "^0.33.3",
49
+ "tmp": "^0.2.3"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/convict": "^6.1.4",
52
+ "@types/convict": "^6.1.6",
53
53
  "@types/debug": "^4.1.12",
54
- "@types/tmp": "^0.2.3",
55
- "msw": "^1.3.0"
54
+ "@types/tmp": "^0.2.6",
55
+ "msw": "^2.2.13"
56
56
  },
57
57
  "scripts": {
58
58
  "prebuild": "rm -rf dist",
59
59
  "build": "rollup -c",
60
60
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
61
61
  },
62
- "gitHead": "4da90d82cfb93a1377497731164b9fbaeb9fb7f6"
62
+ "gitHead": "1d91294d32a09302aa8890807ddd810e14e9950b"
63
63
  }