Skip to content

Commit 8f85b30

Browse files
authored
Refactor tsconfig.json
Closes GH-2250.
1 parent a5728c7 commit 8f85b30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+553
-278
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
"remark-squeeze-paragraphs": "^5.0.0",
9999
"remark-strip-badges": "^6.0.0",
100100
"remark-toc": "^8.0.0",
101-
"rimraf": "^3.0.0",
102101
"rodemirror": "^2.0.0",
103102
"type-coverage": "^2.0.0",
104103
"typescript": "^4.0.0",
@@ -119,7 +118,6 @@
119118
"scripts": {
120119
"postinstall": "patch-package",
121120
"prepare": "husky install",
122-
"clean": "npm exec -c \"rimraf node_modules\" --workspaces",
123121
"docs-prep": "node --unhandled-rejections=strict website/prep.js && postcss docs/_asset/index.css -o public/index.css",
124122
"docs-bundle-dev": "cross-env NODE_ENV=development node --unhandled-rejections=strict website/bundle.js",
125123
"docs-bundle-prod": "cross-env NODE_ENV=production node --unhandled-rejections=strict website/bundle.js",

packages/esbuild/lib/index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
* @typedef {import('esbuild').Message} Message
88
* @typedef {import('vfile').VFileValue} VFileValue
99
* @typedef {import('vfile-message').VFileMessage} VFileMessage
10-
* @typedef {import('unist').Point} Point
1110
* @typedef {import('@mdx-js/mdx/lib/core.js').ProcessorOptions} ProcessorOptions
12-
*
13-
* @typedef {ProcessorOptions & {allowDangerousRemoteMdx?: boolean}} Options
11+
*/
12+
13+
/**
14+
* @typedef {ProcessorOptions & {allowDangerousRemoteMdx?: boolean | null | undefined}} Options
15+
* Configuration.
1416
*/
1517

1618
import assert from 'node:assert'
@@ -32,11 +34,11 @@ const p = process
3234
/**
3335
* Compile MDX w/ esbuild.
3436
*
35-
* @param {Options} [options]
37+
* @param {Options | null | undefined} [options]
3638
* @return {Plugin}
3739
*/
38-
export function esbuild(options = {}) {
39-
const {allowDangerousRemoteMdx, ...rest} = options
40+
export function esbuild(options) {
41+
const {allowDangerousRemoteMdx, ...rest} = options || {}
4042
const name = '@mdx-js/esbuild'
4143
const remoteNamespace = name + '-remote'
4244
const {extnames, process} = createFormatAwareProcessors(rest)
@@ -123,22 +125,24 @@ export function esbuild(options = {}) {
123125
}
124126

125127
/**
126-
* @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: string|Buffer}}} data
128+
* @param {Omit<OnLoadArgs, 'pluginData'> & {pluginData?: {contents?: Buffer | string | null | undefined}}} data
127129
* @returns {Promise<OnLoadResult>}
128130
*/
129131
async function onload(data) {
130132
/** @type {string} */
131133
const doc = String(
132-
data.pluginData && data.pluginData.contents !== undefined
134+
data.pluginData &&
135+
data.pluginData.contents !== null &&
136+
data.pluginData.contents !== undefined
133137
? data.pluginData.contents
134138
: /* eslint-disable-next-line security/detect-non-literal-fs-filename */
135139
await fs.readFile(data.path)
136140
)
137141

138142
let file = new VFile({value: doc, path: data.path})
139-
/** @type {VFileValue|undefined} */
143+
/** @type {VFileValue | undefined} */
140144
let value
141-
/** @type {Array<VFileMessage|Error>} */
145+
/** @type {Array<Error | VFileMessage>} */
142146
let messages = []
143147
/** @type {Array<Message>} */
144148
const errors = []
@@ -150,7 +154,7 @@ export function esbuild(options = {}) {
150154
value = file.value
151155
messages = file.messages
152156
} catch (error_) {
153-
const error = /** @type {VFileMessage|Error} */ (error_)
157+
const error = /** @type {Error | VFileMessage} */ (error_)
154158
if ('fatal' in error) error.fatal = true
155159
messages.push(error)
156160
}
@@ -225,7 +229,7 @@ export function esbuild(options = {}) {
225229
// V8 on Erbium.
226230
/* c8 ignore next 9 */
227231
return {
228-
contents: value,
232+
contents: value || '',
229233
errors,
230234
warnings,
231235
resolveDir: http.test(file.path)

packages/esbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"scripts": {
5858
"prepack": "npm run build",
59-
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
59+
"build": "tsc --build --clean && tsc --build && type-coverage",
6060
"test-api": "uvu test \"\\.js$\"",
6161
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
6262
"test": "npm run build && npm run test-coverage"

packages/esbuild/test/index.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* @typedef {import('esbuild').BuildFailure} BuildFailure
3-
* @typedef {import('esbuild').Message} Message
43
* @typedef {import('hast').Root} Root
54
* @typedef {import('vfile').VFile} VFile
65
* @typedef {import('mdx/types.js').MDXContent} MDXContent
76
*
8-
* @typedef {import('remark-mdx')}
7+
* @typedef {import('remark-mdx')} DoNotTouchIncludeMathInTree
98
*/
109

1110
import {promises as fs} from 'fs'
@@ -251,7 +250,6 @@ test('@mdx-js/esbuild', async () => {
251250
assert.ok(text && text.type === 'text')
252251
const jsx = head.children[1] // JSX in heading
253252
assert.ok(jsx && jsx.type === 'mdxJsxTextElement')
254-
console.log(head)
255253
file.message('1')
256254
file.message('2', eol)
257255
file.message('3', tree)

packages/esbuild/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"extends": "../../tsconfig.json",
3-
"include": ["lib/**/*.js", "test/**/*.js", "index.js"]
3+
"include": ["**/*.cjs", "**/*.js", "**/*.jsx"],
4+
"exclude": ["coverage/", "node_modules/"]
45
}

packages/loader/index.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
/**
2+
* @typedef {import('webpack').LoaderContext<unknown>} LoaderContext
3+
*/
4+
15
'use strict'
26

37
/**
48
* Webpack loader
59
*
610
* @todo once webpack supports ESM loaders, remove this wrapper.
711
*
12+
* @this {LoaderContext}
813
* @param {string} code
914
*/
1015
module.exports = function (code) {

packages/loader/index.d.cts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Some TS versions use this file, some `index.d.ts`.
2+
type LoaderContext = import('webpack').LoaderContext<unknown>
3+
4+
declare function mdxLoader(this: LoaderContext, code: string): void
5+
export = mdxLoader
6+
7+
export type Options = import('@mdx-js/mdx/lib/core.js').ProcessorOptions

packages/loader/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Some TS versions use this file, some `index.d.cts`.
12
import type {ProcessorOptions} from '@mdx-js/mdx/lib/core.js'
23
import type {LoaderContext} from 'webpack'
34

packages/loader/lib/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
/**
2+
* @typedef {import('@mdx-js/mdx').CompileOptions} CompileOptions
23
* @typedef {import('vfile').VFileCompatible} VFileCompatible
34
* @typedef {import('vfile').VFile} VFile
45
* @typedef {import('vfile-message').VFileMessage} VFileMessage
5-
* @typedef {import('@mdx-js/mdx').CompileOptions} CompileOptions
6-
* @typedef {Pick<CompileOptions, 'SourceMapGenerator'>} Defaults
7-
* @typedef {Omit<CompileOptions, 'SourceMapGenerator'>} Options
86
* @typedef {import('webpack').LoaderContext<unknown>} LoaderContext
97
* @typedef {import('webpack').Compiler} WebpackCompiler
10-
* @typedef {(vfileCompatible: VFileCompatible) => Promise<VFile>} Process
8+
*/
9+
10+
/**
11+
* @typedef {Pick<CompileOptions, 'SourceMapGenerator'>} Defaults
12+
* @typedef {Omit<CompileOptions, 'SourceMapGenerator'>} Options
13+
* Configuration.
14+
*
15+
* @callback Process
16+
* Process.
17+
* @param {VFileCompatible} vfileCompatible
18+
* Input.
19+
* @returns {Promise<VFile>}
20+
* File.
1121
*/
1222

1323
import {createHash} from 'node:crypto'
@@ -30,7 +40,7 @@ const cache = new WeakMap()
3040
*
3141
* @this {LoaderContext}
3242
* @param {string} value
33-
* @param {(error: Error|null|undefined, content?: string|Buffer, map?: Object) => void} callback
43+
* @param {LoaderContext['callback']} callback
3444
*/
3545
export function loader(value, callback) {
3646
/** @type {Defaults} */
@@ -69,7 +79,9 @@ export function loader(value, callback) {
6979

7080
process({value, path: this.resourcePath}).then(
7181
(file) => {
72-
callback(null, file.value, file.map || undefined)
82+
// @ts-expect-error: `webpack` is not compiled with `exactOptionalPropertyTypes`,
83+
// so it does not allow `file.map` to be `undefined` here.
84+
callback(null, file.value, file.map)
7385
},
7486
(/** @type VFileMessage */ error) => {
7587
const fpath = path.relative(this.context, this.resourcePath)

0 commit comments

Comments
 (0)