From 24cc078df18b723d50931bc632ba5d07d7d5605d Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 24 Mar 2023 14:38:06 +0100 Subject: [PATCH] refactor plugin loading --- .circleci/config.yml | 8 ++--- apps/doc-gen/project.json | 6 ++-- apps/doc-gen/{ => src}/profile.json | 0 apps/doc-viewer/project.json | 6 ++-- apps/doc-viewer/{ => src}/profile.json | 0 apps/etherscan/project.json | 6 ++-- apps/etherscan/src/profile.json | 16 ++++++++++ ...etherscan_api.ts => etherscan_api.test.ts} | 2 +- .../tests/{vyper_api.ts => vyper_api.test.ts} | 2 +- apps/remix-ide/project.json | 5 ++- apps/remix-ide/src/remixAppManager.js | 31 +++++++++++++++---- apps/remix-ide/webpack.config.js | 24 +++++++++++--- apps/vyper/project.json | 6 ++-- apps/vyper/src/app/app.tsx | 3 +- apps/vyper/src/{app => assets}/logo.svg | 0 apps/vyper/src/{app => assets}/star.svg | 0 apps/vyper/src/profile.json | 14 +++++++++ 17 files changed, 96 insertions(+), 33 deletions(-) rename apps/doc-gen/{ => src}/profile.json (100%) rename apps/doc-viewer/{ => src}/profile.json (100%) create mode 100644 apps/etherscan/src/profile.json rename apps/remix-ide-e2e/src/tests/{etherscan_api.ts => etherscan_api.test.ts} (98%) rename apps/remix-ide-e2e/src/tests/{vyper_api.ts => vyper_api.test.ts} (96%) rename apps/vyper/src/{app => assets}/logo.svg (100%) rename apps/vyper/src/{app => assets}/star.svg (100%) create mode 100644 apps/vyper/src/profile.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 599e19a2ef..8fa877f28e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -286,7 +286,7 @@ workflows: - build-plugin: matrix: parameters: - plugin: ["etherscan", "vyper", "plugin_api", "doc-gen", "doc-viewer"] + plugin: ["plugin_api"] - lint: requires: - build @@ -299,15 +299,11 @@ workflows: matrix: alias: plugins parameters: - plugin: ["etherscan", "vyper", "plugin_api"] + plugin: ["plugin_api"] parallelism: [1, 9] exclude: - plugin: plugin_api parallelism: 1 - - plugin: etherscan - parallelism: 9 - - plugin: vyper - parallelism: 9 - remix-ide-browser: requires: diff --git a/apps/doc-gen/project.json b/apps/doc-gen/project.json index 55bb62bd16..4b997606a5 100644 --- a/apps/doc-gen/project.json +++ b/apps/doc-gen/project.json @@ -14,11 +14,12 @@ "compiler": "babel", "outputPath": "dist/apps/doc-gen", "index": "apps/doc-gen/src/index.html", - "baseHref": "/", + "baseHref": "./", "main": "apps/doc-gen/src/main.tsx", "tsConfig": "apps/doc-gen/tsconfig.app.json", "assets": [ - "apps/doc-gen/src/favicon.ico" + "apps/doc-gen/src/favicon.ico", + "apps/doc-gen/src/profile.json" ], "styles": [], "scripts": [], @@ -28,7 +29,6 @@ "development": { }, "production": { - "baseHref": "./", "fileReplacements": [ { "replace": "apps/doc-gen/src/environments/environment.ts", diff --git a/apps/doc-gen/profile.json b/apps/doc-gen/src/profile.json similarity index 100% rename from apps/doc-gen/profile.json rename to apps/doc-gen/src/profile.json diff --git a/apps/doc-viewer/project.json b/apps/doc-viewer/project.json index 46e4ff5219..2e5455cc30 100644 --- a/apps/doc-viewer/project.json +++ b/apps/doc-viewer/project.json @@ -14,11 +14,12 @@ "compiler": "babel", "outputPath": "dist/apps/doc-viewer", "index": "apps/doc-viewer/src/index.html", - "baseHref": "/", + "baseHref": "./", "main": "apps/doc-viewer/src/main.tsx", "tsConfig": "apps/doc-viewer/tsconfig.app.json", "assets": [ - "apps/doc-viewer/src/favicon.ico" + "apps/doc-viewer/src/favicon.ico", + "apps/doc-viewer/src/profile.json" ], "styles": [], "scripts": [], @@ -28,7 +29,6 @@ "development": { }, "production": { - "baseHref": "./", "fileReplacements": [ { "replace": "apps/doc-viewer/src/environments/environment.ts", diff --git a/apps/doc-viewer/profile.json b/apps/doc-viewer/src/profile.json similarity index 100% rename from apps/doc-viewer/profile.json rename to apps/doc-viewer/src/profile.json diff --git a/apps/etherscan/project.json b/apps/etherscan/project.json index 09d17bc0a2..fe53c7f39e 100644 --- a/apps/etherscan/project.json +++ b/apps/etherscan/project.json @@ -18,7 +18,8 @@ "tsConfig": "apps/etherscan/tsconfig.app.json", "assets": [ "apps/etherscan/src/favicon.ico", - "apps/etherscan/src/assets" + "apps/etherscan/src/assets", + "apps/etherscan/src/profile.json" ], "styles": ["apps/etherscan/src/styles.css"], "scripts": [], @@ -42,7 +43,8 @@ "defaultConfiguration": "development", "options": { "buildTarget": "etherscan:build", - "hmr": true + "hmr": true, + "baseHref": "/" }, "configurations": { "development": { diff --git a/apps/etherscan/src/profile.json b/apps/etherscan/src/profile.json new file mode 100644 index 0000000000..a15f25009d --- /dev/null +++ b/apps/etherscan/src/profile.json @@ -0,0 +1,16 @@ +{ + "name": "etherscan", + "displayName": "Etherscan - Contract verification", + "description": "Verify Solidity contract code using Etherscan API", + "version": "0.1.0", + "events": [], + "methods": ["verify", "receiptStatus"], + "kind": "none", + "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHsAAAB7CAYAAABUx/9/AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAHBklEQVR42u2dy3WbTBTH/+ikgFEFwZ8K8HQAm6yjDkIHdiogHWBXgDqADgQVaLLJToZ1NtAB38JC0QNJIPGYx73nsIgcHVvz033OnblWVVXQQcqyhBACQgiUZYk0TfHnz5/q79+/rd7PGPsA8I1z/gEAjuOAMQbOOVzX1WKNLFVhCyGQJAnSNEUcx0N/CMu2bXDO4TgOXNcF51y9RauqSomnKApEUQTG2BZANeXDGNsyxuB5HqIoUmYNpf8DoyjC1HBbPEqAl/KPyrJMCg2+V+N930eWZQT72rNer6Ea4FvavtlsCLbGkM+gu66L9XptNuwsy3SG3KjpU5r3ySJrgyCfQfd93wzYmpvs1sBt2x7dtJM2S2DatYJN2nxby8eI2of/BQSzNfQgCNSETWb7PuDL5VIt2IalVL0D55wPwmXW98bKfD7fPj096bFvOtHeVJ7n2/l8DiGEvLteKtazZa+z9xm4EWiDgBNog4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203fJdu2G9uPSbNHkjHvcr904cGXa5Eo3V+ijtk+yB7w+vraDbZqaVj9QW3bNlKb63QrCIKjdOvoSzfyLM5eRi3UR1Bt2wbnHI7jwHVdae4az/McT09PYyvKzVmcSvrsLMss2bR4Km0+lCAIrv+HsUcHDlFqlOHZHaedbFxGL/Oze67bagd5ZzYnm4tS18Db1OxbmfGiKBZxHO/nRDHG8Pz8fC1YOvKftm1LaXJVibJvBWW+77da315nU1HOPP73zXXd1jcy0H52B1mtVrAsq5IBdN2F0ulGBl0Dpj6f3YJKN8PscEBbq0CbYCoHuaqrZF0/D/lsuX1yo5++5y408tknVa/5fL6VxSdfq5J1vSKLfLb8proxn95sNvf31JkIuOUUXa1AGwd7VztWanJwX6CNgK2KmR4atJawsyxTUoOHBq0N7CiK6u6MSodnCNDKwtYNLhom+Qxx8kT65oUkSSCEwO/fv7FarXSvAFnL5RJhGF5sLXpEpICd5znyPIcQAmVZIk1TJEliWmnPCoLgYrOgUrCTJEGSJAD+TWo3EOjFqlgYhsOPwRrT12rqYx+eYHh40nLQ9TesV0sayHWNe1RlmyqiNhm07/ujabM0qdfUzXpTmOyhDvMrk2fv9ma1hVz3iU29ztSWO7Am910F066ClmUZfN9XdofK9/1JzbWy5dIoilSAjuVyiSiKpF5L5WriMjQd1BrseR6iKJoksr7nUbbhUAiBJEmQpiniOB7lNgMZT4x2+hA6dZfWmyZ1fV0I0bpLtL4Gq4boOM7+GFN9q6/q8j8QmqQtM04gOgAAAABJRU5ErkJggg==", + "location": "sidePanel", + "url": "https://ipfs-cluster.ethdevops.io/ipfs/QmQsZbBSYCVBVpz2mVRbPRVTrcz59oJEpuuoxiT9otu3mh", + "repo": "https://github.com/ethereum/remix-project/tree/master/apps/etherscan", + "documentation": "https://remix-etherscan-plugin.readthedocs.io/en/latest", + "maintainedBy": "Remix", + "authorContact": "remix@ethereum.org" +} \ No newline at end of file diff --git a/apps/remix-ide-e2e/src/tests/etherscan_api.ts b/apps/remix-ide-e2e/src/tests/etherscan_api.test.ts similarity index 98% rename from apps/remix-ide-e2e/src/tests/etherscan_api.ts rename to apps/remix-ide-e2e/src/tests/etherscan_api.test.ts index 33009f2101..65cafd3b81 100644 --- a/apps/remix-ide-e2e/src/tests/etherscan_api.ts +++ b/apps/remix-ide-e2e/src/tests/etherscan_api.test.ts @@ -9,7 +9,7 @@ declare global { module.exports = { '@disabled': true, before: function (browser: NightwatchBrowser, done: VoidFunction) { - init(browser, done, null, true, { name: 'etherscan', url: 'http://127.0.0.1:9999'}) + init(browser, done, null) }, 'Should load etherscan plugin #group1': function (browser: NightwatchBrowser) { diff --git a/apps/remix-ide-e2e/src/tests/vyper_api.ts b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts similarity index 96% rename from apps/remix-ide-e2e/src/tests/vyper_api.ts rename to apps/remix-ide-e2e/src/tests/vyper_api.test.ts index 1dc8000f51..67dd5afb1f 100644 --- a/apps/remix-ide-e2e/src/tests/vyper_api.ts +++ b/apps/remix-ide-e2e/src/tests/vyper_api.test.ts @@ -9,7 +9,7 @@ declare global { module.exports = { '@disabled': true, before: function (browser: NightwatchBrowser, done: VoidFunction) { - init(browser, done, null, true, { name: 'vyper', url: 'http://127.0.0.1:9999'}) + init(browser, done) }, 'Should connect to vyper plugin #group1': function (browser: NightwatchBrowser) { diff --git a/apps/remix-ide/project.json b/apps/remix-ide/project.json index e118e366a7..4e413240ee 100644 --- a/apps/remix-ide/project.json +++ b/apps/remix-ide/project.json @@ -3,8 +3,7 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "apps/remix-ide/src", "projectType": "application", - "implicitDependencies": [ - ], + "implicitDependencies": ["doc-gen", "doc-viewer", "etherscan", "vyper"], "targets": { "build": { "executor": "@nrwl/webpack:webpack", @@ -47,7 +46,7 @@ "executor": "@nrwl/webpack:dev-server", "defaultConfiguration": "development", "options": { - "buildTarget": "remix-ide:build", + "buildTarget": "remix-ide:build" }, "configurations": { diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 59a13e819b..ab5c6be766 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -9,12 +9,14 @@ const requiredModules = [ // services + layout views + system views 'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'locale', 'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity', 'solidity-logic', 'gistHandler', 'layout', - 'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries', 'openzeppelin-proxy', + 'notification', 'permissionhandler', 'walkthrough', 'storage', 'restorebackupzip', 'link-libraries', 'deploy-libraries', 'openzeppelin-proxy', 'hardhat-provider', 'ganache-provider', 'foundry-provider', 'basic-http-provider', 'injected', 'injected-trustwallet', 'injected-optimism-provider', 'injected-arbitrum-one-provider', 'vm-custom-fork', 'vm-goerli-fork', 'vm-mainnet-fork', 'vm-sepolia-fork', 'vm-merge', 'vm-london', 'vm-berlin', - 'compileAndRun', 'search', 'recorder', 'fileDecorator', 'codeParser', 'codeFormatter', 'solidityumlgen', 'contractflattener', 'doc-gen', 'doc-viewer', 'solidity-script'] + 'compileAndRun', 'search', 'recorder', 'fileDecorator', 'codeParser', 'codeFormatter', 'solidityumlgen', 'contractflattener', 'solidity-script'] // dependentModules shouldn't be manually activated (e.g hardhat is activated by remixd) -const dependentModules = ['foundry', 'hardhat', 'truffle', 'slither'] +const dependentModules = ['foundry', 'hardhat', 'truffle', 'slither'] + +const loadLocalPlugins = ["doc-gen", "doc-viewer", "etherscan", "vyper"] const sensitiveCalls = { 'fileManager': ['writeFile', 'copyFile', 'rename', 'copyDir'], @@ -24,9 +26,9 @@ const sensitiveCalls = { export function isNative(name) { // nativePlugin allows to bypass the permission request - const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'solidity-logic', 'solidityStaticAnalysis', 'solidityUnitTesting', + const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'solidity-logic', 'solidityStaticAnalysis', 'solidityUnitTesting', 'layout', 'notification', 'hardhat-provider', 'ganache-provider', 'foundry-provider', 'basic-http-provider', 'injected-optimism-provider', - 'tabs', 'injected-arbitrum-one-provider', 'injected'] + 'tabs', 'injected-arbitrum-one-provider', 'injected', 'doc-gen', 'doc-viewer'] return nativePlugins.includes(name) || requiredModules.includes(name) } @@ -149,7 +151,24 @@ export class RemixAppManager extends PluginManager { } const testPluginName = localStorage.getItem('test-plugin-name') const testPluginUrl = localStorage.getItem('test-plugin-url') - return plugins.map(plugin => { + + for (let plugin of loadLocalPlugins) { + // fetch the profile from the local plugin + try { + const profile = await fetch(`plugins/${plugin}/profile.json`) + const profileJson = await profile.json() + // remove duplicates + plugins = plugins.filter((p) => p.name !== profileJson.name && p.displayName !== profileJson.displayName) + // change url + profileJson.url = `plugins/${plugin}/index.html` + // add the local plugin + plugins.push(profileJson) + } catch (e) { + console.log(e) + } + } + + return plugins.map(plugin => { if (plugin.name === testPluginName) plugin.url = testPluginUrl return new IframePlugin(plugin) }) diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index e97caf26e9..1843eb3a6b 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -15,6 +15,23 @@ const versionData = { fs.writeFileSync('./apps/remix-ide/src/assets/version.json', JSON.stringify(versionData)) +const project = fs.readFileSync('./apps/remix-ide/project.json', 'utf8') + +const implicitDependencies = JSON.parse(project).implicitDependencies + +const copyPatterns = implicitDependencies.map((dep) => { + try { + fs.statSync(__dirname + `/../../dist/apps/${dep}`).isDirectory() + return { from: `../../dist/apps/${dep}`, to: `plugins/${dep}` } + } + catch (e) { + console.log('error', e) + return false + } +}) + +console.log('Copying plugins... ', copyPatterns) + // Nx plugins for webpack. module.exports = composePlugins(withNx(), withReact(), (config) => { // Update the webpack config as needed here. @@ -41,7 +58,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { "buffer": require.resolve("buffer/"), "vm": require.resolve('vm-browserify'), } - + // add externals config.externals = { @@ -61,8 +78,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { new CopyPlugin({ patterns: [ { from: '../../node_modules/monaco-editor/min/vs', to: 'assets/js/monaco-editor/min/vs' }, - { from: '../../dist/apps/doc-gen', to: 'plugins/doc-gen' }, - { from: '../../dist/apps/doc-gen', to: 'plugins/doc-viewer' }, + ...copyPatterns ].filter(Boolean) }), new webpack.ProvidePlugin({ @@ -79,7 +95,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => { enforce: "pre" }) - config.ignoreWarnings = [/Failed to parse source map/, /require function/ ] // ignore source-map-loader warnings & AST warnings + config.ignoreWarnings = [/Failed to parse source map/, /require function/] // ignore source-map-loader warnings & AST warnings // set minimizer config.optimization.minimizer = [ diff --git a/apps/vyper/project.json b/apps/vyper/project.json index aad6a9b746..543c0873fd 100644 --- a/apps/vyper/project.json +++ b/apps/vyper/project.json @@ -18,7 +18,8 @@ "tsConfig": "apps/vyper/tsconfig.app.json", "assets": [ "apps/vyper/src/favicon.ico", - "apps/vyper/src/assets" + "apps/vyper/src/assets", + "apps/vyper/src/profile.json" ], "styles": ["apps/vyper/src/styles.css"], "scripts": [], @@ -42,7 +43,8 @@ "defaultConfiguration": "development", "options": { "buildTarget": "vyper:build", - "hmr": true + "hmr": true, + "baseHref": "/" }, "configurations": { "development": { diff --git a/apps/vyper/src/app/app.tsx b/apps/vyper/src/app/app.tsx index ad91f29c3f..e5f9d80159 100644 --- a/apps/vyper/src/app/app.tsx +++ b/apps/vyper/src/app/app.tsx @@ -12,7 +12,6 @@ import ToggleButtonGroup from 'react-bootstrap/ToggleButtonGroup' import ToggleButton from 'react-bootstrap/ToggleButton' import Button from 'react-bootstrap/Button' -import vyperLogo from './logo.svg' import './app.css' interface AppState { @@ -71,7 +70,7 @@ const App: React.FC = () => {
- Vyper logo + Vyper logo

yper Compiler