Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit 7eb1b26

Browse files
committedSep 7, 2021
solved web build
1 parent dafc0cf commit 7eb1b26

File tree

9 files changed

+586
-44
lines changed

9 files changed

+586
-44
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ Single bundle file (web only - use the NPM method if using Node).
5151

5252
```html
5353
<!-- Latest -->
54-
<script src="https://unpkg.com/ardk/dist/ardk.js"></script>
54+
<script src="https://unpkg.com/ardk/dist/ardk-web.js"></script>
5555

5656
<!-- Latest, minified-->
57-
<script src="https://unpkg.com/ardk/bundles/web.bundle.min.js"></script>
57+
<script src="https://unpkg.com/ardk/dist/ardk-web.min.js"></script>
5858

5959
<!-- Specific version -->
60-
<script src="https://unpkg.com/ardk@1.0.0/dist/ardk.js"></script>
60+
<script src="https://unpkg.com/ardk@1.0.0/dist/ardk-web.js"></script>
6161

6262
<!-- Specific version, minified -->
63-
<script src="https://unpkg.com/ardk@1.0.0/dist/ardk.min.js"></script>
63+
<script src="https://unpkg.com/ardk@1.0.0/dist/ardk-web.min.js"></script>
6464
```
6565

6666

@@ -84,7 +84,7 @@ const ardk = new Ardk();
8484
<head>
8585
<meta charset="UTF-8">
8686
<title>Hello world</title>
87-
<script src="https://unpkg.com/ardk/dist/ardk.js"></script>
87+
<script src="https://unpkg.com/ardk/dist/ardk-web.js"></script>
8888
<script>
8989
const ardk = new Ardk();
9090
ardk.network.getInfo().then(console.log);

‎build.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
const { build } = require('esbuild');
1+
import { build } from 'esbuild';
2+
import { nodeBuiltIns } from 'esbuild-node-builtins';
23

