Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: improve bundle size (#1070)
Browse files Browse the repository at this point in the history
Co-authored-by: T6 <t6@t6.fyi>
  • Loading branch information
kratico and tjjfvi authored Jun 15, 2023
1 parent b645ce9 commit 858e97e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _tasks/generate_artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as $ from "../deps/scale.ts"
import { emptyDir } from "../deps/std/fs.ts"
import * as path from "../deps/std/path.ts"
import dprintConfig from "../dprint.json" assert { type: "json" }
import { devUser } from "../nets/chain_spec/addDevUsers.ts"
import { devUser } from "../mod.ts"
import { compress } from "../util/compression.ts"

export const DEV_USER_COUNT = 10_000
Expand Down
8 changes: 4 additions & 4 deletions cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ async function runInitNode(packageJsonPath: string) {
scripts["capi:sync"] = "capi sync node"
scripts["capi:serve"] = "capi serve"
Deno.writeTextFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
await Promise.all([netsInit("capi"), updateGitignore()])
await Promise.all([netsInit("capi/nets"), updateGitignore()])
}

async function runInitDeno(denoJsonPath: string) {
const denoJson = parse(Deno.readTextFileSync(denoJsonPath))
assertManifest(denoJson)
const tasks = denoJson.tasks ??= {}
const version = detectVersion()
const versioned = `http://deno.land/x/capi${version ? `@${version}` : ""}/main.ts`
tasks["capi"] = `deno run -A ${versioned}`
const versioned = `http://deno.land/x/capi${version ? `@${version}` : ""}`
tasks["capi"] = `deno run -A ${versioned}/main.ts`
tasks["capi:sync"] = "deno task capi sync node"
tasks["capi:serve"] = "deno task capi serve"
Deno.writeTextFileSync(denoJsonPath, JSON.stringify(denoJson, null, 2))
await Promise.all([netsInit(versioned), updateGitignore()])
await Promise.all([netsInit(`${versioned}/nets/mod.ts`), updateGitignore()])
}

async function netsInit(specifier: string) {
Expand Down
6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ if (CAPI_MARKER in globalThis) {

export * as $ from "./deps/scale.ts"
export { BitSequence } from "./deps/scale.ts"
export * from "./server/client/mod.ts"
export * from "./server/client/createDevUsers.ts"
export * from "./server/client/detectConnect.ts"

// moderate --exclude main.ts nets.ts util server
// moderate --exclude main.ts nets.ts util server nets

export * from "./crypto/mod.ts"
export * from "./fluent/mod.ts"
export * from "./frame_metadata/mod.ts"
export * from "./nets/mod.ts"
export * from "./rpc/mod.ts"
export * from "./rune/mod.ts"
export * from "./scale_info/mod.ts"
2 changes: 1 addition & 1 deletion nets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bins, net } from "./mod.ts"
import { bins, net } from "./nets/mod.ts"

const bin = bins({
polkadot: ["polkadot-fast", "v0.9.38"],
Expand Down
6 changes: 1 addition & 5 deletions nets/chain_spec/addDevUsers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blake2_512, Sr25519, ss58 } from "../../crypto/mod.ts"
import { ss58 } from "../../crypto/mod.ts"
import * as $ from "../../deps/scale.ts"
import { devUserPublicKeysData } from "../../util/_artifacts/devUserPublicKeysData.ts"
import { GenesisConfig } from "./ChainSpec.ts"
Expand All @@ -15,7 +15,3 @@ export function addDevUsers(genesisConfig: GenesisConfig) {
balances.push([ss58.encode(networkPrefix, publicKey), devUserInitialFunds])
}
}

export function devUser(userId: number) {
return Sr25519.fromSeed64(blake2_512.hash(new TextEncoder().encode(`capi-dev-user-${userId}`)))
}
7 changes: 5 additions & 2 deletions server/client/createDevUsers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Sr25519 } from "../../crypto/mod.ts"
import { devUser } from "../../nets/mod.ts"
import { blake2_512, Sr25519 } from "../../crypto/mod.ts"
import { ArrayOfLength } from "../../util/ArrayOfLength.ts"
import { detectServer } from "./detectServer.ts"

export function devUser(userId: number) {
return Sr25519.fromSeed64(blake2_512.hash(new TextEncoder().encode(`capi-dev-user-${userId}`)))
}

export function createDevUsers(): Promise<Record<typeof devUserNames[number], Sr25519>>
export function createDevUsers<N extends number>(count: N): Promise<ArrayOfLength<Sr25519, N>>
export async function createDevUsers(count?: number): Promise<Record<string, Sr25519> | Sr25519[]> {
Expand Down

0 comments on commit 858e97e

Please sign in to comment.