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

Add module field to package.json #2143

Merged
merged 1 commit into from
Aug 4, 2021
Merged

Conversation

benmccann
Copy link
Contributor

@benmccann benmccann commented Jul 23, 2021

Marked version: master

Markdown flavor: n/a

Description

Allows marked to be used with SvelteKit / Vite without the currently required workaround (#2021 (comment))

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Jul 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/markedjs/markedjs/2zVNDAbAcU12RbGZxtEhmVSHwvCE
✅ Preview: https://markedjs-git-fork-benmccann-module-markedjs.vercel.app

@UziTech
Copy link
Member

UziTech commented Aug 2, 2021

It looks like the module field was remove previously because of an issue with webpack and the "module" field. see #1571 (comment)

@benmccann
Copy link
Contributor Author

Yeah, default exports should be avoided because they're not compatible between CJS and ESM. Luckily there are named exports available, so people don't have to use the default export if they run into that. And since this is going into a major version it's a good time to do breaking changes

@UziTech
Copy link
Member

UziTech commented Aug 2, 2021

using a named export is something I would like to change to in the future along with having marked create instances instead of being one global object. Maybe that will be a v4 fix.

@benmccann
Copy link
Contributor Author

This PR shouldn't be an issue in the meantime. It may mean that different users have to import marked slightly differently if they want to use the default export depending on whether they're building for the browser or server, but at least they can import directly from marked instead of ./lib/marked.esm.js if they want to use ESM

@UziTech
Copy link
Member

UziTech commented Aug 3, 2021

This PR is an issue for anyone using webpack according to #1571 (comment)

@benmccann
Copy link
Contributor Author

There's a big difference in this PR vs the last time module was attempted to be added, which is that package.json now contains a browser field. Webpack, by default, will find the browser field first, which is the same as main and so shouldn't cause any issues for people using Webpack as a result.

Even if someone asked Webpack to use the module field for marked, it wouldn't stop people from using Webpack. It just wouldn't be backwards compatible with using the main field. But that shouldn't matter since the browser field will be chosen

The other solution to this would be to use the exports field in package.json

@UziTech
Copy link
Member

UziTech commented Aug 3, 2021

Webpack, by default, will find the browser field first, which is the same as main and so shouldn't cause any issues for people using Webpack as a result.

OK i'm convinced.

The other solution to this would be to use the exports field in package.json

There actually is a PR to add the exports field #1725 that looks abandoned. If you wanted to create a PR for that we could get that in as well.

@benmccann
Copy link
Contributor Author

There actually is a PR to add the exports field #1725 that looks abandoned. If you wanted to create a PR for that we could get that in as well.

That PR generally looks good to me. I just left some comments on it. It was adding build output in lib/marked.esm.mjs and I wasn't sure if it should be?

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

I'm not a huge fan of module since its not standardized, but it seems more tools are relying on it so we can try it out with 3.0 since its semver major

@UziTech UziTech merged commit edc2e6d into markedjs:master Aug 4, 2021
github-actions bot pushed a commit that referenced this pull request Aug 16, 2021
# [3.0.0](v2.1.3...v3.0.0) (2021-08-16)

### Bug Fixes

* Add module field to package.json ([#2143](#2143)) ([edc2e6d](edc2e6d))
* drop node 10 support ([#2157](#2157)) ([433b16f](433b16f))
* Full Commonmark compliance for Lists ([#2112](#2112)) ([eb33d3b](eb33d3b))
* Refactor table tokens ([#2166](#2166)) ([bc400ac](bc400ac))

### BREAKING CHANGES

* - `table` tokens `header` property changed to contain an array of objects for each header cell with `text` and `tokens` properties.
- `table` tokens `cells` property changed to `rows` and is an array of rows where each row contains an array of objects for each cell with `text` and `tokens` properties.

v2:

```json
{
  "type": "table",
  "align": [null, null],
  "raw": "| a | b |\n|---|---|\n| 1 | 2 |\n",
  "header": ["a", "b"],
  "cells": [["1", "2"]],
  "tokens": {
    "header": [
      [{ "type": "text", "raw": "a", "text": "a" }],
      [{ "type": "text", "raw": "b", "text": "b" }]
    ],
    "cells": [[
      [{ "type": "text", "raw": "1", "text": "1" }],
      [{ "type": "text", "raw": "2", "text": "2" }]
    ]]
  }
}
```

v3:

```json
{
  "type": "table",
  "align": [null, null],
  "raw": "| a | b |\n|---|---|\n| 1 | 2 |\n",
  "header": [
    {
      "text": "a",
      "tokens": [{ "type": "text", "raw": "a", "text": "a" }]
    },
    {
      "text": "b",
      "tokens": [{ "type": "text", "raw": "b", "text": "b" }]
    }
  ],
  "rows": [
    {
      "text": "1",
      "tokens": [{ "type": "text", "raw": "1", "text": "1" }]
    },
    {
      "text": "2",
      "tokens": [{ "type": "text", "raw": "2", "text": "2" }]
    }
  ]
}
```
* Add module field to package.json
* drop node 10 support
@github-actions
Copy link

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@benmccann benmccann deleted the module branch August 16, 2021 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add module field to package.json
3 participants