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

Dependency enforcement #544

Closed
kaisalmen opened this issue Dec 17, 2024 · 5 comments
Closed

Dependency enforcement #544

kaisalmen opened this issue Dec 17, 2024 · 5 comments

Comments

@kaisalmen
Copy link
Collaborator

Hello @CGNonofr I may have found the reason why dependency enforcement does not work properly. All your packages refer to vscode like this:

"dependencies": {
  "vscode": "npm:@codingame/[email protected]"
}

This is syntactically correct and it resolves the dependency, but in dependent projects (like monaco-languageclient) the package @codingame/monaco-vscode-api is not seen as an independent package with a version. The downstream dependency resolution by npm is unable to understand "@codingame/monaco-vscode-java-default-extension": "~10.0.0" and "@codingame/monaco-vscode-model-service-override": "~11.1.2" should be deduped. It is not done correctly, because the resolution mechanism only sees vscode and not @codingame/monaco-vscode-api and its version.

I hope this makes sense. At least this explains why my peerDependency definitions were completely ineffective in the past.

@kaisalmen
Copy link
Collaborator Author

It could be sufficient to add the dependency explicitly along, like this:

  "dependencies": {
    "@codingame/monaco-vscode-api": "~11.1.2",
    "vscode": "npm:@codingame/monaco-vscode-api@~11.1.2",
  }

@CGNonofr
Copy link
Contributor

I'm sorry, I've read your message 3 times without understanding what you meant

I don't know how using an alias has any consequence on the version management. I'm not sure either what is the problem you are referring to 🤔

It could be sufficient to add the dependency explicitly along, like this:

  "dependencies": {
    "@codingame/monaco-vscode-api": "~11.1.2",
    "vscode": "npm:@codingame/monaco-vscode-api@~11.1.2",
  }

Won't you end up with @codingame/monaco-vscode-api being duplicated in the node_modules? (in both @codingame/monaco-vscode-api and vscode). Also no idea how it would change anything

@kaisalmen
Copy link
Collaborator Author

@CGNonofr I may have found a way. I need to verify this and explain after lunch. Yes, this was confusing. I hope to clear things up later...

@kaisalmen
Copy link
Collaborator Author

kaisalmen commented Dec 18, 2024

I don't know how using an alias has any consequence on the version management. I'm not sure either what is the problem you are referring to 🤔

@CGNonofr sorry I missed to linkt the issue: TypeFox/monaco-languageclient#789

TIL if you specify a peerDependency and a normal dependency in a package then the peer dependency has no effect in a package that depends on it. So, what I did in monaco-languageclient until today was rubbish.

The proposed solution above ⬆️ does not make sense. But due to the hard wiring of "vscode": "npm:@codingame/monaco-vscode-api@~11.1.2" using overrides, resolutions or single peerDependencies to enforce the base package are ineffective.

What works is to define all @codingame/monaco-vscode packages as peerDependency but mark only some of them to be non-optional, see client package.json, then a downstream project like this that uses such dependencies:

"dependencies": {
  "@codingame/monaco-vscode-extensions-service-override": "^10",
  "monaco-editor-wrapper": "~6.0.0-next.13"
}

now provokes the following error when npm i is used:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: @typefox/[email protected]
npm error Found: @codingame/[email protected]
npm error node_modules/@codingame/monaco-vscode-extensions-service-override
npm error   @codingame/monaco-vscode-extensions-service-override@"^10" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @codingame/monaco-vscode-extensions-service-override@"~11.1.2" from [email protected]
npm error node_modules/monaco-languageclient
npm error   peer monaco-languageclient@"~9.0.0-next.13" from [email protected]
npm error   node_modules/monaco-editor-wrapper
npm error     monaco-editor-wrapper@"~6.0.0-next.13" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

It works, because every possible package is covered that all the monaco-vscode packages depend on.

@kaisalmen
Copy link
Collaborator Author

This approach seems to work with yarn and pnpm as well. I am performing final test with -next.14 build. Closing this issue. We can discuss further in TypeFox/monaco-languageclient#809

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