Skip to content

Commit bc2ba11

Browse files
committed
Merge branch 'feat/tinny-standalone' into feature/lit-3748-naga
2 parents ac2b87f + fbe39cc commit bc2ba11

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed

local-tests/build.mjs

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
11
import * as esbuild from 'esbuild';
22
import { nodeExternalsPlugin } from 'esbuild-node-externals';
3-
import fs from 'fs';
43
import { fileURLToPath } from 'url';
5-
import { dirname, resolve } from 'path';
4+
5+
const ALLOW_LIST = [
6+
'ethers',
7+
'@lit-protocol/accs-schemas',
8+
'@lit-protocol/contracts',
9+
'crypto',
10+
'secp256k1',
11+
];
12+
13+
const getPath = (relativePath) =>
14+
fileURLToPath(new URL(relativePath, import.meta.url));
15+
16+
/**
17+
* Common esbuild configuration options.
18+
* @param {string} entry - Entry file path.
19+
* @param {string} outfile - Output file path.
20+
* @param {string} [globalName] - Optional global name for the bundle.
21+
* @returns {esbuild.BuildOptions} Esbuild configuration object.
22+
*/
23+
const createBuildConfig = (entry, outfile, globalName) => ({
24+
entryPoints: [getPath(entry)],
25+
outfile: getPath(outfile),
26+
bundle: true,
27+
plugins: [
28+
nodeExternalsPlugin({
29+
allowList: ALLOW_LIST,
30+
}),
31+
],
32+
platform: 'node',
33+
target: 'esnext',
34+
format: 'esm',
35+
inject: [getPath('./shim.mjs')],
36+
mainFields: ['module', 'main'],
37+
...(globalName ? { globalName } : {}),
38+
});
639

740
/**
8-
* Builds the project using esbuild.
9-
* @returns {Promise<void>} A promise that resolves when the build is complete.
41+
* Builds the CLI-enabled version of Tinny.
1042
*/
1143
export const build = async () => {
12-
await esbuild.build({
13-
entryPoints: [fileURLToPath(new URL('./index.ts', import.meta.url))],
14-
outfile: fileURLToPath(new URL('./index.js', import.meta.url)),
15-
bundle: true,
16-
globalName: 'tinnySdk',
17-
plugins: [
18-
nodeExternalsPlugin({
19-
allowList: [
20-
'ethers',
21-
'@lit-protocol/accs-schemas',
22-
'@lit-protocol/contracts',
23-
'crypto',
24-
'secp256k1',
25-
],
26-
}),
27-
],
28-
platform: 'node',
29-
target: 'esnext',
30-
format: 'esm',
31-
inject: [fileURLToPath(new URL('./shim.mjs', import.meta.url))],
32-
mainFields: ['module', 'main'],
33-
});
44+
await esbuild.build(createBuildConfig('./test.ts', './build/test.mjs'));
45+
};
46+
47+
/**
48+
* Bundles Tinny as a standalone package.
49+
*/
50+
export const bundle = async () => {
51+
await esbuild.build(
52+
createBuildConfig('./index.ts', './index.js', 'tinnySdk')
53+
);
3454
};
3555

3656
// Go!
3757
(async () => {
3858
const start = Date.now();
39-
await build();
40-
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`);
59+
try {
60+
await build();
61+
await bundle();
62+
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`);
63+
} catch (error) {
64+
console.error(`[build.mjs] ❌ Build failed:`, error);
65+
}
4166
})();

local-tests/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export {
1414
getEoaSessionSigs,
1515
getLitActionSessionSigs,
1616
getPkpSessionSigs,
17-
AccessControlConditions
17+
AccessControlConditions,
1818
};
1919

2020
// Usage

local-tests/setup/tinny-environment.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class TinnyEnvironment {
5050
DEBUG: process.env['DEBUG'] === 'true',
5151
REQUEST_PER_KILOSECOND:
5252
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
53-
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
53+
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
5454
? 1
5555
: 200,
5656
LIT_RPC_URL: process.env['LIT_RPC_URL'],
@@ -107,8 +107,9 @@ export class TinnyEnvironment {
107107
private _shivaClient: ShivaClient = new ShivaClient();
108108
private _contractContext: LitContractContext | LitContractResolverContext;
109109

110-
constructor(override?: Partial<ProcessEnvs> & { customNetworkContext?: any }) {
111-
110+
constructor(
111+
override?: Partial<ProcessEnvs> & { customNetworkContext?: any }
112+
) {
112113
this.customNetworkContext = override?.customNetworkContext;
113114

114115
// Merge default processEnvs with custom overrides
@@ -126,11 +127,12 @@ export class TinnyEnvironment {
126127
}
127128

128129
// -- setup network
129-
this.network = override.NETWORK || this.processEnvs.NETWORK;
130+
this.network = override?.NETWORK || this.processEnvs.NETWORK;
130131

131132
if (Object.values(LIT_NETWORK).indexOf(this.network) === -1) {
132133
throw new Error(
133-
`Invalid network environment ${this.network
134+
`Invalid network environment ${
135+
this.network
134136
}. Please use one of ${Object.values(LIT_NETWORK)}`
135137
);
136138
}
@@ -253,7 +255,8 @@ export class TinnyEnvironment {
253255

254256
if (this.network === LIT_NETWORK.Custom || centralisation === 'unknown') {
255257
const networkContext =
256-
this.customNetworkContext || (this?.testnet?.ContractContext ?? this._contractContext);
258+
this.customNetworkContext ||
259+
(this?.testnet?.ContractContext ?? this._contractContext);
257260
this.litNodeClient = new LitNodeClient({
258261
litNetwork: LIT_NETWORK.Custom,
259262
rpcUrl: this.rpc,
@@ -391,7 +394,8 @@ export class TinnyEnvironment {
391394

392395
await this.testnet.getTestnetConfig();
393396
} else if (this.network === LIT_NETWORK.Custom) {
394-
const context = this.customNetworkContext || await import('./networkContext.json');
397+
const context =
398+
this.customNetworkContext || (await import('./networkContext.json'));
395399
this._contractContext = context;
396400
}
397401

0 commit comments

Comments
 (0)