Skip to content

luftywiranda13/has-lockfile

Repository files navigation

has-lockfile

Detect lockfiles in the working directory

Package Version Downloads Status Build Status: Linux Coverage Status

Useful for tools that need to know whether to use yarn or npm.

Installation

npm install has-lockfile

Usage

$ tree
.
├── bar
│   ├── package-lock.json
│   └── package.json
├── baz
│   ├── package.json
│   └── yarn.lock
├── foo
│   ├── npm-shrinkwrap.json
│   └── package.json
├── qux
│   ├── npm-shrinkwrap.json
│   ├── package-lock.json
│   ├── package.json
│   └── yarn.lock
└── package.json
const hasLockfile = require('has-lockfile');

hasLockfile();
// => false

hasLockfile('bar');
//=> true

hasLockfile.lockfiles();
//=> []

hasLockfile.lockfiles('bar');
//=> ['package-lock.json']

hasLockfile.lockfiles('baz');
//=> ['yarn.lock']

hasLockfile.lockfiles('foo');
//=> ['npm-shrinkwrap.json']

hasLockfile.lockfiles('qux');
//=> ['package-lock.json', 'yarn.lock', 'npm-shrinkwrap.json']

API

hasLockfile([cwd])

Returns boolean.

hasLockfile.lockfiles([cwd])

Returns Array of lockfiles.

cwd

Type: string
Default: process.cwd()

Current working directory.

Related

  • has-package-lock - Check if a package-lock.json is present in the working directory
  • has-shrinkwrap - Check if npm-shrinkwrap.json is present in the working directory
  • has-yarn - Check if a project is using Yarn
  • pkg-man - Detect which package manager that should be used

License

MIT © Lufty Wiranda