trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.32k forks source link

Support for Truffle plugins in Yarn workspaces #2409

Open rkalis opened 5 years ago

rkalis commented 5 years ago

Issue

@PaulRBerg raised an issue in truffle-plugin-verify about the plugin not working in Yarn workspaces. The contents of his issue:


Yarn workspaces is this new way of intelligently managing your npm modules in a monorepo by installing them only once (or multiple times if there are overlapping versions). What it does is that it aggregates all the modules at the root of your project.

If I install truffle-plugin-verify in the "contracts" package of this monorepo and I try to run it, I get the following error:

Error: truffle-plugin-verify listed as a plugin, but not found in global or local node modules!

Of course, I moved on and installed the module globally, but I can't use this plugin on CI.


I'm guessing that Truffle searches for installed plugins in the node_modules of the directory containing truffle.js, while in this case the plugin is installed in the root node_modules of the workspace, several levels higher.

Steps to Reproduce

  1. Start a project with Yarn workspaces.
  2. Start a Truffle project inside this project.
  3. Install a Truffle plugin (e.g. truffle-plugin-verify) into the Truffle project.
  4. Try to use the plugin (e.g. truffle plugin run verify Roscoin --network goerli).

Expected Behavior

Acknowledge that the plugin is installed into the root of the project rather than the current directory, and access it from there.

Actual Results

Error: truffle-plugin-verify listed as a plugin, but not found in global or local node modules!

Environment

PaulRBerg commented 5 years ago

Thanks @rkalis!

Environment

gnidan commented 5 years ago

Thanks both of you! We'll triage this and get it sorted out.

sirhill commented 4 years ago

Creating a symlink from the parent node_modules to the repo node_modules seems to be a valid workaround.

PaulRBerg commented 4 years ago

Yeah, that works. I learned about the nohoist option in the meantime:

{
  "workspaces": {
    "packages": [
      "packages/*"
     ],
     "nohoist": [
       "**/package-name-here",
       "**/package-name-here/**"
     ]
  }
}
6gunner commented 2 years ago

Is there any way to specify my plugin directory through truffle.config.js? Usually I just want to write a special plugin for my project, and I don't wanna publish or install it through npm

rkalis commented 2 years ago

Iirc you can also specify relative paths for specific plugins if it's a local plugin. Note that you do need to add a "truffle-plugin.json" file in the directory of your local plugin. Perhaps @gnidan can confirm?