Skip to content

[markdown-it] Move to ES modules#68924

Merged
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
runarberg:master
Apr 5, 2024
Merged

[markdown-it] Move to ES modules#68924
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
runarberg:master

Conversation

@runarberg
Copy link
Copy Markdown
Contributor

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Mar 7, 2024

@runarberg Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

6 packages in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

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

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ A DT maintainer needs to approve changes which affect more than one package

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": 68924,
  "author": "runarberg",
  "headCommitOid": "a0a8f417f48ea59bb0af2cf12d967d646cc74d8b",
  "mergeBaseOid": "5796940dfa7daf1b8a701dbe24df678bd8ab8e81",
  "lastPushDate": "2024-03-07T02:53:11.000Z",
  "lastActivityDate": "2024-04-05T21:22:59.000Z",
  "mergeOfferDate": "2024-04-05T19:54:53.000Z",
  "mergeRequestDate": "2024-04-05T21:22:59.000Z",
  "mergeRequestUser": "runarberg",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "markdown-it-container",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it-container/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it-container/markdown-it-container-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "hronex"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "markdown-it-emoji",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it-emoji/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it-emoji/test/markdown-it-emoji-global.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Shinigami92",
        "peterblazejewicz"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "markdown-it-external-links",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it-external-links/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "grawl"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "markdown-it-link-attributes",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it-link-attributes/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "cowpewter",
        "peterblazejewicz"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "markdown-it-plantuml",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it-plantuml/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "gmunguia"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    },
    {
      "name": "markdown-it",
      "kind": "edit",
      "files": [
        {
          "path": "types/markdown-it/dist/index.cjs.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/dist/markdown-it.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/dist/markdown-it.min.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/index.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/common/entities.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/common/html_blocks.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/common/html_re.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/common/utils.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/common/utils.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/helpers/index.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/helpers/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/helpers/parse_link_destination.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/helpers/parse_link_label.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/helpers/parse_link_title.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/index.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/parser_block.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/parser_core.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/parser_core.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/parser_inline.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/renderer.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/ruler.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/rules_block/state_block.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/rules_core/state_core.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/rules_inline/state_inline.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/lib/token.d.mts",
          "kind": "definition"
        },
        {
          "path": "types/markdown-it/markdown-it-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/package.json",
          "kind": "package-meta-ok"
        },
        {
          "path": "types/markdown-it/test/common/utils.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/helpers/index.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/helpers/index.ts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/index.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/parser_block.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/parser_core.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/parser_core.ts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/parser_inline.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/parser_inline.ts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/renderer.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/ruler.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/rules_block/state_block.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/rules_core/state_core.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/rules_inline/state_inline.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/test/token.mts",
          "kind": "test"
        },
        {
          "path": "types/markdown-it/tsconfig.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "plantain-00",
        "rapropos",
        "duduluu",
        "peterblazejewicz"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-04-05T19:54:06.000Z",
      "isMaintainer": true
    },
    {
      "type": "stale",
      "reviewer": "RyanCavanaugh",
      "date": "2024-04-04T20:28:37.000Z",
      "abbrOid": "34f3509"
    },
    {
      "type": "stale",
      "reviewer": "weswigham",
      "date": "2024-03-11T22:52:35.000Z",
      "abbrOid": "a8abc64"
    }
  ],
  "mainBotCommentID": 1982243797,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Mar 7, 2024

🔔 @Hronex @Shinigami92 @peterblazejewicz @Grawl @cowpewter @gmunguia @plantain-00 @rapropos @duduluu — 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 typescript-bot added the The CI failed When GH Actions fails label Mar 7, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@runarberg
Copy link
Copy Markdown
Contributor Author

This is my first contribution, and I’m not sure if I’m doing things correctly here.

I couldn’t get the tests to pass, unless I duplicated the code for the commonjs modules. Version 14 of Markdown-It builds the dist/ directory, and only exports a single file there. So I’m not sure if you can actually import from /lib (or subdirectories inside /dist) any more using commonjs any longer.

@typescript-bot typescript-bot added Edits multiple packages The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Mar 7, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Mar 7, 2024
@DangerBotOSS
Copy link
Copy Markdown

DangerBotOSS commented Mar 7, 2024

Formatting

The following files are not formatted:

  1. types/markdown-it/test/index.mts
  2. types/markdown-it/lib/index.d.mts
  3. types/markdown-it/lib/parser_inline.d.mts
  4. types/markdown-it/test/helpers/index.mts
  5. types/markdown-it/lib/helpers/index.d.mts
as well as these 1 other files...

types/markdown-it/dist/markdown-it.d.ts

Consider running pnpm dprint fmt on these files to make review easier.

Generated by 🚫 dangerJS against a0a8f41

Copy link
Copy Markdown
Contributor

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

I couldn’t get the tests to pass, unless I duplicated the code for the commonjs modules. Version 14 of Markdown-It builds the dist/ directory, and only exports a single file there. So I’m not sure if you can actually import from /lib (or subdirectories inside /dist) any more using commonjs any longer.

Looks like the package ships a single cjs file in dist, but exclusively esm in lib, and actually does expose both in its exports map (imo, a sloppy and very breaky migration to esm!). You'll want to duplicate that structure here - dist should just have a single markdown-it.d.ts in it, with types reexported in index.cjs.d.ts and markdown-it.min.d.ts. lib also needs all its files renamed to .d.mts to match all the .mjs files now in lib (which you've done). You'll also need to add an export map that roughly matches their published one (which you've also done).

