@squiz/component-cli-lib 1.32.1-alpha.7 → 1.32.1-alpha.9

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": "@squiz/component-cli-lib",
3
- "version": "1.32.1-alpha.7",
3
+ "version": "1.32.1-alpha.9",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -13,12 +13,12 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "devDependencies": {
16
- "@squiz/component-lib": "1.32.1-alpha.7",
17
- "@squiz/component-web-api-lib": "1.32.1-alpha.7",
18
- "@squiz/dx-common-lib": "1.32.1-alpha.7",
19
- "@squiz/dx-json-schema-lib": "1.32.1-alpha.7",
20
- "@squiz/dx-logger-lib": "1.32.1-alpha.7",
21
- "@squiz/virus-scanner-lib": "1.32.1-alpha.7",
16
+ "@squiz/component-lib": "1.32.1-alpha.9",
17
+ "@squiz/component-web-api-lib": "1.32.1-alpha.9",
18
+ "@squiz/dx-common-lib": "1.32.1-alpha.9",
19
+ "@squiz/dx-json-schema-lib": "1.32.1-alpha.9",
20
+ "@squiz/dx-logger-lib": "1.32.1-alpha.9",
21
+ "@squiz/virus-scanner-lib": "1.32.1-alpha.9",
22
22
  "@types/cli-color": "2.0.2",
23
23
  "@types/express": "4.17.17",
24
24
  "@types/jest": "28.1.8",
@@ -32,12 +32,12 @@
32
32
  "typescript": "4.9.4"
33
33
  },
34
34
  "dependencies": {
35
- "@squiz/render-runtime-lib": "1.32.1-alpha.7",
35
+ "@squiz/render-runtime-lib": "1.32.1-alpha.9",
36
36
  "archiver": "5.3.1",
37
37
  "axios": "1.3.2",
38
38
  "cli-color": "^2.0.2",
39
39
  "open": "^8.4.0",
40
40
  "supertest": "^6.2.3"
41
41
  },
42
- "gitHead": "7a8dbe890700b2df2f6194aff44a569267f32d35"
42
+ "gitHead": "61f757e6b67833114010b04397303c1cd41a180d"
43
43
  }
@@ -19,7 +19,12 @@ export async function uploadComponentFolder(
19
19
  const tmpDir = await fsp.mkdtemp(path.resolve(baseTempDir, 'cmp-upload'));
20
20
 
21
21
  try {
22
- await preUploadChecks(apiClient, componentServiceManagementUrl, folderPath);
22
+ const manifestService = new ManifestServiceForDev(folderPath, logger);
23
+ const manifestPath = path.join(folderPath, `manifest.json`);
24
+ const manifest = await manifestService.readManifest(manifestPath);
25
+ await manifestService.assertManifestIsValid(manifestPath, manifest.getModel());
26
+
27
+ await preUploadChecks(apiClient, componentServiceManagementUrl, manifest);
23
28
  logger.info('Initial scanning');
24
29
  const zip = await zipDirectory(folderPath, tmpDir);
25
30
 
@@ -39,28 +44,27 @@ export async function uploadComponentFolder(
39
44
  apiClient.post(`/v1/upload-component/next/${initialUpload.id}`, {}, { baseURL: componentServiceManagementUrl }),
40
45
  );
41
46
 
42
- if (result.toString().includes('504 Gateway Time-out')) {
43
- let retriesAllowed = 3;
44
- while (retriesAllowed > 0 && result.toString().includes('504 Gateway Time-out')) {
47
+ if (!isAxiosResponse(result)) {
48
+ let retriesAllowed = 12;
49
+ while (retriesAllowed > 0) {
45
50
  logger.info(
46
51
  `deployment id: ${initialUpload.id} status: ${color.yellow(
47
- `timed out, retrying ${retriesAllowed} more times`,
52
+ `unknown, retrying to check the upload status ${retriesAllowed} more times`,
48
53
  )}`,
49
54
  );
50
- result = await handleResponse<any>(
51
- apiClient.post(
52
- `/v1/upload-component/next/${initialUpload.id}`,
53
- {},
54
- {
55
- baseURL: componentServiceManagementUrl,
56
- },
57
- ),
58
- );
55
+ if (await checkIfVersionExists(apiClient, componentServiceManagementUrl, manifest)) {
56
+ result = {
57
+ status: 'successful',
58
+ accessLink: 'unknown',
59
+ };
60
+ break;
61
+ }
62
+ await new Promise((r) => setTimeout(r, 10000));
59
63
  retriesAllowed--;
60
64
  }
61
65
  if (retriesAllowed === 0) {
62
- logger.error(`deployment id: ${initialUpload.id} status: ${color.red('failed due to timeout')}`);
63
- throw new Error('504 Gateway Time-out');
66
+ logger.error(`deployment id: ${initialUpload.id} status: ${color.red('failed to check the upload status')}`);
67
+ throw new Error(result.toString());
64
68
  }
65
69
  }
66
70
 
@@ -86,16 +90,9 @@ export async function uploadComponentFolder(
86
90
  }
87
91
  }
88
92
 
89
- async function preUploadChecks(apiClient: AxiosInstance, managementURL: string, folderPath: string) {
90
- const service = new ManifestServiceForDev(folderPath, logger);
91
- const manifestPath = path.join(folderPath, `manifest.json`);
92
-
93
- const result = await service.readManifest(manifestPath);
94
-
95
- await service.assertManifestIsValid(manifestPath, result.getModel());
96
-
97
- if (await checkIfVersionExists(apiClient, managementURL, result)) {
98
- throw new Error(`Cannot upload component version, ${result.getName()} ${result.getVersion()} already exists`);
93
+ async function preUploadChecks(apiClient: AxiosInstance, managementURL: string, manifest: Manifest) {
94
+ if (await checkIfVersionExists(apiClient, managementURL, manifest)) {
95
+ throw new Error(`Cannot upload component version, ${manifest.getName()} ${manifest.getVersion()} already exists`);
99
96
  }
100
97
  }
101
98
 
@@ -185,3 +182,7 @@ function handleError(error: any): Error {
185
182
  function isAxiosError(error: any): error is AxiosError {
186
183
  return error && error.isAxiosError === true;
187
184
  }
185
+
186
+ function isAxiosResponse(response: unknown): response is AxiosResponse {
187
+ return response instanceof Object && Object.prototype.hasOwnProperty.call(response, 'status');
188
+ }