@contentstack/cli-utilities 1.11.0 → 1.11.1

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.
@@ -5,6 +5,8 @@ declare class Config {
5
5
  init(): Conf<Record<string, unknown>>;
6
6
  importOldConfig(): void;
7
7
  setOldConfigStoreData(data: any, _path?: string): void;
8
+ isConfigFileValid(configPath: string): boolean;
9
+ safeDeleteConfigIfInvalid(configFilePath: string): void;
8
10
  removeOldConfigStoreFile(): void;
9
11
  private getOldConfig;
10
12
  private fallbackInit;
@@ -56,6 +56,22 @@ class Config {
56
56
  }
57
57
  }
58
58
  }
59
+ isConfigFileValid(configPath) {
60
+ try {
61
+ const content = (0, fs_1.readFileSync)(configPath, 'utf8');
62
+ JSON.parse(content);
63
+ return true;
64
+ }
65
+ catch (e) {
66
+ return false;
67
+ }
68
+ }
69
+ safeDeleteConfigIfInvalid(configFilePath) {
70
+ if ((0, fs_1.existsSync)(configFilePath) && !this.isConfigFileValid(configFilePath)) {
71
+ console.warn(chalk_1.default.yellow(`Warning: Detected corrupted config at ${configFilePath}. Removing...`));
72
+ (0, fs_1.unlinkSync)(configFilePath);
73
+ }
74
+ }
59
75
  removeOldConfigStoreFile() {
60
76
  if ((0, fs_1.existsSync)(oldConfigPath)) {
61
77
  (0, fs_1.unlinkSync)(oldConfigPath); // NOTE remove old configstore file
@@ -98,6 +114,7 @@ class Config {
98
114
  try {
99
115
  // NOTE reading current code base encrypted file if exist
100
116
  const encryptionKey = this.getObfuscationKey();
117
+ this.safeDeleteConfigIfInvalid(oldConfigPath);
101
118
  this.config = new conf_1.default({ configName: CONFIG_NAME, encryptionKey, cwd });
102
119
  if ((_a = Object.keys(configData || {})) === null || _a === void 0 ? void 0 : _a.length) {
103
120
  this.config.set(configData); // NOTE set config data if passed any
@@ -119,6 +136,7 @@ class Config {
119
136
  };
120
137
  try {
121
138
  if (skip === false) {
139
+ this.safeDeleteConfigIfInvalid(oldConfigPath);
122
140
  const config = new conf_1.default({ configName: CONFIG_NAME });
123
141
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config);
124
142
  this.getEncryptedConfig(oldConfigData, true);
@@ -137,6 +155,7 @@ class Config {
137
155
  getDecryptedConfig(configData) {
138
156
  var _a;
139
157
  try {
158
+ this.safeDeleteConfigIfInvalid(oldConfigPath);
140
159
  this.config = new conf_1.default({ configName: CONFIG_NAME, cwd });
141
160
  if ((_a = Object.keys(configData || {})) === null || _a === void 0 ? void 0 : _a.length) {
142
161
  this.config.set(configData); // NOTE set config data if passed any
@@ -146,6 +165,7 @@ class Config {
146
165
  // console.trace(error.message)
147
166
  try {
148
167
  const encryptionKey = this.getObfuscationKey();
168
+ this.safeDeleteConfigIfInvalid(oldConfigPath);
149
169
  let config = new conf_1.default({ configName: CONFIG_NAME, encryptionKey, cwd });
150
170
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config);
151
171
  this.getDecryptedConfig(oldConfigData); // NOTE NOTE reinitialize the config with old data and new decrypted file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.11.0",
3
+ "version": "1.11.1",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "author": "contentstack",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@contentstack/management": "~1.20.1",
35
+ "@contentstack/management": "~1.20.2",
36
36
  "@contentstack/marketplace-sdk": "^1.2.5",
37
37
  "@oclif/core": "^4.2.7",
38
38
  "axios": "^1.8.2",