Skip to content

Commit

Permalink
feat: fix webpack v5 options
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Jul 4, 2024
1 parent 857060d commit b896052
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 64 deletions.
1 change: 0 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}
]
],
"plugins": ["rewire"],
"ignore": ["dist/*.js"],
"env": {
"test": {
Expand Down
13 changes: 7 additions & 6 deletions build/webpack.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
/* eslint-env node */
const { merge } = require('webpack-merge');
const baseConfig = require('./webpack.common');
const {OUTPUT_PATH} = require('./utils');
const { OUTPUT_PATH } = require('./utils');

const browserConfig = {
mode: 'production',
output: {
path: OUTPUT_PATH,
filename: 'aelf.umd.js',
library: 'AElf',
libraryTarget: 'umd',
library: {
name: 'AElf',
type: 'umd'
},
libraryExport: 'default',
globalObject: "globalThis",
globalObject: 'globalThis',
umdNamedDefine: true
},
resolve: {
Expand Down Expand Up @@ -52,9 +54,8 @@ const browserConfig = {
chunkIds: 'total-size',
moduleIds: 'size',
sideEffects: true,
minimize: true
minimize: false
}
};


module.exports = merge(baseConfig, browserConfig);
10 changes: 5 additions & 5 deletions build/webpack.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
/* eslint-env node */
const { merge } = require('webpack-merge');
const baseConfig = require('./webpack.common');
const {OUTPUT_PATH} = require('./utils');
const { OUTPUT_PATH } = require('./utils');

const nodeConfig = {
const nodeConfig = {
mode: 'production',
output: {
path: OUTPUT_PATH,
filename: 'aelf.cjs.js',
library: 'AElf',
libraryTarget: 'commonjs2',
library: {
type: 'commonjs2'
},
libraryExport: 'default'
},
resolve: {
Expand All @@ -32,5 +33,4 @@ const nodeConfig = {
}
};


module.exports = merge(baseConfig, nodeConfig);
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class AElf {
static version = process.env.SDK_VERSION;

static providers = {
HttpProvider,
HttpProvider
};

/**
Expand All @@ -41,11 +41,11 @@ export default class AElf {
...utils,
...bloom,
sha256,
transform,
transform
};

providers = {
HttpProvider,
HttpProvider
};

settings = new Settings();
Expand All @@ -55,7 +55,7 @@ export default class AElf {
* @type {{api: string}}
*/
version = {
api: process.env.SDK_VERSION,
api: process.env.SDK_VERSION
};

/**
Expand Down
83 changes: 37 additions & 46 deletions src/util/httpProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (process.env.RUNTIME_ENV === 'browser') {
// eslint-disable-next-line global-require
RequestLibraryXMLOnly = require('xmlhttprequest').XMLHttpRequest;
// eslint-disable-next-line global-require
RequestLibrary = require('node-fetch');
RequestLibrary = require('node-fetch').default;
isFetch = true;
}

Expand All @@ -57,7 +57,7 @@ export default class HttpProvider {
} else {
this.headers = {
...defaultHeaders,
...headers,
...headers
};
}
}
Expand All @@ -80,9 +80,9 @@ export default class HttpProvider {
status: parseRequest.status,
error: parseRequest.status === 200 ? 0 : parseRequest.status,
Error: {
message: request.statusText,
message: request.statusText
},
statusText: request.statusText,
statusText: request.statusText
};
} catch (e) {
result = request;
Expand All @@ -101,13 +101,8 @@ export default class HttpProvider {
}

requestSendByFetch(requestConfig, request) {
const {
url,
method = 'POST',
params = {},
signal
} = requestConfig;
const path = `/api/${url}`.replace(/\/\//g, '\/');
const { url, method = 'POST', params = {}, signal } = requestConfig;
const path = `/api/${url}`.replace(/\/\//g, '/');
let uri = `${this.host}${path}`.replace();
const myHeaders = new Headers();
let body = JSON.stringify(params);
Expand All @@ -133,44 +128,40 @@ export default class HttpProvider {
const control = typeof AbortController === 'function' ? new AbortController() : {};
const config = { ...requestConfig, signal: control.signal, credentials: 'omit' };
// Simulation timeout
return Promise.race([
this.requestSendByFetch(config, request),
HttpProvider.timeoutPromise(timeout)
]).then(result => new Promise((resolve, reject) => {
// @deprecated unuse timeout=1
// if (timeout !== 1) {
try {
if (result.type === 'timeout') {
// Cancel timeout request
if (control.abort) control.abort();
reject(result);
} else {
result
.text()
.then(text => {
const res = HttpProvider.formatResponse(text);
if (result.status !== 200 || !result.ok) {
reject(res);
return;
}
resolve(res);
})
.catch(err => reject(err));
}
} catch (e) {
reject(e);
}
// }
}));
return Promise.race([this.requestSendByFetch(config, request), HttpProvider.timeoutPromise(timeout)]).then(
result =>
new Promise((resolve, reject) => {
// @deprecated unuse timeout=1
// if (timeout !== 1) {
try {
if (result.type === 'timeout') {
// Cancel timeout request
if (control.abort) control.abort();
reject(result);
} else {
result
.text()
.then(text => {
const res = HttpProvider.formatResponse(text);
if (result.status !== 200 || !result.ok) {
reject(res);
return;
}
resolve(res);
})
.catch(err => reject(err));
}
} catch (e) {
reject(e);
}
// }
})
);
}

requestSend(requestConfig, request, isAsync = false) {
const {
url,
method = 'POST',
params = {}
} = requestConfig;
const path = `/api/${url}`.replace(/\/\//g, '\/');
const { url, method = 'POST', params = {} } = requestConfig;
const path = `/api/${url}`.replace(/\/\//g, '/');
let uri = `${this.host}${path}`.replace();
if (method.toUpperCase() === 'GET' || method.toUpperCase() === 'DELETE') {
uri = Object.keys(params).length > 0 ? `${uri}?${stringify(params)}` : uri;
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"strictFunctionTypes": true,
"noEmit": true,
"allowJs": false,
"allowSyntheticDefaultImports": false,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"aelf-web3": ["types"]
},
"esModuleInterop": true,
"declaration": true
"declaration": false
}
}

0 comments on commit b896052

Please sign in to comment.