花花花 SuperLaserNino 花花花

Don’t manually hunt around for yarn.lock or package-lock.json

27 Aug 2024

86 words

#!/usr/bin/env perl

# Node dependency manager. Never wonder whether to use `yarn` or `npm` again.

# Usage:
# np        --> runs `yarn` or `npm i`
# np <args> --> runs `yarn <args>` or `npm run <args>`

use strict;
use warnings;

if (!-e 'package.json') {
  print "No package.json found. Exiting.\n";
  exit;
}

if (-e 'package-lock.json') {
  if (@ARGV) {
    system('npm run ' . join(' ', @ARGV));
  } else {
    system('npm i');
  }
} else {
  system('yarn ' . join(' ', @ARGV));
}