34
const runBuild = async () => {
45
// Build to browser js
56
build({
6-
external: ['fs', 'path', 'os', 'crypto'],
7+
plugins: [nodeBuiltIns()],
78
entryPoints: ['./src/ardk.ts'],
89
minify: false,
910
bundle: true,
1011
platform: 'browser',
1112
target: ['es2019'],
12-
outfile: './lib/ardk-web.js',
13+
outfile: './dist/ardk-web.js',
1314
sourcemap: 'external',
1415
define: {
15-
'process.env.NODE_DEBUG': false,
16+
'process.env.NODE_DEBUG': 'false',
1617
'process.env.NODE_ENV': 'production',
17-
'process.env.DEBUG': false,
18+
'process.env.DEBUG': 'false',
19+
'global': 'window',
20+
'process.cwd': 'String',
21+
'_smartweave_1.LoggerFactory.INST': '{"create": "function() {}"}',
22+
'__filename': 'String',
1823
}
1924
}).catch((e) => {
2025
console.log(e);
@@ -23,18 +28,22 @@ const runBuild = async () => {
2328

2429
// Minified version
2530
build({
26-
external: ['fs', 'path', 'os', 'crypto'],
31+
plugins: [nodeBuiltIns()],
2732
entryPoints: ['./src/ardk.ts'],
2833
minify: true,
2934
bundle: true,
3035
platform: 'browser',
3136
target: ['es2019'],
32-
outfile: './lib/ardk-web.min.js',
37+
outfile: './dist/ardk-web.min.js',
3338
sourcemap: 'external',
3439
define: {
35-
'process.env.NODE_DEBUG': false,
40+
'process.env.NODE_DEBUG': 'false',
3641
'process.env.NODE_ENV': 'production',
37-
'process.env.DEBUG': false,
42+
'process.env.DEBUG': 'false',
43+
'global': 'window',
44+
'process.cwd': 'String',
45+
'_smartweave_1.LoggerFactory.INST': '{"create": "function() {}"}',
46+
'__filename': 'String',
3847
}
3948
}).catch((e) => {
4049
console.log(e);

‎package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "ardk",
33
"version": "1.0.1",
4-
"main": "lib/ardk.js",
4+
"main": "dist/ardk.js",
55
"repository": "https://github.com/textury/ardk.git",
66
"author": "Cedrik <cedrik.git@tryninja.io>",
77
"license": "MIT",
88
"files": [
9-
"lib/**/*"
9+
"dist/**/*"
1010
],
1111
"scripts": {
12-
"prebuild": "rimraf lib",
12+
"prebuild": "rimraf dist",
1313
"build": "tsc && ts-node build.ts",
1414
"format": "prettier --write \"src/**/*.ts\"",
1515
"test": "npm run test:node && npm run test:web",
@@ -27,7 +27,7 @@
2727
"arconnect": "^0.2.9",
2828
"axios": "^0.21.1",
2929
"bignumber.js": "^9.0.1",
30-
"redstone-smartweave": "^0.3.8-alpha.1",
30+
"redstone-smartweave": "^0.3.10-alpha.1",
3131
"util": "^0.12.4"
3232
},
3333
"devDependencies": {
@@ -37,6 +37,7 @@
3737
"@types/node": "^16.7.10",
3838
"browserslist": "^4.16.8",
3939
"esbuild": "^0.12.25",
40+
"esbuild-node-builtins": "^0.1.0",
4041
"jest": "^27.1.0",
4142
"jest-config": "^27.1.0",
4243
"prettier": "^2.3.2",
@@ -49,4 +50,4 @@
4950
"typedoc-plugin-markdown": "^3.10.4",
5051
"typescript": "^4.4.2"
5152
}
52-
}
53+
}

‎src/ardk.ts

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export default class Ardk {
6969
}
7070
}
7171

72+
if (window) {
73+
window.Ardk = Ardk;
74+
}
75+
7276
declare global {
7377
interface Window {
7478
Ardk: typeof Ardk;

‎src/utils/buffer.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toByteArray, fromByteArray } from './b64';
2+
import util from 'util';
23

34
export type Base64UrlString = string;
45

@@ -28,8 +29,7 @@ export function b64UrlToString(b64UrlString: string): string {
2829

2930
// TextEncoder will be available in browsers, but not in node
3031
if (typeof TextDecoder === 'undefined') {
31-
const TextDecoder = require('util').TextDecoder;
32-
return new TextDecoder('utf-8', { fatal: true }).decode(buffer);
32+
return new util.TextDecoder('utf-8', { fatal: true }).decode(buffer);
3333
}
3434

3535
return new TextDecoder('utf-8', { fatal: true }).decode(buffer);
@@ -38,8 +38,7 @@ export function b64UrlToString(b64UrlString: string): string {
3838
export function bufferToString(buffer: Uint8Array | ArrayBuffer): string {
3939
// TextEncoder will be available in browsers, but not in node
4040
if (typeof TextDecoder === 'undefined') {
41-
const TextDecoder = require('util').TextDecoder;
42-
return new TextDecoder('utf-8', { fatal: true }).decode(buffer);
41+
return new util.TextDecoder('utf-8', { fatal: true }).decode(buffer);
4342
}
4443

4544
return new TextDecoder('utf-8', { fatal: true }).decode(buffer);
@@ -48,8 +47,7 @@ export function bufferToString(buffer: Uint8Array | ArrayBuffer): string {
4847
export function stringToBuffer(str: string): Uint8Array {
4948
// TextEncoder will be available in browsers, but not in node
5049
if (typeof TextEncoder === 'undefined') {
51-
const TextEncoder = require('util').TextEncoder;
52-
return new TextEncoder().encode(str);
50+
return new util.TextEncoder().encode(str);
5351
}
5452
return new TextEncoder().encode(str);
5553
}

‎src/utils/crypto.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JWKInterface } from '../faces/lib/wallet';
22
import CryptoInterface, { SignatureOptions } from '../faces/utils/crypto';
33
import { concatBuffers, stringToBuffer } from './buffer';
4+
import { webcrypto } from 'crypto';
45

56
export default class CryptoDriver implements CryptoInterface {
67
public readonly keyLength = 4096;
@@ -14,8 +15,8 @@ export default class CryptoDriver implements CryptoInterface {
1415
}
1516

1617
if (!this.driver) {
17-
const crypto = require('crypto').webcrypto;
18-
this.driver = crypto.subtle;
18+
// @ts-ignore
19+
this.driver = webcrypto.subtle;
1920
}
2021
}
2122

‎src/utils/fee.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SmartWeaveNodeFactory, LoggerFactory } from 'redstone-smartweave';
1+
import { SmartWeaveWebFactory } from 'redstone-smartweave';
22
import Ardk from '../ardk';
33

44
export default async function selectWeightedHolder(ardk: Ardk): Promise<string> {
@@ -48,10 +48,8 @@ async function getState(ardk: Ardk): Promise<{
4848
}> {
4949
const cxyzContractTxId = 'mzvUgNc8YFk0w5K5H7c8pyT-FC5Y_ba0r7_8766Kx74';
5050

51-
LoggerFactory.INST.logLevel('fatal');
52-
5351
// @ts-ignore
54-
const smartweave = SmartWeaveNodeFactory.memCached(ardk);
52+
const smartweave = SmartWeaveWebFactory.memCached(ardk);
5553

5654
// connecting to a given contract
5755
const cxyzContract = smartweave.contract(cxyzContractTxId);

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"target": "esnext",
44
"module": "commonjs",
55
"declaration": true,
6-
"outDir": "./lib",
6+
"outDir": "./dist",
77
"esModuleInterop": true,
88
"skipLibCheck": true
99
},

‎yarn.lock

+543-12
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
This repository has been archived.