Skip to content

Commit

Permalink
feat: polyfill node core modules (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-ziv committed Aug 14, 2023
1 parent 3372e0a commit ee6290c
Show file tree
Hide file tree
Showing 7 changed files with 1,988 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
@@ -1,2 +1,3 @@
node_modules
dist
dist
webpack.config.js
12 changes: 12 additions & 0 deletions .mocharc.json
@@ -0,0 +1,12 @@
{
"diff": true,
"extension": ["js", "ts"],
"package": "./package.json",
"reporter": "spec",
"require": "ts-node/register",
"recursive": true,
"slow": 75,
"timeout": 60000,
"ui": "bdd",
"watch-files": ["src/**/*.js", "src/**/*.ts", "test/**/*.js", "test/**/*.ts"]
}
23 changes: 17 additions & 6 deletions package.json
Expand Up @@ -20,8 +20,8 @@
},
"license": "Apache-2.0",
"author": "StarkWare Industries Ltd.",
"main": "dist/src/js/index.js",
"types": "dist/src/js/index.d.ts",
"main": "dist/index.js",
"types": "dist/types/src/js/index.d.ts",
"files": [
"dist",
"src/config",
Expand All @@ -32,21 +32,25 @@
],
"scripts": {
"prebuild": "npm run clean",
"build": "tsc --build",
"build": "webpack --mode production",
"clean": "rm -rf ./dist",
"dev": "webpack-dev-server --mode development",
"docs:generate": "typedoc",
"format": "prettier --write \"**/*.+(ts|js|json|md|html|yml)\"",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"npm-publish": "npm publish --access public",
"release": "semantic-release",
"release:dry": "semantic-release --no-ci --dry-run",
"test": "tsc --build && mocha 'dist/test/**/*.spec.js' --recursive"
"test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha"
},
"dependencies": {
"assert": "^2.0.0",
"bip39": "^3.0.4",
"bn.js": "^4.12.0",
"brorand": "^1.1.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"elliptic": "^6.5.4",
"enc-utils": "^3.0.0",
"ethereumjs-wallet": "^1.0.2",
Expand All @@ -55,7 +59,8 @@
"inherits": "^2.0.4",
"js-sha3": "^0.8.0",
"minimalistic-assert": "^1.0.1",
"minimalistic-crypto-utils": "^1.0.1"
"minimalistic-crypto-utils": "^1.0.1",
"stream-browserify": "^3.0.0"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.0",
Expand All @@ -77,7 +82,13 @@
"mocha": "^10.2.0",
"prettier": "^2.8.7",
"semantic-release": "^19.0.5",
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typedoc": "^0.23.16",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -12,7 +12,7 @@
"skipLibCheck": true,
"removeComments": true,
"resolveJsonModule": true,
"outDir": "./dist"
"outDir": "./dist/types"
},
"include": ["src/**/*", "test/**/*"],
"exclude": ["node_modules"]
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.testing.json
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es2017", "es7", "es6", "dom"],
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"inlineSourceMap": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true
}
}
40 changes: 40 additions & 0 deletions webpack.config.js
@@ -0,0 +1,40 @@
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
entry: './src/js/index.ts',
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
fallback: {
assert: require.resolve('assert/'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer/'),
crypto: require.resolve('crypto-browserify')
},
extensions: ['.ts', '.js']
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist')
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false
})
]
},
devServer: {
static: path.join(__dirname, 'dist'),
compress: true,
port: 4000
}
};

0 comments on commit ee6290c

Please sign in to comment.