Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
b60ff245
Unverified
Commit
b60ff245
authored
May 29, 2018
by
yann300
Committed by
GitHub
May 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1328 from ethereum/truffleImport
Import module from `installed_contracts` and `node_modules` folder
parents
d6417d31
21cb49c8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
23 deletions
+43
-23
app.js
src/app.js
+24
-10
compiler-imports.js
src/app/compiler/compiler-imports.js
+18
-11
fileManager.js
src/app/files/fileManager.js
+1
-2
No files found.
src/app.js
View file @
b60ff245
...
@@ -36,7 +36,7 @@ var modalDialogCustom = require('./app/ui/modal-dialog-custom')
...
@@ -36,7 +36,7 @@ var modalDialogCustom = require('./app/ui/modal-dialog-custom')
var
TxLogger
=
require
(
'./app/execution/txLogger'
)
var
TxLogger
=
require
(
'./app/execution/txLogger'
)
var
Txlistener
=
remixLib
.
execution
.
txListener
var
Txlistener
=
remixLib
.
execution
.
txListener
var
EventsDecoder
=
remixLib
.
execution
.
EventsDecoder
var
EventsDecoder
=
remixLib
.
execution
.
EventsDecoder
var
handleImports
=
require
(
'./app/compiler/compiler-imports'
)
var
CompilerImport
=
require
(
'./app/compiler/compiler-imports'
)
var
FileManager
=
require
(
'./app/files/fileManager'
)
var
FileManager
=
require
(
'./app/files/fileManager'
)
var
ContextualListener
=
require
(
'./app/editor/contextualListener'
)
var
ContextualListener
=
require
(
'./app/editor/contextualListener'
)
var
ContextView
=
require
(
'./app/editor/contextView'
)
var
ContextView
=
require
(
'./app/editor/contextView'
)
...
@@ -135,6 +135,7 @@ class App {
...
@@ -135,6 +135,7 @@ class App {
self
.
_api
.
filesProviders
[
'ipfs'
]
=
new
BasicReadOnlyExplorer
(
'ipfs'
)
self
.
_api
.
filesProviders
[
'ipfs'
]
=
new
BasicReadOnlyExplorer
(
'ipfs'
)
self
.
_view
=
{}
self
.
_view
=
{}
self
.
_components
=
{}
self
.
_components
=
{}
self
.
_components
.
compilerImport
=
new
CompilerImport
()
self
.
data
=
{
self
.
data
=
{
_layout
:
{
_layout
:
{
right
:
{
right
:
{
...
@@ -235,7 +236,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
...
@@ -235,7 +236,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
}
function
importExternal
(
url
,
cb
)
{
function
importExternal
(
url
,
cb
)
{
handleImports
.
import
(
url
,
self
.
_components
.
compilerImport
.
import
(
url
,
(
loadingMsg
)
=>
{
(
loadingMsg
)
=>
{
toolTip
(
loadingMsg
)
toolTip
(
loadingMsg
)
},
},
...
@@ -249,22 +250,34 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
...
@@ -249,22 +250,34 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
})
})
}
}
// ----------------- Compiler -----------------
function
importFileCb
(
url
,
filecb
)
{
var
compiler
=
new
Compiler
((
url
,
cb
)
=>
{
var
provider
=
fileManager
.
fileProviderOf
(
url
)
var
provider
=
fileManager
.
fileProviderOf
(
url
)
if
(
provider
)
{
if
(
provider
)
{
provider
.
exists
(
url
,
(
error
,
exist
)
=>
{
provider
.
exists
(
url
,
(
error
,
exist
)
=>
{
if
(
error
)
return
cb
(
error
)
if
(
error
)
return
file
cb
(
error
)
if
(
exist
)
{
if
(
exist
)
{
return
provider
.
get
(
url
,
cb
)
return
provider
.
get
(
url
,
file
cb
)
}
else
{
}
else
{
importExternal
(
url
,
cb
)
importExternal
(
url
,
file
cb
)
}
}
})
})
}
else
if
(
self
.
_components
.
compilerImport
.
isRelativeImport
(
url
))
{
// try to resolve localhost modules (aka truffle imports)
var
splitted
=
/
([^/]
+
)\/(
.*
)
$/g
.
exec
(
url
)
async
.
tryEach
([
(
cb
)
=>
{
importFileCb
(
'localhost/installed_contracts/'
+
url
,
cb
)
},
(
cb
)
=>
{
if
(
!
splitted
)
{
cb
(
'url not parseable'
+
url
)
}
else
{
importFileCb
(
'localhost/installed_contracts/'
+
splitted
[
1
]
+
'/contracts/'
+
splitted
[
2
],
cb
)
}
},
(
cb
)
=>
{
importFileCb
(
'localhost/node_modules/'
+
url
,
cb
)
},
(
cb
)
=>
{
if
(
!
splitted
)
{
cb
(
'url not parseable'
+
url
)
}
else
{
importFileCb
(
'localhost/node_modules/'
+
splitted
[
1
]
+
'/contracts/'
+
splitted
[
2
],
cb
)
}
}],
(
error
,
result
)
=>
{
filecb
(
error
,
result
)
}
)
}
else
{
}
else
{
importExternal
(
url
,
cb
)
importExternal
(
url
,
file
cb
)
}
}
})
}
// ----------------- Compiler -----------------
var
compiler
=
new
Compiler
(
importFileCb
)
var
offsetToLineColumnConverter
=
new
OffsetToLineColumnConverter
(
compiler
.
event
)
var
offsetToLineColumnConverter
=
new
OffsetToLineColumnConverter
(
compiler
.
event
)
// ----------------- UniversalDApp -----------------
// ----------------- UniversalDApp -----------------
...
@@ -553,7 +566,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
...
@@ -553,7 +566,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
var
fileManager
=
new
FileManager
({
var
fileManager
=
new
FileManager
({
config
:
config
,
config
:
config
,
editor
:
editor
,
editor
:
editor
,
filesProviders
:
filesProviders
filesProviders
:
filesProviders
,
compilerImport
:
self
.
_components
.
compilerImport
})
})
// Add files received from remote instance (i.e. another remix-ide)
// Add files received from remote instance (i.e. another remix-ide)
...
...
src/app/compiler/compiler-imports.js
View file @
b60ff245
...
@@ -3,9 +3,12 @@ var base64 = require('js-base64').Base64
...
@@ -3,9 +3,12 @@ var base64 = require('js-base64').Base64
var
swarmgw
=
require
(
'swarmgw'
)
var
swarmgw
=
require
(
'swarmgw'
)
var
request
=
require
(
'request'
)
var
request
=
require
(
'request'
)
module
.
exports
=
{
module
.
exports
=
class
CompilerImports
{
previouslyHandled
:
{},
// cache import so we don't make the request at each compilation.
constructor
()
{
handleGithubCall
:
function
(
root
,
path
,
cb
)
{
this
.
previouslyHandled
=
{}
// cache import so we don't make the request at each compilation.
}
handleGithubCal
(
root
,
path
,
cb
)
{
return
request
.
get
(
return
request
.
get
(
{
{
url
:
'https://api.github.com/repos/'
+
root
+
'/contents/'
+
path
,
url
:
'https://api.github.com/repos/'
+
root
+
'/contents/'
+
path
,
...
@@ -26,15 +29,15 @@ module.exports = {
...
@@ -26,15 +29,15 @@ module.exports = {
cb
(
'Content not received'
)
cb
(
'Content not received'
)
}
}
})
})
}
,
}
handleSwarmImport
:
function
(
url
,
cleanUrl
,
cb
)
{
handleSwarmImport
(
url
,
cleanUrl
,
cb
)
{
swarmgw
.
get
(
url
,
function
(
err
,
content
)
{
swarmgw
.
get
(
url
,
function
(
err
,
content
)
{
cb
(
err
,
content
,
cleanUrl
)
cb
(
err
,
content
,
cleanUrl
)
})
})
}
,
}
handleIPFS
:
function
(
url
,
cb
)
{
handleIPFS
(
url
,
cb
)
{
// replace ipfs:// with /ipfs/
// replace ipfs:// with /ipfs/
url
=
url
.
replace
(
/^ipfs:
\/\/?
/
,
'ipfs/'
)
url
=
url
.
replace
(
/^ipfs:
\/\/?
/
,
'ipfs/'
)
...
@@ -51,17 +54,21 @@ module.exports = {
...
@@ -51,17 +54,21 @@ module.exports = {
}
}
cb
(
null
,
data
,
url
)
cb
(
null
,
data
,
url
)
})
})
}
,
}
handlers
:
function
()
{
handlers
()
{
return
[
return
[
{
type
:
'github'
,
match
:
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)\/(
.*
)
/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleGithubCall
(
match
[
3
],
match
[
4
],
cb
)
}
},
{
type
:
'github'
,
match
:
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)\/(
.*
)
/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleGithubCall
(
match
[
3
],
match
[
4
],
cb
)
}
},
{
type
:
'swarm'
,
match
:
/^
(
bzz
[
ri
]?
:
\/\/?(
.*
))
$/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleSwarmImport
(
match
[
1
],
match
[
2
],
cb
)
}
},
{
type
:
'swarm'
,
match
:
/^
(
bzz
[
ri
]?
:
\/\/?(
.*
))
$/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleSwarmImport
(
match
[
1
],
match
[
2
],
cb
)
}
},
{
type
:
'ipfs'
,
match
:
/^
(
ipfs:
\/\/?
.+
)
/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleIPFS
(
match
[
1
],
cb
)
}
}
{
type
:
'ipfs'
,
match
:
/^
(
ipfs:
\/\/?
.+
)
/
,
handler
:
(
match
,
cb
)
=>
{
this
.
handleIPFS
(
match
[
1
],
cb
)
}
}
]
]
},
}
isRelativeImport
(
url
)
{
return
/^
([
A-Za-z0-9
]
+
)
/
.
exec
(
url
)
}
import
:
function
(
url
,
loadingCb
,
cb
)
{
import
(
url
,
loadingCb
,
cb
)
{
var
self
=
this
var
self
=
this
var
imported
=
this
.
previouslyHandled
[
url
]
var
imported
=
this
.
previouslyHandled
[
url
]
if
(
imported
)
{
if
(
imported
)
{
...
...
src/app/files/fileManager.js
View file @
b60ff245
...
@@ -4,7 +4,6 @@ var $ = require('jquery')
...
@@ -4,7 +4,6 @@ var $ = require('jquery')
var
remixLib
=
require
(
'remix-lib'
)
var
remixLib
=
require
(
'remix-lib'
)
var
yo
=
require
(
'yo-yo'
)
var
yo
=
require
(
'yo-yo'
)
var
EventManager
=
remixLib
.
EventManager
var
EventManager
=
remixLib
.
EventManager
var
imports
=
require
(
'../compiler/compiler-imports'
)
/*
/*
attach to files event (removed renamed)
attach to files event (removed renamed)
...
@@ -161,7 +160,7 @@ class FileManager {
...
@@ -161,7 +160,7 @@ class FileManager {
if
(
provider
!==
null
&&
this
.
opt
.
filesProviders
[
provider
[
0
]])
{
if
(
provider
!==
null
&&
this
.
opt
.
filesProviders
[
provider
[
0
]])
{
return
this
.
opt
.
filesProviders
[
provider
[
0
]]
return
this
.
opt
.
filesProviders
[
provider
[
0
]]
}
else
{
}
else
{
for
(
var
handler
of
imports
.
handlers
())
{
for
(
var
handler
of
this
.
opt
.
compilerImport
.
handlers
())
{
if
(
handler
.
match
.
exec
(
file
))
{
if
(
handler
.
match
.
exec
(
file
))
{
return
this
.
opt
.
filesProviders
[
handler
.
type
]
return
this
.
opt
.
filesProviders
[
handler
.
type
]
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment