From b79b73a8801ba9c0cfad8a0f2b63ac49fd33ed3d Mon Sep 17 00:00:00 2001 From: Titus Date: Tue, 25 Jan 2022 16:03:30 +0100 Subject: [PATCH] Miscellaneous cleaning tasks (#1915) Reviewed-by: Christian Murphy --- docs/community/contribute.server.mdx | 4 +-- docs/community/support.server.mdx | 2 +- packages/esbuild/package.json | 2 +- packages/esbuild/readme.md | 2 +- packages/esbuild/test/index.test.js | 28 +++++++++++----- packages/loader/package.json | 2 +- packages/loader/readme.md | 2 +- packages/loader/test/index.test.js | 33 +++++++++--------- packages/mdx/lib/core.js | 3 +- packages/mdx/lib/node-types.js | 6 ++-- packages/mdx/lib/plugin/recma-stringify.js | 39 +++++++++++----------- packages/mdx/package.json | 2 +- packages/mdx/readme.md | 2 +- packages/mdx/test/compile.js | 19 ++++------- packages/mdx/test/evaluate.js | 5 +-- packages/node-loader/package.json | 2 +- packages/node-loader/readme.md | 2 +- packages/preact/package.json | 2 +- packages/preact/readme.md | 2 +- packages/preact/test/test.jsx | 4 ++- packages/react/package.json | 2 +- packages/react/readme.md | 2 +- packages/react/test/test.jsx | 4 ++- packages/register/package.json | 2 +- packages/register/readme.md | 2 +- packages/remark-mdx/package.json | 2 +- packages/remark-mdx/readme.md | 2 +- packages/rollup/package.json | 2 +- packages/rollup/readme.md | 2 +- packages/vue/package.json | 2 +- packages/vue/readme.md | 2 +- readme.md | 2 +- website/generate.server.js | 2 +- 33 files changed, 101 insertions(+), 90 deletions(-) diff --git a/docs/community/contribute.server.mdx b/docs/community/contribute.server.mdx index 84eaa883e..999648276 100644 --- a/docs/community/contribute.server.mdx +++ b/docs/community/contribute.server.mdx @@ -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 @@ -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 diff --git a/docs/community/support.server.mdx b/docs/community/support.server.mdx index 35af8f4e1..bb4f764dc 100644 --- a/docs/community/support.server.mdx +++ b/docs/community/support.server.mdx @@ -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 diff --git a/packages/esbuild/package.json b/packages/esbuild/package.json index 37295da67..22c3456a1 100644 --- a/packages/esbuild/package.json +++ b/packages/esbuild/package.json @@ -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, diff --git a/packages/esbuild/readme.md b/packages/esbuild/readme.md index b4583cee2..b12733209 100644 --- a/packages/esbuild/readme.md +++ b/packages/esbuild/readme.md @@ -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 diff --git a/packages/esbuild/test/index.test.js b/packages/esbuild/test/index.test.js index 2d4eb60c7..4a52e343a 100644 --- a/packages/esbuild/test/index.test.js +++ b/packages/esbuild/test/index.test.js @@ -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 } ] }) diff --git a/packages/loader/package.json b/packages/loader/package.json index 2814d9da0..22962ebc4 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -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, diff --git a/packages/loader/readme.md b/packages/loader/readme.md index 63b0b10b0..d605fafd5 100644 --- a/packages/loader/readme.md +++ b/packages/loader/readme.md @@ -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 diff --git a/packages/loader/test/index.test.js b/packages/loader/test/index.test.js index a912a7d23..a5adf06c6 100644 --- a/packages/loader/test/index.test.js +++ b/packages/loader/test/index.test.js @@ -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', @@ -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)), '

Hello, World!

', 'should compile (react)' ) @@ -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', @@ -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, {})), '

Hello, World!

', 'should compile (preact)' ) @@ -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', @@ -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: '' }) ) diff --git a/packages/mdx/lib/core.js b/packages/mdx/lib/core.js index 350b324d7..ef5bf55f3 100644 --- a/packages/mdx/lib/core.js +++ b/packages/mdx/lib/core.js @@ -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" diff --git a/packages/mdx/lib/node-types.js b/packages/mdx/lib/node-types.js index ee486738e..59bd74549 100644 --- a/packages/mdx/lib/node-types.js +++ b/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', diff --git a/packages/mdx/lib/plugin/recma-stringify.js b/packages/mdx/lib/plugin/recma-stringify.js index 70c8c128d..57424f321 100644 --- a/packages/mdx/lib/plugin/recma-stringify.js +++ b/packages/mdx/lib/plugin/recma-stringify.js @@ -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 @@ -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 }) diff --git a/packages/mdx/package.json b/packages/mdx/package.json index 1dc258574..030cdb5f7 100644 --- a/packages/mdx/package.json +++ b/packages/mdx/package.json @@ -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, diff --git a/packages/mdx/readme.md b/packages/mdx/readme.md index 75cbd78b7..976563d8c 100644 --- a/packages/mdx/readme.md +++ b/packages/mdx/readme.md @@ -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 diff --git a/packages/mdx/test/compile.js b/packages/mdx/test/compile.js index 51307f605..a6f5c7e26 100644 --- a/packages/mdx/test/compile.js +++ b/packages/mdx/test/compile.js @@ -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'})), {}) - // ), - // '

?

', - // 'should support an import source (`@jsxImportSource`)' - // ) + assert.equal( + render( + h(await run(compileSync('?', {jsxImportSource: 'preact/compat'})), {}) + ), + '

?

', + 'should support an import source (`@jsxImportSource`)' + ) assert.equal( render( diff --git a/packages/mdx/test/evaluate.js b/packages/mdx/test/evaluate.js index 9eb2c2429..7b03afe02 100644 --- a/packages/mdx/test/evaluate.js +++ b/packages/mdx/test/evaluate.js @@ -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) diff --git a/packages/node-loader/package.json b/packages/node-loader/package.json index ead25d0ae..96138f485 100644 --- a/packages/node-loader/package.json +++ b/packages/node-loader/package.json @@ -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, diff --git a/packages/node-loader/readme.md b/packages/node-loader/readme.md index b268b3ce9..c1f75bee9 100644 --- a/packages/node-loader/readme.md +++ b/packages/node-loader/readme.md @@ -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 diff --git a/packages/preact/package.json b/packages/preact/package.json index b74424ba7..433b7154b 100644 --- a/packages/preact/package.json +++ b/packages/preact/package.json @@ -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, diff --git a/packages/preact/readme.md b/packages/preact/readme.md index d0fc57e92..2ebf9fd13 100644 --- a/packages/preact/readme.md +++ b/packages/preact/readme.md @@ -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 diff --git a/packages/preact/test/test.jsx b/packages/preact/test/test.jsx index 550661ae8..66dd10a83 100644 --- a/packages/preact/test/test.jsx +++ b/packages/preact/test/test.jsx @@ -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( { }) 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(