npm-fill-gaps
v1.0.15
Published
Automatically scans your JavaScript or TypeScript files for external imports and installs missing packages from `npm`.
Downloads
14
Readme
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:
- The script scans your JS/TS files for
import
statements. - It compares the found imports against the dependencies in your
package.json
. - 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 todependencies
.--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.