-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Example Plugin Implementation #5393
Changes from 35 commits
2da30e0
530b4ce
546fa28
cb636c2
3233a76
d0d388b
db296ff
a2f43db
45881ee
6514f13
9b4896e
dbc133f
dc36d4b
755d6d6
1036836
08cbe72
7642f41
816f2f5
eaceff9
5e6d3a2
0666cff
c7c2a06
75bf686
3978175
205b928
b3c9140
369e024
7acb576
3ad7e1d
de3403d
5be6ef5
b455e21
051a35f
bba74e6
6093e5b
9481519
c1b2cc5
744bfc2
c939cbc
e55e65f
8d90ddd
f242b48
56bf6b7
b79c68b
d1ba3ec
1e271b9
4375a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,4 +323,5 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>. | |
*/ | ||
import Web3 from './web3'; | ||
|
||
export = Web3; | ||
export * from './web3'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those changes revert back the modifications made at: https://github.com/web3/web3.js/pull/5221/files#diff-bef53270c59945a684e63b962974a96318e07549c207ea92bbc9c369e35bc476R326 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't break anything as mentioned here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I am referring to how web3 will be imported inside javascript and typescript files. So the question is: After this MR, can the user still use the old way? import Web3 from 'web3'; // without the curly brackets around Web3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, on line export default Web3; An example of this working is in the contract_method_wrappers tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a simple javascript project with the following code: const Web3 = require('web3');
const web3 = new Web3(); And only when using this branch, the following error occurs:
So, could you please revert back any changes made to how Web3 is exported? Or else, if it is necessary to have those changes for the plugin, then please let me know where exactly this is needed so we can investigate more on this matter... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you face any problems reverting this MR's changes to the Web3 export statement? import Web3 from './web3';
export = Web3; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, TypeScript module augmentation seems to be designed to work with named ES modules. So only exporting test/unit/contract_method_wrappers.test.ts:27:16 - error TS2664: Invalid module name in augmentation, module 'web3' cannot be found.
27 declare module 'web3' { I've tried many different ways to work around this, but it boils down to us not being able to mix CommonJS and ES modules, the latter being needed to provide module augmentation However, we can use import Web3 from './web3';
export * from './web3';
export default Web3; and the user would still be able to do const Web3 = require('web3').default; but of course this still results in a breaking change and module augmentation doesn't work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @spacesailor24 Limitation is for module augmentation there must be named export as mentioned in ts docs Module Augmentation part: so If we do named export of Web3 in current CJS settings module augmentation works fine. As discussed earlier for supporting legacy applications, and not introducing breaking change, I am in favour of keeping current Web3 4x export settings ( Also mentioned by Muhammad-Altabba ) and there is a workaround for module augmentation for now: so in user plugin project where web3 augmentation is required: if Web3 is imported and reexported as named, users can augment. web3.ts in user project
and pluginConsumer.ts using named reexported web3 from user's web3.ts
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Muhammad-Altabba @jdevcs This commit adds the work around mentioned above by Junaid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @jdevcs for the great workaround. |
||
export default Web3; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ import { initAccountsForContext } from './accounts'; | |
import { Web3EthInterface } from './types'; | ||
import { Web3PkgInfo } from './version'; | ||
|
||
export default class Web3 extends Web3Context<EthExecutionAPI> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break minified web3.js build #5345 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit updates |
||
export class Web3 extends Web3Context<EthExecutionAPI> { | ||
public static version = Web3PkgInfo.version; | ||
public static utils = utils; | ||
public static modules = { | ||
|
@@ -128,3 +128,4 @@ export default class Web3 extends Web3Context<EthExecutionAPI> { | |
}); | ||
} | ||
} | ||
export default Web3; |
Uh oh!
There was an error while loading. Please reload this page.