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

Prevent @types/node and @types/requirejs-confusion #35946

Closed
wants to merge 6 commits into from

Conversation

manuth
Copy link
Contributor

@manuth manuth commented Jun 4, 2019

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:

About this PR

According to the documentation, @types/requirejs can be invoked through require() and requirejs().
As require() is declared by @types/node, too, which is part of most projects.

For that reason I decided to make @types/requirejs exporting requirejs() rather than require().

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics.

Let’s review the numbers, shall we?

These typings are for a package that doesn’t yet exist on master, so I don’t have anything to compare against yet! In the future, I’ll be able to compare PRs to requirejs with its source on master.

**Comparison details** 📊
Batch compilation
Type count 8964
Assignability cache size 32520
Subtype cache size 3
Identity cache size 3
Language service measurements
Samples taken 140
Identifiers in tests 28
getCompletionsAtPosition
    Mean duration (ms) 315.8
    Median duration (ms) 308.3
    Std. deviation (ms) 49.8
    Worst duration (ms) 365.3
    Worst identifier recOne
getQuickInfoAtPosition
    Mean duration (ms) 312.8
    Median duration (ms) 299.5
    Std. deviation (ms) 50.4
    Worst duration (ms) 373.1
    Worst identifier config
System information
Node version v10.15.3
CPU count 2
CPU speed 2.294 GHz
CPU model Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz
CPU Architecture x64
Memory 6.8 GiB
Platform linux
Release 4.15.0-1045-azure

If you have any questions or comments about me, you can ping @andrewbranch. Have a nice day!

@typescript-bot typescript-bot added this to Waiting for Reviewers in Pull Request Status Board Jun 4, 2019
@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Jun 4, 2019
@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 4, 2019

@manuth Thank you for submitting this PR!

🔔 @jbaldwin - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot typescript-bot removed the Popular package This PR affects a popular package (as counted by NPM download counts). label Jun 9, 2019
@typescript-bot typescript-bot moved this from Waiting for Reviewers to Review in Pull Request Status Board Jun 9, 2019
@typescript-bot typescript-bot added the Unmerged The author did not merge the PR when it was ready. label Jun 9, 2019
@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 9, 2019

We've gotten sign-off from a reviewer 👏. A maintainer will soon review this PR and merge it if there are no issues. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for contributing to DefinitelyTyped!

@RyanCavanaugh
Copy link
Member

This seems extremely dangerous in terms of breaking existing code and JS users. I would need to see data in terms of what % of extant code uses require vs requirejs to be OK publishing this.

@manuth
Copy link
Contributor Author

manuth commented Jul 1, 2019

Oh - I thought this should not damage any code as I increased the major version-number.

@manuth
Copy link
Contributor Author

manuth commented Jul 2, 2019

@RyanCavanaugh is this a wrong assumption?
Is there anything else I need to do in order to increase the major version-number but changing the file-header of index.d.ts?

@manuth
Copy link
Contributor Author

manuth commented Jul 7, 2019

So I just checked the guide of DefinitelyTyped and it says that there is nothing to do but increasing the version-number in the first line of the index.d.ts-file:
https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library

I updated the major version which means that no package will be affected.
Is there anything more I have to do?

@typescript-bot typescript-bot added the Popular package This PR affects a popular package (as counted by NPM download counts). label Jul 12, 2019
@Eagle94T
Copy link

@RyanCavanaugh what's the status for this PR?
With updating the major version, this shouldn't affect any existing projects.

@Eagle94T
Copy link

I'm sorry to ask again, but why is this PR still not merged?
I need this change, since I'm using aurelia-bundler (uses @types/node) and @types/select2 (uses @types/requirejs)

@andrewbranch
Copy link
Member

Oh - I thought this should not damage any code as I increased the major version-number.

...is this a wrong assumption?

Yes—the version number is supposed to represent the version of the JavaScript library on npm. The latest release of RequireJS is 2.3.6. In fact, @sandersn just added a CI rule to prevent type definitions from referencing non-existent versions of their JS counterparts.

