npm-fill-gaps

1.0.15 • Public • Published

npm-fill-gaps

Automatically scans your JavaScript or TypeScript files for external imports and installs missing packages from npm.

Features:

  • Scans your project's JS/TS files for import statements.
  • Checks for missing dependencies in your package.json.
  • Installs any missing dependencies via npm.
  • Ignores relative paths and specific path notations like @/.

Installation:

While you don't need to install npm-fill-gaps globally, if you wish to use it without npx, you can do:

npm install -g npm-fill-gaps

Usage:

Using npx (recommended):

npx npm-fill-gaps

How It Works:

  1. The script scans your JS/TS files for import statements.
  2. It compares the found imports against the dependencies in your package.json.
  3. Any missing dependencies are then installed using npm.

Exclusions:

The following import paths/patterns are excluded from the scan:

  • Relative imports starting with ./ or ../.
  • Imports starting with @/ (e.g., aliases in some configurations).

Ignoring Specific Patterns

The --ignore flag allows you to specify patterns that should be excluded when scanning for imports. This is particularly useful if there are certain libraries or internal modules that you don't want to be automatically installed or checked against.

Usage:

npx npm-fill-gaps --ignore pattern1 pattern2 pattern3

For example, to ignore anything related to react, any import starting with @/, and any imports that start with jotai/, you can run:

npx npm-fill-gaps --ignore react @/** jotai/*

Patterns support the * wildcard character, making it easy to specify broader matching criteria. Each pattern is separated by a space.

Passing npm Flags

The script allows for passing npm-related flags directly to the npm install command, providing flexibility in how the installation process is executed.

Usage:

npx npm-fill-gaps --ignore somePattern --force --dry-run

In the above example, --force and --dry-run are passed directly to the npm install command.

Supported npm Flags:

  • --force: Force npm to fetch remote resources even if a local copy exists on disk.
  • --legacy-peer-deps: Install the package even if it has peer dependencies that conflict with already installed versions.
  • --no-save: Prevents saving to dependencies.
  • --dry-run: Indicates that you don't want npm to make any changes and just report what it would do.

You can append any of these flags after your regular script arguments, and they will be considered during the installation process.

Note:

  • Ensure you run the script in a directory containing your package.json.
  • The script assumes a standard import format. Complex import patterns or dynamic imports might not be captured accurately.
  • Always review and ensure you trust packages before allowing them to be installed.

Contributing:

We welcome contributions! Please open an issue or submit a PR if you have improvements, bug fixes, or new features.

License:

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i npm-fill-gaps

Weekly Downloads

13

Version

1.0.15

License

ISC

Unpacked Size

9.34 kB

Total Files

4

Last publish

Collaborators

  • ibealec