# 🍈 Vendorin

> Experimental software, use with caution

Vendor ES modules locally from esm.sh CDN - no more node_modules! Similar to npm but fetches ES modules directly and organizes them in a somewhat clean `./vendor/` directory.

## Features

- 📦 Reads dependencies from `package.json`
- 🌐 Fetches modules from esm.sh CDN
- 🔧 Uses AST-grep to analyze and rewrite import statements
- 📁 Organizes modules in `./vendor/` directory
- 🔄 Handles recursive dependencies
- ⚡ Skips already processed files

## Quick Start

```bash
# Install locally (recommended)
npm install --save-dev vendorin

# Or install globally
npm install -g vendorin
```

## Installation & Usage

### Global Installation

```bash
npm install -g vendorin
vendorin
```

### Local Installation (recommended)

```bash
npm install --save-dev vendorin
```

1. Add your dependencies to `package.json`:

```json
{
  "vendorin": {
    "dependencies": {
      "react": "^18.2.0",
      "lodash": "^4.17.21"
    }
  }
}
```

2. Run the vendor tool:

```bash
# If installed globally:
vendorin

# If installed locally:
npx vendorin
# or
npm run vendor  # (add "vendor": "vendorin" to scripts)
node src/cli.js
```

### Configuration

Configure your dependencies in `package.json`:

```json
{
  "vendorin": {
    "dependencies": {
      "react": "^18.2.0",
      "lodash": "^4.17.21",
      "axios": "^1.0.0"
    }
  }
}
```

Then import from the vendor directory:

```javascript
import React from './vendor/react.mjs';
import _ from './vendor/lodash.mjs';
import axios from './vendor/axios.mjs';
```

## CLI Usage

After installation, you can use the `vendorin` command directly:

```bash
# Vendor dependencies from package.json
vendorin

# The command will:
# 1. Read vendorin.dependencies from package.json
# 2. Fetch modules from esm.sh
# 3. Rewrite import paths
# 4. Save to ./vendor/ directory
```

## How it Works

1. **Package Analysis**: Reads `package.json` to discover dependencies
2. **Module Fetching**: Downloads ES modules from esm.sh CDN
3. **AST Processing**: Uses `ast-grep` to analyze JavaScript and rewrite imports
4. **Path Rewriting**: Converts esm.sh URLs to relative `./vendor/` paths
5. **Recursive Resolution**: Follows and processes all imported dependencies
6. **Local Organization**: Saves all modules in structured `./vendor/` directory

## Architecture

- **CLI Interface**: `src/cli.js` - Command-line entry point
- **Vendor Manager**: `src/vendor-manager.js` - Core fetching and processing logic
- **AST Helpers**: `src/utils/ast-helpers.js` - JavaScript AST analysis utilities

## Benefits

- **Offline Usage**: All dependencies stored locally
- **No node_modules**: Clean, organized vendor directory
- **ES Modules**: Native ESM support without bundling
- **CDN Optimization**: Leverages esm.sh's optimized builds
- **Dependency Transparency**: Clear visibility of all fetched modules
