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

eszip

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

111 releases (breaking)

0.79.1 Sep 26, 2024
0.78.0 Aug 30, 2024
0.73.0 Jul 31, 2024
0.64.2 Feb 23, 2024
0.7.0 Mar 31, 2021

#338 in Parser implementations

Download history 1155/week @ 2024-07-29 901/week @ 2024-08-05 966/week @ 2024-08-12 1371/week @ 2024-08-19 1462/week @ 2024-08-26 1183/week @ 2024-09-02 1189/week @ 2024-09-09 1060/week @ 2024-09-16 1168/week @ 2024-09-23 1098/week @ 2024-09-30 1924/week @ 2024-10-07 1643/week @ 2024-10-14 814/week @ 2024-10-21 412/week @ 2024-10-28 420/week @ 2024-11-04 397/week @ 2024-11-11

2,156 downloads per month
Used in 12 crates (9 directly)

MIT license

180KB
4.5K SLoC

Rust 4K SLoC // 0.0% comments TypeScript 537 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

~24–35MB
~580K SLoC