near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 21 forks source link

near-workspaces-ava on main branch cannot be `npm link` to test #116

Closed ailisp closed 2 years ago

ailisp commented 2 years ago

Currently, near-workspaces-init generates a near-workspaces directory, which has a package.json, and has near-workspaces-ava 1.0.0 as dependency.

Because some new commits haven't released, I want to use main branch of near-workspaces-ava. So I run npm link in packages/ava. And run npm link near-workspaces-ava in generated near-workspaces. However, run npm run test now fails at:

npm run test

> test
> near-workspaces-ava

/Users/bo/.nvm/versions/node/v16.14.0/lib/node_modules/near-workspaces-ava/node_modules/ava/lib/api.js:27
                        throw new Error(`Could not resolve required module ’${name}’`);
                              ^

Error: Could not resolve required module ’ts-node/register’
    at /Users/bo/.nvm/versions/node/v16.14.0/lib/node_modules/near-workspaces-ava/node_modules/ava/lib/api.js:27:10
    at Array.map (<anonymous>)
    at resolveModules (/Users/bo/.nvm/versions/node/v16.14.0/lib/node_modules/near-workspaces-ava/node_modules/ava/lib/api.js:23:25)
    at new Api (/Users/bo/.nvm/versions/node/v16.14.0/lib/node_modules/near-workspaces-ava/node_modules/ava/lib/api.js:48:26)
    at Object.exports.run (/Users/bo/.nvm/versions/node/v16.14.0/lib/node_modules/near-workspaces-ava/node_modules/ava/lib/cli.js:386:14)****
ailisp commented 2 years ago

When not using npm link, node_modules have near-workspaces-ava and its dependencies installed. Such as above ts-node, and therefore no error happens. When using npm link, node_modules look like this (note on the nested node_modules dir structure): image

Now below code cannot find dependencies, so we need to fix this function:

function resolveModules(modules) {
    return arrify(modules).map(name => {
        const modulePath = resolveCwd.silent(name);

        if (modulePath === undefined) {
            throw new Error(`Could not resolve required module ’${name}’`);
        }
ailisp commented 2 years ago

Indeed the bug is resolveCwd doesn't handle npm link module well. And resolveCwd is used in ava, not part of our codebase. So the fix should be in ava (not near-workspaces-ava), and use the fixed version of ava in near-workspaces-ava

willemneal commented 2 years ago

We had been using yarn which handled all of the linking out of the box as it was a yarn workspace.

ailisp commented 2 years ago

@willemneal Have also tried yarn link, aboveresolveCwd bug also prevented me to link of workspaces-ava. The bug has been tracked in https://github.com/avajs/ava/pull/2971 and https://github.com/avajs/ava/issues/2985

willemneal commented 2 years ago

I'm saying that yarn link isn't needed. Since it was a workspace yarn or yarn install handles it.