Discover the features that make `cnsh` a powerful and efficient package manager.
`cnsh` is designed to be lightweight, ensuring fast and efficient package management without unnecessary bloat.
Optimized for performance, `cnsh` minimizes overhead during package installation, making it a swift choice for developers.
With a straightforward command structure, `cnsh` integrates seamlessly into your development workflow, simplifying package management.
Support for both global and local package installations allows for flexible management of dependencies and tools.
The `--verbose` flag provides detailed logging, aiding in debugging and tracking installation processes.
`cnsh` automatically fetches the tarball URL from the API, ensuring accurate and up-to-date installations.
The package manager retrieves and handles package versions from the API, ensuring your project uses the correct version.
`cnsh` creates and uses a `cnsh.lock` file to manage package versions and tarball URLs, providing consistency across installations.
Here's a step-by-step guide on how `cnsh` operates:
`cnsh` detects if you typed the command `cnsh add` and begins the process of adding a package.
`cnsh` uses `ora` to display a loading animation while processing the request, keeping you informed of the progress.
`cnsh` calls `axios` to fetch the tarball of the npm package from the npm registry API.
`cnsh` uses `tar` to extract the tarball, which contains the package files.
`cnsh` saves the extracted files into a directory called `cnsh_lib`, created by `fs-extra`.
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.
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();
`cnsh` is written in a variant of JavaScript called ECMAScript Modules (ESM), which provides a modern approach to module management and imports.