Skip to main content

A Python utility to update Node.js project dependencies safely.

Project description

PackUpdate

PackUpdate is a Python utility designed to help developers manage and update their Node.js project dependencies efficiently. It ensures that package updates are validated through tests and resolves audit issues automatically. The tool prioritizes updating packages to their latest versions, but if issues are detected, it falls back to updating to the "wanted" version.

Features

  • Update Packages: Updates Node.js project dependencies to their latest versions if no issues are detected.
  • Fallback to Wanted Version: If issues arise during testing, updates packages to the "wanted" version instead.
  • Audit Fix: Automatically resolves audit issues in the project.
  • Validation: Runs tests to ensure package updates do not introduce breaking changes.

Prerequisites

  • Python (v3.8 or higher)
  • Node.js (v14 or higher)
  • npm (v6 or higher)

Installation

Install the library using pip:

pip install packupdate

Usage

Run the CLI tool to update Node.js project dependencies:

updatePackages <project_path> [--safe] [--pass=N]

Examples

  • Basic Update:

    updatePackages /path/to/project
    
  • Safe Mode:

    updatePackages /path/to/project --safe
    
  • Multiple Passes:

    updatePackages /path/to/project --pass=3
    
  • Safe Mode with Multiple Passes:

    updatePackages /path/to/project --safe --pass=3
    

Clone the repository to your local machine:

git clone <repository-url>
cd PackUpdate

Install the required Python dependencies:

pip install -r requirements.txt

Usage

1. Run the Update Process

To update the packages in your Node.js project, use the following command:

python updatePackages.py <project_path> [--safe] [--pass=N]

2. Available Commands and Options

  • <project_path>: (Required) The path to the Node.js project directory containing package.json and package-lock.json.

  • --safe: (Optional) Enables safe mode. In this mode:

    • The script first attempts to update packages to their latest versions.
    • If tests fail, it reverts to the "wanted" version.
    • If tests fail again, it reverts to the current version.
  • --pass=N: (Optional) Specifies the number of passes to attempt updating packages. Default is 1.

3. Examples

Example 1: Basic Update

Run the script to update packages in a project located at /path/to/project:

python updatePackages.py /path/to/project

Example 2: Safe Mode

Run the script in safe mode to ensure updates are validated with tests:

python updatePackages.py /path/to/project --safe

Example 3: Multiple Passes

Run the script with 3 passes to attempt updates multiple times:

python updatePackages.py /path/to/project --pass=3

Example 4: Safe Mode with Multiple Passes

Combine safe mode and multiple passes:

python updatePackages.py /path/to/project --safe --pass=3

4. How It Works

  1. Dependency Update:

    • The script identifies outdated packages using npm outdated.
    • It attempts to update each package to the latest version or the "wanted" version based on the mode.
  2. Audit Fix:

    • After updating dependencies, the script runs npm audit fix to resolve any security vulnerabilities.
  3. Validation:

    • The script runs your project's test suite (npm test) to ensure that the updates do not break functionality.
  4. Build:

    • After updates, the script runs npm run build to ensure the project builds successfully.

5. Logs and Output

  • The script provides detailed logs during the update process, indicating:
    • Which packages were updated successfully.
    • Which packages were reverted to the "wanted" or current version due to issues.
    • Audit issues that were resolved.

6. Rollback

If you encounter issues after running the script, you can manually revert to a previous state using your version control system (e.g., Git).

Example Workflow

  1. Ensure your project has a valid package.json and package-lock.json.
  2. Run the script:
    python updatePackages.py /path/to/project --safe --pass=2
    
  3. Review the logs to confirm updates and audit fixes.
  4. Run your application to verify everything works as expected.

Publishing to PyPI

To publish the PackUpdate package to PyPI, follow these steps:

  1. Install Required Tools: Ensure you have setuptools, wheel, and twine installed:

    pip install setuptools wheel twine
    
  2. Build the Package: Run the following command to create the distribution files:

    python setup.py sdist bdist_wheel
    

    This will generate the dist/ directory containing the .tar.gz and .whl files.

  3. Upload to PyPI: Use twine to upload the package to PyPI:

    twine upload dist/*
    
  4. Authenticate: Enter your PyPI username and password when prompted.

  5. Verify the Upload: Visit https://pypi.org/project/PackUpdate/ to confirm the package is live.

Notes:

  • Ensure your setup.py file is correctly configured with metadata like name, version, author, etc.
  • If you are testing the upload, use the Test PyPI repository:
    twine upload --repository-url https://test.pypi.org/legacy/ dist/*
    

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes and push them to your fork.
  4. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

If you encounter any issues or have questions, feel free to open an issue in the repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packupdate-1.0.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packupdate-1.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file packupdate-1.0.2.tar.gz.

File metadata

  • Download URL: packupdate-1.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for packupdate-1.0.2.tar.gz
Algorithm Hash digest
SHA256 eef67cc77fc392694635d3304fe1d6fafda396dbeadd7028d9c56b35ea3a8180
MD5 ba636142225c296ce0007d17196fdc27
BLAKE2b-256 644b9ae502cd32f71ff953adcea8cc7f36edf837b3cdd43fd192830dc33a6b5d

See more details on using hashes here.

File details

Details for the file packupdate-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: packupdate-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for packupdate-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 464ae62b833ff5094a414a66ec5fdf6ec4b359685fb58047611db15195df675f
MD5 43c1a84f139d1eff1b3edb54c995c74c
BLAKE2b-256 53301cfdae5e392df9355ea52ee981014cf381cbf9965352008ff7962647e97f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page