Skip to content

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

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

Closed
ailisp opened this issue Feb 15, 2022 · 5 comments · Fixed by #115
Closed

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

ailisp opened this issue Feb 15, 2022 · 5 comments · Fixed by #115

Comments

@ailisp
Copy link
Member

ailisp commented Feb 15, 2022

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
Copy link
Member Author

ailisp commented Feb 15, 2022

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
Copy link
Member Author

ailisp commented Feb 15, 2022

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

@ailisp ailisp changed the title main branch of near-workspaces-ava is broken near-workspaces-ava on main branch cannot be npm link to test Feb 16, 2022
@willemneal
Copy link
Contributor

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

@ailisp
Copy link
Member Author

ailisp commented Apr 7, 2022

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

@willemneal
Copy link
Contributor

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

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