Skip to content

Commit

Permalink
Miscellaneous cleaning tasks (#1915)
Browse files Browse the repository at this point in the history
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
  • Loading branch information
wooorm committed Jan 25, 2022
1 parent 4ca2299 commit b79b73a
Show file tree
Hide file tree
Showing 33 changed files with 101 additions and 90 deletions.
4 changes: 1 addition & 3 deletions docs/community/contribute.server.mdx
Expand Up @@ -93,8 +93,6 @@ This produces the website in `public/`.

### Release

{/* To do: update release guidelines */}

To release a new version, do:

1. update `version`s of packages with a patch, minor, or major (make sure to
Expand Down Expand Up @@ -123,7 +121,7 @@ To release a new version, do:
* [Using pull requests](https://help.github.com/articles/about-pull-requests/)
* [GitHub help](https://help.github.com)

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[unit-test]: https://twitter.com/sindresorhus/status/579306280495357953

Expand Down
2 changes: 1 addition & 1 deletion docs/community/support.server.mdx
Expand Up @@ -45,7 +45,7 @@ Here are some tips:
messages in them, please also provide those as text
* The more time you put into asking your question, the better we can help you

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[rubberduck]: https://rubberduckdebugging.com

Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild/package.json
Expand Up @@ -58,7 +58,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"test-api": "uvu test \"\\.js$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild/readme.md
Expand Up @@ -196,7 +196,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/esbuild/license

Expand Down
28 changes: 20 additions & 8 deletions packages/esbuild/test/index.test.js
Expand Up @@ -240,16 +240,28 @@ test('@mdx-js/esbuild', async () => {
* @param {VFile} file
*/
(tree, file) => {
const esm = tree.children[0] // Export
// @ts-expect-error To do: mdast-util-mdx should probably also extend hast?
assert.ok(esm && esm.type === 'mdxjsEsm')
const eol = tree.children[1] // EOL between both, no position.
assert.ok(eol && eol.type === 'text')
assert.ok(!eol.position)
const head = tree.children[2] // Heading
assert.ok(head && head.type === 'element')
assert.ok(head.position)
const text = head.children[0] // Text in heading
assert.ok(text && text.type === 'text')
const jsx = head.children[1] // JSX in heading
// @ts-expect-error To do: mdast-util-mdx should probably also extend hast?
assert.ok(jsx && jsx.type === 'mdxJsxTextElement')
console.log(head)
file.message('1')
file.message('2', tree.children[1]) // EOL between both, no position.
file.message('2', eol)
file.message('3', tree)
file.message('4', tree.children[0]) // Export
// @ts-expect-error: fine.
file.message('5', tree.children[2].children[0]) // Text in heading
// @ts-expect-error: fine.
file.message('6', tree.children[2].children[1]) // Expression in heading
// @ts-expect-error: fine.
file.message('7', tree.children[2].position.end).fatal = true // End of heading
file.message('4', esm)
file.message('5', text) // Text in heading
file.message('6', jsx) // JSX in heading
file.message('7', head.position.end).fatal = true // End of heading
}
]
})
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/package.json
Expand Up @@ -67,7 +67,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage",
"test-api": "uvu test \"\\.js$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/readme.md
Expand Up @@ -183,7 +183,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/loader/license

Expand Down
33 changes: 15 additions & 18 deletions packages/loader/test/index.test.js
Expand Up @@ -29,7 +29,7 @@ test('@mdx-js/loader', async () => {

// React.
await promisify(webpack)({
// @ts-expect-error context does not exist on the webpack options types.
// @ts-expect-error To do: webpack types miss support for `context`.
context: fileURLToPath(base),
entry: './webpack.mdx',
mode: 'none',
Expand All @@ -49,14 +49,13 @@ test('@mdx-js/loader', async () => {
})

// One for ESM loading CJS, one for webpack.
const ContentReact = /** @type {MDXContent} */ (
/* @ts-expect-error file is dynamically generated */
// type-coverage:ignore-next-line
(await import('./react.cjs')).default.default
const modReact = /** @type {{default: {default: MDXContent}}} */ (
// @ts-expect-error file is dynamically generated
await import('./react.cjs')
)

assert.equal(
renderToStaticMarkup(React.createElement(ContentReact)),
renderToStaticMarkup(React.createElement(modReact.default.default)),
'<h1>Hello, World!</h1>',
'should compile (react)'
)
Expand All @@ -65,7 +64,7 @@ test('@mdx-js/loader', async () => {

// Preact and source maps
await promisify(webpack)({
// @ts-expect-error context does not exist on the webpack options types.
// @ts-expect-error To do: webpack types miss support for `context`.
context: fileURLToPath(base),
entry: './webpack.mdx',
mode: 'development',
Expand All @@ -91,14 +90,13 @@ test('@mdx-js/loader', async () => {
})

// One for ESM loading CJS, one for webpack.
const ContentPreact = /** @type {PreactComponent} */ (
/* @ts-expect-error file is dynamically generated */
// type-coverage:ignore-next-line
(await import('./preact.cjs')).default.default
const modPreact = /** @type {{default: {default: PreactComponent}}} */ (
// @ts-expect-error file is dynamically generated.
await import('./preact.cjs')
)

assert.equal(
render(h(ContentPreact, {})),
render(h(modPreact.default.default, {})),
'<h1>Hello, World!</h1>',
'should compile (preact)'
)
Expand All @@ -113,7 +111,7 @@ test('@mdx-js/loader', async () => {

// Vue.
await promisify(webpack)({
// @ts-expect-error context does not exist on the webpack options types.
// @ts-expect-error To do: webpack types miss support for `context`.
context: fileURLToPath(base),
entry: './webpack.mdx',
mode: 'none',
Expand Down Expand Up @@ -143,15 +141,14 @@ test('@mdx-js/loader', async () => {
})

// One for ESM loading CJS, one for webpack.
const ContentVue = /** @type {VueComponent} */ (
/* @ts-expect-error file is dynamically generated */
// type-coverage:ignore-next-line
(await import('./vue.cjs')).default.default
const modVue = /** @type {{default: {default: VueComponent}}} */ (
// @ts-expect-error file is dynamically generated
await import('./vue.cjs')
)

const vueResult = await serverRenderer.renderToString(
vue.createSSRApp({
components: {Content: ContentVue},
components: {Content: modVue.default.default},
template: '<Content />'
})
)
Expand Down
3 changes: 2 additions & 1 deletion packages/mdx/lib/core.js
Expand Up @@ -86,7 +86,8 @@ export function createProcessor(options = {}) {
}
}

// @ts-expect-error allowed in `compile`, but not here.
// @ts-expect-error runtime exception for disallowed field here, which is
// allowed in `compile`.
if (format === 'detect') {
throw new Error(
"Incorrect `format: 'detect'`: `createProcessor` can support either `md` or `mdx`; it does not support detecting the format"
Expand Down
6 changes: 4 additions & 2 deletions packages/mdx/lib/node-types.js
@@ -1,5 +1,7 @@
// List of node types made by `mdast-util-mdx`, which have to be passed
// through untouched from the mdast tree to the hast tree.
/**
* List of node types made by `mdast-util-mdx`, which have to be passed
* through untouched from the mdast tree to the hast tree.
*/
export const nodeTypes = [
'mdxFlowExpression',
'mdxJsxFlowElement',
Expand Down
39 changes: 20 additions & 19 deletions packages/mdx/lib/plugin/recma-stringify.js
Expand Up @@ -28,8 +28,7 @@
* in.
*/

// @ts-expect-error baseGenerator is not yet exported by astring typings
import {baseGenerator, generate} from 'astring'
import {GENERATOR, generate} from 'astring'

/**
* A plugin that adds an esast compiler: a small wrapper around `astring` to add
Expand All @@ -51,24 +50,26 @@ export function recmaStringify(options = {}) {
sourceMap = new SourceMapGenerator({file: file.path || 'unknown.mdx'})
}

const generator = {
...GENERATOR,
JSXAttribute,
JSXClosingElement,
JSXClosingFragment,
JSXElement,
JSXEmptyExpression,
JSXExpressionContainer,
JSXFragment,
JSXIdentifier,
JSXMemberExpression,
JSXNamespacedName,
JSXOpeningElement,
JSXOpeningFragment,
JSXSpreadAttribute,
JSXText
}

const result = generate(tree, {
generator: {
...baseGenerator,
JSXAttribute,
JSXClosingElement,
JSXClosingFragment,
JSXElement,
JSXEmptyExpression,
JSXExpressionContainer,
JSXFragment,
JSXIdentifier,
JSXMemberExpression,
JSXNamespacedName,
JSXOpeningElement,
JSXOpeningFragment,
JSXSpreadAttribute,
JSXText
},
generator,
comments: true,
sourceMap
})
Expand Down
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Expand Up @@ -85,7 +85,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"test-api": "uvu test \"^(compile|evaluate)\\.js$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/mdx/readme.md
Expand Up @@ -1035,7 +1035,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/mdx/license

Expand Down
19 changes: 7 additions & 12 deletions packages/mdx/test/compile.js
Expand Up @@ -160,18 +160,13 @@ test('compile', async () => {
'should support the automatic runtime (`@jsxRuntime`)'
)

// console.log(
// '\nnote: the next deprecation is expected (preact is missing an export map)\n'
// )
//
// To do: re-enable when `preact/compat` has a correct export map.
// assert.equal(
// render(
// h(await run(compileSync('?', {jsxImportSource: 'preact/compat'})), {})
// ),
// '<p>?</p>',
// 'should support an import source (`@jsxImportSource`)'
// )
assert.equal(
render(
h(await run(compileSync('?', {jsxImportSource: 'preact/compat'})), {})
),
'<p>?</p>',
'should support an import source (`@jsxImportSource`)'
)

assert.equal(
render(
Expand Down
5 changes: 3 additions & 2 deletions packages/mdx/test/evaluate.js
Expand Up @@ -179,8 +179,9 @@ test('evaluate', async () => {
'should support an `export class` (1)'
)

// @ts-expect-error TODO figure out how to narrow class type in JSDoc typescript
assert.equal(new mod.A().b, 1, 'should support an `export class` (2)')
const A = /** @type {new () => {b: number}} */ (mod.A)
const a = new A()
assert.equal(a.b, 1, 'should support an `export class` (2)')

mod = await evaluate('export const a = 1\nexport {a as b}\n\n{a}', runtime)

Expand Down
2 changes: 1 addition & 1 deletion packages/node-loader/package.json
Expand Up @@ -50,7 +50,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"test-api": "node --no-warnings --experimental-loader=./test/react-18-node-loader.js ../../node_modules/uvu/bin.js test \"\\.js$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-loader/readme.md
Expand Up @@ -181,7 +181,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/node-loader/license

Expand Down
2 changes: 1 addition & 1 deletion packages/preact/package.json
Expand Up @@ -56,7 +56,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
"test-api": "node --no-warnings --experimental-loader=../../script/jsx-loader.js ../../node_modules/uvu/bin.js test \"\\.jsx?$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/preact/readme.md
Expand Up @@ -212,7 +212,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/preact/license

Expand Down
4 changes: 3 additions & 1 deletion packages/preact/test/test.jsx
Expand Up @@ -131,7 +131,9 @@ test('should support `withComponents`', async () => {
})
const With = withMDXComponents((props) => props.children)

// To do: should this use the `h2` component too?
// Bug: this should use the `h2` component too, logically?
// As `withMDXComponents` is deprecated, and it would probably be a breaking
// change, we can just remove it later.
assert.equal(
render(
<MDXProvider
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Expand Up @@ -58,7 +58,7 @@
"prepack": "npm run build",
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
"test-api": "node --no-warnings --experimental-loader=../../script/jsx-loader.js ../../node_modules/uvu/bin.js test \"\\.jsx?$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run test-coverage"
},
"xo": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/readme.md
Expand Up @@ -212,7 +212,7 @@ abide by its terms.

[support]: https://mdxjs.com/community/support/

[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md

[mit]: https://github.com/mdx-js/mdx/blob/main/packages/react/license

Expand Down
4 changes: 3 additions & 1 deletion packages/react/test/test.jsx
Expand Up @@ -129,7 +129,9 @@ test('should support `withComponents`', async () => {
})
const With = withMDXComponents((props) => props.children)

// To do: should this use the `h2` component too?
// Bug: this should use the `h2` component too, logically?
// As `withMDXComponents` is deprecated, and it would probably be a breaking
// change, we can just remove it later.
assert.equal(
renderToString(
<MDXProvider
Expand Down
2 changes: 1 addition & 1 deletion packages/register/package.json
Expand Up @@ -51,7 +51,7 @@
"#1": "to do when TS supports CJS: `build: rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage`",
"#2": "to do: re-enable when `deasync` is built on Node 17",
"#test-api": "uvu -r index.cjs test \"\\.c?js$\"",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run test-coverage"
},
"xo": false,
Expand Down

1 comment on commit b79b73a

@vercel
Copy link

@vercel vercel bot commented on b79b73a Jan 25, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

Please sign in to comment.