11#! /usr/bin/env bash
22
3+ # Quick sanity check for consumers of @lit-protocol/constants and contracts-sdk.
4+ # We spin up two tiny entry points, bundle them with esbuild, and dump which
5+ # @lit-protocol/contracts artifacts actually end up in the output. That makes it
6+ # easy to see whether only the intended network blobs are being shipped.
7+
38set -euo pipefail
49
510SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
1419
1520mkdir -p " $BUNDLE_DIR "
1621
17- # Ensure entry files exist so the script is self-contained.
22+ # Modules that are Node-only; when bundling for browsers we treat them as
23+ # externals so esbuild doesn't error on builtins like `crypto`.
24+ BROWSER_EXTERNALS=(
25+ assert buffer child_process crypto fs http https module net os path stream
26+ timers tls tty url util zlib
27+ )
28+ BROWSER_EXTERNAL_ARGS=()
29+ for mod in " ${BROWSER_EXTERNALS[@]} " ; do
30+ BROWSER_EXTERNAL_ARGS+=(--external:" $mod " )
31+ done
32+
33+ # Generate the constants entry: loads NETWORK_CONTEXT_BY_NETWORK so the mapper
34+ # import path is exercised the same way a consuming app would.
1835cat > " $BUNDLE_DIR /constants-entry.js" << 'JS '
1936const { NETWORK_CONTEXT_BY_NETWORK } = require('@lit-protocol/constants');
2037
@@ -25,6 +42,8 @@ if (!NETWORK_CONTEXT_BY_NETWORK?.datil) {
2542console.log('datil contracts count:', NETWORK_CONTEXT_BY_NETWORK.datil.data.length);
2643JS
2744
45+ # Generate the contracts SDK entry: touches LitContracts to mimic a typical SDK
46+ # consumer without pulling in unrelated code.
2847cat > " $BUNDLE_DIR /contracts-sdk-entry.js" << 'JS '
2948const { LitContracts } = require('@lit-protocol/contracts-sdk');
3049
@@ -35,57 +54,97 @@ if (typeof LitContracts !== 'function') {
3554console.log('LitContracts ready');
3655JS
3756
38- echo " Bundling constants mapper (browser)..."
57+ # Bundle both entries for browser + node targets so we catch regressions in
58+ # either environment.
59+ echo " ⭐️ [Browser] Bundling @lit-protocol/constants mapper..."
3960" $ESBUILD " " $BUNDLE_DIR /constants-entry.js" \
4061 --bundle \
4162 --platform=browser \
4263 --format=esm \
43- --outfile=" $BUNDLE_DIR /constants-bundle.js" \
44- --metafile=" $BUNDLE_DIR /constants-meta.json" \
64+ --outfile=" $BUNDLE_DIR /constants-browser-bundle.js" \
65+ --metafile=" $BUNDLE_DIR /constants-browser-meta.json" \
66+ " ${BROWSER_EXTERNAL_ARGS[@]} " \
67+ --log-level=info > /dev/null
68+
69+ echo " ⭐️ [CJS] Bundling @lit-protocol/constants mapper..."
70+ " $ESBUILD " " $BUNDLE_DIR /constants-entry.js" \
71+ --bundle \
72+ --platform=node \
73+ --format=cjs \
74+ --outfile=" $BUNDLE_DIR /constants-node-bundle.cjs" \
75+ --metafile=" $BUNDLE_DIR /constants-node-meta.json" \
76+ --log-level=info > /dev/null
77+
78+ echo " ⭐️ [Browser] Bundling @lit-protocol/contracts-sdk..."
79+ " $ESBUILD " " $BUNDLE_DIR /contracts-sdk-entry.js" \
80+ --bundle \
81+ --platform=browser \
82+ --format=esm \
83+ --outfile=" $BUNDLE_DIR /contracts-sdk-browser-bundle.js" \
84+ --metafile=" $BUNDLE_DIR /contracts-sdk-browser-meta.json" \
85+ " ${BROWSER_EXTERNAL_ARGS[@]} " \
4586 --log-level=info > /dev/null
4687
47- echo " Bundling contracts SDK (node target for CJS) ..."
88+ echo " ⭐️ [CJS] Bundling @lit-protocol/contracts-sdk ..."
4889" $ESBUILD " " $BUNDLE_DIR /contracts-sdk-entry.js" \
4990 --bundle \
5091 --platform=node \
5192 --format=cjs \
52- --outfile=" $BUNDLE_DIR /contracts-sdk-bundle.cjs" \
53- --metafile=" $BUNDLE_DIR /contracts-sdk-meta.json" \
93+ --outfile=" $BUNDLE_DIR /contracts-sdk-node- bundle.cjs" \
94+ --metafile=" $BUNDLE_DIR /contracts-sdk-node- meta.json" \
5495 --log-level=info > /dev/null
5596
97+ # Pretty-print the relevant portion of esbuild's metafile so it's obvious which
98+ # contract blobs made it into the bundle and their combined size.
5699summarise_meta () {
57100 local label=" $1 "
58101 local meta_path=" $2 "
102+ local indent=" ${3:- } "
59103 echo " "
60- echo " $label "
61- META_PATH=" $meta_path " node - << 'NODE '
104+ echo " ${indent}${label} "
105+ echo " ${indent} (Every line below lists a bundled @lit-protocol/contracts file and its raw size)"
106+ META_PATH=" $meta_path " INDENT=" $indent " node - << 'NODE '
62107const path = require('path');
63108const metaPath = process.env.META_PATH;
64109const meta = require(metaPath);
110+ const indent = process.env.INDENT || '';
65111const entries = Object.entries(meta.inputs)
66112 .filter(([p]) => p.includes(path.join('@lit-protocol', 'contracts')));
67113
68114if (entries.length === 0) {
69- console.log(' <no @lit-protocol/contracts files detected>' );
115+ console.log(`${indent} <no @lit-protocol/contracts files detected>` );
70116 process.exit(0);
71117}
72118
73119let total = 0;
74120for (const [file, info] of entries) {
75121 total += info.bytes;
76- console.log(
77- ` ${file} -> ${(info.bytes / 1024).toFixed(2)} KiB`
78- );
122+ console.log(`${indent} ${file} -> ${(info.bytes / 1024).toFixed(2)} KiB`);
79123}
80124
81- console.log(
82- ` Total -> ${(total / 1024 / 1024).toFixed(3)} MiB`
83- );
125+ console.log(`${indent} Total -> ${(total / 1024 / 1024).toFixed(3)} MiB`);
84126NODE
127+ echo " ${indent} (Total reflects the sum of those files before compression/minification)"
85128}
86129
87- summarise_meta " Constants bundle includes:" " $BUNDLE_DIR /constants-meta.json"
88- summarise_meta " Contracts SDK bundle includes:" " $BUNDLE_DIR /contracts-sdk-meta.json"
130+ summarise_package () {
131+ local package_label=" $1 "
132+ local browser_meta=" $2 "
133+ local node_meta=" $3 "
134+
135+ echo " "
136+ echo " ⭐️ ${package_label} bundles:"
137+ summarise_meta " Browser includes:" " $browser_meta " " "
138+ summarise_meta " Node includes:" " $node_meta " " "
139+ }
140+
141+ summarise_package " @lit-protocol/constants" \
142+ " $BUNDLE_DIR /constants-browser-meta.json" \
143+ " $BUNDLE_DIR /constants-node-meta.json"
144+
145+ summarise_package " @lit-protocol/contracts-sdk" \
146+ " $BUNDLE_DIR /contracts-sdk-browser-meta.json" \
147+ " $BUNDLE_DIR /contracts-sdk-node-meta.json"
89148
90149echo " "
91150echo " Artifacts written to $BUNDLE_DIR "
0 commit comments