Skip to content

Commit

Permalink
Client post ESM migration cleanup (#3414)
Browse files Browse the repository at this point in the history
* Find package.json the right way

* remove client cjs build

* Remove cjs build entirely

---------

Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com>
  • Loading branch information
acolytec3 and jochem-brouwer committed May 10, 2024
1 parent ded3c6b commit 344c173
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"binWorkaround": "test -f dist/bin/cli.js || echo 'install fails if bin script does not exist (https://github.com/npm/cli/issues/2632), creating placeholder file at \"dist/bin/cli.js\"' && mkdir -p 'dist/bin' && touch dist/bin/cli.js",
"build": "npm run build:common && mkdir -p ./src/trustedSetup/ && cp -Rf ./src/trustedSetups ./dist/src/",
"build:common": "../../config/cli/ts-build.sh && ./scripts/postBuildFixes.sh",
"build:common": "./scripts/ts-build.sh && ./scripts/postBuildFixes.sh",
"bundle": "webpack",
"clean": "../../config/cli/clean-package.sh",
"client:start:ts": "tsx bin/cli.ts",
Expand Down
7 changes: 0 additions & 7 deletions packages/client/scripts/postBuildFixes.sh
Expand Up @@ -31,13 +31,6 @@ post_build_fixes() {
blue "[Post Build Fixes]"
if [ -f ./dist/esm/bin/cli.js ];
then
echo "Adding ./dist/cjs/package.json"
rm -f ./dist/cjs/package.json
cat <<EOT >> ./dist/cjs/package.json
{
"type": "commonjs"
}
EOT
echo "Adding ./dist/esm/package.json"
rm -f ./dist/esm/package.json
cat <<EOT >> ./dist/esm/package.json
Expand Down
71 changes: 71 additions & 0 deletions packages/client/scripts/ts-build.sh
@@ -0,0 +1,71 @@
#!/bin/sh
set -e
# Purposefully not using `set -o xtrace`, for friendlier output.


# Presentational variables and functions declaration.

BLUE="\033[0;34m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
RED="\033[0;31m"
NOCOLOR="\033[0m"
DIM="\033[2m"

blue() {
printf "${BLUE}$1${NOCOLOR}"
}
green() {
printf "${GREEN}$1${NOCOLOR}"
}
yellow() {
printf "${YELLOW}$1${NOCOLOR}"
}
red() {
printf "${RED}$1${NOCOLOR}"
}
dim() {
printf "${DIM}$1${NOCOLOR}"
}


# Build function declaration.
build_esm() {
if [ -f ./tsconfig.prod.esm.json ];
then
blue "[ESM build] "
echo "Using tsconfig.prod.esm.json"

echo "> tsc --build ./tsconfig.prod.esm.json"
printf "${BLUE}[ESM build] Working... "

tsc --build ./tsconfig.prod.esm.json
green "DONE"
else
echo "Skipping ESM build (no config available)."
fi
echo "\n";
}

post_build_fixes() {
blue "[Post Build Fixes]"
if [ -f ./dist/esm/index.js ];
then
echo "Adding ./dist/esm/package.json"
rm -f ./dist/esm/package.json
cat <<EOT >> ./dist/esm/package.json
{
"type": "module"
}
EOT
else
echo "Skipping post build fixes (no ESM setup yet)."
fi
echo "\n";
}


# Begin build process.
build_esm
post_build_fixes

7 changes: 6 additions & 1 deletion packages/client/src/client.ts
Expand Up @@ -126,7 +126,12 @@ export class EthereumClient {
}
const name = this.config.chainCommon.chainName()
const chainId = this.config.chainCommon.chainId()
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'))
const packageJson = JSON.parse(
readFileSync(
'/' + import.meta.url.split('client')[0].split('file:///')[1] + 'client/package.json',
'utf-8'
)
)
this.config.logger.info(
`Initializing Ethereumjs client version=v${packageJson.version} network=${name} chainId=${chainId}`
)
Expand Down
7 changes: 6 additions & 1 deletion packages/client/src/util/index.ts
Expand Up @@ -19,7 +19,12 @@ export function short(bytes: Uint8Array | string): string {
}

export function getClientVersion() {
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'))
const packageJson = JSON.parse(
readFileSync(
'/' + import.meta.url.split('client')[0].split('file:///')[1] + 'client/package.json',
'utf-8'
)
)
const { version } = process
return `EthereumJS/${packageJson.version}/${platform()}/node${version.substring(1)}`
}
Expand Down
20 changes: 0 additions & 20 deletions packages/client/tsconfig.prod.cjs.json

This file was deleted.

0 comments on commit 344c173

Please sign in to comment.