Features of cnsh

Discover the features that make `cnsh` a powerful and efficient package manager.

Lightweight

`cnsh` is designed to be lightweight, ensuring fast and efficient package management without unnecessary bloat.

Performance-Friendly

Optimized for performance, `cnsh` minimizes overhead during package installation, making it a swift choice for developers.

Easy Integration

With a straightforward command structure, `cnsh` integrates seamlessly into your development workflow, simplifying package management.

Global and Local Installations

Support for both global and local package installations allows for flexible management of dependencies and tools.

Detailed Logging

The `--verbose` flag provides detailed logging, aiding in debugging and tracking installation processes.

Automated Tarball Fetching

`cnsh` automatically fetches the tarball URL from the API, ensuring accurate and up-to-date installations.

Version Management

The package manager retrieves and handles package versions from the API, ensuring your project uses the correct version.

Lock File Integration

`cnsh` creates and uses a `cnsh.lock` file to manage package versions and tarball URLs, providing consistency across installations.

How It Works

Here's a step-by-step guide on how `cnsh` operates:

1. Command Detection

`cnsh` detects if you typed the command `cnsh add` and begins the process of adding a package.

2. Loading Animation

`cnsh` uses `ora` to display a loading animation while processing the request, keeping you informed of the progress.

3. Fetching Package

`cnsh` calls `axios` to fetch the tarball of the npm package from the npm registry API.

4. Extracting Tarball

`cnsh` uses `tar` to extract the tarball, which contains the package files.

5. Saving Files

`cnsh` saves the extracted files into a directory called `cnsh_lib`, created by `fs-extra`.

6. Error Handling

If an error occurs during any step, `cnsh` uses `chalk` to display colored error messages in the terminal, helping you quickly identify and address issues.

7. Using the Package

You can now use the installed package in your project. For example:

async function fetchData() {
    try {
        const axios = await import('./cnsh_lib/axios/package/dist/esm/axios.min.js');
        const response = await axios.default.get('https://jsonplaceholder.typicode.com/posts/1');
        console.log('Data fetched:', response.data);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}

fetchData();

8. Written in ESM

`cnsh` is written in a variant of JavaScript called ECMAScript Modules (ESM), which provides a modern approach to module management and imports.