Echoing Ryan, I think we would want to see some data here. I think my hunch is that lots of RequireJS users probably use require() (and want to keep it that way), in which case this change is probably a non-starter, although well-intentioned. If you can prove me wrong, then we can proceed. 👍

@typescript-bot typescript-bot moved this from Review to Other in Pull Request Status Board Jul 17, 2019
@typescript-bot typescript-bot added Other Approved This PR was reviewed and signed-off by a community member. Merge:LGTM and removed Unmerged The author did not merge the PR when it was ready. labels Jul 17, 2019
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

It appears that @typescript-bot might have interpreted my trailing “👍” in that last comment as an approval? I’m requesting changes just so it’s clear the status is not mergeable without further research/discussion.

@typescript-bot typescript-bot moved this from Other to Needs Author Attention in Pull Request Status Board Jul 18, 2019
@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Other Approved This PR was reviewed and signed-off by a community member. Awaiting reviewer feedback labels Jul 18, 2019
@typescript-bot
Copy link
Contributor

@manuth One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

@manuth
Copy link
Contributor Author

manuth commented Jul 18, 2019

Honestly I don't think "people may want to keep using require()" is a pretty bad argument.
By now you cannot write typescript-modules which have both @types/requirejs and @types/node in their dependency-tree which often might be the case as some types in DefinitelyTyped use either parts of @types/requirejs or @types/node.

To me its a bad idea to prevent people from writing typescript-code just because "people want to use require().

@sandersn
Copy link
Contributor

Here's a workaround: provide a node-specific version of the package which basically implements this change, but copy it into a subdirectory named node. Then people who have the conflict can add the following path mapping to their tsconfig:

        "baseUrl": ".",
        "paths": {
            "requirejs": ["node_modules/@types/requirejs/node/index.d.ts"]
        }

It should be possible to share the types between the main file and the node file, so that they only differ in the last few lines -- the main file would have 3 globals and the node file would have a single export =.

@andrewbranch
Copy link
Member

andrewbranch commented Jul 18, 2019

@sandersn I tried this locally, but node_modules/@types/requirejs/index.d.ts (with its ambient declarations) still get pulled into the program. I think you’d have to combine this approach with specifying typeRoots or types in your tsconfig, which could be pretty frustrating if you have tons of @types packages and you just need to prevent one file in them from being included. (Related: microsoft/TypeScript#18588)

@typescript-bot
Copy link
Contributor

@manuth I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Jul 24, 2019
@typescript-bot
Copy link
Contributor

@manuth To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you!

Pull Request Status Board automation moved this from Needs Author Attention to Done Jul 24, 2019
@manuth
Copy link
Contributor Author

manuth commented Jul 25, 2019

@RyanCavanaugh. @andrewbranch I'd be glad if you guys could discuss this further so I can open a new PR for resolving the node/requirejs-intersection.

@sandersn
Copy link
Contributor

@andrewbranch I was wrong about my fix, the errors you saw got lost in a bunch of others. I'm out of ideas on this one.

@manuth
Copy link
Contributor Author

manuth commented Jul 25, 2019

Should I wait for you guys to work out a solution or should I rather open a new PR?

@andrewbranch
Copy link
Member

My only idea is to publish a separate package, e.g. @types/requirejs-node.

LeSuisse pushed a commit to Enalean/tuleap that referenced this pull request Apr 3, 2020
Part of request #14752 Unify scripts and themes build for Core

Everything is supposed to work as before.

Notes:
Once again select2 has given me hell!
I had to remove @types/select2 from TLP and fork it due to a types
conflict between @types/node and @types/requirejs. The latter is a
dependency of @types/select2, although we never use it in production
code. I could not figure out how to exclude @types/requirejs, so the
only solution left was to fork @types/select2 and remove manually the
dependencies to @types/requirejs.
The situation is unlikely to be resolved, see a related PR at [0]

[0]: DefinitelyTyped/DefinitelyTyped#35946

Change-Id: I81b599c0094c13379fbebbe1abfb0d854044436f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abandoned This PR had no activity for a long time, and is considered abandoned Popular package This PR affects a popular package (as counted by NPM download counts). Revision needed This PR needs code changes before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants