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:

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

Examples

  • Basic Update:

    updatenpmpackages /path/to/project
    
  • Safe Mode:

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

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

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

Run using code

Clone the repository to your local machine:

git clone <repository-url>
cd PackUpdate/python

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.4.tar.gz (9.7 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.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for packupdate-1.0.4.tar.gz
Algorithm Hash digest
SHA256 fd5de80ce370040a9d9fd8e57c23716d886da1a7c39c87cec5a6726cbd0838a5
MD5 eff27728eec7a46e42979ea78786c970
BLAKE2b-256 ef69d3c257f882fc0ab13162fd16c7a1f6a0a47e1ad5cb751999a0323bcbe328

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for packupdate-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0b05d5618db62539faa4830c66481f1cf4f5fcd54c5c8c852d4fbe4d7a7cc545
MD5 455462dc9d12ed6c1d5175ab0236fc10
BLAKE2b-256 7aae3283a20f057f053d922725bed93c07dd77b3689b89b481cc39e5d86530fe

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