#typescript #javascript #graph #module #file-format #serialization #compact

eszip

A utility that can download JavaScript and TypeScript module graphs and store them locally in a special zip file

103 releases (breaking)

new 0.72.2 Jul 9, 2024
0.71.0 Jun 4, 2024
0.64.2 Feb 23, 2024
0.56.0 Dec 5, 2023
0.7.0 Mar 31, 2021

#244 in Parser implementations

Download history 1037/week @ 2024-03-14 992/week @ 2024-03-21 1646/week @ 2024-03-28 1218/week @ 2024-04-04 1663/week @ 2024-04-11 1573/week @ 2024-04-18 1402/week @ 2024-04-25 1277/week @ 2024-05-02 1352/week @ 2024-05-09 1800/week @ 2024-05-16 1341/week @ 2024-05-23 1240/week @ 2024-05-30 982/week @ 2024-06-06 1271/week @ 2024-06-13 1398/week @ 2024-06-20 784/week @ 2024-06-27

4,674 downloads per month
Used in 8 crates

MIT license

170KB
3.5K SLoC

Rust 3K SLoC // 0.0% comments TypeScript 525 SLoC // 0.1% comments TSX 15 SLoC JavaScript 5 SLoC

eszip

The eszip format lets you losslessly serialize an ECMAScript module graph (represented by deno_graph::ModuleGraph) into a single compact file.

The eszip file format is designed to be compact and streaming capable. This allows for efficient loading of large ECMAScript module graphs.

https://eszip-viewer.deno.dev/ is a tool for inspecting eszip files.

Examples

Creating an eszip

cargo run --example eszip_builder https://deno.land/std/http/file_server.ts file_server.eszip2

Viewing the contents of an eszip

cargo run --example eszip_viewer file_server.eszip2

Loading the eszip into V8

cargo run --example eszip_load file_server.eszip2 https://deno.land/std/http/file_server.ts

File format

The file format looks as follows:

Eszip:
| Magic (8) | Header size (4) | Header (n) | Header hash (32) | Sources size (4) | Sources (n) | SourceMaps size (4) | SourceMaps (n) |

Header:
( | Specifier size (4) | Specifier (n) | Entry type (1) | Entry (n) | )*

Entry (redirect):
| Specifier size (4) | Specifier (n) |

Entry (module):
| Source offset (4) | Source size (4) | SourceMap offset (4) | SourceMap size (4) | Module type (1) |

Sources:
( | Source (n) | Hash (32) | )*

SourceMaps:
( | SourceMap (n) | Hash (32) | )*

There is one optimization for empty source / source map entries. If both the offset and size are set to 0, no entry and no hash is present in the data sections for that module.

Development

When opening a PR make sure to rebuild Wasm by running:

deno task build

Dependencies

~19–28MB
~473K SLoC