App-lms
view release on metacpan or search on metacpan
lib/App/lms/Node.pm view on Meta::CPAN
warn " Using: $node\n" if $DEBUG;
# Validate module name (allow scoped packages like @scope/name)
return if $name =~ /[^\w.\-\/@]/;
# Split into package name and subpath: "npm/lib/cli" -> ("npm", "lib/cli")
my($pkg, $subpath) = $name =~ m{^(@[^/]+/[^/]+|[^/]+)(?:/(.+))?$};
return unless defined $pkg;
my $code = <<"END";
const paths = require('module').globalPaths;
try { console.log(require.resolve('$pkg', {paths})) } catch(e) {}
END
my $entry = Command::Run->new->command($node, '-e', $code)->update->data // return;
chomp $entry;
return unless $entry && -f $entry;
if (defined $subpath) {
# Find package root by locating package.json
my $dir = $entry;
( run in 1.662 second using v1.01-cache-2.11-cpan-995e09ba956 )