@@ -34,6 +34,7 @@ const dir = require('node-dir');
3434const Web3 = require ( 'web3' ) ;
3535const util = require ( 'util' ) ;
3636const globby = require ( 'globby' ) ;
37+ const globalModules = require ( 'global-modules' ) ;
3738
3839async function plugin ( truffleConfig ) {
3940 let app ;
@@ -59,7 +60,7 @@ async function plugin(truffleConfig){
5960 return app . ui . report ( 'truffle-help' )
6061 }
6162
62- truffle = loadTruffleLibrary ( ) ;
63+ truffle = loadTruffleLibrary ( app ) ;
6364
6465 } catch ( err ) {
6566 throw err ;
@@ -152,13 +153,36 @@ function tests(truffle){
152153}
153154
154155
155- function loadTruffleLibrary ( ) {
156- try { return require ( "truffle" ) } catch ( err ) { } ;
157- try { return require ( "./truffle.library" ) } catch ( err ) { } ;
156+ function loadTruffleLibrary ( app ) {
157+
158+ // Case: from local node_modules
159+ try {
160+ const lib = require ( "truffle" ) ;
161+ app . ui . report ( 'truffle-local' ) ;
162+ return lib ;
163+
164+ } catch ( err ) { } ;
165+
166+ // Case: global
167+ try {
168+ const globalTruffle = path . join ( globalModules , 'truffle' ) ;
169+ const lib = require ( globalTruffle ) ;
170+ app . ui . report ( 'truffle-global' ) ;
171+ return lib ;
172+
173+ } catch ( err ) { } ;
174+
175+ // Default: fallback
176+ try {
177+
178+ app . ui . report ( 'truffle-warn' ) ;
179+ return require ( "./truffle.library" ) }
180+
181+ catch ( err ) {
182+ const msg = app . ui . generate ( 'truffle-fail' , [ err ] ) ;
183+ throw new Error ( msg ) ;
184+ } ;
158185
159- // TO DO: throw error? This point should never be reached.
160- // Validate that truffle.ganache exists? Have checked that
161- // a non-existent prop defaults to the ganache-core-sc fallback FWIW.
162186}
163187
164188/**
0 commit comments