Skip to content

Commit

Permalink
fix: Top level init bb.js, but better scoped imports to not incur cos…
Browse files Browse the repository at this point in the history
…t too early (#3629)

Related to this issue:
AztecProtocol/aztec-packages#3618
Gets `aztec-cli help` down to 0.01s!!!!
  • Loading branch information
charlielye authored and AztecBot committed Dec 11, 2023
1 parent 0436001 commit 366d7a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions ts/scripts/cjs_postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ DIR="./dest/node-cjs"
for FILE in $(find "$DIR" -name "*.js"); do
# Use sed to replace 'import.meta.url' with '""'
sed -i.bak 's/import\.meta\.url/""/g' "$FILE" && rm "$FILE.bak"
# Use sed to remove any lines postfixed // POSTPROCESS ESM ONLY
sed -i.bak '/\/\/ POSTPROCESS ESM ONLY$/d' "$FILE" && rm "$FILE.bak"
done
14 changes: 6 additions & 8 deletions ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BarretenbergSync extends BarretenbergApiSync {

static getSingleton() {
if (!barretenbergSyncSingleton) {
throw new Error('Initialise first via initSingleton().');
throw new Error('First call BarretenbergSync.initSingleton() on @aztec/bb.js module.');
}
return barretenbergSyncSingleton;
}
Expand All @@ -75,10 +75,8 @@ export class BarretenbergSync extends BarretenbergApiSync {
}
}

// If we're loading this module in a test environment, just init the singleton immediately for convienience.
if (process.env.NODE_ENV === 'test') {
// Need to ignore for cjs build.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await BarretenbergSync.initSingleton();
}
// If we're in ESM environment, use top level await. CJS users need to call it manually.
// Need to ignore for cjs build.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await BarretenbergSync.initSingleton(); // POSTPROCESS ESM ONLY

0 comments on commit 366d7a7

Please sign in to comment.