@cenk1cenk2/oclif-common 6.3.0 → 6.3.2

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/dist/index.d.ts CHANGED
@@ -255,22 +255,22 @@ declare class LockerService<LockFile extends LockableData = LockableData> {
255
255
  constructor(logger: LoggerService, fs: FileSystemService, parser: ParserService, options: LockerServiceOptions);
256
256
  hasLock(): boolean;
257
257
  hasUnlock(): boolean;
258
- addLock<T extends LockableData = LockFile>(...data: LockData<T>[]): void;
258
+ addLock(...data: LockData<LockFile>[]): void;
259
259
  addUnlock(...data: UnlockData[]): void;
260
- applyLockAll<T extends LockableData = LockFile>(lock: T): Promise<T>;
260
+ applyLockAll(lock: LockFile): Promise<LockFile>;
261
261
  lockAll(): Promise<void>;
262
- applyUnlockAll<T extends LockableData = LockFile>(lock: T): Promise<T>;
262
+ applyUnlockAll(lock: LockFile): Promise<LockFile>;
263
263
  unlockAll(): Promise<void>;
264
264
  all(): Promise<void>;
265
- applyAll<T extends LockableData = LockFile>(lock: T): Promise<T>;
266
- applyLock<T extends LockableData = LockFile>(lock: T, ...data: LockData<T>[]): Promise<T>;
267
- lock<T extends LockableData = LockFile>(...data: LockData<T>[]): Promise<T>;
268
- applyUnlock<T extends LockableData = LockFile>(lock: T, ...data: UnlockData[]): Promise<T | undefined>;
269
- unlock<T extends LockableData = LockFile>(...data: UnlockData[]): Promise<T | undefined>;
270
- read<T extends LockableData = LockFile>(): Promise<T>;
271
- tryRead<T extends LockableData = LockFile>(): Promise<T | undefined>;
265
+ applyAll(lock: LockFile): Promise<LockFile>;
266
+ applyLock(lock: LockFile, ...data: LockData<LockFile>[]): Promise<LockFile>;
267
+ lock(...data: LockData<LockFile>[]): Promise<LockFile>;
268
+ applyUnlock(lock: LockFile, ...data: UnlockData[]): Promise<LockFile>;
269
+ unlock(...data: UnlockData[]): Promise<LockFile | undefined>;
270
+ read(): Promise<LockFile>;
271
+ tryRead(): Promise<LockFile | undefined>;
272
272
  tryRemove(): Promise<void>;
273
- write<T extends LockableData = LockFile>(data: T): Promise<void>;
273
+ write(data: LockFile): Promise<void>;
274
274
  private buildPath;
275
275
  private normalizePath;
276
276
  }
package/dist/index.js CHANGED
@@ -1224,16 +1224,10 @@ var _LockerService = class _LockerService {
1224
1224
  return this.toUnlock.length > 0;
1225
1225
  }
1226
1226
  addLock(...data) {
1227
- this.toLock = [
1228
- ...this.toLock,
1229
- ...data
1230
- ];
1227
+ this.toLock.push(...data);
1231
1228
  }
1232
1229
  addUnlock(...data) {
1233
- this.toUnlock = [
1234
- ...this.toUnlock,
1235
- ...data
1236
- ];
1230
+ this.toUnlock.push(...data);
1237
1231
  }
1238
1232
  async applyLockAll(lock) {
1239
1233
  if (this.hasLock()) {
@@ -1294,14 +1288,11 @@ var _LockerService = class _LockerService {
1294
1288
  return lock;
1295
1289
  }
1296
1290
  async lock(...data) {
1297
- const lock = this.applyLock(await this.tryRead() ?? {}, ...data);
1291
+ const lock = await this.applyLock(await this.tryRead() ?? {}, ...data);
1298
1292
  await this.write(lock);
1299
1293
  return lock;
1300
1294
  }
1301
1295
  async applyUnlock(lock, ...data) {
1302
- if (!lock) {
1303
- return;
1304
- }
1305
1296
  if (data.length > 0) {
1306
1297
  data.forEach((d) => {
1307
1298
  if (d?.enabled === false) {
@@ -1321,17 +1312,19 @@ var _LockerService = class _LockerService {
1321
1312
  }
1322
1313
  }
1323
1314
  });
1324
- } else {
1325
- lock = op2.del(lock, this.options.root);
1326
- this.logger.verbose("Unlocked module: %s", this.options.root);
1315
+ return lock;
1327
1316
  }
1317
+ lock = op2.del(lock, this.options.root);
1318
+ this.logger.verbose("Unlocked module: %s", this.options.root);
1319
+ return lock;
1328
1320
  }
1329
1321
  async unlock(...data) {
1330
- const lock = await this.applyUnlock(await this.tryRead(), ...data);
1331
- if (!lock) {
1322
+ const state = await this.tryRead();
1323
+ if (!state) {
1332
1324
  this.logger.verbose("Lock file not found. Nothing to unlock.");
1333
1325
  return;
1334
1326
  }
1327
+ const lock = await this.applyUnlock(state, ...data);
1335
1328
  await this.write(lock);
1336
1329
  return lock;
1337
1330
  }
@@ -1339,18 +1332,20 @@ var _LockerService = class _LockerService {
1339
1332
  return this.parser.fetch(this.options.parser).parse(await this.fs.read(this.options.file));
1340
1333
  }
1341
1334
  async tryRead() {
1342
- try {
1343
- return this.parser.fetch(this.options.parser).parse(await this.fs.read(this.options.file));
1344
- } catch {
1345
- this.logger.trace("Can not read lockfile: %s", this.options.file);
1335
+ const lock = await this.fs.read(this.options.file).catch((err) => {
1336
+ this.logger.trace("Can not read lockfile: %s -> %s", this.options.file, err.message);
1337
+ });
1338
+ if (!lock) {
1339
+ return;
1346
1340
  }
1341
+ return this.parser.fetch(this.options.parser).parse(lock);
1347
1342
  }
1348
1343
  async tryRemove() {
1349
- try {
1350
- await this.fs.remove(this.options.file);
1351
- } catch {
1352
- this.logger.trace("Can not remove lockfile: %s", this.options.file);
1353
- }
1344
+ return this.fs.remove(this.options.file).then(() => {
1345
+ this.logger.trace("Removed lockfile: %s", this.options.file);
1346
+ }).catch((err) => {
1347
+ this.logger.trace("Can not remove lockfile: %s -> %s", this.options.file, err.message);
1348
+ });
1354
1349
  }
1355
1350
  async write(data) {
1356
1351
  if (!data || Array.isArray(data) && data.length === 0 || typeof data === "object" && Object.keys(data).length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "6.3.0",
3
+ "version": "6.3.2",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "type": "module",