fix: post process generated flow definition

This commit is contained in:
Justin Starry 2021-03-29 19:14:44 +08:00 committed by Justin Starry
parent dfbca76a76
commit 02c0664487
2 changed files with 18 additions and 1 deletions

View File

@ -37,7 +37,7 @@
"/src"
],
"scripts": {
"build": "cross-env NODE_ENV=production rollup -c; npx flowgen lib/types/index.d.ts -o module.flow.js",
"build": "cross-env NODE_ENV=production rollup -c; npm run flowgen",
"build:browser-test": "rollup -c test/rollup.config.js",
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
"clean": "rimraf ./coverage ./lib",
@ -45,6 +45,7 @@
"dev": "cross-env NODE_ENV=development rollup -c",
"doc": "set -ex; typedoc",
"doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
"flowgen": "./scripts/flowgen.sh",
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
"lint:fix": "npm run pretty:fix && eslint . --fix",
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",

16
web3.js/scripts/flowgen.sh Executable file
View File

@ -0,0 +1,16 @@
set -ex
# Generate flowdef
npx flowgen lib/types/index.d.ts -o module.flow.js
# Remove trailing export
sed -i '/declare export {/{:a;N;/}/!ba};//g' module.flow.js
# Change all declarations to exports
sed -i 's/declare/declare export/g' module.flow.js
# Prepend declare module line
sed -i '7s;^;declare module "@solana/web3.js" {\n;' module.flow.js
# Append closing brace for module declaration
echo '}' >> module.flow.js