Contract-library tries to find all contracts on Github even under NPM Link status
benjamistan opened this issue · 1 comments
benjamistan commented
Expected Behavior
When trying to test new contracts using a local dev copy of contracts-library
, the contracts-library
repo should look locally if the HTTP call to find the json on Github fails.
Current Behavior
When trying to test a new GMTetherToken.sol contract using npm link
, it appears that utils.js
is still redirecting to Github to find the json and getting a 404.
Possible Solution
Check local before going to Github?
Steps to Reproduce
- Create new contract in this library using the standard steps
- Run
npm link
in your localcontract-library
folder - Run
npm link @xgm/contract-library
in your localgodmode-sample-project folder
- Run
npx godmode install
in your localgodmode-sample-project-folder
Output
Installing protocols for GM...
/Users/Ben-XGM/gm/contract-library/dist/utils.js:27
throw error_codes_1.HTTPError(res.statusCode, `${url} ${res.statusCode} ${res.statusMessage}`);
^
CustomError [HTTPError]: https://raw.githubusercontent.com/xGodMode/contract-library/main/build/protocols/Tether.json 404 Not Found
at Object.HTTPError (/Users/Ben-XGM/gm/contract-library/node_modules/@xgm/error-codes/dist/index.js:23:12)
at ClientRequest.<anonymous> (/Users/Ben-XGM/gm/contract-library/dist/utils.js:27:41)
at Object.onceWrapper (events.js:422:26)
at ClientRequest.emit (events.js:315:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
at TLSSocket.socketOnData (_http_client.js:509:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9) {
code: 'HTTP404',
timestamp: 1630955568532,
metadata: { statusCode: 404 }
}
Context (Environment)
I need to test local dev copies of contract-library
without having to run npm publish
each time I make changes.
benjamistan commented
Looks like searching on Github is hardcoded here in /src/installer.ts
async function install(protocolName: string) {
const protocolFilePath = path.join(OUTPUT_DIR, protocolName + '.json');
const protocolUrl = `https://raw.githubusercontent.com/xGodMode/contract-library/main/build/protocols/${protocolName}.json`;
const protocol = await handleRequest(protocolUrl, { json: true });
await fs.promises.writeFile(
protocolFilePath,
JSON.stringify(protocol, null, 4)
);
console.log('Saved', protocolName, 'to', protocolFilePath);
}