ethpm / ethpm.js

Javascript library for EthPM package manifest and registry operations
https://ethpm.github.io/ethpm.js/
MIT License
13 stars 7 forks source link

Replace module-alias with ttypescript #47

Closed njgheorghita closed 4 years ago

njgheorghita commented 4 years ago

@gnidan I spent some time trying to remove module-alias in favor of ttypescript as we discussed. I wasn't able to get very far past the basic install code. As expected, tests here and in truffle worked fine locally, but are failing in ci over in the truffle pr. If you have some time to get into it or point me in the right direction, I can dig a little deeper tomorrow.

gnidan commented 4 years ago

I'll be in meetings for much of the workday today, but I'll put this on my list for afterwards.

In the meantime, can you go into the ethpm.js source directory, do a build, and then run:

$ node
> require(".")

and see what happens?

njgheorghita commented 4 years ago

Nice, yeah I've been playing around with this and am left scratching my head.

  1. cd into /Users/nickgheorghita/ethereum/ethpm.js - and run npm run build
  2. cd into ethpm.js/dist - and run node --experimental-repl-await
  3. looking good so far
    > require.resolve('.')
    '/Users/nickgheorghita/ethereum/ethpm.js/dist/index.js'
    > const { EthPM } = require(".");
    undefined
  4. This is where i'm left confused
    > await EthPM.configure({manifest: "ethpm/manifests/v3"}).connect({})
    { Error: Cannot find module 'ethpm/manifests/v3'
    at Object.configure (/Users/nickgheorghita/ethereum/src/ethpm.ts:39:12)
    at new map (/Users/nickgheorghita/node_modules/src/session/session.ts:20:10)
    at Array.map (<anonymous>)
    at load (/Users/nickgheorghita/node_modules/src/session/session.ts:21:29)
    at Object.originalRequire [as load] (/Users/nickgheorghita/node_modules/src/config/loader.ts:11:7)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) code: 'MODULE_NOT_FOUND' }

    I can't figure out why the stack trace is 1) running typescript and 2) jumping around to node_modules/ directories in all kinds of locations. I even went as far to yank out the usage of the original-require library - yet, it ends up making a call to the library. It seems like I'm missing something fundamental about how the code in the dist/ folder is executed? For example - the top line of the stack trace points towards a file that doesn't exist on my machine....

gnidan commented 4 years ago

Ah right, for this:

Error: Cannot find module 'ethpm/manifests/v3'

The problem is that, now that module-alias is gone, nothing tells Node's runtime how to find that module name. I think the solution here requires looking for ethpm/(.*) in configure, and changing that to ethpm/dist/src/\1 (or is it ethpm/dist/lib/\1? Whatever; convert it to the real path)