Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The 'local-pkg' npm package is designed to help developers manage and interact with local packages in a Node.js environment. It provides utilities to check for the existence of local packages, resolve their paths, and require them conditionally.
Check if a local package exists
This feature allows you to check if a specific local package is installed. The function `isPackageExists` returns a boolean indicating the presence of the package.
const { isPackageExists } = require('local-pkg');
if (isPackageExists('some-local-package')) {
console.log('Package exists');
} else {
console.log('Package does not exist');
}
Resolve the path of a local package
This feature helps you resolve the absolute path of a local package. The function `resolvePackagePath` returns the path as a string.
const { resolvePackagePath } = require('local-pkg');
const packagePath = resolvePackagePath('some-local-package');
console.log(`Package path: ${packagePath}`);
Require a local package conditionally
This feature allows you to require a local package conditionally. The function `requireModule` attempts to require the package and returns it if successful, otherwise it returns `null`.
const { requireModule } = require('local-pkg');
const someLocalPackage = requireModule('some-local-package');
if (someLocalPackage) {
console.log('Package loaded successfully');
} else {
console.log('Failed to load package');
}
The 'resolve' package is a library for resolving module paths in Node.js. It provides similar functionality to 'local-pkg' in terms of resolving paths but does not include utilities for checking package existence or conditional requiring.
The 'pkg-up' package finds the closest package.json file by traversing up from a specified directory. While it helps in locating package.json files, it does not offer the same comprehensive utilities for managing local packages as 'local-pkg'.
The 'find-up' package is used to find a file or directory by walking up parent directories. It can be used to locate package.json files but lacks the specific package management utilities provided by 'local-pkg'.
Get information on local packages. Works on both CJS and ESM.
npm i local-pkg
import {
isPackageExists,
getPackageInfo,
resolveModule,
importModule,
} from 'local-pkg'
isPackageExists('local-pkg') // true
isPackageExists('foo') // false
await getPackageInfo('local-pkg')
/* {
* name: "local-pkg",
* version: "0.1.0",
* rootPath: "/path/to/node_modules/local-pkg",
* packageJson: {
* ...
* }
* }
*/
// similar to `require.resolve` but works also in ESM
resolveModule('local-pkg')
// '/path/to/node_modules/local-pkg/dist/index.cjs'
// similar to `await import()` but works also in CJS
const { importModule } = await importModule('local-pkg')
MIT License © 2021 Anthony Fu
FAQs
Get information on local packages.
We found that local-pkg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.