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

Resolve transitive dependencies based on package.json #3286

Open
wants to merge 6 commits into
base: v2
Choose a base branch
from

Conversation

seanoch
Copy link

@seanoch seanoch commented Dec 16, 2024

When the newly added resolveDependenciesFromPackageJson flag is set to true, ATA will resolve the versions of any transitive dependency according to the package.json file of the same module (unless any // types: comment is specified).

Resolve transitive dependencies' versions based on package.json
@seanoch
Copy link
Author

seanoch commented Dec 16, 2024

@microsoft-github-policy-service agree company="wix"

@seanoch seanoch changed the title Support transitive dependencies Resolve transitive dependencies based on pacakge.json Dec 16, 2024
Copy link

@tomenden tomenden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See small comments regarding naming.
I suggest adding a bit more context in the PR description to explain the motivation. I think an example will help the typescript team understand what you did here

Comment on lines 146 to 149
let typesPackageJson
if (config.usePackageJson){
typesPackageJson = moduleMap.get(dts.moduleName)?.typesPackageJson
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let typesPackageJson
if (config.usePackageJson){
typesPackageJson = moduleMap.get(dts.moduleName)?.typesPackageJson
}
const typesPackageJson = config.usePackageJson && moduleMap.get(dts.moduleName)?.typesPackageJson

@jakebailey
Copy link
Member

To be clear, is the intent here to ensure that all dependencies are loaded transitively?

Should this flag be set for the website? Should it be disabled at all?

@seanoch
Copy link
Author

seanoch commented Dec 17, 2024

@jakebailey The intent is to allow resolution of transitive (indirect) dependencies according to their module's package.json file. Before this change, any indirect dependency gets resolved to latest, since the only way to control versioning is via the // types: comment, which is controllable only in the first input file.

For example, if the input file says import a from 'PackageA', and some of PackageA's types imports from PackageB -

  • Before this change, any d.ts from PackageB will be resolved to PackageB@latest
  • After this change, any d.ts from PackageB will be resolved to the version of PackageB that is specified in PackageA's package.json.

@jakebailey jakebailey changed the title Resolve transitive dependencies based on pacakge.json Resolve transitive dependencies based on package.json Dec 17, 2024
@seanoch
Copy link
Author

seanoch commented Dec 23, 2024

@jakebailey Hi, is any additional explanation needed before a review?

@seanoch
Copy link
Author

seanoch commented Jan 23, 2025

@jakebailey Hi again, any updates here? Let me know if any additional explanation is needed :)

@jakebailey
Copy link
Member

The main thing I would like to see is this flag be enabled for ATA on the playground, then be tested there (which I can deploy from this PR).

@seanoch
Copy link
Author

seanoch commented Jan 26, 2025

@jakebailey Hi Jake, I enabled the flag on the playground. For better clarification, this is the new functionality:

  1. user added import from 'sean-test-2'
  2. 'sean-test-2' has a dependency on '[email protected]'
  3. ATA used to fetch 'sean-test-1@latest'. Now it fetches '[email protected]'

As for tests - I didn't find any ATA related tests under the playground package, can you guide me to where you want to add tests?
Screenshot 2025-01-26 at 10 53 52
Screenshot 2025-01-26 at 10 54 20

@jakebailey jakebailey added the deploy-preview Enables automatic deployments to preview environments on a PR label Jan 26, 2025
@jakebailey
Copy link
Member

There aren't any tests, really, not that I'm aware of.

@jakebailey
Copy link
Member

TBH I feel like the website would be better served by https://www.npmjs.com/package/@vscode/ts-package-manager / https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/filesystems/autoInstallerFs.ts which actually uses a package manager to do resolution and place files into the VFS, but that's a larger undertaking. I'd just worry that this PR is potentially wrong for things like version constraints (not that the current code is particularly great on that front either).

If you weren't trying to plug this into the playground originally, why were you updating the ATA package? Where are you using it?

Copy link
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-plant-05c166c10-3286.centralus.5.azurestaticapps.net

@seanoch
Copy link
Author

seanoch commented Jan 26, 2025

We aim to use ATA in our monaco-based code editor. I'm aware of the fact that the solution is far from perfect but it's more accurate then the existing resolution to latest versions of transitive dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy-preview Enables automatic deployments to preview environments on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants