From 9eed8bfcb0820e82ec5603aa0f4096a8202785bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Thu, 24 Jan 2019 18:18:20 +0100 Subject: [PATCH 1/7] Outsourcing resource location resolution to resolver-engine --- package.json | 5 +- src/app.js | 15 ++- src/app/compiler/compiler-imports.js | 115 +++++------------- src/app/files/NotPersistedExplorer.js | 90 +++++++++++++- src/app/files/browser-files.js | 3 + src/app/files/file-explorer.js | 16 +++ src/app/files/fileManager.js | 32 +++-- ...nlyExplorer.js => readOnlyFileProvider.js} | 48 +++++--- src/app/panels/file-panel.js | 29 ++--- src/app/tabs/compile-tab.js | 9 +- src/app/ui/renderer.js | 2 + 11 files changed, 219 insertions(+), 145 deletions(-) rename src/app/files/{basicReadOnlyExplorer.js => readOnlyFileProvider.js} (61%) diff --git a/package.json b/package.json index 31624ddaa82..81e157cdc03 100644 --- a/package.json +++ b/package.json @@ -38,13 +38,14 @@ "npm-link-local": "^1.1.0", "npm-run-all": "^4.0.2", "onchange": "^3.2.1", - "remix-debug": "0.3.1", "remix-analyzer": "0.3.1", + "remix-debug": "0.3.1", "remix-lib": "0.4.1", "remix-solidity": "0.3.1", "remix-tests": "0.1.1", "remixd": "0.1.8-alpha.6", "request": "^2.83.0", + "@resolver-engine/imports": "0.2.2", "rimraf": "^2.6.1", "selenium-standalone": "^6.0.1", "solc": "^0.5.0", @@ -157,7 +158,7 @@ "browsertest": "sleep 5 && npm run nightwatch_local", "csslint": "csslint --ignore=order-alphabetical --errors='errors,duplicate-properties,empty-rules' --exclude-list='assets/css/font-awesome.min.css' assets/css/", "downloadsolc_root": "wget --no-check-certificate https://solc-bin.ethereum.org/bin/soljson-v0.5.1+commit.c8a2cb62.js -O soljson.js", - "lint": "standard | notify-error", + "lint": "standard --fix | notify-error", "make-mock-compiler": "node ci/makeMockCompiler.js", "minify": "uglifyjs --in-source-map inline --source-map-inline -c warnings=false", "nightwatch_local": "nightwatch --config nightwatch.js --env local", diff --git a/src/app.js b/src/app.js index 0b22f7dc236..c7b96f3dee2 100644 --- a/src/app.js +++ b/src/app.js @@ -20,6 +20,7 @@ var Storage = remixLib.Storage var Browserfiles = require('./app/files/browser-files') var BrowserfilesTree = require('./app/files/browser-files-tree') var SharedFolder = require('./app/files/shared-folder') +var ReadOnlyFileProvider = require('./app/files/readOnlyFileProvider') var Config = require('./config') var Renderer = require('./app/ui/renderer') var executionContext = require('./execution-context') @@ -32,7 +33,6 @@ var TxLogger = require('./app/execution/txLogger') var Txlistener = remixLib.execution.txListener var EventsDecoder = remixLib.execution.EventsDecoder var FileManager = require('./app/files/fileManager') -var BasicReadOnlyExplorer = require('./app/files/basicReadOnlyExplorer') var NotPersistedExplorer = require('./app/files/NotPersistedExplorer') var toolTip = require('./app/ui/tooltip') var TransactionReceiptResolver = require('./transactionReceiptResolver') @@ -147,18 +147,21 @@ class App { }) self._components.filesProviders['localhost'] = new SharedFolder(remixd) - self._components.filesProviders['swarm'] = new BasicReadOnlyExplorer('swarm') - self._components.filesProviders['github'] = new BasicReadOnlyExplorer('github') self._components.filesProviders['gist'] = new NotPersistedExplorer('gist') - self._components.filesProviders['ipfs'] = new BasicReadOnlyExplorer('ipfs') - self._components.filesProviders['https'] = new BasicReadOnlyExplorer('https') - self._components.filesProviders['http'] = new BasicReadOnlyExplorer('http') + self._components.readOnly = new ReadOnlyFileProvider() + self._components.filesProviders['swarm'] = self._components.readOnly // new BasicReadOnlyExplorer('swarm') + self._components.filesProviders['github'] = self._components.readOnly // new BasicReadOnlyExplorer('github') + self._components.filesProviders['ipfs'] = self._components.readOnly // new BasicReadOnlyExplorer('ipfs') + self._components.filesProviders['https'] = self._components.readOnly // new BasicReadOnlyExplorer('https') + self._components.filesProviders['http'] = self._components.readOnly // new BasicReadOnlyExplorer('http') + self._components.filesProviders['external'] = self._components.readOnly // hack registry.put({api: self._components.filesProviders['localhost'], name: 'fileproviders/localhost'}) registry.put({api: self._components.filesProviders['swarm'], name: 'fileproviders/swarm'}) registry.put({api: self._components.filesProviders['github'], name: 'fileproviders/github'}) registry.put({api: self._components.filesProviders['gist'], name: 'fileproviders/gist'}) registry.put({api: self._components.filesProviders['ipfs'], name: 'fileproviders/ipfs'}) registry.put({api: self._components.filesProviders, name: 'fileproviders'}) + registry.put({api: self._components.readOnly, name: 'fileproviders/readonly'}) self._view = {} diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 386a3c2957c..8664287a2a4 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -1,7 +1,7 @@ 'use strict' var base64 = require('js-base64').Base64 -var swarmgw = require('swarmgw')() var request = require('request') +var resolver = require('@resolver-engine/imports').ImportsEngine() module.exports = class CompilerImports { constructor (githubAccessToken) { @@ -30,95 +30,44 @@ module.exports = class CompilerImports { }) } - handleSwarmImport (url, cleanUrl, cb) { - swarmgw.get(url, function (err, content) { - cb(err, content, cleanUrl) - }) - } - - handleIPFS (url, cb) { - // replace ipfs:// with /ipfs/ - url = url.replace(/^ipfs:\/\/?/, 'ipfs/') - - return request.get( - { - url: 'https://gateway.ipfs.io/' + url - }, - (err, r, data) => { - if (err) { - return cb(err || 'Unknown transport error') - } - cb(null, data, url) - }) - } - - handleHttpCall (url, cleanUrl, cb) { - return request.get( - { - url - }, - (err, r, data) => { - if (err) { - return cb(err || 'Unknown transport error') - } - cb(null, data, cleanUrl) - }) - } - - handlers () { - return [ - { type: 'github', match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } }, - { type: 'http', match: /^(http?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } }, - { type: 'https', match: /^(https?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } }, - { type: 'swarm', match: /^(bzz-raw?:\/\/?(.*))$/, handler: (match, cb) => { this.handleSwarmImport(match[1], match[2], cb) } }, - { type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } } - ] - } - isRelativeImport (url) { return /^([^/]+)/.exec(url) } - import (url, loadingCb, cb) { - var self = this - var imported = this.previouslyHandled[url] + import (uri, loadingCb, cb) { + var imported = this.previouslyHandled[uri] if (imported) { - return cb(null, imported.content, imported.cleanUrl, imported.type, url) + return cb(null, imported.content, imported.cleanUrl, imported.type, uri) } - var handlers = this.handlers() - - var found = false - handlers.forEach(function (handler) { - if (found) { - return - } - var match = handler.match.exec(url) - if (match) { - found = true - - loadingCb('Loading ' + url + ' ...') - handler.handler(match, function (err, content, cleanUrl) { - if (err) { - cb('Unable to import "' + cleanUrl + '": ' + err) - return - } - self.previouslyHandled[url] = { - content: content, - cleanUrl: cleanUrl, - type: handler.type - } - cb(null, content, cleanUrl, handler.type, url) - }) - } - }) + var self = this + resolver + .resolve(uri) + .then(result => { + if (!result) { + cb('Unable to import "' + uri + '"') + return Promise.reject('Just no.') + } else { + loadingCb('Loading ' + uri + ' ...') + console.log(`Resolved to ${result}`) + return resolver.require(uri) + } + }) + .then(result => { + if (!result) { + return + } - if (found) { - return - } else if (/^[^:]*:\/\//.exec(url)) { - cb('Unable to import "' + url + '": Unsupported URL schema') - } else { - cb('Unable to import "' + url + '": File not found') - } + var cleanUrl = result.url + var content = result.source + var type = result.provider + self.previouslyHandled[uri] = { + content, + cleanUrl, + type + } + cb(null, content, cleanUrl, type, uri) + }) + .catch(cb) } } diff --git a/src/app/files/NotPersistedExplorer.js b/src/app/files/NotPersistedExplorer.js index 2ab8b1d9383..edd1cce5fb4 100644 --- a/src/app/files/NotPersistedExplorer.js +++ b/src/app/files/NotPersistedExplorer.js @@ -1,13 +1,93 @@ 'use strict' -var ReadOnlyExplorer = require('./basicReadOnlyExplorer') var toolTip = require('../ui/tooltip') +var EventManager = require('../../lib/events') -class NotPersistedExplorer extends ReadOnlyExplorer { +class NotPersistedExplorer { constructor (type) { - super(type) + this.event = new EventManager() + this.files = {} + this.paths = {} + this.normalizedNames = {} // contains the raw url associated with the displayed path + this.paths[type] = {} + this.type = type this.readonly = false } + close (cb) { + this.files = {} + cb() + } + + init (cb) { + this.files = {} + } + + exists (path, cb) { + if (!this.files) return cb(null, false) + var unprefixedPath = this.removePrefix(path) + cb(null, this.files[unprefixedPath] !== undefined) + } + + get (path, cb) { + if (this.normalizedNames[path]) path = this.normalizedNames[path] // ensure we actually use the normalized path from here + var unprefixedPath = this.removePrefix(path) + var content = this.files[unprefixedPath] + if (!content) { + content = this.files[this.type + '/' + this.normalizedNames[path]] + } + if (cb) { + cb(null, content) + } + return content + } + + set (path, content, cb) { + var unprefixedPath = this.removePrefix(path) + this.addReadOnly(unprefixedPath, content) + if (cb) cb() + return true + } + + addReadOnly (path, content, rawPath) { + try { // lazy try to format JSON + content = JSON.stringify(JSON.parse(content), null, '\t') + } catch (e) {} + if (!rawPath) rawPath = path + // splitting off the path in a tree structure, the json tree is used in `resolveDirectory` + var split = path + var folder = false + while (split.lastIndexOf('/') !== -1) { + var subitem = split.substring(split.lastIndexOf('/')) + split = split.substring(0, split.lastIndexOf('/')) + if (!this.paths[this.type + '/' + split]) { + this.paths[this.type + '/' + split] = {} + } + this.paths[this.type + '/' + split][split + subitem] = { isDirectory: folder } + folder = true + } + this.paths[this.type][split] = { isDirectory: folder } + this.files[path] = content + this.normalizedNames[rawPath] = path + this.event.trigger('fileAdded', [path, true]) + return true + } + + list () { + return this.files + } + + resolveDirectory (path, callback) { + var self = this + if (path[0] === '/') path = path.substring(1) + if (!path) return callback(null, { [self.type]: { } }) + // we just return the json tree populated by `addReadOnly` + callback(null, this.paths[path]) + } + + removePrefix (path) { + return path.indexOf(this.type + '/') === 0 ? path.replace(this.type + '/', '') : path + } + remove (path) { var unprefixedPath = this.removePrefix(path) var folderPath = path.substring(0, path.lastIndexOf('/')) @@ -31,8 +111,8 @@ class NotPersistedExplorer extends ReadOnlyExplorer { }) } - isReadOnly (path) { - return false + isReadOnly () { + return this.readonly } } diff --git a/src/app/files/browser-files.js b/src/app/files/browser-files.js index de84eb664fb..c5a163fd408 100644 --- a/src/app/files/browser-files.js +++ b/src/app/files/browser-files.js @@ -8,6 +8,9 @@ function Files (storage) { var readonly = {} this.type = 'browser' + window['bro'] = this + this.storage = storage + this.exists = function (path, cb) { cb(null, this._exists(path)) } diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index b1d90ea71a9..b3b64e04a10 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -84,6 +84,22 @@ function fileExplorer (localRegistry, files) { } }) } + + // after adding the file, immediately show it in the tree view + try { + var allPaths = Object.keys(self.files.paths) + allPaths = allPaths.sort((a, b) => a.length - b.length) + allPaths.forEach(path => { + self.files.resolveDirectory(path, (error, fileTree) => { + if (error) console.error(error) + if (!fileTree) return + var newTree = normalize(path, fileTree) + self.treeView.updateNodeFromJSON(path, newTree, true) + }) + }) + } catch (err) { + console.log('Jumping to ', filepath) + } }) } diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 5361093123a..67a938b3511 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -29,7 +29,8 @@ class FileManager { localhostExplorer: self._components.registry.get('fileproviders/localhost').api, configExplorer: self._components.registry.get('fileproviders/config').api, gistExplorer: self._components.registry.get('fileproviders/gist').api, - filesProviders: self._components.registry.get('fileproviders').api + filesProviders: self._components.registry.get('fileproviders').api, + readOnly: self._components.registry.get('fileproviders/readonly').api } self._deps.browserExplorer.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) @@ -42,6 +43,9 @@ class FileManager { self._deps.gistExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) self._deps.localhostExplorer.event.register('errored', (event) => { this.removeTabsOf(self._deps.localhostExplorer) }) self._deps.localhostExplorer.event.register('closed', (event) => { this.removeTabsOf(self._deps.localhostExplorer) }) + + self._deps.readOnly.event.register('fileRenamed', (oldName, newName, isFolder) => { this.fileRenamedEvent(oldName, newName, isFolder) }) + self._deps.readOnly.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) } fileRenamedEvent (oldName, newName, isFolder) { @@ -151,10 +155,16 @@ class FileManager { }) } function _switchFile (file) { + var provider = self.fileProviderOf(file) + if (!provider) { + console.error(`Provider for ${file} does not exist`) + return + } self.saveCurrentFile() self._deps.config.set('currentFile', file) self.refreshTabs(file) - self.fileProviderOf(file).get(file, (error, content) => { + + provider.get(file, (error, content) => { if (error) { console.log(error) } else { @@ -177,19 +187,25 @@ class FileManager { cb(`provider for path ${path} not found`) } + // fileProviderOf (file) { + // var provider = this._fileProviderOf(file) + // console.log(`Provider of ${file} is ${provider && provider.type ? provider.type : 'unknown'}`) + // return provider + // } + fileProviderOf (file) { if (!file) return null var provider = file.match(/[^/]*/) if (provider !== null && this._deps.filesProviders[provider[0]]) { return this._deps.filesProviders[provider[0]] } else { - for (var handler of this._components.compilerImport.handlers()) { - if (handler.match.exec(file)) { - return this._deps.filesProviders[handler.type] - } - } + // for (var handler of this._components.compilerImport.handlers()) { + // if (handler.match.exec(file)) { + // return this._deps.filesProviders[handler.type] + // } + // } + return this._deps.readOnly } - return null } saveCurrentFile () { diff --git a/src/app/files/basicReadOnlyExplorer.js b/src/app/files/readOnlyFileProvider.js similarity index 61% rename from src/app/files/basicReadOnlyExplorer.js rename to src/app/files/readOnlyFileProvider.js index df4f17c11c0..4477afbff6b 100644 --- a/src/app/files/basicReadOnlyExplorer.js +++ b/src/app/files/readOnlyFileProvider.js @@ -1,15 +1,18 @@ 'use strict' var EventManager = require('../../lib/events') -class BasicReadOnlyExplorer { - constructor (type) { +var URL = URL || window.URL +const readOnlyFileProviderType = 'external' +class ReadOnlyFileProvider { + constructor () { this.event = new EventManager() this.files = {} this.paths = {} this.normalizedNames = {} // contains the raw url associated with the displayed path - this.paths[type] = {} - this.type = type + this.type = readOnlyFileProviderType this.readonly = true + + window['ext'] = this } close (cb) { @@ -28,11 +31,11 @@ class BasicReadOnlyExplorer { } get (path, cb) { + path = this.removePrefix(path) if (this.normalizedNames[path]) path = this.normalizedNames[path] // ensure we actually use the normalized path from here - var unprefixedPath = this.removePrefix(path) - var content = this.files[unprefixedPath] + var content = this.files[path] if (!content) { - content = this.files[this.type + '/' + this.normalizedNames[path]] + content = this.files[this.normalizedNames[path]] } if (cb) { cb(null, content) @@ -41,19 +44,27 @@ class BasicReadOnlyExplorer { } set (path, content, cb) { - var unprefixedPath = this.removePrefix(path) - this.addReadOnly(unprefixedPath, content) + path = this.removePrefix(path) + this.addReadOnly(path, content) if (cb) cb() return true } - addReadOnly (path, content, rawPath) { + addReadOnly (path, content, rawPath, provider) { + provider = provider || 'http' + + // we really care about slashes for internal consistency + // so we gather as much as we can from the raw url we got + var recoveredSlashesPath = path.replace(/%2F/gi, '/') // global, ignore case + var schemalessPath = this.removeHTTPScheme(recoveredSlashesPath) + var procuredPath = provider + '/' + schemalessPath + try { // lazy try to format JSON content = JSON.stringify(JSON.parse(content), null, '\t') } catch (e) {} if (!rawPath) rawPath = path // splitting off the path in a tree structure, the json tree is used in `resolveDirectory` - var split = path + var split = procuredPath var folder = false while (split.lastIndexOf('/') !== -1) { var subitem = split.substring(split.lastIndexOf('/')) @@ -64,10 +75,12 @@ class BasicReadOnlyExplorer { this.paths[this.type + '/' + split][split + subitem] = { isDirectory: folder } folder = true } + if (!this.paths[this.type]) this.paths[this.type] = {} // ensure this exists, because other functions determine root by checking for this.type this.paths[this.type][split] = { isDirectory: folder } - this.files[path] = content - this.normalizedNames[rawPath] = path - this.event.trigger('fileAdded', [path, true]) + this.files[procuredPath] = content + this.normalizedNames[rawPath] = procuredPath + console.log('Added', path) + this.event.trigger('fileAdded', [procuredPath, true]) return true } @@ -97,6 +110,11 @@ class BasicReadOnlyExplorer { removePrefix (path) { return path.indexOf(this.type + '/') === 0 ? path.replace(this.type + '/', '') : path } + + removeHTTPScheme (path) { + const httpScheme = /https?:\/\// + return httpScheme.exec(path) ? path.replace(httpScheme, '') : path + } } -module.exports = BasicReadOnlyExplorer +module.exports = ReadOnlyFileProvider diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index a1586dd56be..d289af70b2a 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -46,6 +46,7 @@ function filepanel (localRegistry) { self._components = {} self._components.registry = localRegistry || globalRegistry self._deps = { + readOnly: self._components.registry.get('fileproviders/readonly').api, fileProviders: self._components.registry.get('fileproviders').api, fileManager: self._components.registry.get('filemanager').api, config: self._components.registry.get('config').api, @@ -53,12 +54,10 @@ function filepanel (localRegistry) { } var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser']) var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost']) - var swarmExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['swarm']) - var githubExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['github']) - var gistExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['gist']) var configExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['config']) - var httpExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['http']) - var httpsExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['https']) + var gistExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['gist']) + + var readonlyExplorer = new FileExplorer(self._components.registry, self._deps.readOnly) // ----------------- editor panel ---------------------- self._compilerMetadata = new CompilerMetadata( @@ -121,11 +120,9 @@ function filepanel (localRegistry) {
${fileExplorer.init()}
${configExplorer.init()}
${fileSystemExplorer.init()}
-
${swarmExplorer.init()}
-
${githubExplorer.init()}
${gistExplorer.init()}
-
${httpExplorer.init()}
-
${httpsExplorer.init()}
+ +
${readonlyExplorer.init()}
${dragbar} @@ -174,11 +171,7 @@ function filepanel (localRegistry) { self._deps.fileManager.switchFile(path) }) - swarmExplorer.events.register('focus', function (path) { - self._deps.fileManager.switchFile(path) - }) - - githubExplorer.events.register('focus', function (path) { + readonlyExplorer.events.register('focus', function (path) { self._deps.fileManager.switchFile(path) }) @@ -186,14 +179,6 @@ function filepanel (localRegistry) { self._deps.fileManager.switchFile(path) }) - httpExplorer.events.register('focus', function (path) { - self._deps.fileManager.switchFile(path) - }) - - httpsExplorer.events.register('focus', function (path) { - self._deps.fileManager.switchFile(path) - }) - self.render = function render () { return element } function uploadFile (event) { diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 15730c2a750..34647d8d97b 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -483,9 +483,10 @@ module.exports = class CompileTab { if (provider) { provider.get(target, (error, content) => { if (error) { - console.log(error) + console.log('runCompiler', error) } else { sources[target] = { content } + console.log('sources', sources) self._components.compiler.compile(sources, target) } }) @@ -501,10 +502,10 @@ module.exports = class CompileTab { (loadingMsg) => { addTooltip(loadingMsg) }, - (error, content, cleanUrl, type, url) => { + (error, content, cleanUrl, type, url) => { // these two lines if (!error) { if (self._deps.fileProviders[type]) { - self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url) + self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url, type) // for eventual changes } cb(null, content) } else { @@ -514,7 +515,7 @@ module.exports = class CompileTab { } importFileCb (url, filecb) { const self = this - if (url.indexOf('/remix_tests.sol') !== -1) { + if (url.indexOf('remix_tests.sol') !== -1) { return filecb(null, remixTests.assertLibCode) } var provider = self._deps.fileManager.fileProviderOf(url) diff --git a/src/app/ui/renderer.js b/src/app/ui/renderer.js index f90e756971d..1e4e226e764 100644 --- a/src/app/ui/renderer.js +++ b/src/app/ui/renderer.js @@ -67,6 +67,8 @@ Renderer.prototype.error = function (message, container, opt) { message = yo`${message}` } else if (message.innerText) { text = message.innerText + } else { + text = 'Renderer internal error' } var errLocation = text.match(/^([^:]*):([0-9]*):(([0-9]*):)? /) From db79bdb91a428c62b0da1bf74457c121268f4128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Thu, 31 Jan 2019 16:55:42 +0100 Subject: [PATCH 2/7] Clean-up --- package.json | 2 +- src/app.js | 12 ++++++------ src/app/compiler/compiler-imports.js | 6 +++--- src/app/files/browser-files.js | 1 - src/app/files/fileManager.js | 11 ----------- src/app/files/readOnlyFileProvider.js | 3 --- src/app/tabs/compile-tab.js | 7 +++---- 7 files changed, 13 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 81e157cdc03..30d0a9d8b96 100644 --- a/package.json +++ b/package.json @@ -158,7 +158,7 @@ "browsertest": "sleep 5 && npm run nightwatch_local", "csslint": "csslint --ignore=order-alphabetical --errors='errors,duplicate-properties,empty-rules' --exclude-list='assets/css/font-awesome.min.css' assets/css/", "downloadsolc_root": "wget --no-check-certificate https://solc-bin.ethereum.org/bin/soljson-v0.5.1+commit.c8a2cb62.js -O soljson.js", - "lint": "standard --fix | notify-error", + "lint": "standard | notify-error", "make-mock-compiler": "node ci/makeMockCompiler.js", "minify": "uglifyjs --in-source-map inline --source-map-inline -c warnings=false", "nightwatch_local": "nightwatch --config nightwatch.js --env local", diff --git a/src/app.js b/src/app.js index c7b96f3dee2..312836f7990 100644 --- a/src/app.js +++ b/src/app.js @@ -149,12 +149,12 @@ class App { self._components.filesProviders['localhost'] = new SharedFolder(remixd) self._components.filesProviders['gist'] = new NotPersistedExplorer('gist') self._components.readOnly = new ReadOnlyFileProvider() - self._components.filesProviders['swarm'] = self._components.readOnly // new BasicReadOnlyExplorer('swarm') - self._components.filesProviders['github'] = self._components.readOnly // new BasicReadOnlyExplorer('github') - self._components.filesProviders['ipfs'] = self._components.readOnly // new BasicReadOnlyExplorer('ipfs') - self._components.filesProviders['https'] = self._components.readOnly // new BasicReadOnlyExplorer('https') - self._components.filesProviders['http'] = self._components.readOnly // new BasicReadOnlyExplorer('http') - self._components.filesProviders['external'] = self._components.readOnly // hack + self._components.filesProviders['swarm'] = self._components.readOnly // proof of concept, awaiting acceptance before digging deeper + self._components.filesProviders['github'] = self._components.readOnly + self._components.filesProviders['ipfs'] = self._components.readOnly + self._components.filesProviders['https'] = self._components.readOnly + self._components.filesProviders['http'] = self._components.readOnly + self._components.filesProviders['external'] = self._components.readOnly registry.put({api: self._components.filesProviders['localhost'], name: 'fileproviders/localhost'}) registry.put({api: self._components.filesProviders['swarm'], name: 'fileproviders/swarm'}) registry.put({api: self._components.filesProviders['github'], name: 'fileproviders/github'}) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 8664287a2a4..2c5e0e8df6e 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -45,11 +45,11 @@ module.exports = class CompilerImports { .resolve(uri) .then(result => { if (!result) { - cb('Unable to import "' + uri + '"') - return Promise.reject('Just no.') + var errMsg = 'Unable to import "' + uri + '"' + cb(errMsg) + return Promise.reject(errMsg) } else { loadingCb('Loading ' + uri + ' ...') - console.log(`Resolved to ${result}`) return resolver.require(uri) } }) diff --git a/src/app/files/browser-files.js b/src/app/files/browser-files.js index c5a163fd408..291a135d7ec 100644 --- a/src/app/files/browser-files.js +++ b/src/app/files/browser-files.js @@ -8,7 +8,6 @@ function Files (storage) { var readonly = {} this.type = 'browser' - window['bro'] = this this.storage = storage this.exists = function (path, cb) { diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 67a938b3511..3149eeac3b4 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -187,23 +187,12 @@ class FileManager { cb(`provider for path ${path} not found`) } - // fileProviderOf (file) { - // var provider = this._fileProviderOf(file) - // console.log(`Provider of ${file} is ${provider && provider.type ? provider.type : 'unknown'}`) - // return provider - // } - fileProviderOf (file) { if (!file) return null var provider = file.match(/[^/]*/) if (provider !== null && this._deps.filesProviders[provider[0]]) { return this._deps.filesProviders[provider[0]] } else { - // for (var handler of this._components.compilerImport.handlers()) { - // if (handler.match.exec(file)) { - // return this._deps.filesProviders[handler.type] - // } - // } return this._deps.readOnly } } diff --git a/src/app/files/readOnlyFileProvider.js b/src/app/files/readOnlyFileProvider.js index 4477afbff6b..0de42050d1f 100644 --- a/src/app/files/readOnlyFileProvider.js +++ b/src/app/files/readOnlyFileProvider.js @@ -11,8 +11,6 @@ class ReadOnlyFileProvider { this.normalizedNames = {} // contains the raw url associated with the displayed path this.type = readOnlyFileProviderType this.readonly = true - - window['ext'] = this } close (cb) { @@ -79,7 +77,6 @@ class ReadOnlyFileProvider { this.paths[this.type][split] = { isDirectory: folder } this.files[procuredPath] = content this.normalizedNames[rawPath] = procuredPath - console.log('Added', path) this.event.trigger('fileAdded', [procuredPath, true]) return true } diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 34647d8d97b..6cdd52a83ad 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -483,10 +483,9 @@ module.exports = class CompileTab { if (provider) { provider.get(target, (error, content) => { if (error) { - console.log('runCompiler', error) + console.log(error) } else { sources[target] = { content } - console.log('sources', sources) self._components.compiler.compile(sources, target) } }) @@ -502,10 +501,10 @@ module.exports = class CompileTab { (loadingMsg) => { addTooltip(loadingMsg) }, - (error, content, cleanUrl, type, url) => { // these two lines + (error, content, cleanUrl, type, url) => { if (!error) { if (self._deps.fileProviders[type]) { - self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url, type) // for eventual changes + self._deps.fileProviders[type].addReadOnly(cleanUrl, content, url, type) } cb(null, content) } else { From f24fe6eee2131fbb8cc5e89d583bfc28a68264c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Thu, 31 Jan 2019 18:30:44 +0100 Subject: [PATCH 3/7] Bumped up the version of resolver-engine --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 30d0a9d8b96..c9ca92148f7 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "remix-tests": "0.1.1", "remixd": "0.1.8-alpha.6", "request": "^2.83.0", - "@resolver-engine/imports": "0.2.2", + "@resolver-engine/imports": "^0.3.0", "rimraf": "^2.6.1", "selenium-standalone": "^6.0.1", "solc": "^0.5.0", From dbf45fe01a7dd520e7c502bef0355031cb40fcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Mon, 18 Feb 2019 18:15:28 +0100 Subject: [PATCH 4/7] Correctly handling returns/exceptions --- src/app/compiler/compiler-imports.js | 36 +++++++++++----------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 2c5e0e8df6e..cb112e9987c 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -44,30 +44,22 @@ module.exports = class CompilerImports { resolver .resolve(uri) .then(result => { - if (!result) { - var errMsg = 'Unable to import "' + uri + '"' - cb(errMsg) - return Promise.reject(errMsg) - } else { - loadingCb('Loading ' + uri + ' ...') - return resolver.require(uri) - } + loadingCb('Loading ' + uri + ' ...') + return resolver.require(uri) }) .then(result => { - if (!result) { - return - } - - var cleanUrl = result.url - var content = result.source - var type = result.provider - self.previouslyHandled[uri] = { - content, - cleanUrl, - type - } - cb(null, content, cleanUrl, type, uri) + var cleanUrl = result.url + var content = result.source + var type = result.provider + self.previouslyHandled[uri] = { + content, + cleanUrl, + type + } + cb(null, content, cleanUrl, type, uri) + }) + .catch(err => { + cb('Unable to import "' + uri + '"') }) - .catch(cb) } } From 66e8fabf9392792165619cc1f597072e7810c407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Mon, 18 Feb 2019 18:22:01 +0100 Subject: [PATCH 5/7] standard --- src/app/compiler/compiler-imports.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index cb112e9987c..ac15f5b2dc4 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -44,22 +44,23 @@ module.exports = class CompilerImports { resolver .resolve(uri) .then(result => { - loadingCb('Loading ' + uri + ' ...') - return resolver.require(uri) + loadingCb('Loading ' + uri + ' ...') + return resolver.require(uri) }) .then(result => { - var cleanUrl = result.url - var content = result.source - var type = result.provider - self.previouslyHandled[uri] = { - content, - cleanUrl, - type - } - cb(null, content, cleanUrl, type, uri) + var cleanUrl = result.url + var content = result.source + var type = result.provider + self.previouslyHandled[uri] = { + content, + cleanUrl, + type + } + cb(null, content, cleanUrl, type, uri) }) .catch(err => { - cb('Unable to import "' + uri + '"') + console.log('import', err) + cb('Unable to import "' + uri + '"') }) } } From 83d3ac05813fb9e3281d0ac671e686ab3610b624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Mon, 18 Feb 2019 20:59:19 +0100 Subject: [PATCH 6/7] I think this should do it and tests should start passing again --- src/app/compiler/compiler-imports.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index ac15f5b2dc4..5cfab5a95c4 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -60,7 +60,7 @@ module.exports = class CompilerImports { }) .catch(err => { console.log('import', err) - cb('Unable to import "' + uri + '"') + cb('Unable to import "' + uri + '": File not found') }) } } From 2544d6ac00823fcf0c28fb1d79b9343164ab1491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Cymer?= Date: Mon, 18 Feb 2019 21:32:53 +0100 Subject: [PATCH 7/7] No-op change, just in case of non-deterministic tests --- src/app/compiler/compiler-imports.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 5cfab5a95c4..66f4e59266e 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -59,7 +59,7 @@ module.exports = class CompilerImports { cb(null, content, cleanUrl, type, uri) }) .catch(err => { - console.log('import', err) + console.log('import', err) // TODO remove this and all my other console logs cb('Unable to import "' + uri + '": File not found') }) }