diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index da85eadf54..4f0ccccedd 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -4,8 +4,10 @@ import Editor, { loader } from '@monaco-editor/react' import { reducerActions, reducerListener, initialState } from './actions/editor' import { language, conf } from './syntax' import { cairoLang, cairoConf } from './cairoSyntax' -import { ethers } from 'ethers' +// import { ethersDTS, test } from './types' + import './remix-ui-editor.css' +import { loadTypes } from './types' type cursorPosition = { startLineNumber: number, @@ -223,7 +225,6 @@ export const EditorUI = (props: EditorUIProps) => { useEffect(() => { if (!monacoRef.current) return defineAndSetTheme(monacoRef.current) - monacoRef.current.languages.typescript.typescriptDefaults.addExtraLib('declare function require(module: string): any;') }) @@ -410,6 +411,8 @@ export const EditorUI = (props: EditorUIProps) => { monacoRef.current.languages.setMonarchTokensProvider('remix-cairo', cairoLang) monacoRef.current.languages.setLanguageConfiguration('remix-cairo', cairoConf) + + loadTypes(monacoRef.current) } return ( diff --git a/libs/remix-ui/editor/src/lib/types.ts b/libs/remix-ui/editor/src/lib/types.ts new file mode 100644 index 0000000000..57811a0545 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/types.ts @@ -0,0 +1,131 @@ +export const loadTypes = async (monaco) => { + // @ts-ignore + const ethersAbi = await import('raw-loader!@ethersproject/abi/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersAbi.default, `file:///node_modules/@types/@ethersproject/abi/index.d.ts`) + + // @ts-ignore + const ethersAbstract = await import('raw-loader!@ethersproject/abstract-provider/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersAbstract.default, `file:///node_modules/@types/@ethersproject/abstract-provider/index.d.ts`) + + // @ts-ignore + const ethersSigner = await import('raw-loader!@ethersproject/abstract-signer/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersSigner.default, `file:///node_modules/@types/@ethersproject/abstract-signer/index.d.ts`) + + // @ts-ignore + const ethersAddress = await import('raw-loader!@ethersproject/address/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersAddress.default, `file:///node_modules/@types/@ethersproject/address/index.d.ts`) + + // @ts-ignore + const ethersBase64 = await import('raw-loader!@ethersproject/base64/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersBase64.default, `file:///node_modules/@types/@ethersproject/base64/index.d.ts`) + + // @ts-ignore + const ethersBasex = await import('raw-loader!@ethersproject/basex/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersBasex.default, `file:///node_modules/@types/@ethersproject/basex/index.d.ts`) + + // @ts-ignore + const ethersBignumber = await import('raw-loader!@ethersproject/bignumber/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersBignumber.default, `file:///node_modules/@types/@ethersproject/bignumber/index.d.ts`) + + // @ts-ignore + const ethersBytes = await import('raw-loader!@ethersproject/bytes/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersBytes.default, `file:///node_modules/@types/@ethersproject/bytes/index.d.ts`) + + // @ts-ignore + const ethersConstants = await import('raw-loader!@ethersproject/constants/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersConstants.default, `file:///node_modules/@types/@ethersproject/constants/index.d.ts`) + + // @ts-ignore + const ethersContracts = await import('raw-loader!@ethersproject/contracts/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersContracts.default, `file:///node_modules/@types/@ethersproject/contracts/index.d.ts`) + + // @ts-ignore + const ethersHash = await import('raw-loader!@ethersproject/hash/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersHash.default, `file:///node_modules/@types/@ethersproject/lib/index.d.ts`) + + // @ts-ignore + const ethersHdnode = await import('raw-loader!@ethersproject/hdnode/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersHdnode.default, `file:///node_modules/@types/@ethersproject/hdnode/index.d.ts`) + + // @ts-ignore + const ethersJsonWallets = await import('raw-loader!@ethersproject/json-wallets/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersJsonWallets.default, `file:///node_modules/@types/@ethersproject/json-wallets/index.d.ts`) + + // @ts-ignore + const ethersKeccak256 = await import('raw-loader!@ethersproject/keccak256/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersKeccak256.default, `file:///node_modules/@types/@ethersproject/keccak256/index.d.ts`) + + // @ts-ignore + const ethersLogger = await import('raw-loader!@ethersproject/logger/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersLogger.default, `file:///node_modules/@types/@ethersproject/logger/index.d.ts`) + + // @ts-ignore + const ethersNetworks = await import('raw-loader!@ethersproject/networks/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersNetworks.default, `file:///node_modules/@types/@ethersproject/networks/index.d.ts`) + + // @ts-ignore + const ethersPbkdf2 = await import('raw-loader!@ethersproject/pbkdf2/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersPbkdf2.default, `file:///node_modules/@types/@ethersproject/pbkdf2/index.d.ts`) + + // @ts-ignore + const ethersProperties = await import('raw-loader!@ethersproject/properties/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersProperties.default, `file:///node_modules/@types/@ethersproject/properties/index.d.ts`) + + // @ts-ignore + const ethersProviders = await import('raw-loader!@ethersproject/providers/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersProviders.default, `file:///node_modules/@types/@ethersproject/providers/index.d.ts`) + + // @ts-ignore + const ethersRandom = await import('raw-loader!@ethersproject/random/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersRandom.default, `file:///node_modules/@types/@ethersproject/random/index.d.ts`) + + // @ts-ignore + const ethersRlp = await import('raw-loader!@ethersproject/rlp/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersRlp.default, `file:///node_modules/@types/@ethersproject/rlp/index.d.ts`) + + // @ts-ignore + const ethersSha2 = await import('raw-loader!@ethersproject/sha2/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersSha2.default, `file:///node_modules/@types/@ethersproject/sha2/index.d.ts`) + + // @ts-ignore + const ethersSingningkey = await import('raw-loader!@ethersproject/signing-key/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersSingningkey.default, `file:///node_modules/@types/@ethersproject/signing-key/index.d.ts`) + + // @ts-ignore + const ethersSolidity = await import('raw-loader!@ethersproject/solidity/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersSolidity.default, `file:///node_modules/@types/@ethersproject/solidity/index.d.ts`) + + // @ts-ignore + const ethersStrings = await import('raw-loader!@ethersproject/strings/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersStrings.default, `file:///node_modules/@types/@ethersproject/strings/index.d.ts`) + + // @ts-ignore + const ethersTransactions = await import('raw-loader!@ethersproject/transactions/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersTransactions.default, `file:///node_modules/@types/@ethersproject/transactions/index.d.ts`) + + // @ts-ignore + const ethersUnits = await import('raw-loader!@ethersproject/units/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersUnits.default, `file:///node_modules/@types/@ethersproject/units/index.d.ts`) + + // @ts-ignore + const ethersWallet = await import('raw-loader!@ethersproject/wallet/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersWallet.default, `file:///node_modules/@types/@ethersproject/wallet/index.d.ts`) + + // @ts-ignore + const ethersWeb = await import('raw-loader!@ethersproject/web/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersWeb.default, `file:///node_modules/@types/@ethersproject/web/index.d.ts`) + + // @ts-ignore + const ethersWordlists = await import('raw-loader!@ethersproject/wordlists/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethersWordlists.default, `file:///node_modules/@types/@ethersproject/wordlists/index.d.ts`) + + // @ts-ignore + const ethers = await import('raw-loader!ethers/lib/ethers.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(ethers.default, `file:///node_modules/@types/ethers/ethers.d.ts`) + + // @ts-ignore + const indexEthers = await import('raw-loader!ethers/lib/index.d.ts') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexEthers.default, `file:///node_modules/@types/ethers/index.d.ts`) + + console.log('loaded monaco types') +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 86fb091bf5..0d31f1b3ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9308,6 +9308,16 @@ "find-up": "^4.0.0" } }, + "raw-loader": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-3.1.0.tgz", + "integrity": "sha512-lzUVMuJ06HF4rYveaz9Tv0WRlUMxJ0Y1hgSkkgg+50iEdaI0TthyEDe08KIHb0XsF6rn8WYTqPCaGTZg3sX+qA==", + "dev": true, + "requires": { + "loader-utils": "^1.1.0", + "schema-utils": "^2.0.1" + } + }, "readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -10797,8 +10807,7 @@ "@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", - "integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==", - "dev": true + "integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==" }, "@types/json5": { "version": "0.0.29", @@ -11657,8 +11666,7 @@ "ajv-keywords": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", - "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", - "dev": true + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==" }, "align-text": { "version": "0.1.4", @@ -13652,8 +13660,7 @@ "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", - "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", - "dev": true + "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" }, "bignumber.js": { "version": "9.0.1", @@ -17611,8 +17618,7 @@ "emojis-list": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", - "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", - "dev": true + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==" }, "enabled": { "version": "2.0.0", @@ -29711,7 +29717,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz", "integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==", - "dev": true, "requires": { "big.js": "^5.2.2", "emojis-list": "^3.0.0", @@ -36442,8 +36447,7 @@ "commander": { "version": "2.17.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", - "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", - "optional": true + "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==" }, "commondir": { "version": "1.0.1", @@ -37332,8 +37336,7 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "optional": true + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" } } }, @@ -40139,33 +40142,22 @@ } }, "raw-loader": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-3.1.0.tgz", - "integrity": "sha512-lzUVMuJ06HF4rYveaz9Tv0WRlUMxJ0Y1hgSkkgg+50iEdaI0TthyEDe08KIHb0XsF6rn8WYTqPCaGTZg3sX+qA==", - "dev": true, + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-4.0.2.tgz", + "integrity": "sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA==", "requires": { - "loader-utils": "^1.1.0", - "schema-utils": "^2.0.1" + "loader-utils": "^2.0.0", + "schema-utils": "^3.0.0" }, "dependencies": { - "json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "requires": { - "minimist": "^1.2.0" - } - }, - "loader-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", - "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", - "dev": true, + "schema-utils": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz", + "integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==", "requires": { - "big.js": "^5.2.2", - "emojis-list": "^3.0.0", - "json5": "^1.0.1" + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" } } } @@ -48113,4 +48105,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index ae8b3c6666..16d9ea14b8 100644 --- a/package.json +++ b/package.json @@ -189,6 +189,7 @@ "merge": "^2.1.1", "monaco-editor": "^0.30.1", "npm-install-version": "^6.0.2", + "raw-loader": "^4.0.2", "react": "^17.0.2", "react-beautiful-dnd": "^13.1.0", "react-bootstrap": "^1.6.4",