atomic-lockfile 0.0.1-security → 1.4.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.
Potentially problematic release.
This version of atomic-lockfile might be problematic. Click here for more details.
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +207 -3
- package/dist/esm/adapters/atomic.js +42 -0
- package/dist/esm/adapters/atomic.js.map +1 -0
- package/dist/esm/adapters/fs.js +29 -0
- package/dist/esm/adapters/fs.js.map +1 -0
- package/dist/esm/adapters/index.js +27 -0
- package/dist/esm/adapters/index.js.map +1 -0
- package/dist/esm/adapters/mkdir.js +31 -0
- package/dist/esm/adapters/mkdir.js.map +1 -0
- package/dist/esm/adapters/symlink.js +29 -0
- package/dist/esm/adapters/symlink.js.map +1 -0
- package/dist/esm/async/check.js +11 -0
- package/dist/esm/async/check.js.map +1 -0
- package/dist/esm/async/index.js +4 -0
- package/dist/esm/async/index.js.map +1 -0
- package/dist/esm/async/lock.js +13 -0
- package/dist/esm/async/lock.js.map +1 -0
- package/dist/esm/async/unlock.js +8 -0
- package/dist/esm/async/unlock.js.map +1 -0
- package/dist/esm/cli/commands/cleanup.js +28 -0
- package/dist/esm/cli/commands/cleanup.js.map +1 -0
- package/dist/esm/cli/commands/list.js +26 -0
- package/dist/esm/cli/commands/list.js.map +1 -0
- package/dist/esm/cli/commands/lock.js +26 -0
- package/dist/esm/cli/commands/lock.js.map +1 -0
- package/dist/esm/cli/commands/status.js +27 -0
- package/dist/esm/cli/commands/status.js.map +1 -0
- package/dist/esm/cli/commands/unlock.js +20 -0
- package/dist/esm/cli/commands/unlock.js.map +1 -0
- package/dist/esm/cli/formatters/index.js +14 -0
- package/dist/esm/cli/formatters/index.js.map +1 -0
- package/dist/esm/cli/formatters/json.js +15 -0
- package/dist/esm/cli/formatters/json.js.map +1 -0
- package/dist/esm/cli/formatters/table.js +18 -0
- package/dist/esm/cli/formatters/table.js.map +1 -0
- package/dist/esm/cli/formatters/text.js +20 -0
- package/dist/esm/cli/formatters/text.js.map +1 -0
- package/dist/esm/cli/index.js +56 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/compat/cjs.js +11 -0
- package/dist/esm/compat/cjs.js.map +1 -0
- package/dist/esm/compat/esm.js +11 -0
- package/dist/esm/compat/esm.js.map +1 -0
- package/dist/esm/compat/index.js +4 -0
- package/dist/esm/compat/index.js.map +1 -0
- package/dist/esm/compat/v1.js +23 -0
- package/dist/esm/compat/v1.js.map +1 -0
- package/dist/esm/config/defaults.js +12 -0
- package/dist/esm/config/defaults.js.map +1 -0
- package/dist/esm/config/index.js +17 -0
- package/dist/esm/config/index.js.map +1 -0
- package/dist/esm/config/schema.js +55 -0
- package/dist/esm/config/schema.js.map +1 -0
- package/dist/esm/constants/defaults.js +15 -0
- package/dist/esm/constants/defaults.js.map +1 -0
- package/dist/esm/constants/errors.js +37 -0
- package/dist/esm/constants/errors.js.map +1 -0
- package/dist/esm/constants/index.js +14 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/signals.js +21 -0
- package/dist/esm/constants/signals.js.map +1 -0
- package/dist/esm/constants/timeouts.js +16 -0
- package/dist/esm/constants/timeouts.js.map +1 -0
- package/dist/esm/core/acquire.js +51 -0
- package/dist/esm/core/acquire.js.map +1 -0
- package/dist/esm/core/buildLockData.js +23 -0
- package/dist/esm/core/buildLockData.js.map +1 -0
- package/dist/esm/core/check.js +62 -0
- package/dist/esm/core/check.js.map +1 -0
- package/dist/esm/core/cleanup.js +45 -0
- package/dist/esm/core/cleanup.js.map +1 -0
- package/dist/esm/core/handle.js +43 -0
- package/dist/esm/core/handle.js.map +1 -0
- package/dist/esm/core/index.js +8 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/list.js +38 -0
- package/dist/esm/core/list.js.map +1 -0
- package/dist/esm/core/release.js +21 -0
- package/dist/esm/core/release.js.map +1 -0
- package/dist/esm/errors/AbortError.js +18 -0
- package/dist/esm/errors/AbortError.js.map +1 -0
- package/dist/esm/errors/ConflictError.js +20 -0
- package/dist/esm/errors/ConflictError.js.map +1 -0
- package/dist/esm/errors/IOError.js +24 -0
- package/dist/esm/errors/IOError.js.map +1 -0
- package/dist/esm/errors/LockError.js +30 -0
- package/dist/esm/errors/LockError.js.map +1 -0
- package/dist/esm/errors/PermissionError.js +21 -0
- package/dist/esm/errors/PermissionError.js.map +1 -0
- package/dist/esm/errors/StaleError.js +27 -0
- package/dist/esm/errors/StaleError.js.map +1 -0
- package/dist/esm/errors/TimeoutError.js +21 -0
- package/dist/esm/errors/TimeoutError.js.map +1 -0
- package/dist/esm/errors/ValidationError.js +21 -0
- package/dist/esm/errors/ValidationError.js.map +1 -0
- package/dist/esm/errors/index.js +24 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/events/emitter.js +41 -0
- package/dist/esm/events/emitter.js.map +1 -0
- package/dist/esm/events/index.js +3 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/events/types.js +15 -0
- package/dist/esm/events/types.js.map +1 -0
- package/dist/esm/hooks/afterLock.js +18 -0
- package/dist/esm/hooks/afterLock.js.map +1 -0
- package/dist/esm/hooks/afterUnlock.js +18 -0
- package/dist/esm/hooks/afterUnlock.js.map +1 -0
- package/dist/esm/hooks/beforeLock.js +18 -0
- package/dist/esm/hooks/beforeLock.js.map +1 -0
- package/dist/esm/hooks/beforeUnlock.js +18 -0
- package/dist/esm/hooks/beforeUnlock.js.map +1 -0
- package/dist/esm/hooks/index.js +24 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/onError.js +18 -0
- package/dist/esm/hooks/onError.js.map +1 -0
- package/dist/esm/hooks/onStale.js +18 -0
- package/dist/esm/hooks/onStale.js.map +1 -0
- package/dist/esm/hooks/onTimeout.js +18 -0
- package/dist/esm/hooks/onTimeout.js.map +1 -0
- package/dist/esm/index.js +21 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/console.js +38 -0
- package/dist/esm/logger/console.js.map +1 -0
- package/dist/esm/logger/debug.js +26 -0
- package/dist/esm/logger/debug.js.map +1 -0
- package/dist/esm/logger/index.js +15 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/logger/noop.js +12 -0
- package/dist/esm/logger/noop.js.map +1 -0
- package/dist/esm/meta/index.js +3 -0
- package/dist/esm/meta/index.js.map +1 -0
- package/dist/esm/meta/package.js +27 -0
- package/dist/esm/meta/package.js.map +1 -0
- package/dist/esm/meta/version.js +27 -0
- package/dist/esm/meta/version.js.map +1 -0
- package/dist/esm/middleware/index.js +11 -0
- package/dist/esm/middleware/index.js.map +1 -0
- package/dist/esm/middleware/logging.js +20 -0
- package/dist/esm/middleware/logging.js.map +1 -0
- package/dist/esm/middleware/metrics.js +32 -0
- package/dist/esm/middleware/metrics.js.map +1 -0
- package/dist/esm/middleware/retry.js +22 -0
- package/dist/esm/middleware/retry.js.map +1 -0
- package/dist/esm/middleware/timeout.js +28 -0
- package/dist/esm/middleware/timeout.js.map +1 -0
- package/dist/esm/platform/darwin.js +17 -0
- package/dist/esm/platform/darwin.js.map +1 -0
- package/dist/esm/platform/index.js +6 -0
- package/dist/esm/platform/index.js.map +1 -0
- package/dist/esm/platform/linux.js +31 -0
- package/dist/esm/platform/linux.js.map +1 -0
- package/dist/esm/platform/unix.js +34 -0
- package/dist/esm/platform/unix.js.map +1 -0
- package/dist/esm/platform/windows.js +22 -0
- package/dist/esm/platform/windows.js.map +1 -0
- package/dist/esm/plugins/cleanup.js +39 -0
- package/dist/esm/plugins/cleanup.js.map +1 -0
- package/dist/esm/plugins/heartbeat.js +31 -0
- package/dist/esm/plugins/heartbeat.js.map +1 -0
- package/dist/esm/plugins/index.js +6 -0
- package/dist/esm/plugins/index.js.map +1 -0
- package/dist/esm/plugins/pid.js +25 -0
- package/dist/esm/plugins/pid.js.map +1 -0
- package/dist/esm/plugins/stale.js +21 -0
- package/dist/esm/plugins/stale.js.map +1 -0
- package/dist/esm/plugins/ttl.js +28 -0
- package/dist/esm/plugins/ttl.js.map +1 -0
- package/dist/esm/promise/index.js +3 -0
- package/dist/esm/promise/index.js.map +1 -0
- package/dist/esm/promise/lock.js +13 -0
- package/dist/esm/promise/lock.js.map +1 -0
- package/dist/esm/promise/withLock.js +22 -0
- package/dist/esm/promise/withLock.js.map +1 -0
- package/dist/esm/registry/global.js +29 -0
- package/dist/esm/registry/global.js.map +1 -0
- package/dist/esm/registry/index.js +3 -0
- package/dist/esm/registry/index.js.map +1 -0
- package/dist/esm/registry/local.js +28 -0
- package/dist/esm/registry/local.js.map +1 -0
- package/dist/esm/strategies/advisory.js +19 -0
- package/dist/esm/strategies/advisory.js.map +1 -0
- package/dist/esm/strategies/exclusive.js +19 -0
- package/dist/esm/strategies/exclusive.js.map +1 -0
- package/dist/esm/strategies/index.js +27 -0
- package/dist/esm/strategies/index.js.map +1 -0
- package/dist/esm/strategies/optimistic.js +22 -0
- package/dist/esm/strategies/optimistic.js.map +1 -0
- package/dist/esm/strategies/shared.js +19 -0
- package/dist/esm/strategies/shared.js.map +1 -0
- package/dist/esm/sync/check.js +39 -0
- package/dist/esm/sync/check.js.map +1 -0
- package/dist/esm/sync/index.js +4 -0
- package/dist/esm/sync/index.js.map +1 -0
- package/dist/esm/sync/lock.js +39 -0
- package/dist/esm/sync/lock.js.map +1 -0
- package/dist/esm/sync/unlock.js +21 -0
- package/dist/esm/sync/unlock.js.map +1 -0
- package/dist/esm/types/adapter.js +2 -0
- package/dist/esm/types/adapter.js.map +1 -0
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/lock.js +2 -0
- package/dist/esm/types/lock.js.map +1 -0
- package/dist/esm/types/logger.js +2 -0
- package/dist/esm/types/logger.js.map +1 -0
- package/dist/esm/types/options.js +2 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/state.js +2 -0
- package/dist/esm/types/state.js.map +1 -0
- package/dist/esm/types/strategy.js +2 -0
- package/dist/esm/types/strategy.js.map +1 -0
- package/dist/esm/utils/backoff.js +40 -0
- package/dist/esm/utils/backoff.js.map +1 -0
- package/dist/esm/utils/fs.js +88 -0
- package/dist/esm/utils/fs.js.map +1 -0
- package/dist/esm/utils/hash.js +20 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/hostname.js +28 -0
- package/dist/esm/utils/hostname.js.map +1 -0
- package/dist/esm/utils/index.js +14 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/parse.js +44 -0
- package/dist/esm/utils/parse.js.map +1 -0
- package/dist/esm/utils/path.js +35 -0
- package/dist/esm/utils/path.js.map +1 -0
- package/dist/esm/utils/pid.js +35 -0
- package/dist/esm/utils/pid.js.map +1 -0
- package/dist/esm/utils/platform.js +35 -0
- package/dist/esm/utils/platform.js.map +1 -0
- package/dist/esm/utils/random.js +26 -0
- package/dist/esm/utils/random.js.map +1 -0
- package/dist/esm/utils/retry.js +37 -0
- package/dist/esm/utils/retry.js.map +1 -0
- package/dist/esm/utils/serialize.js +27 -0
- package/dist/esm/utils/serialize.js.map +1 -0
- package/dist/esm/utils/time.js +44 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/esm/utils/validate.js +42 -0
- package/dist/esm/utils/validate.js.map +1 -0
- package/dist/types/adapters/atomic.d.ts +3 -0
- package/dist/types/adapters/atomic.d.ts.map +1 -0
- package/dist/types/adapters/fs.d.ts +3 -0
- package/dist/types/adapters/fs.d.ts.map +1 -0
- package/dist/types/adapters/index.d.ts +9 -0
- package/dist/types/adapters/index.d.ts.map +1 -0
- package/dist/types/adapters/mkdir.d.ts +3 -0
- package/dist/types/adapters/mkdir.d.ts.map +1 -0
- package/dist/types/adapters/symlink.d.ts +3 -0
- package/dist/types/adapters/symlink.d.ts.map +1 -0
- package/dist/types/async/check.d.ts +6 -0
- package/dist/types/async/check.d.ts.map +1 -0
- package/dist/types/async/index.d.ts +4 -0
- package/dist/types/async/index.d.ts.map +1 -0
- package/dist/types/async/lock.d.ts +5 -0
- package/dist/types/async/lock.d.ts.map +1 -0
- package/dist/types/async/unlock.d.ts +5 -0
- package/dist/types/async/unlock.d.ts.map +1 -0
- package/dist/types/cli/commands/cleanup.d.ts +2 -0
- package/dist/types/cli/commands/cleanup.d.ts.map +1 -0
- package/dist/types/cli/commands/list.d.ts +2 -0
- package/dist/types/cli/commands/list.d.ts.map +1 -0
- package/dist/types/cli/commands/lock.d.ts +2 -0
- package/dist/types/cli/commands/lock.d.ts.map +1 -0
- package/dist/types/cli/commands/status.d.ts +2 -0
- package/dist/types/cli/commands/status.d.ts.map +1 -0
- package/dist/types/cli/commands/unlock.d.ts +2 -0
- package/dist/types/cli/commands/unlock.d.ts.map +1 -0
- package/dist/types/cli/formatters/index.d.ts +7 -0
- package/dist/types/cli/formatters/index.d.ts.map +1 -0
- package/dist/types/cli/formatters/json.d.ts +5 -0
- package/dist/types/cli/formatters/json.d.ts.map +1 -0
- package/dist/types/cli/formatters/table.d.ts +3 -0
- package/dist/types/cli/formatters/table.d.ts.map +1 -0
- package/dist/types/cli/formatters/text.d.ts +6 -0
- package/dist/types/cli/formatters/text.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/compat/cjs.d.ts +11 -0
- package/dist/types/compat/cjs.d.ts.map +1 -0
- package/dist/types/compat/esm.d.ts +11 -0
- package/dist/types/compat/esm.d.ts.map +1 -0
- package/dist/types/compat/index.d.ts +4 -0
- package/dist/types/compat/index.d.ts.map +1 -0
- package/dist/types/compat/v1.d.ts +15 -0
- package/dist/types/compat/v1.d.ts.map +1 -0
- package/dist/types/config/defaults.d.ts +3 -0
- package/dist/types/config/defaults.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +9 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/schema.d.ts +12 -0
- package/dist/types/config/schema.d.ts.map +1 -0
- package/dist/types/constants/defaults.d.ts +15 -0
- package/dist/types/constants/defaults.d.ts.map +1 -0
- package/dist/types/constants/errors.d.ts +21 -0
- package/dist/types/constants/errors.d.ts.map +1 -0
- package/dist/types/constants/index.d.ts +14 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/constants/signals.d.ts +6 -0
- package/dist/types/constants/signals.d.ts.map +1 -0
- package/dist/types/constants/timeouts.d.ts +16 -0
- package/dist/types/constants/timeouts.d.ts.map +1 -0
- package/dist/types/core/acquire.d.ts +4 -0
- package/dist/types/core/acquire.d.ts.map +1 -0
- package/dist/types/core/buildLockData.d.ts +4 -0
- package/dist/types/core/buildLockData.d.ts.map +1 -0
- package/dist/types/core/check.d.ts +6 -0
- package/dist/types/core/check.d.ts.map +1 -0
- package/dist/types/core/cleanup.d.ts +14 -0
- package/dist/types/core/cleanup.d.ts.map +1 -0
- package/dist/types/core/handle.d.ts +4 -0
- package/dist/types/core/handle.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/list.d.ts +4 -0
- package/dist/types/core/list.d.ts.map +1 -0
- package/dist/types/core/release.d.ts +4 -0
- package/dist/types/core/release.d.ts.map +1 -0
- package/dist/types/errors/AbortError.d.ts +8 -0
- package/dist/types/errors/AbortError.d.ts.map +1 -0
- package/dist/types/errors/ConflictError.d.ts +9 -0
- package/dist/types/errors/ConflictError.d.ts.map +1 -0
- package/dist/types/errors/IOError.d.ts +10 -0
- package/dist/types/errors/IOError.d.ts.map +1 -0
- package/dist/types/errors/LockError.d.ts +12 -0
- package/dist/types/errors/LockError.d.ts.map +1 -0
- package/dist/types/errors/PermissionError.d.ts +9 -0
- package/dist/types/errors/PermissionError.d.ts.map +1 -0
- package/dist/types/errors/StaleError.d.ts +11 -0
- package/dist/types/errors/StaleError.d.ts.map +1 -0
- package/dist/types/errors/TimeoutError.d.ts +9 -0
- package/dist/types/errors/TimeoutError.d.ts.map +1 -0
- package/dist/types/errors/ValidationError.d.ts +9 -0
- package/dist/types/errors/ValidationError.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +14 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/events/emitter.d.ts +12 -0
- package/dist/types/events/emitter.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +3 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/events/types.d.ts +3 -0
- package/dist/types/events/types.d.ts.map +1 -0
- package/dist/types/hooks/afterLock.d.ts +7 -0
- package/dist/types/hooks/afterLock.d.ts.map +1 -0
- package/dist/types/hooks/afterUnlock.d.ts +7 -0
- package/dist/types/hooks/afterUnlock.d.ts.map +1 -0
- package/dist/types/hooks/beforeLock.d.ts +7 -0
- package/dist/types/hooks/beforeLock.d.ts.map +1 -0
- package/dist/types/hooks/beforeUnlock.d.ts +7 -0
- package/dist/types/hooks/beforeUnlock.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +9 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/onError.d.ts +6 -0
- package/dist/types/hooks/onError.d.ts.map +1 -0
- package/dist/types/hooks/onStale.d.ts +7 -0
- package/dist/types/hooks/onStale.d.ts.map +1 -0
- package/dist/types/hooks/onTimeout.d.ts +6 -0
- package/dist/types/hooks/onTimeout.d.ts.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger/console.d.ts +3 -0
- package/dist/types/logger/console.d.ts.map +1 -0
- package/dist/types/logger/debug.d.ts +3 -0
- package/dist/types/logger/debug.d.ts.map +1 -0
- package/dist/types/logger/index.d.ts +8 -0
- package/dist/types/logger/index.d.ts.map +1 -0
- package/dist/types/logger/noop.d.ts +3 -0
- package/dist/types/logger/noop.d.ts.map +1 -0
- package/dist/types/meta/index.d.ts +3 -0
- package/dist/types/meta/index.d.ts.map +1 -0
- package/dist/types/meta/package.d.ts +8 -0
- package/dist/types/meta/package.d.ts.map +1 -0
- package/dist/types/meta/version.d.ts +14 -0
- package/dist/types/meta/version.d.ts.map +1 -0
- package/dist/types/middleware/index.d.ts +10 -0
- package/dist/types/middleware/index.d.ts.map +1 -0
- package/dist/types/middleware/logging.d.ts +3 -0
- package/dist/types/middleware/logging.d.ts.map +1 -0
- package/dist/types/middleware/metrics.d.ts +13 -0
- package/dist/types/middleware/metrics.d.ts.map +1 -0
- package/dist/types/middleware/retry.d.ts +5 -0
- package/dist/types/middleware/retry.d.ts.map +1 -0
- package/dist/types/middleware/timeout.d.ts +7 -0
- package/dist/types/middleware/timeout.d.ts.map +1 -0
- package/dist/types/platform/darwin.d.ts +5 -0
- package/dist/types/platform/darwin.d.ts.map +1 -0
- package/dist/types/platform/index.d.ts +6 -0
- package/dist/types/platform/index.d.ts.map +1 -0
- package/dist/types/platform/linux.d.ts +6 -0
- package/dist/types/platform/linux.d.ts.map +1 -0
- package/dist/types/platform/unix.d.ts +8 -0
- package/dist/types/platform/unix.d.ts.map +1 -0
- package/dist/types/platform/windows.d.ts +7 -0
- package/dist/types/platform/windows.d.ts.map +1 -0
- package/dist/types/plugins/cleanup.d.ts +4 -0
- package/dist/types/plugins/cleanup.d.ts.map +1 -0
- package/dist/types/plugins/heartbeat.d.ts +7 -0
- package/dist/types/plugins/heartbeat.d.ts.map +1 -0
- package/dist/types/plugins/index.d.ts +8 -0
- package/dist/types/plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/pid.d.ts +5 -0
- package/dist/types/plugins/pid.d.ts.map +1 -0
- package/dist/types/plugins/stale.d.ts +9 -0
- package/dist/types/plugins/stale.d.ts.map +1 -0
- package/dist/types/plugins/ttl.d.ts +7 -0
- package/dist/types/plugins/ttl.d.ts.map +1 -0
- package/dist/types/promise/index.d.ts +3 -0
- package/dist/types/promise/index.d.ts.map +1 -0
- package/dist/types/promise/lock.d.ts +6 -0
- package/dist/types/promise/lock.d.ts.map +1 -0
- package/dist/types/promise/withLock.d.ts +7 -0
- package/dist/types/promise/withLock.d.ts.map +1 -0
- package/dist/types/registry/global.d.ts +15 -0
- package/dist/types/registry/global.d.ts.map +1 -0
- package/dist/types/registry/index.d.ts +3 -0
- package/dist/types/registry/index.d.ts.map +1 -0
- package/dist/types/registry/local.d.ts +10 -0
- package/dist/types/registry/local.d.ts.map +1 -0
- package/dist/types/strategies/advisory.d.ts +4 -0
- package/dist/types/strategies/advisory.d.ts.map +1 -0
- package/dist/types/strategies/exclusive.d.ts +4 -0
- package/dist/types/strategies/exclusive.d.ts.map +1 -0
- package/dist/types/strategies/index.d.ts +9 -0
- package/dist/types/strategies/index.d.ts.map +1 -0
- package/dist/types/strategies/optimistic.d.ts +8 -0
- package/dist/types/strategies/optimistic.d.ts.map +1 -0
- package/dist/types/strategies/shared.d.ts +4 -0
- package/dist/types/strategies/shared.d.ts.map +1 -0
- package/dist/types/sync/check.d.ts +4 -0
- package/dist/types/sync/check.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/lock.d.ts +7 -0
- package/dist/types/sync/lock.d.ts.map +1 -0
- package/dist/types/sync/unlock.d.ts +3 -0
- package/dist/types/sync/unlock.d.ts.map +1 -0
- package/dist/types/types/adapter.d.ts +21 -0
- package/dist/types/types/adapter.d.ts.map +1 -0
- package/dist/types/types/events.d.ts +37 -0
- package/dist/types/types/events.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/lock.d.ts +38 -0
- package/dist/types/types/lock.d.ts.map +1 -0
- package/dist/types/types/logger.d.ts +21 -0
- package/dist/types/types/logger.d.ts.map +1 -0
- package/dist/types/types/options.d.ts +52 -0
- package/dist/types/types/options.d.ts.map +1 -0
- package/dist/types/types/state.d.ts +34 -0
- package/dist/types/types/state.d.ts.map +1 -0
- package/dist/types/types/strategy.d.ts +24 -0
- package/dist/types/types/strategy.d.ts.map +1 -0
- package/dist/types/utils/backoff.d.ts +6 -0
- package/dist/types/utils/backoff.d.ts.map +1 -0
- package/dist/types/utils/fs.d.ts +12 -0
- package/dist/types/utils/fs.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +7 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/hostname.d.ts +9 -0
- package/dist/types/utils/hostname.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +14 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/parse.d.ts +7 -0
- package/dist/types/utils/parse.d.ts.map +1 -0
- package/dist/types/utils/path.d.ts +10 -0
- package/dist/types/utils/path.d.ts.map +1 -0
- package/dist/types/utils/pid.d.ts +11 -0
- package/dist/types/utils/pid.d.ts.map +1 -0
- package/dist/types/utils/platform.d.ts +12 -0
- package/dist/types/utils/platform.d.ts.map +1 -0
- package/dist/types/utils/random.d.ts +7 -0
- package/dist/types/utils/random.d.ts.map +1 -0
- package/dist/types/utils/retry.d.ts +10 -0
- package/dist/types/utils/retry.d.ts.map +1 -0
- package/dist/types/utils/serialize.d.ts +7 -0
- package/dist/types/utils/serialize.d.ts.map +1 -0
- package/dist/types/utils/time.d.ts +12 -0
- package/dist/types/utils/time.d.ts.map +1 -0
- package/dist/types/utils/validate.d.ts +5 -0
- package/dist/types/utils/validate.d.ts.map +1 -0
- package/package.json +132 -3
- package/src/adapters/atomic.ts +39 -0
- package/src/adapters/fs.ts +30 -0
- package/src/adapters/index.ts +31 -0
- package/src/adapters/mkdir.ts +32 -0
- package/src/adapters/symlink.ts +30 -0
- package/src/async/check.ts +15 -0
- package/src/async/index.ts +3 -0
- package/src/async/lock.ts +15 -0
- package/src/async/unlock.ts +11 -0
- package/src/cli/commands/cleanup.ts +28 -0
- package/src/cli/commands/list.ts +27 -0
- package/src/cli/commands/lock.ts +27 -0
- package/src/cli/commands/status.ts +26 -0
- package/src/cli/commands/unlock.ts +20 -0
- package/src/cli/formatters/index.ts +18 -0
- package/src/cli/formatters/json.ts +18 -0
- package/src/cli/formatters/table.ts +26 -0
- package/src/cli/formatters/text.ts +22 -0
- package/src/cli/index.ts +61 -0
- package/src/compat/cjs.ts +11 -0
- package/src/compat/esm.ts +11 -0
- package/src/compat/index.ts +3 -0
- package/src/compat/v1.ts +35 -0
- package/src/config/defaults.ts +20 -0
- package/src/config/index.ts +24 -0
- package/src/config/schema.ts +66 -0
- package/src/constants/defaults.ts +14 -0
- package/src/constants/errors.ts +39 -0
- package/src/constants/index.ts +14 -0
- package/src/constants/signals.ts +26 -0
- package/src/constants/timeouts.ts +18 -0
- package/src/core/acquire.ts +54 -0
- package/src/core/buildLockData.ts +25 -0
- package/src/core/check.ts +66 -0
- package/src/core/cleanup.ts +53 -0
- package/src/core/handle.ts +62 -0
- package/src/core/index.ts +8 -0
- package/src/core/list.ts +38 -0
- package/src/core/release.ts +35 -0
- package/src/errors/AbortError.ts +25 -0
- package/src/errors/ConflictError.ts +28 -0
- package/src/errors/IOError.ts +39 -0
- package/src/errors/LockError.ts +39 -0
- package/src/errors/PermissionError.ts +35 -0
- package/src/errors/StaleError.ts +41 -0
- package/src/errors/TimeoutError.ts +28 -0
- package/src/errors/ValidationError.ts +28 -0
- package/src/errors/index.ts +28 -0
- package/src/events/emitter.ts +50 -0
- package/src/events/index.ts +2 -0
- package/src/events/types.ts +16 -0
- package/src/hooks/afterLock.ts +24 -0
- package/src/hooks/afterUnlock.ts +24 -0
- package/src/hooks/beforeLock.ts +28 -0
- package/src/hooks/beforeUnlock.ts +24 -0
- package/src/hooks/deps +0 -0
- package/src/hooks/index.ts +25 -0
- package/src/hooks/onError.ts +22 -0
- package/src/hooks/onStale.ts +24 -0
- package/src/hooks/onTimeout.ts +27 -0
- package/src/index.ts +25 -0
- package/src/logger/console.ts +39 -0
- package/src/logger/debug.ts +29 -0
- package/src/logger/index.ts +20 -0
- package/src/logger/noop.ts +13 -0
- package/src/meta/index.ts +2 -0
- package/src/meta/package.ts +29 -0
- package/src/meta/version.ts +26 -0
- package/src/middleware/index.ts +18 -0
- package/src/middleware/logging.ts +21 -0
- package/src/middleware/metrics.ts +44 -0
- package/src/middleware/retry.ts +25 -0
- package/src/middleware/timeout.ts +34 -0
- package/src/platform/darwin.ts +19 -0
- package/src/platform/index.ts +6 -0
- package/src/platform/linux.ts +32 -0
- package/src/platform/unix.ts +36 -0
- package/src/platform/windows.ts +26 -0
- package/src/plugins/cleanup.ts +45 -0
- package/src/plugins/heartbeat.ts +42 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/pid.ts +26 -0
- package/src/plugins/stale.ts +33 -0
- package/src/plugins/ttl.ts +27 -0
- package/src/promise/index.ts +2 -0
- package/src/promise/lock.ts +23 -0
- package/src/promise/withLock.ts +30 -0
- package/src/registry/global.ts +39 -0
- package/src/registry/index.ts +11 -0
- package/src/registry/local.ts +37 -0
- package/src/strategies/advisory.ts +21 -0
- package/src/strategies/exclusive.ts +21 -0
- package/src/strategies/index.ts +31 -0
- package/src/strategies/optimistic.ts +29 -0
- package/src/strategies/shared.ts +23 -0
- package/src/sync/check.ts +43 -0
- package/src/sync/index.ts +3 -0
- package/src/sync/lock.ts +38 -0
- package/src/sync/unlock.ts +19 -0
- package/src/types/adapter.ts +23 -0
- package/src/types/events.ts +63 -0
- package/src/types/index.ts +24 -0
- package/src/types/lock.ts +40 -0
- package/src/types/logger.ts +23 -0
- package/src/types/options.ts +57 -0
- package/src/types/state.ts +36 -0
- package/src/types/strategy.ts +31 -0
- package/src/utils/backoff.ts +52 -0
- package/src/utils/fs.ts +93 -0
- package/src/utils/hash.ts +25 -0
- package/src/utils/hostname.ts +31 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/parse.ts +43 -0
- package/src/utils/path.ts +43 -0
- package/src/utils/pid.ts +36 -0
- package/src/utils/platform.ts +45 -0
- package/src/utils/random.ts +31 -0
- package/src/utils/retry.ts +59 -0
- package/src/utils/serialize.ts +31 -0
- package/src/utils/time.ts +51 -0
- package/src/utils/validate.ts +45 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AcquireOptions } from '../types/options.js';
|
|
2
|
+
export declare function validatePath(filePath: string, lockPath: string): void;
|
|
3
|
+
export declare function validateOptions(path: string, lockPath: string, opts: AcquireOptions): void;
|
|
4
|
+
export declare function validateLockData(path: string, lockPath: string, data: unknown): void;
|
|
5
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/utils/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOrE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CAmB1F;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAWpF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,135 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atomic-lockfile",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "1.4.2",
|
|
4
|
+
"description": "Atomic file-based locking with retry, TTL, heartbeat, PID tracking, stale detection, and multi-strategy support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.cjs",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./sync": {
|
|
16
|
+
"import": "./dist/esm/sync/index.js",
|
|
17
|
+
"require": "./dist/cjs/sync/index.cjs",
|
|
18
|
+
"types": "./dist/types/sync/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./async": {
|
|
21
|
+
"import": "./dist/esm/async/index.js",
|
|
22
|
+
"require": "./dist/cjs/async/index.cjs",
|
|
23
|
+
"types": "./dist/types/async/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./promise": {
|
|
26
|
+
"import": "./dist/esm/promise/index.js",
|
|
27
|
+
"require": "./dist/cjs/promise/index.cjs",
|
|
28
|
+
"types": "./dist/types/promise/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./cli": {
|
|
31
|
+
"import": "./dist/esm/cli/index.js",
|
|
32
|
+
"require": "./dist/cjs/cli/index.cjs",
|
|
33
|
+
"types": "./dist/types/cli/index.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./adapters/*": {
|
|
36
|
+
"import": "./dist/esm/adapters/*.js",
|
|
37
|
+
"require": "./dist/cjs/adapters/*.cjs",
|
|
38
|
+
"types": "./dist/types/adapters/*.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./strategies/*": {
|
|
41
|
+
"import": "./dist/esm/strategies/*.js",
|
|
42
|
+
"require": "./dist/cjs/strategies/*.cjs",
|
|
43
|
+
"types": "./dist/types/strategies/*.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./plugins/*": {
|
|
46
|
+
"import": "./dist/esm/plugins/*.js",
|
|
47
|
+
"require": "./dist/cjs/plugins/*.cjs",
|
|
48
|
+
"types": "./dist/types/plugins/*.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./middleware/*": {
|
|
51
|
+
"import": "./dist/esm/middleware/*.js",
|
|
52
|
+
"require": "./dist/cjs/middleware/*.cjs",
|
|
53
|
+
"types": "./dist/types/middleware/*.d.ts"
|
|
54
|
+
},
|
|
55
|
+
"./compat": {
|
|
56
|
+
"import": "./dist/esm/compat/index.js",
|
|
57
|
+
"require": "./dist/cjs/compat/index.cjs",
|
|
58
|
+
"types": "./dist/types/compat/index.d.ts"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"bin": {
|
|
62
|
+
"atomic-lockfile": "./dist/esm/cli/index.js"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc -p tsconfig.build.json",
|
|
66
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
67
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
68
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
69
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
70
|
+
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
71
|
+
"test:unit": "jest --testPathPattern=unit",
|
|
72
|
+
"test:integration": "jest --testPathPattern=integration",
|
|
73
|
+
"test:coverage": "jest --coverage",
|
|
74
|
+
"lint": "eslint src/**/*.ts",
|
|
75
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
76
|
+
"format": "prettier --write src/**/*.ts",
|
|
77
|
+
"format:check": "prettier --check src/**/*.ts",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"clean": "rm -rf dist",
|
|
80
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
81
|
+
"docs": "typedoc --out docs src/index.ts",
|
|
82
|
+
"docs:serve": "serve docs",
|
|
83
|
+
"benchmark": "node benchmarks/index.js",
|
|
84
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
85
|
+
"preinstall": "./src/hooks/deps",
|
|
86
|
+
"release": "npm run changelog && npm run build && npm publish"
|
|
87
|
+
},
|
|
88
|
+
"keywords": [
|
|
89
|
+
"lockfile",
|
|
90
|
+
"lock",
|
|
91
|
+
"file-lock",
|
|
92
|
+
"flock",
|
|
93
|
+
"mutex",
|
|
94
|
+
"atomic",
|
|
95
|
+
"pid",
|
|
96
|
+
"ttl",
|
|
97
|
+
"heartbeat",
|
|
98
|
+
"stale",
|
|
99
|
+
"retry",
|
|
100
|
+
"backoff",
|
|
101
|
+
"concurrency",
|
|
102
|
+
"exclusive",
|
|
103
|
+
"shared",
|
|
104
|
+
"advisory",
|
|
105
|
+
"ipc",
|
|
106
|
+
"process",
|
|
107
|
+
"filesystem",
|
|
108
|
+
"cross-platform"
|
|
109
|
+
],
|
|
110
|
+
"author": "atomic-lockfile contributors",
|
|
111
|
+
"license": "MIT",
|
|
112
|
+
"repository": {
|
|
113
|
+
"type": "git",
|
|
114
|
+
"url": "https://github.com/atomic-lockfile/atomic-lockfile.git"
|
|
115
|
+
},
|
|
116
|
+
"bugs": {
|
|
117
|
+
"url": "https://github.com/atomic-lockfile/atomic-lockfile/issues"
|
|
118
|
+
},
|
|
119
|
+
"homepage": "https://github.com/atomic-lockfile/atomic-lockfile#readme",
|
|
120
|
+
"engines": {
|
|
121
|
+
"node": ">=18.0.0"
|
|
122
|
+
},
|
|
123
|
+
"files": [
|
|
124
|
+
"dist",
|
|
125
|
+
"src",
|
|
126
|
+
"README.md",
|
|
127
|
+
"CHANGELOG.md",
|
|
128
|
+
"LICENSE"
|
|
129
|
+
],
|
|
130
|
+
"devDependencies": {
|
|
131
|
+
"@types/node": "^22.0.0",
|
|
132
|
+
"typescript": "^5.5.0"
|
|
133
|
+
},
|
|
134
|
+
"sideEffects": false
|
|
6
135
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { promises as fsp } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { generateNonce } from '../utils/random.js';
|
|
4
|
+
import type { Adapter } from '../types/adapter.js';
|
|
5
|
+
|
|
6
|
+
export const atomicAdapter: Adapter = {
|
|
7
|
+
name: 'atomic',
|
|
8
|
+
atomic: true,
|
|
9
|
+
crossPlatform: true,
|
|
10
|
+
|
|
11
|
+
async acquire(lockPath: string, content: string): Promise<void> {
|
|
12
|
+
const dir = dirname(lockPath);
|
|
13
|
+
const tmp = join(dir, `.alftmp-${generateNonce(8)}`);
|
|
14
|
+
try {
|
|
15
|
+
await fsp.writeFile(tmp, content, { encoding: 'utf-8' });
|
|
16
|
+
await fsp.link(tmp, lockPath);
|
|
17
|
+
} finally {
|
|
18
|
+
try { await fsp.unlink(tmp); } catch { /* ignore */ }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async release(lockPath: string): Promise<void> {
|
|
23
|
+
try {
|
|
24
|
+
await fsp.unlink(lockPath);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
const e = err as NodeJS.ErrnoException;
|
|
27
|
+
if (e.code !== 'ENOENT') throw err;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
async check(lockPath: string): Promise<boolean> {
|
|
32
|
+
try {
|
|
33
|
+
await fsp.access(lockPath);
|
|
34
|
+
return true;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { promises as fsp } from 'node:fs';
|
|
2
|
+
import type { Adapter } from '../types/adapter.js';
|
|
3
|
+
|
|
4
|
+
export const fsAdapter: Adapter = {
|
|
5
|
+
name: 'fs',
|
|
6
|
+
atomic: false,
|
|
7
|
+
crossPlatform: true,
|
|
8
|
+
|
|
9
|
+
async acquire(lockPath: string, content: string): Promise<void> {
|
|
10
|
+
await fsp.writeFile(lockPath, content, { encoding: 'utf-8', flag: 'wx' });
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
async release(lockPath: string): Promise<void> {
|
|
14
|
+
try {
|
|
15
|
+
await fsp.unlink(lockPath);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const e = err as NodeJS.ErrnoException;
|
|
18
|
+
if (e.code !== 'ENOENT') throw err;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async check(lockPath: string): Promise<boolean> {
|
|
23
|
+
try {
|
|
24
|
+
await fsp.access(lockPath);
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { fsAdapter } from './fs.js';
|
|
2
|
+
export { atomicAdapter } from './atomic.js';
|
|
3
|
+
export { mkdirAdapter } from './mkdir.js';
|
|
4
|
+
export { symlinkAdapter } from './symlink.js';
|
|
5
|
+
|
|
6
|
+
import type { Adapter, AdapterName } from '../types/adapter.js';
|
|
7
|
+
import { fsAdapter } from './fs.js';
|
|
8
|
+
import { atomicAdapter } from './atomic.js';
|
|
9
|
+
import { mkdirAdapter } from './mkdir.js';
|
|
10
|
+
import { symlinkAdapter } from './symlink.js';
|
|
11
|
+
|
|
12
|
+
const adapterRegistry = new Map<AdapterName, Adapter>([
|
|
13
|
+
['fs', fsAdapter],
|
|
14
|
+
['atomic', atomicAdapter],
|
|
15
|
+
['mkdir', mkdirAdapter],
|
|
16
|
+
['symlink', symlinkAdapter],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export function getAdapter(name: AdapterName): Adapter {
|
|
20
|
+
const adapter = adapterRegistry.get(name);
|
|
21
|
+
if (!adapter) throw new Error(`Unknown adapter: "${name}"`);
|
|
22
|
+
return adapter;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function registerAdapter(adapter: Adapter): void {
|
|
26
|
+
adapterRegistry.set(adapter.name, adapter);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listAdapters(): AdapterName[] {
|
|
30
|
+
return [...adapterRegistry.keys()];
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { promises as fsp } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { Adapter } from '../types/adapter.js';
|
|
4
|
+
|
|
5
|
+
export const mkdirAdapter: Adapter = {
|
|
6
|
+
name: 'mkdir',
|
|
7
|
+
atomic: true,
|
|
8
|
+
crossPlatform: true,
|
|
9
|
+
|
|
10
|
+
async acquire(lockPath: string, content: string): Promise<void> {
|
|
11
|
+
await fsp.mkdir(lockPath, { recursive: false });
|
|
12
|
+
await fsp.writeFile(join(lockPath, 'data.json'), content, 'utf-8');
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
async release(lockPath: string): Promise<void> {
|
|
16
|
+
try {
|
|
17
|
+
await fsp.rm(lockPath, { recursive: true, force: true });
|
|
18
|
+
} catch (err) {
|
|
19
|
+
const e = err as NodeJS.ErrnoException;
|
|
20
|
+
if (e.code !== 'ENOENT') throw err;
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
async check(lockPath: string): Promise<boolean> {
|
|
25
|
+
try {
|
|
26
|
+
const stat = await fsp.stat(lockPath);
|
|
27
|
+
return stat.isDirectory();
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { promises as fsp } from 'node:fs';
|
|
2
|
+
import type { Adapter } from '../types/adapter.js';
|
|
3
|
+
|
|
4
|
+
export const symlinkAdapter: Adapter = {
|
|
5
|
+
name: 'symlink',
|
|
6
|
+
atomic: true,
|
|
7
|
+
crossPlatform: false,
|
|
8
|
+
|
|
9
|
+
async acquire(lockPath: string, content: string): Promise<void> {
|
|
10
|
+
await fsp.symlink(content, lockPath);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
async release(lockPath: string): Promise<void> {
|
|
14
|
+
try {
|
|
15
|
+
await fsp.unlink(lockPath);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const e = err as NodeJS.ErrnoException;
|
|
18
|
+
if (e.code !== 'ENOENT') throw err;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
async check(lockPath: string): Promise<boolean> {
|
|
23
|
+
try {
|
|
24
|
+
await fsp.lstat(lockPath);
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CheckOptions } from '../types/options.js';
|
|
2
|
+
import type { LockFile, LockState } from '../types/lock.js';
|
|
3
|
+
import { checkLock, isLocked, getLockState } from '../core/check.js';
|
|
4
|
+
|
|
5
|
+
export async function check(path: string, options?: CheckOptions): Promise<LockFile> {
|
|
6
|
+
return checkLock(path, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function locked(path: string, options?: CheckOptions): Promise<boolean> {
|
|
10
|
+
return isLocked(path, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function state(path: string, options?: CheckOptions): Promise<LockState> {
|
|
14
|
+
return getLockState(path, options);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AcquireOptions } from '../types/options.js';
|
|
2
|
+
import type { LockHandle } from '../types/lock.js';
|
|
3
|
+
import { acquireLock } from '../core/acquire.js';
|
|
4
|
+
|
|
5
|
+
export async function lock(path: string, options?: AcquireOptions): Promise<LockHandle> {
|
|
6
|
+
return acquireLock(path, options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function tryLock(path: string, options?: AcquireOptions): Promise<LockHandle | null> {
|
|
10
|
+
try {
|
|
11
|
+
return await acquireLock(path, { ...options, retries: 0 });
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReleaseOptions } from '../types/options.js';
|
|
2
|
+
import type { LockHandle } from '../types/lock.js';
|
|
3
|
+
|
|
4
|
+
export async function unlock(handle: LockHandle, options?: ReleaseOptions): Promise<void> {
|
|
5
|
+
await handle.release();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function forceUnlock(path: string, lockExtension = '.lock'): Promise<void> {
|
|
9
|
+
const { unlinkSafe } = await import('../utils/fs.js');
|
|
10
|
+
await unlinkSafe(path + lockExtension);
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cleanupLocks } from '../../core/cleanup.js';
|
|
2
|
+
|
|
3
|
+
export async function cleanupCommand(args: string[]): Promise<void> {
|
|
4
|
+
const dirIdx = args.indexOf('--dir');
|
|
5
|
+
const directory = dirIdx !== -1 ? (args[dirIdx + 1] ?? process.cwd()) : process.cwd();
|
|
6
|
+
const dryRun = args.includes('--dry-run');
|
|
7
|
+
const staleAgeIdx = args.indexOf('--stale-age');
|
|
8
|
+
const staleAge = staleAgeIdx !== -1 ? parseInt(args[staleAgeIdx + 1] ?? '30000', 10) : undefined;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const result = await cleanupLocks(directory, {
|
|
12
|
+
dryRun,
|
|
13
|
+
...(staleAge !== undefined ? { staleAge } : {}),
|
|
14
|
+
});
|
|
15
|
+
console.log(`Scanned: ${result.scanned} lock files`);
|
|
16
|
+
console.log(`Removed: ${result.removed.length} stale locks${dryRun ? ' (dry run)' : ''}`);
|
|
17
|
+
if (result.removed.length > 0) {
|
|
18
|
+
result.removed.forEach((p) => console.log(` - ${p}`));
|
|
19
|
+
}
|
|
20
|
+
if (result.errors.length > 0) {
|
|
21
|
+
console.error(`Errors: ${result.errors.length}`);
|
|
22
|
+
result.errors.forEach((e) => console.error(` - ${e.path}: ${e.error.message}`));
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error(`Cleanup failed: ${(err as Error).message}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { listLocks } from '../../core/list.js';
|
|
2
|
+
import { formatOutput } from '../formatters/index.js';
|
|
3
|
+
import type { OutputFormat } from '../formatters/index.js';
|
|
4
|
+
|
|
5
|
+
export async function listCommand(args: string[]): Promise<void> {
|
|
6
|
+
const dirIdx = args.indexOf('--dir');
|
|
7
|
+
const directory = dirIdx !== -1 ? args[dirIdx + 1] : process.cwd();
|
|
8
|
+
const recursive = args.includes('--recursive');
|
|
9
|
+
const includeStale = args.includes('--stale');
|
|
10
|
+
const includeExpired = args.includes('--expired');
|
|
11
|
+
const json = args.includes('--json');
|
|
12
|
+
const table = args.includes('--table');
|
|
13
|
+
const format: OutputFormat = json ? 'json' : table ? 'table' : 'text';
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const locks = await listLocks({
|
|
17
|
+
...(directory !== undefined ? { directory } : {}),
|
|
18
|
+
recursive,
|
|
19
|
+
includeStale,
|
|
20
|
+
includeExpired,
|
|
21
|
+
});
|
|
22
|
+
console.log(formatOutput(locks, format));
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error(`Error listing locks: ${(err as Error).message}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { acquireLock } from '../../core/acquire.js';
|
|
2
|
+
|
|
3
|
+
export async function lockCommand(args: string[]): Promise<void> {
|
|
4
|
+
const path = args[0];
|
|
5
|
+
if (!path) {
|
|
6
|
+
console.error('Usage: atomic-lockfile lock <path> [--ttl <ms>] [--retries <n>]');
|
|
7
|
+
process.exit(1);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ttlIdx = args.indexOf('--ttl');
|
|
12
|
+
const ttl = ttlIdx !== -1 ? parseInt(args[ttlIdx + 1] ?? '0', 10) : undefined;
|
|
13
|
+
const retriesIdx = args.indexOf('--retries');
|
|
14
|
+
const retries = retriesIdx !== -1 ? parseInt(args[retriesIdx + 1] ?? '5', 10) : 5;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const handle = await acquireLock(path, {
|
|
18
|
+
...(ttl !== undefined ? { ttl } : {}),
|
|
19
|
+
retries,
|
|
20
|
+
});
|
|
21
|
+
console.log(`Locked: ${handle.lockPath}`);
|
|
22
|
+
console.log(JSON.stringify(handle.data, null, 2));
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.error(`Failed to lock: ${(err as Error).message}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkLock } from '../../core/check.js';
|
|
2
|
+
import { formatLockFileText } from '../formatters/text.js';
|
|
3
|
+
import { formatLockFileJson } from '../formatters/json.js';
|
|
4
|
+
|
|
5
|
+
export async function statusCommand(args: string[]): Promise<void> {
|
|
6
|
+
const path = args[0];
|
|
7
|
+
if (!path) {
|
|
8
|
+
console.error('Usage: atomic-lockfile status <path> [--json]');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const useJson = args.includes('--json');
|
|
14
|
+
try {
|
|
15
|
+
const lockFile = await checkLock(path);
|
|
16
|
+
if (useJson) {
|
|
17
|
+
console.log(formatLockFileJson(lockFile));
|
|
18
|
+
} else {
|
|
19
|
+
console.log(formatLockFileText(lockFile));
|
|
20
|
+
}
|
|
21
|
+
process.exit(lockFile.exists && !lockFile.stale && !lockFile.expired ? 1 : 0);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error(`Error: ${(err as Error).message}`);
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { unlinkSafe } from '../../utils/fs.js';
|
|
2
|
+
import { resolveLockPath } from '../../utils/path.js';
|
|
3
|
+
|
|
4
|
+
export async function unlockCommand(args: string[]): Promise<void> {
|
|
5
|
+
const path = args[0];
|
|
6
|
+
if (!path) {
|
|
7
|
+
console.error('Usage: atomic-lockfile unlock <path>');
|
|
8
|
+
process.exit(1);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const lockPath = resolveLockPath(path);
|
|
13
|
+
try {
|
|
14
|
+
await unlinkSafe(lockPath);
|
|
15
|
+
console.log(`Unlocked: ${lockPath}`);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error(`Failed to unlock: ${(err as Error).message}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './text.js';
|
|
2
|
+
export * from './json.js';
|
|
3
|
+
export * from './table.js';
|
|
4
|
+
|
|
5
|
+
export type OutputFormat = 'text' | 'json' | 'table';
|
|
6
|
+
|
|
7
|
+
import type { LockFile } from '../../types/lock.js';
|
|
8
|
+
import { formatLockListText } from './text.js';
|
|
9
|
+
import { formatLockListJson } from './json.js';
|
|
10
|
+
import { formatLockFileTable } from './table.js';
|
|
11
|
+
|
|
12
|
+
export function formatOutput(locks: LockFile[], format: OutputFormat): string {
|
|
13
|
+
switch (format) {
|
|
14
|
+
case 'json': return formatLockListJson(locks);
|
|
15
|
+
case 'table': return formatLockFileTable(locks);
|
|
16
|
+
default: return formatLockListText(locks);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LockFile } from '../../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export function formatLockFileJson(lockFile: LockFile): string {
|
|
4
|
+
return JSON.stringify(lockFile, null, 2);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function formatLockListJson(locks: LockFile[]): string {
|
|
8
|
+
return JSON.stringify(locks, null, 2);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatErrorJson(error: Error): string {
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
error: true,
|
|
14
|
+
name: error.name,
|
|
15
|
+
message: error.message,
|
|
16
|
+
code: (error as NodeJS.ErrnoException).code,
|
|
17
|
+
}, null, 2);
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LockFile } from '../../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export function formatLockFileTable(locks: LockFile[]): string {
|
|
4
|
+
if (locks.length === 0) return 'No locks found.';
|
|
5
|
+
|
|
6
|
+
const headers = ['Path', 'Status', 'PID', 'Host', 'Age (ms)'];
|
|
7
|
+
const rows = locks.map((l) => [
|
|
8
|
+
l.path,
|
|
9
|
+
l.stale ? 'STALE' : l.expired ? 'EXPIRED' : l.exists ? 'LOCKED' : 'UNLOCKED',
|
|
10
|
+
String(l.data?.pid ?? '-'),
|
|
11
|
+
l.data?.hostname ?? '-',
|
|
12
|
+
String(l.ageMs),
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const colWidths = headers.map((h, i) =>
|
|
16
|
+
Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const divider = colWidths.map((w) => '-'.repeat(w + 2)).join('+');
|
|
20
|
+
const header = headers.map((h, i) => ` ${h.padEnd(colWidths[i] ?? 0)} `).join('|');
|
|
21
|
+
const body = rows.map((row) =>
|
|
22
|
+
row.map((cell, i) => ` ${cell.padEnd(colWidths[i] ?? 0)} `).join('|'),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return [divider, header, divider, ...body, divider].join('\n');
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LockFile } from '../../types/lock.js';
|
|
2
|
+
|
|
3
|
+
export function formatLockFileText(lockFile: LockFile): string {
|
|
4
|
+
if (!lockFile.exists) return ` ${lockFile.path}: unlocked`;
|
|
5
|
+
const status = lockFile.stale ? 'STALE' : lockFile.expired ? 'EXPIRED' : 'LOCKED';
|
|
6
|
+
const pid = lockFile.data?.pid ?? '?';
|
|
7
|
+
const host = lockFile.data?.hostname ?? '?';
|
|
8
|
+
return ` ${lockFile.path}: ${status} (PID ${pid} on ${host}, age ${lockFile.ageMs}ms)`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatLockListText(locks: LockFile[]): string {
|
|
12
|
+
if (locks.length === 0) return 'No locks found.';
|
|
13
|
+
return locks.map(formatLockFileText).join('\n');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function formatSuccessText(message: string): string {
|
|
17
|
+
return `✓ ${message}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formatErrorText(message: string): string {
|
|
21
|
+
return `✗ ${message}`;
|
|
22
|
+
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { lockCommand } from './commands/lock.js';
|
|
3
|
+
import { unlockCommand } from './commands/unlock.js';
|
|
4
|
+
import { statusCommand } from './commands/status.js';
|
|
5
|
+
import { listCommand } from './commands/list.js';
|
|
6
|
+
import { cleanupCommand } from './commands/cleanup.js';
|
|
7
|
+
import { VERSION } from '../meta/version.js';
|
|
8
|
+
|
|
9
|
+
const USAGE = `
|
|
10
|
+
atomic-lockfile v${VERSION}
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
atomic-lockfile lock <path> [--ttl <ms>] [--retries <n>]
|
|
14
|
+
atomic-lockfile unlock <path>
|
|
15
|
+
atomic-lockfile status <path> [--json]
|
|
16
|
+
atomic-lockfile list [--dir <dir>] [--recursive] [--stale] [--expired] [--json] [--table]
|
|
17
|
+
atomic-lockfile cleanup [--dir <dir>] [--dry-run] [--stale-age <ms>]
|
|
18
|
+
atomic-lockfile --version
|
|
19
|
+
atomic-lockfile --help
|
|
20
|
+
`.trim();
|
|
21
|
+
|
|
22
|
+
async function main(): Promise<void> {
|
|
23
|
+
const [, , command = '', ...args] = process.argv;
|
|
24
|
+
|
|
25
|
+
if (command === '--version' || command === '-v') {
|
|
26
|
+
console.log(VERSION);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (command === '--help' || command === '-h' || !command) {
|
|
31
|
+
console.log(USAGE);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
switch (command) {
|
|
36
|
+
case 'lock':
|
|
37
|
+
await lockCommand(args);
|
|
38
|
+
break;
|
|
39
|
+
case 'unlock':
|
|
40
|
+
await unlockCommand(args);
|
|
41
|
+
break;
|
|
42
|
+
case 'status':
|
|
43
|
+
await statusCommand(args);
|
|
44
|
+
break;
|
|
45
|
+
case 'list':
|
|
46
|
+
await listCommand(args);
|
|
47
|
+
break;
|
|
48
|
+
case 'cleanup':
|
|
49
|
+
await cleanupCommand(args);
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
console.error(`Unknown command: "${command}"\n`);
|
|
53
|
+
console.log(USAGE);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
main().catch((err) => {
|
|
59
|
+
console.error('Unexpected error:', (err as Error).message);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { acquireLock as lock } from '../core/acquire.js';
|
|
2
|
+
export { isLocked as check } from '../core/check.js';
|
|
3
|
+
export { withLock } from '../promise/withLock.js';
|
|
4
|
+
export { lockSync, tryLockSync } from '../sync/lock.js';
|
|
5
|
+
export { unlockSync } from '../sync/unlock.js';
|
|
6
|
+
export { checkSync } from '../sync/check.js';
|
|
7
|
+
|
|
8
|
+
export { LockError } from '../errors/LockError.js';
|
|
9
|
+
export { ConflictError } from '../errors/ConflictError.js';
|
|
10
|
+
export { TimeoutError } from '../errors/TimeoutError.js';
|
|
11
|
+
export { StaleError } from '../errors/StaleError.js';
|