Truffle: 5.0.0-beta2 run plugins with callbacks not working

Created on 30 Nov 2018  路  8Comments  路  Source: trufflesuite/truffle

- [x] I've asked for help in the Truffle Gitter

Issue

I am not able to write a simple plugin that uses a callback and see the results of the callback. Here is plugin code:

const request = require('request');
module.exports = (config) => request('http://google.com', {}, (err, res, body) => {
    console.log("Hi, rocky!")
  })

Running this produces no output.

Steps to Reproduce

Go through the plugin instruction at https://github.com/trufflesuite/truffle/releases and use the above code.

Expected Behavior

Hi, rocky

Actual Results

no output.

Most helpful comment

@daniyarchambylov thanks for investigating this!

I spoke with @rocky and concluded that we should support plugins that accept a callback as well as plugins that return a promise. I don't suppose you would be interested in opening a PR containing this change?

Thank you!

All 8 comments

Tried same code and it doesn't work. It would be useful to allow truffle handle plugins with asynchronous code correctly. I don't see any reason why it can't be implemented. I've looked into source code and found that callback function done is called right after plugin command has been called. Why just not pass done as second parameter to a plugin's exposed function?

https://github.com/trufflesuite/truffle/blob/c1da40e23a7f30fa0673130c428c72725c06c05f/packages/truffle-core/lib/commands/run.js#L31
So this is a code responsible for calling plugin command

if (config.plugins) {
      let pluginConfigs = Plugin.load(config, done);
      Run.run(pluginConfigs, customCommand, config);
      done();
    } else {

If we could rewrite it as

if (config.plugins) {
      let pluginConfigs = Plugin.load(config, done);
      Run.run(pluginConfigs, customCommand, config, done);
    } else {

and here https://github.com/trufflesuite/truffle/blob/c1da40e23a7f30fa0673130c428c72725c06c05f/packages/truffle-core/lib/run.js#L57

From

  run(pluginConfigs, customCommand, config) {
    let runCommand = this.initializeCommand(pluginConfigs, customCommand);
    runCommand(config);
  }

to

  run(pluginConfigs, customCommand, config, done) {
    let runCommand = this.initializeCommand(pluginConfigs, customCommand);
    runCommand(config, done);
  }

We could then write plugin as

const request = require('request');
module.exports = (config, done) => request('http://google.com', {}, (err, res, body) => {
    console.log("Hi, rocky!");
    done();
  })

@daniyarchambylov thanks for investigating this!

I spoke with @rocky and concluded that we should support plugins that accept a callback as well as plugins that return a promise. I don't suppose you would be interested in opening a PR containing this change?

Thank you!

@gnidan
Working on it!

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

After PR #1519 has been merged and truffle version updated to v5.0.0-next.20 running 3rd party plugins fail due to missing dependency. Required package app-module-path hasn't been installed.

Steps to Reproduce

  1. Install truffle (v5.0.0-next.20) - npm i [email protected]
  2. Install 3rd party plugin and add it in plugin section in truffle-config.js
  3. Run plugin (in my case I call it _analyze_ - ./node_modules/.bin/truffle run analyze

Expected Behavior

Command should execute successfully without errors.

Actual Results

$ ./node_modules/.bin/truffle run analyze --help
Error: Cannot find module 'app-module-path'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at checkPluginModules (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/lib/plugin.js:18:1)
    at /home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/~/lodash/_createFlow.js:71:1
    at Object.load (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/lib/plugin.js:70:1)
    at Object.run (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/lib/commands/run.js:29:1)
    at Command.run (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/lib/command.js:113:1)
    at Object.<anonymous> (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/packages/truffle-core/cli.js:47:1)
    at __webpack_require__ (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/webpack/bootstrap 89bbbec125c6289b9791:19:1)
    at /home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/webpack:/webpack/bootstrap 89bbbec125c6289b9791:65:1
    at Object.<anonymous> (/home/daniyar/tmp/truffle-next-20/node_modules/truffle/build/cli.bundled.js:71:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
Truffle v5.0.0-next.20 (core: 5.0.0-beta.2)
Solidity v0.5.0 (solc-js)
Node v8.10.0

Environment

  • Operating System: Ubuntu 18.04
  • Truffle version (truffle version): v5.0.0-next.20 (core: 5.0.0-beta.2)
  • node version (node --version): v8.10.0
  • npm version (npm --version): v.3.5.2

@daniyarchambylov the app-module-path problem should be resolved now on 5.0.0-next.22

All fixed now. Thanks for all the great work!

@gnidan I confirm it's working with 5.0.0-next.24 for sure!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmmpxf picture bmmpxf  路  3Comments

hefgi picture hefgi  路  3Comments

oed picture oed  路  3Comments

abcoathup picture abcoathup  路  3Comments

ferittuncer picture ferittuncer  路  3Comments