Skip to content

Commit

Permalink
chore: using path-browserify
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Dec 19, 2024
1 parent 3476894 commit 6b06bfa
Show file tree
Hide file tree
Showing 8 changed files with 3,131 additions and 6,129 deletions.
134 changes: 48 additions & 86 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,97 +20,35 @@ module.exports = function override(config, env) {
os: require.resolve('os-browserify/browser'),
buffer: require.resolve('buffer'),
stream: require.resolve('stream-browserify'),
path: require.resolve('path-browserify'),
vm: require.resolve('vm-browserify'),
path: require.resolve("path-browserify"),
};

// Read the generated policy file
let policy = {};
const policyPath = path.join(__dirname, 'lavamoat', 'webpack');
const policyFile = path.join(policyPath, 'policy.json');

try {
policy = JSON.parse(fs.readFileSync(policyFile, 'utf8'));
} catch (err) {
console.warn('No existing LavaMoat policy found, will generate one');
}

// Add custom policies
/* if (policy.resources) {
// WalletConnect policy
if (!policy.resources['@walletconnect/core']) {
policy.resources['@walletconnect/core'] = {
globals: {
ArrayBuffer: true,
Uint8Array: true,
Object: true,
'Object.prototype': true,
'Object.getPrototypeOf': true,
Symbol: true,
'Function.prototype': true
}
};
}
// React policy
if (!policy.resources['react']) {
policy.resources['react'] = {
globals: {
Object: true,
'Object.prototype': true,
'Function.prototype': true
}
};
}
// Lodash policy
if (!policy.resources['lodash']) {
policy.resources['lodash'] = {
globals: {
Object: true,
'Object.prototype': true,
'Function.prototype': true
}
};
}
}*/
// Configure module resolution
config.resolve = {
...config.resolve,
mainFields: ['browser', 'module', 'main'],
conditionNames: ['require', 'browser', 'default']
};

// Don't use LavaMoat when running in electron
if (process.env.ELECTRON_RUN === 'true') {
config.plugins = [
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
];
} else {
config.plugins = [
new LavaMoatPlugin({
generatePolicy: true,
HtmlWebpackPluginInterop: true,
readableResourceIds: true,
diagnosticsVerbosity: 1,
lockdown: {
consoleTaming: 'unsafe',
errorTrapping: 'none',
unhandledRejectionTrapping: 'none',
overrideTaming: 'severe',
// Add a rule to inject debug logs into axios-related files
config.module.rules.push({
test: /[\\/]axios[\\/].*\.js$/,
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-modules-commonjs',
['@babel/plugin-transform-runtime', {
helpers: false,
regenerator: true
}]
]
}
}),
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
];
}
}
]
});

config.module.rules.push({
test: /\.m?js/,
Expand All @@ -119,5 +57,29 @@ module.exports = function override(config, env) {
}
});

config.plugins = [
new LavaMoatPlugin({
generatePolicy: true,
HtmlWebpackPluginInterop: true,
readableResourceIds: true,
diagnosticsVerbosity: 1,
lockdown: {
consoleTaming: 'unsafe',
errorTrapping: 'none',
unhandledRejectionTrapping: 'none',
overrideTaming: 'severe',
}
}),
...config.plugins,
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
path: ['path-browserify', 'default']
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env)
})
];

return config;
}
76 changes: 76 additions & 0 deletions lavamoat/webpack/policy-override.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,82 @@
"packages": {
"bn.js": true
}
},
"axios": {
"globals": {
"process": true,
"console": true,
"Error": true,
"Object": true,
"XMLHttpRequest": true,
"FormData": true,
"Blob": true,
"window": true,
"Object.prototype": true,
"Function.prototype": true,
"Object.defineProperty": true,
"Object.getOwnPropertyDescriptor": true,
"Symbol": true,
"Symbol.toStringTag": true,
"__esModule": true,
"require": true,
"module": true,
"exports": true
},
"packages": {
"follow-redirects": true,
"form-data": true,
"proxy-from-env": true
}
},
"@hathor/wallet-lib": {
"globals": {
"process": true,
"console": true,
"Error": true,
"Object": true,
"XMLHttpRequest": true,
"FormData": true,
"Blob": true,
"window": true,
"document": true,
"navigator": true,
"location": true,
"setTimeout": true,
"clearTimeout": true,
"Function": true,
"Array": true,
"String": true,
"Promise": true,
"Object.prototype": true,
"Function.prototype": true,
"Array.prototype": true,
"String.prototype": true,
"URL": true,
"URLSearchParams": true,
"Object.defineProperty": true,
"Object.getOwnPropertyDescriptor": true,
"Symbol": true,
"Symbol.toStringTag": true,
"__esModule": true,
"require": true,
"module": true,
"exports": true
},
"packages": {
"axios": true,
"follow-redirects": true,
"form-data": true,
"proxy-from-env": true,
"url": true,
"http": true,
"https": true,
"assert": true,
"stream": true,
"tty": true,
"util": true,
"zlib": true
}
}
}
}
Loading

0 comments on commit 6b06bfa

Please sign in to comment.