cnsh
is a lightweight package manager that provides a minimal alternative to Yarn. It fetches packages from the npm registry and installs them in a simplified directory structure.
- Add Packages: Install packages from the npm registry.
- Remove Packages: Uninstall packages from your project.
- Install Dependencies: Install all dependencies listed in
package.json
. - Global and Local Installation: Supports both global and local package management.
- Simple and Efficient: Focuses on essential features for ease of use.
To install cnsh
globally, follow these steps:
-
Install via pnpm
Run the following command in your terminal:
pnpm install -g cnsh --verbose
This will install
cnsh
globally, making it available from any directory on your system. -
Verify Installation
To check if
cnsh
is installed correctly, run:cnsh
If
cnsh
is installed, you should see the following output in red text along with the output from the--help
command:
Unknown command.
This confirms that cnsh
is properly installed and recognizing commands.
cnsh
offers a simple set of commands for managing packages. Here’s how to use it:
To add a package to your project, use:
cnsh add <package-name> --verbose
For example, to add lodash
:
cnsh add lodash --verbose
This installs lodash
into your project's cnsh_lib
directory.
To update it, run this command in your terminal:
pnpm install -g cnsh@latest
To remove a package, use:
cnsh remove <package-name>
For example, to remove lodash
:
cnsh remove lodash
To install all dependencies listed in your package.json
, use:
cnsh install
This reads the package.json
file and installs all listed dependencies into your cnsh_lib
directory.
To install a package globally, use:
cnsh add -g <package-name>
Global packages will be installed in a global directory (typically ~/.cnsh-global/cnsh_lib
).
For a list of available commands and help, use:
cnsh --help
Here’s a demonstration of how to use axios
with cnsh
:
-
Install
axios
cnsh add axios
-
Create a Simple Node.js Script
Create a file named
app.js
with the following content:// Import axios from the local path where cnsh stores it import axios from './cnsh_lib/axios/package/dist/esm/axios.min.js'; // Function to fetch data from a public API async function fetchData() { try { const response = await axios.get('https://jsonplaceholder.typicode.com/posts/1'); console.log('Data fetched:', response.data); } catch (error) { console.error('Error fetching data:', error); } } // Call the fetchData function fetchData();
or if you like CommonJS better:
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();
UMD:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['axios'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node.js or CommonJS
module.exports = factory(require('./cnsh_lib/axios/package/dist/axios.js'));
} else {
// Browser global
root.fetchData = factory(root.axios);
}
}(typeof self !== 'undefined' ? self : this, function (axios) {
'use strict';
// Function to fetch data from a public API
async function fetchData() {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/posts/1');
console.log('Data fetched:', response.data);
} catch (error) {
console.error('Error fetching data:', error);
}
}
// Return the function as part of the UMD module
return fetchData;
}));
// To call fetchData in a browser environment:
fetchData();
-
Run Your Script
Execute your script using Node.js:
node app.js
You should see the data fetched from the public API printed to your console.
Feel free to open issues or submit pull requests to help improve cnsh
. If you have suggestions or feature requests, please let us know!
- needs to install packages in
node_modules/.cnsh
and create a symlink - can only be used for packages without dependencies
- Needs a
run
command - needs to make a exported path for global packages
- needs a update Alert for The version specified in the
package.json
does not matchThe version according to the npm API
Once you Fork the package, publish it to npm with a name like @cnsh/{id}
Thanks for contributing!
This project is licensed under the ISC License - see the LICENSE file for details.