Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input undefined -- library use case for Truffle #393

Open
mfigurski80 opened this issue Jun 25, 2022 · 1 comment
Open

Input undefined -- library use case for Truffle #393

mfigurski80 opened this issue Jun 25, 2022 · 1 comment

Comments

@mfigurski80
Copy link

Trying to get solidity-docgen (installed from npm, specified as '^0.6.0-beta.17' in package.json) to compile files for me, without transitioning from Truffle to Hardhat, by using the following script:

const { docgen } = require('solidity-docgen');
const fs = require("fs");

const json = JSON.parse(fs.readFileSync('build/contracts/CurrencyManager.json'));
// console.log(json);
docgen([{ output: json }]).then(res => {
    console.log(res);
});

Note that the CurrencyManager.json file is the json output after truffle compiled -- it does have an 'ast' field present, as indicated by the readme. To my understanding, this this script is equivalent the current readme example usage, although I am of course confused by what exactly the 'output' parameter needs to be. The error I get if I run this:

undefined:1
undefined
^

SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at clone (/home/miko/solidity/karmaToken/node_modules/solidity-docgen/dist/utils/clone.js:9:29)
    at buildSite (/home/miko/solidity/karmaToken/node_modules/solidity-docgen/dist/site.js:27:41)
    at main (/home/miko/solidity/karmaToken/node_modules/solidity-docgen/dist/main.js:20:39)
    at Object.<anonymous> (/home/miko/solidity/karmaToken/docify.js:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

Taking a look at the offending function in site.js, I get the following -- the error occurs when we try to pass originalBuild.input to some function clone, where originalBuild is actually the element inside the array I passed in the config. The error seems to be happening because the code required the 'input' field to be json-parseable, while it is recommended to be undefined in the readme.

function buildSite(builds, siteConfig) {
    var _a;
    const assign = typeof siteConfig.pages === 'string' ? exports.pageAssigner[siteConfig.pages] : siteConfig.pages;
    const seen = new Set();
    const items = [];
    const pages = {};
    for (const originalBuild of builds) {
        // Clone because we will mutate in order to add item context.
        const output = (0, clone_1.clone)(originalBuild.output);
        const input = (0, clone_1.clone)(originalBuild.input);
        const deref = (0, utils_1.astDereferencer)(output);
        const build = { input, output, deref };
        for (const { ast: file } of Object.values(build.output.sources)) {

I understand that this project is mostly concerned with supporting the hardhat use-case. Was hoping for clarification if this raw use-case is even possible and, if so, how we should go about doing it.

👍👍 Thanks for supporting!

@frangio
Copy link
Contributor

frangio commented Jun 25, 2022

Hardhat isn't required, this library just needs the output from solc, the compiler. The JSON file that you mention doesn't contain this full output, it's just a subset of it, so it won't be enough. Truffle doesn't expose the full output from the compiler so it won't be possible to use it out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants