Skip to content

Commit

Permalink
Change to use exports
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 18, 2023
1 parent 23914b6 commit 4223ed9
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 41 deletions.
3 changes: 1 addition & 2 deletions packages/rehype-katex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
Expand Down
5 changes: 0 additions & 5 deletions packages/rehype-mathjax/index.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/rehype-mathjax/lib/create-adapter.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {browserAdaptor as createAdapter} from 'mathjax-full/js/adaptors/browserAdaptor.js'
6 changes: 6 additions & 0 deletions packages/rehype-mathjax/lib/create-adapter.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {JSDOM} from 'jsdom'
import {jsdomAdaptor as jsdomAdapter} from 'mathjax-full/js/adaptors/jsdomAdaptor.js'

export function createAdapter() {
return jsdomAdapter(JSDOM)
}
1 change: 0 additions & 1 deletion packages/rehype-mathjax/lib/create-adaptor.browser.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/rehype-mathjax/lib/create-adaptor.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/rehype-mathjax/lib/create-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js'
import {TeX} from 'mathjax-full/js/input/tex.js'
import {AllPackages} from 'mathjax-full/js/input/tex/AllPackages.js'
import {mathjax} from 'mathjax-full/js/mathjax.js'
import {createAdaptor} from './create-adaptor.js'
import {createAdapter} from '#create-adapter'

const adaptor = createAdaptor()
const adapter = createAdapter()

// To do next major: Keep resultant HTML handler from `register(adaptor)` to
// To do next major: Keep resultant HTML handler from `register(adapter)` to
// allow registering the `AssistiveMmlHandler` as in this demo:
// <https://github.com/mathjax/MathJax-demos-node/tree/master/direct>
//
Expand All @@ -27,7 +27,7 @@ const adaptor = createAdaptor()
// That is to prevent memory leak in `mathjax.handlers` whenever a new instance
// of the plugin is used.
/* eslint-disable-next-line new-cap */
RegisterHTMLHandler(adaptor)
RegisterHTMLHandler(adapter)

/**
* Create a renderer.
Expand Down Expand Up @@ -56,7 +56,7 @@ export function createRenderer(options, output) {
node.children = [hastNode]
},
styleSheet() {
const value = adaptor.textContent(output.styleSheet(doc))
const value = adapter.textContent(output.styleSheet(doc))

return {
type: 'element',
Expand Down
27 changes: 19 additions & 8 deletions packages/rehype-mathjax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": {
".": "./svg.js",
"./browser": "./browser.js",
"./chtml": "./chtml.js",
"./svg": "./svg.js"
},
"imports": {
"#create-adapter": {
"deno": "./lib/create-adapter.default.js",
"react-native": "./lib/create-adapter.default.js",
"worker": "./lib/create-adapter.default.js",
"browser": "./lib/create-adapter.browser.js",
"default": "./lib/create-adapter.default.js"
}
},
"files": [
"lib/",
"browser.d.ts",
"browser.js",
"chtml.d.ts",
"chtml.js",
"index.d.ts",
"index.js",
"svg.d.ts",
"svg.js"
],
"browser": {
"./lib/create-adaptor.js": "./lib/create-adaptor.browser.js"
},
"dependencies": {
"@types/hast": "^3.0.0",
"@types/mathjax": "^0.0.37",
Expand All @@ -65,6 +73,9 @@
"test": "npm run build && npm run test-api"
},
"xo": {
"prettier": true
"prettier": true,
"rules": {
"n/file-extension-in-import": "off"
}
}
}
23 changes: 11 additions & 12 deletions packages/rehype-mathjax/test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import test from 'node:test'
import rehypeMathJaxBrowser from 'rehype-mathjax/browser.js'
import rehypeMathJaxChtml from 'rehype-mathjax/chtml.js'
import rehypeMathJaxSvg from 'rehype-mathjax/svg.js'
import rehypeMathJaxBrowser from 'rehype-mathjax/browser'
import rehypeMathJaxChtml from 'rehype-mathjax/chtml'
import rehypeMathJaxSvg from 'rehype-mathjax/svg'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import remarkMath from 'remark-math'
Expand All @@ -24,32 +24,31 @@ test('rehype-mathjax', async function (t) {
)

await t.test(
'should expose the public api for `rehype-mathjax/browser.js`',
'should expose the public api for `rehype-mathjax/browser`',
async function () {
assert.deepEqual(
Object.keys(await import('rehype-mathjax/browser.js')).sort(),
Object.keys(await import('rehype-mathjax/browser')).sort(),
['default']
)
}
)

await t.test(
'should expose the public api for `rehype-mathjax/chtml.js`',
'should expose the public api for `rehype-mathjax/chtml`',
async function () {
assert.deepEqual(
Object.keys(await import('rehype-mathjax/chtml.js')).sort(),
Object.keys(await import('rehype-mathjax/chtml')).sort(),
['default']
)
}
)

await t.test(
'should expose the public api for `rehype-mathjax/svg.js`',
'should expose the public api for `rehype-mathjax/svg`',
async function () {
assert.deepEqual(
Object.keys(await import('rehype-mathjax/svg.js')).sort(),
['default']
)
assert.deepEqual(Object.keys(await import('rehype-mathjax/svg')).sort(), [
'default'
])
}
)

Expand Down
4 changes: 2 additions & 2 deletions packages/remark-math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
Expand Down

0 comments on commit 4223ed9

Please sign in to comment.