Skip to content

Commit 5148f01

Browse files
committed
chore: cleanup tinny build scripts
1 parent 1f33367 commit 5148f01

File tree

10 files changed

+26
-162
lines changed

10 files changed

+26
-162
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/out-tsc
77
**/dist
88
**/out-tsc
9+
local-tests/**/*.js
910

1011
# dependencies
1112
node_modules

local-tests/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

local-tests/build.mjs

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
11
import * as esbuild from 'esbuild';
22
import { nodeExternalsPlugin } from 'esbuild-node-externals';
33
import fs from 'fs';
4-
5-
const TEST_DIR = 'local-tests';
4+
import { fileURLToPath } from 'url';
5+
import { dirname, resolve } from 'path';
66

77
/**
88
* Builds the project using esbuild.
99
* @returns {Promise<void>} A promise that resolves when the build is complete.
1010
*/
1111
export const build = async () => {
1212
await esbuild.build({
13-
entryPoints: [`${TEST_DIR}/test.ts`],
14-
outfile: `./${TEST_DIR}/build/test.mjs`,
15-
bundle: true,
16-
plugins: [
17-
nodeExternalsPlugin({
18-
allowList: [
19-
'ethers',
20-
'@lit-protocol/accs-schemas',
21-
'@lit-protocol/contracts',
22-
'crypto',
23-
'secp256k1',
24-
],
25-
}),
26-
],
27-
platform: 'node',
28-
target: 'esnext',
29-
format: 'esm',
30-
inject: [`./${TEST_DIR}/shim.mjs`],
31-
mainFields: ['module', 'main'],
32-
});
33-
34-
await esbuild.build({
35-
entryPoints: [`${TEST_DIR}/index.ts`],
36-
outfile: `./${TEST_DIR}/index.js`,
13+
entryPoints: [fileURLToPath(new URL('./index.ts', import.meta.url))],
14+
outfile: fileURLToPath(new URL('./index.js', import.meta.url)),
3715
bundle: true,
3816
globalName: 'tinnySdk',
3917
plugins: [
@@ -50,39 +28,14 @@ export const build = async () => {
5028
platform: 'node',
5129
target: 'esnext',
5230
format: 'esm',
53-
inject: [`./${TEST_DIR}/shim.mjs`],
31+
inject: [fileURLToPath(new URL('./shim.mjs', import.meta.url))],
5432
mainFields: ['module', 'main'],
5533
});
5634
};
5735

58-
/**
59-
* Inserts a polyfill at the beginning of a file.
60-
* The polyfill ensures that the global `fetch` function is available.
61-
* @returns {void}
62-
*/
63-
export const postBuildPolyfill = () => {
64-
try {
65-
const file = fs.readFileSync(`./${TEST_DIR}/build/test.mjs`, 'utf8');
66-
const content = `import fetch from 'node-fetch';
67-
try {
68-
if (!globalThis.fetch) {
69-
globalThis.fetch = fetch;
70-
}
71-
} catch (error) {
72-
console.error('❌ Error in polyfill', error);
73-
}
74-
`;
75-
const newFile = content + file;
76-
fs.writeFileSync(`./${TEST_DIR}/build/test.mjs`, newFile);
77-
} catch (e) {
78-
throw new Error(`Error in postBuildPolyfill: ${e}`);
79-
}
80-
};
81-
8236
// Go!
8337
(async () => {
8438
const start = Date.now();
8539
await build();
86-
postBuildPolyfill();
8740
console.log(`[build.mjs] 🚀 Build time: ${Date.now() - start}ms`);
8841
})();

local-tests/build/package.json

Lines changed: 0 additions & 93 deletions
This file was deleted.

local-tests/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { TinnyEnvironment } from './setup/tinny-environment';
22
import { runInBand, runTestsParallel } from './setup/tinny-operations';
33
import * as tinnyTests from './tests';
44

5-
export {
6-
TinnyEnvironment,
7-
runInBand,
8-
runTestsParallel,
9-
tinnyTests
10-
}
5+
export { TinnyEnvironment, runInBand, runTestsParallel, tinnyTests };
116

127
// Usage
138
// const devEnv = new TinnyEnvironment();
@@ -22,4 +17,4 @@ export {
2217
// }
2318

2419
// const res = await runTestsParallel(testConfig);
25-
// console.log("res:", res);
20+
// console.log("res:", res);

local-tests/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
2-
"name": "tinnytest",
3-
"version": "0.0.18",
2+
"name": "@lit-protocol/tinny",
3+
"version": "0.0.3",
44
"description": "A package to run the test script for Lit Protocol with custom commands",
55
"type": "module",
66
"main": "./index.js",
77
"typings": "./index.ts",
88
"license": "MIT",
99
"author": "Anson (https://github.com/ansonhkg)",
10+
"publishConfig": {
11+
"access": "public",
12+
"directory": "./"
13+
},
1014
"dependencies": {
1115
"@cosmjs/amino": "0.30.1",
1216
"@cosmjs/crypto": "0.30.1",

local-tests/setup/tinny-environment.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class TinnyEnvironment {
3636
DEBUG: process.env['DEBUG'] === 'true',
3737
REQUEST_PER_KILOSECOND:
3838
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
39-
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
39+
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
4040
? 1
4141
: 200,
4242
LIT_RPC_URL: process.env['LIT_RPC_URL'],
@@ -105,9 +105,13 @@ export class TinnyEnvironment {
105105
private _shivaClient: ShivaClient = new ShivaClient();
106106
private _contractContext: LitContractContext | LitContractResolverContext;
107107

108-
constructor(network?: LIT_NETWORK_VALUES) {
109-
// -- setup network
110-
this.network = network || this.processEnvs.NETWORK;
108+
constructor(override?: Partial<ProcessEnvs>) {
109+
110+
// Merge default processEnvs with custom overrides
111+
this.processEnvs = {
112+
...this.processEnvs,
113+
...override,
114+
};
111115

112116
if (Object.values(LIT_NETWORK).indexOf(this.network) === -1) {
113117
throw new Error(

local-tests/test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,4 @@ setLitActionsCodeToLocal();
325325
}
326326
await devEnv.stopTestnet();
327327
process.exit(res);
328-
329328
})();

local-tests/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,4 @@ export const tinnyTests = {
393393

394394
...relayerTests,
395395
...wrappedKeysTests,
396-
};
396+
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"publish:packages": "yarn node ./tools/scripts/pub.mjs --prod",
2424
"publish:beta": "yarn node ./tools/scripts/pub.mjs --tag beta",
2525
"publish:staging": "yarn node ./tools/scripts/pub.mjs --tag staging",
26+
"build:tinny": "node ./local-tests/build.mjs",
27+
"publish:tinny": "cd ./local-tests && npm publish",
2628
"gen:docs": "node ./tools/scripts/gen-doc.mjs",
2729
"gen:readme": "yarn node ./tools/scripts/gen-readme.mjs",
2830
"update:contracts-sdk": "yarn node ./packages/contracts-sdk/tools.mjs",
@@ -126,4 +128,4 @@
126128
"workspaces": [
127129
"packages/*"
128130
]
129-
}
131+
}

0 commit comments

Comments
 (0)