Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esmgen

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esmgen - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

package.json
{
"name": "esmgen",
"version": "2.0.0",
"version": "2.0.1",
"description": "A CLI tool that generates and packages ESM modules from npm into a structured directory, serving with a static file server.",

@@ -5,0 +5,0 @@ "main": "cli.js",

# ESMGen
ESMGen is a self-hosted alternative to esm.sh, focusing on simplicity. It generates and organizes ECMAScript Modules from npm packages for static storage, allowing developers to self-host these ESM packages without external service dependencies.

@@ -9,30 +10,15 @@

- Serve ESM modules over a local HTTP server.
- Remove ESM packages and update dependencies in `package.json`.
- Emphasizes self-hosting and static file generation for efficient and private module usage.
## Commands Overview
## Basic Usage
This CLI tool offers commands to manage ESM modules efficiently:
```
npx esmgen dl lodash
```
### Add and Convert Command
Result:
```plaintext
esm/
└── lodash@4.17.21/
├── bundle.js
└── ...
```
## Usage
ESMGen provides two primary commands: `download` and `serve`.
### Download and Convert Command
**Command:**
```bash
npx esmgen download [pkg] [version] [options]
npx esmgen add [pkg] [version] [options]
```

@@ -42,15 +28,15 @@

- `dl`
- `d`
- `a`
**Description:** Downloads a specified npm package, converts it to an ESM module, and organizes it in a directory structure that reflects its name and version for easy identification and use.
**Description:** Downloads a specified npm package, converts it to an ESM module, organizes it in a directory structure by name and version, and optionally serves the package immediately.
**Options:**
- `--registry <url>`: Specify the npm registry source (default: `https://registry.npmjs.org/`).
- `--dir <dir>`: Specify the directory to store the converted ESM modules (default: `./esm`).
- `--serve`: Serve the converted ESM modules over HTTP immediately after conversion.
- `--port <port>`: Set the port for the server (default: `3000`).
- `--host <host>`: Set the host address for binding the server (default: `127.0.0.1`).
- `--entry <entryFile>`: Specify a custom HTML entry file to be served as the root (used when serving).
- `--registry`: Registry to download the package from (default: `https://registry.npmjs.org/`).
- `--dir <dir>`: Directory for storing the converted ESM modules (default: `./esm`).
- `--serve`: Serve the converted ESM modules over HTTP immediately.
- `--port <port>`: Port for the local server (default: `3000`).
- `--host <host>`: Host address for binding the server (default: `127.0.0.1`).
- `--entry <entryFile>`: Specify a custom HTML entry file to serve as the root.
- `--include-all-assets`: Include all non-JS assets in the conversion.

@@ -60,3 +46,3 @@ **Example:**

```bash
npx esmgen download react 17.0.0 --serve --port 4001 --entry customIndex.html
npx esmgen add react 17.0.0 --serve --port 4001 --entry customIndex.html
```

@@ -74,10 +60,10 @@

**Description:** Start an HTTP server to serve ESM modules from the specified directory.
**Description:** Start an HTTP server to serve ESM modules from a specified directory.
**Options:**
- `--port <port>`: Specify the serve port (default: `3000`).
- `--host <host>`: Specify the host for binding (default: `127.0.0.1`).
- `--dir <dir>`: Specify the directory of ESM modules to serve (default: `./esm`).
- `--entry <entryFile>`: Specify a custom HTML entry file to serve as the root.
- `--port <port>`: Specify the server's port (default: `3000`).
- `--host <host>`: Specify the server's host binding (default: `127.0.0.1`).
- `--dir <dir>`: Directory of ESM modules to serve (default: `./esm`).
- `--entry <entryFile>`: Specify a custom HTML entry file as the root input.

@@ -90,5 +76,26 @@ **Example:**

### Remove Command
**Command:**
```bash
npx esmgen remove <pkg>
```
**Aliases:**
- `rm`
- `r`
**Description:** Removes an ESM package from the local directory and updates `package.json`.
**Example:**
```bash
npx esmgen remove lodash
```
## Organization of ESM Modules
The converted ESM modules are organized in a folder structure based on the package name and version. This facilitates easy self-hosting and retrieval of specific module versions. Example folder structure after conversion might look like this:
The converted ESM modules are organized in a folder structure based on the package name and version, facilitating easy self-hosting and retrieval of specific module versions. Example folder structure:

@@ -102,11 +109,11 @@ ```plaintext

This organization makes it simple to manage multiple versions of modules and ensure compatibility across projects by selectively including the necessary files.
This arrangement ensures compatibility across projects by allowing selective inclusion and facilitation of multiple module versions.
## Using the Converted Modules in a Browser
Once converted and optionally served, you can import these modules using modern web practices:
Once converted and optionally served, you can import these modules using standard browser import techniques:
### Direct Import
If you're running an internal server via the `--serve` flag, import directly:
When running an internal server with the `--serve` flag:

@@ -116,3 +123,2 @@ ```html

import { something } from 'http://127.0.0.1:3000/react@17.0.0/bundle.js';
console.log(something);

@@ -124,3 +130,3 @@ </script>

Use import maps to define module paths for browser ease.
Define module paths for direct browser usage with import maps:

@@ -138,9 +144,4 @@ ```html

import React from 'react';
console.log(React);
</script>
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc