Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client post ESM migration cleanup #3414

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.