This will break every other package doing a deep import of markdown-it - but so, too, did the source package. If the dependencies actually work with the new markdown-it, they'll have to be updated to use a shallow import or mode-appropriate import, otherwise be fixed to an old version of the markdown-it types.

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Mar 11, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg 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!

@runarberg
Copy link
Copy Markdown
Contributor Author

@weswigham You can still access the exported symbols from the default export, albeit sometimes via a very roundabout way:

const MarkdownIt = require("markdown-it");

// import Token from "markdown-it/lib/token.mjs";
const Token = MarkdownIt().core.State.prototype.Token;

I’m guessing downstream libraries will have to go an equally roundabout way of getting the type symbols:

import MarkdownIt = require("markdown-it");
type Token = InstanceType<MarkdownIt["core"]["State"]>["Token"];

@weswigham
Copy link
Copy Markdown
Contributor

I’m guessing downstream libraries will have to go an equally roundabout way of getting the type symbols

Yes and no - for actual value shapes, yes - if that's where the values are at runtime, that's where they gotta be. For type-only things like interfaces? You can probably get away with exposing them under a namespace merged with the top level call (for cjs), or directly at the top level (for esm). There's a long history of types being more easily accessible than the existing values that use them.

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed Revision needed This PR needs code changes before it can be merged. labels Mar 14, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Apr 4, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Apr 11th (in a week) if the issues aren't addressed.

@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 Abandoned This PR had no activity for a long time, and is considered abandoned The CI failed When GH Actions fails labels Apr 4, 2024
@typescript-bot
Copy link
Copy Markdown
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, @runarberg.

(Ping @Hronex, @Shinigami92, @peterblazejewicz, @Grawl, @cowpewter, @gmunguia, @plantain-00, @rapropos, @duduluu.)

@typescript-bot
Copy link
Copy Markdown
Contributor

@weswigham 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?

@typescript-bot typescript-bot added 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 Apr 4, 2024
@runarberg
Copy link
Copy Markdown
Contributor Author

There is a fair bit of duplicated code here, I’m wondering if it were better to import the typedefs from dist/markdown-it.d.ts to the lib/*.mts files.

I also worry that the tests are separated between the lib/*.mts typedefs and dist/markdown-it.d.ts typedefs. I didn’t really add tests that cover the stuff I moved to the main namespace from the various modules in the commonjs portion.

@jakebailey
Copy link
Copy Markdown
Member

You can totally do that; if it compiles and node16 is enabled, that should work.

@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 Self Merge This PR can now be self-merged by the PR author or an owner Maintainer Approved labels Apr 5, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@RyanCavanaugh, @weswigham 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?

@runarberg
Copy link
Copy Markdown
Contributor Author

@jakebailey I tried to reference the type definitions in dist/markdown-it.d.ts from the lib/*.mts files, but couldn’t cleanly separate the namespace imports from the class/value imports (unsurprising really, I never use namespaces in my own code and don’t really know what I’m doing 😉). So I’m gonna leave the duplicated typedefs as is.

However I amended the PR with the tests copy-pasted from /tests/*.mts files over to the main markdown-it-tests.ts (and discovered an error and a type-o doing so), so I feel a little more confident in the correctness now.

Copy link
Copy Markdown
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.

alright, so long as you are okay with someone potentially accidentally changing one declaration file but not another!

@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 Apr 5, 2024
@typescript-bot
Copy link
Copy Markdown
Contributor

@runarberg: Everything looks good here. I am ready to merge this PR (at a0a8f41) 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! ❤️

@runarberg
Copy link
Copy Markdown
Contributor Author

Ready to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Edits multiple packages Maintainer Approved 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.

7 participants