Skip to content

Commit d83c9c5

Browse files
committed
Stabilize production build test
1 parent 66187b1 commit d83c9c5

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

ui/build/production.mts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ globalThis.global ??= globalThis
2626
function createBrowserVendorAliasPlugin() {
2727
const aliasEntries: Array<[RegExp, string]> = [
2828
[/^pino$/, path.join(MODULES_ROOT_PATH, 'pino', 'browser.js')],
29-
[/^viem$/, path.join(MODULES_ROOT_PATH, 'viem', 'index.ts')],
30-
[/^viem\/chains$/, path.join(MODULES_ROOT_PATH, 'viem', 'chains', 'index.ts')],
31-
[/^viem\/window$/, path.join(MODULES_ROOT_PATH, 'viem', 'window', 'index.ts')],
32-
[/^viem\/actions$/, path.join(MODULES_ROOT_PATH, 'viem', 'actions', 'index.ts')],
33-
[/^viem\/accounts$/, path.join(MODULES_ROOT_PATH, 'viem', 'accounts', 'index.ts')],
34-
[/^viem\/utils$/, path.join(MODULES_ROOT_PATH, 'viem', 'utils', 'index.ts')],
29+
[/^viem$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'index.js')],
30+
[/^viem\/chains$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'chains', 'index.js')],
31+
[/^viem\/window$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'window', 'index.js')],
32+
[/^viem\/actions$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'actions', 'index.js')],
33+
[/^viem\/accounts$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'accounts', 'index.js')],
34+
[/^viem\/utils$/, path.join(MODULES_ROOT_PATH, 'viem', '_esm', 'utils', 'index.js')],
3535
[/^tevm$/, path.join(MODULES_ROOT_PATH, '@tevm', 'memory-client', 'dist', 'index.js')],
3636
[/^tevm\/common$/, path.join(MODULES_ROOT_PATH, '@tevm', 'common', 'dist', 'index.js')],
3737
[/^@tevm\/memory-client$/, path.join(MODULES_ROOT_PATH, '@tevm', 'memory-client', 'dist', 'index.js')],
@@ -53,7 +53,11 @@ function createBrowserVendorAliasPlugin() {
5353

5454
async function copyStaticAsset(sourcePath: string, destinationPath: string) {
5555
await fs.mkdir(path.dirname(destinationPath), { recursive: true })
56-
await fs.copyFile(sourcePath, destinationPath)
56+
const sourceFile = Bun.file(sourcePath)
57+
if (!(await sourceFile.exists())) {
58+
throw new Error(`Missing static asset: ${sourcePath}`)
59+
}
60+
await Bun.write(destinationPath, await sourceFile.arrayBuffer())
5761
}
5862

5963
async function writeProductionIndexHtml() {

ui/build/productionBuild.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { afterAll, beforeAll, expect, test } from 'bun:test'
2+
import { spawnSync } from 'node:child_process'
23
import * as fs from 'node:fs/promises'
34
import * as path from 'node:path'
45
import * as url from 'node:url'
5-
import { buildProductionBundle } from './production.mts'
66

77
const directoryOfThisFile = path.dirname(url.fileURLToPath(import.meta.url))
88
const repositoryRootPath = path.join(directoryOfThisFile, '..', '..')
@@ -19,7 +19,13 @@ const productionFaviconPaths = [path.join(distRootPath, 'favicon.ico'), path.joi
1919
let server: Bun.Server | undefined
2020

2121
beforeAll(async () => {
22-
await buildProductionBundle()
22+
const result = spawnSync('bun', ['run', 'ui:build:prod'], {
23+
cwd: repositoryRootPath,
24+
encoding: 'utf8',
25+
})
26+
if (result.status !== 0) {
27+
throw new Error(`ui:build:prod failed\n${result.stdout}${result.stderr}`)
28+
}
2329

2430
server = Bun.serve({
2531
fetch: async request => {

0 commit comments

Comments
 (0)