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

feat: support punycode js file imports #68273

Merged

Conversation

hrueger
Copy link
Contributor

@hrueger hrueger commented Jan 21, 2024

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the package.json.
  • Other: punycode is also a builtin node module. To explicitely load the npm package instead, people have been adding a / suffix to the import. However, this breaks some bundlers and esm (example), which means the import needs to be punycode/punycode.js (example). Currently, typescript complains about that, but this PR fixes that.

@typescript-bot
Copy link
Contributor

typescript-bot commented Jan 21, 2024

@hrueger Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 68273,
  "author": "hrueger",
  "headCommitOid": "26cfd1d5d06beaef2e59c45212e43c545ce69a2b",
  "mergeBaseOid": "c7c3b75eeed5fd5edc16914acb1e011769f9a643",
  "lastPushDate": "2024-01-21T20:13:11.000Z",
  "lastActivityDate": "2024-02-12T17:20:18.000Z",
  "mergeOfferDate": "2024-02-12T17:19:17.000Z",
  "mergeRequestDate": "2024-02-12T17:20:18.000Z",
  "mergeRequestUser": "hrueger",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Popular",
  "pkgInfo": [
    {
      "name": "punycode",
      "kind": "edit",
      "files": [
        {
          "path": "types/punycode/punycode-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/punycode/punycode.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/punycode/tsconfig.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "yavanosta"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Popular"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-02-12T17:18:34.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 1902748520,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added the Popular package This PR affects a popular package (as counted by NPM download counts). label Jan 21, 2024
@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Jan 21, 2024
@typescript-bot
Copy link
Contributor

🔔 @Yavanosta — 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.

@typescript-bot
Copy link
Contributor

Re-ping @Yavanosta:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Feb 2, 2024
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Action in New Pull Request Status Board Feb 9, 2024
@typescript-bot
Copy link
Contributor

It has been more than two weeks and this PR still has no reviews.

I'll bump it to the DT maintainer queue. Thank you for your patience, @hrueger.

(Ping @Yavanosta.)

Copy link
Member

Choose a reason for hiding this comment

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

This should just be punycode.d.ts, because d.ts files type .js files. But, it's not clear to me why this is needed.

Copy link
Member

Choose a reason for hiding this comment

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

I see now that this shadows a node module, so that makes slightly more sense. Probably this should be export = require("punycode") to match module shape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jakebailey,
thanks for reviewing.

When I rename the file from punycode.js.d.ts to punycode.d.ts, I get the following error message in the test: Could not find a declaration file for module 'punycode/punycode.js'. :
grafik

If I use export = require("punycode"), I get this:
grafik

I added the reason for this change in the pr description at the bottom, maybe it was not clear enough:
As you said, punycode is also a builtin node module. To explicitely load the npm package instead, people have been adding a / suffix to the import. However, this breaks some bundlers and esm (salesforce/tough-cookie#256), which means the import needs to be punycode/punycode.js (example). Currently, typescript complains about that, but this PR fixes that.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have the same problem with this diff:

diff --git a/types/punycode/punycode.d.ts b/types/punycode/punycode.d.ts
new file mode 100644
index 0000000000..fd4ea774ee
--- /dev/null
+++ b/types/punycode/punycode.d.ts
@@ -0,0 +1,2 @@
+import punycode = require(".");
+export = punycode;
diff --git a/types/punycode/punycode.js.d.ts b/types/punycode/punycode.js.d.ts
deleted file mode 100644
index ef8f0464f7..0000000000
--- a/types/punycode/punycode.js.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "punycode";
diff --git a/types/punycode/tsconfig.json b/types/punycode/tsconfig.json
index 5a7dfe15b2..674baae5b8 100644
--- a/types/punycode/tsconfig.json
+++ b/types/punycode/tsconfig.json
@@ -14,7 +14,7 @@
     },
     "files": [
         "index.d.ts",
-        "punycode.js.d.ts",
+        "punycode.d.ts",
         "punycode-tests.ts"
     ]
 }

I made a mistake on export = require("punycode"); sorry about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification @jakebailey . Could you please take another look?

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Feb 9, 2024
@typescript-bot typescript-bot moved this from Needs Maintainer Action to Needs Author Action in New Pull Request Status Board Feb 9, 2024
@typescript-bot
Copy link
Contributor

@hrueger 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. Thank you!

@typescript-bot typescript-bot added Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. and removed Revision needed This PR needs code changes before it can be merged. labels Feb 12, 2024
@typescript-bot typescript-bot moved this from Needs Author Action to Needs Maintainer Action in New Pull Request Status Board Feb 12, 2024
@typescript-bot
Copy link
Contributor

@jakebailey Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

LGTM, but I think in the future we're going to attempt to make index.d.ts not a required file for DT packages such that this code could just be stored in punycode.d.ts only and be more accurate.

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Feb 12, 2024
@typescript-bot typescript-bot moved this from Needs Maintainer Action to Waiting for Author to Merge in New Pull Request Status Board Feb 12, 2024
@typescript-bot
Copy link
Contributor

@hrueger: Everything looks good here. I am ready to merge this PR (at 26cfd1d) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@Yavanosta: you can do this too.)

@hrueger
Copy link
Contributor Author

hrueger commented Feb 12, 2024

Thanks @jakebailey !

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Feb 12, 2024
@typescript-bot typescript-bot merged commit 0c791fe into DefinitelyTyped:master Feb 12, 2024
4 checks passed
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintainer Approved Popular package This PR affects a popular package (as counted by NPM download counts). Self Merge This PR can now be self-merged by the PR author or an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants