Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acir_tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY . .
# Run all native tests.
RUN ./run_acir_tests.sh
# Just run double_verify_proof as a sanity check as bb.js is quite slow.
RUN BB=../ts/dest/main.js ./run_acir_tests.sh double_verify_proof
RUN BB=./run_bb.sh ./run_acir_tests.sh double_verify_proof
4 changes: 4 additions & 0 deletions acir_tests/run_bb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# Used to call this script from a stable path
DIR=$(dirname "$0")
exec node "$DIR/../ts/dest/node/main.js" $@
4 changes: 2 additions & 2 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"build:dev": "tsc -b --watch",
"build:wasm": "cd ../cpp && cmake --preset wasm-threads && cmake --build --preset wasm-threads && cmake --preset wasm && cmake --build --preset wasm",
"build:ts:browser": "tsc -b tsconfig.browser.json && BUILD_TARGET=browser webpack && chmod +x ./dest/browser/main.js && BUILD_TARGET=browser node replace_imports.cjs",
"build:ts:node": "tsc -b tsconfig.node.json && BUILD_TARGET=node webpack && chmod +x ./dest/node/main.js && BUILD_TARGET=node node replace_imports.cjs",
"build:ts:node": "tsc -b tsconfig.node.json && chmod +x ./dest/node/main.js && BUILD_TARGET=node node replace_imports.cjs",
"build:bindings": "cd .. && ./scripts/bindgen.sh",
"serve": "webpack serve",
"formatting": "prettier --check ./src && eslint --max-warnings 0 ./src",
"formatting:fix": "prettier -w ./src",
"test": "yarn build && yarn test:jest && yarn test:bin",
"test": "yarn build:ts:browser && yarn build:ts:node && yarn test:jest && yarn test:bin",
"test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests",
"test:bin": "cd ./bin-test && ./bin-test.sh",
"test-debug": "NODE_NO_WARNINGS=1 node --inspect-brk=0.0.0.0 --experimental-vm-modules $(yarn bin jest) --no-cache --passWithNoTests --runInBand",
Expand Down
19 changes: 12 additions & 7 deletions ts/replace_imports.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const replaceInFile = require('replace-in-file');
const fs = require('fs');
const path = require('path');

const buildTarget = process.env.BUILD_TARGET;
Expand All @@ -12,14 +13,18 @@ async function replaceImports() {
from: new RegExp(`'dynamic\\/${item}';`, 'g'),
to: `'./${buildTarget}/index.js';`,
});
});

// hack to allow for shared .wasm files between build targets
await replaceInFile({
files: path.resolve(__dirname, `dest/${buildTarget}/barretenberg_wasm/${buildTarget}/index.js`),
from: /\.\.\/\.\.\//g,
to: `../../../`,
});
const filePath = path.resolve(__dirname, `dest/${buildTarget}/barretenberg_wasm/${buildTarget}/index.js`);
// Grab the contents for a hacky check if this has ran twice
const contents = fs.readFileSync(filePath, 'utf8');
// hack to allow for shared .wasm files between build targets
if (contents.includes('../../') && !contents.includes('../../../')) {
await replaceInFile({
files: filePath,
from: /\.\.\/\.\.\//g,
to: `../../../`,
});
}
} catch (error) {
console.error('Error occurred:', error);
}
Expand Down
13 changes: 6 additions & 7 deletions ts/webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Builds both the web and node version of the worker, and outputs it to the dest directory.
* NOTE: Currently only runs on web, has issues with translating node imports to require.
* Currently node passes only through typescript compiler.
*/
const path = require('path');
const ResolveTypeScriptPlugin = require('resolve-typescript-plugin');
Expand All @@ -10,12 +12,12 @@ const { resolve } = path;

const buildTarget = process.env.BUILD_TARGET;
const isNode = buildTarget === 'node';
const configFile = path.resolve(__dirname, `./tsconfig.${buildTarget}.json`) ;
const configFile = path.resolve(__dirname, `./tsconfig.${buildTarget}.json`);

module.exports = {
mode: 'production',
entry: './src/index.ts',
target: isNode ? "node" : "web",
target: isNode ? 'node' : 'web',
output: {
path: resolve(__dirname, `./dest/${buildTarget}`),
filename: '[name].js',
Expand All @@ -29,10 +31,7 @@ module.exports = {
],
},
resolve: {
plugins: [
new ResolveTypeScriptPlugin(),
new TsconfigPathsPlugin({ configFile })
],
plugins: [new ResolveTypeScriptPlugin(), new TsconfigPathsPlugin({ configFile })],
},
optimization: {
minimize: isNode,
Expand All @@ -53,4 +52,4 @@ module.exports = {
],
}),
],
}
};