Skip to content

Commit df5c04e

Browse files
committed
chore: upgrade jsdoc to latest to support node 23+
INSTUI-4574
1 parent 7d2ed73 commit df5c04e

File tree

9 files changed

+311
-143
lines changed

9 files changed

+311
-143
lines changed

package-lock.json

Lines changed: 259 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,8 @@
127127
},
128128
"browserslist": [
129129
"extends @instructure/browserslist-config-instui"
130-
]
130+
],
131+
"dependencies": {
132+
"clipboardy": "^4.0.0"
133+
}
131134
}

packages/__docs__/buildScripts/build-docs.mts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const pathsToProcess = [
6767
'**/src/*/*.{js,ts,tsx}', // component src files
6868
'**/src/*/*/*.{js,ts,tsx}', // child component src files
6969
'CODE_OF_CONDUCT.md',
70-
'LICENSE.md'
70+
'LICENSE.md',
7171
]
7272

7373
const pathsToIgnore = [
@@ -117,7 +117,7 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
117117
buildDocs()
118118
}
119119

120-
function buildDocs() {
120+
async function buildDocs() {
121121
// eslint-disable-next-line no-console
122122
console.log('Start building application data')
123123

@@ -127,17 +127,20 @@ function buildDocs() {
127127
// globby needs the posix format
128128
const files = pathsToProcess.map((file) => path.posix.join(packagesDir, file))
129129
const ignore = pathsToIgnore.map((file) => path.posix.join(packagesDir, file))
130+
130131
globby(files, { ignore })
131-
.then((matches) => {
132+
.then(async (matches) => {
133+
132134
fs.mkdirSync(buildDir + 'docs/', { recursive: true })
133135
// eslint-disable-next-line no-console
134136
console.log(
135137
'Parsing markdown and source files... (' + matches.length + ' files)'
136138
)
137-
const docs = matches.map((relativePath) => {
139+
const docs = await Promise.all(matches.map(async (relativePath) => {
138140
// loop trough every source and Readme file
139-
return processSingleFile(path.resolve(relativePath))
140-
})
141+
return await processSingleFile(path.resolve(relativePath))
142+
}))
143+
141144
const themes = parseThemes()
142145
const clientProps = getClientProps(docs, library)
143146
const props: MainDocsData = {
@@ -146,6 +149,7 @@ function buildDocs() {
146149
library
147150
}
148151
const markdownsAndSources = JSON.stringify(props)
152+
149153
fs.writeFileSync(
150154
buildDir + 'markdown-and-sources-data.json',
151155
markdownsAndSources
@@ -182,12 +186,13 @@ function buildDocs() {
182186
// This function is also called by Webpack if a file changes
183187
// TODO this parses some files twice, its needed for the Webpack watcher but not
184188
// for the full build.
185-
function processSingleFile(fullPath: string) {
189+
async function processSingleFile(fullPath: string) {
190+
186191
let docObject
187192
const dirName = path.dirname(fullPath)
188193
const fileName = path.parse(fullPath).name
189194
if (fileName === 'index') {
190-
docObject = processFile(fullPath, projectRoot, library)
195+
docObject = await processFile(fullPath, projectRoot, library)
191196
// Some Components (e.g. Alert) store their descriptions in README.md files.
192197
// Add this to the final JSON if it's edited
193198
const readmeDesc = tryParseReadme(dirName)
@@ -203,20 +208,23 @@ function processSingleFile(fullPath: string) {
203208
componentIndexFile = path.join(dirName, 'index.ts')
204209
}
205210
if (componentIndexFile) {
206-
docObject = processFile(componentIndexFile, projectRoot, library)
211+
docObject = await processFile(componentIndexFile, projectRoot, library)
207212
const readmeDesc = tryParseReadme(dirName)
208213
docObject.description = readmeDesc ? readmeDesc : docObject.description
209214
} else {
210215
// just a README.md, has no index file
211-
docObject = processFile(fullPath, projectRoot, library)
216+
docObject = await processFile(fullPath, projectRoot, library)
212217
}
213218
} else {
214219
// documentation .md files, utils ts and tsx files
215-
docObject = processFile(fullPath, projectRoot, library)
220+
docObject = await processFile(fullPath, projectRoot, library)
216221
}
222+
217223
const docJSON = JSON.stringify(docObject!)
218224
fs.writeFileSync(buildDir + 'docs/' + docObject!.id + '.json', docJSON)
225+
219226
return docObject!
227+
220228
}
221229

222230
function tryParseReadme(dirName: string) {

packages/__docs__/buildScripts/processFile.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ import { parseDoc } from './utils/parseDoc.mjs'
2828
import { getPathInfo } from './utils/getPathInfo.mjs'
2929
import type { LibraryOptions, ProcessedFile } from './DataTypes.mjs'
3030

31-
export function processFile(
31+
export async function processFile(
3232
fullPath: string,
3333
projectRoot: string,
3434
library: LibraryOptions
35-
): ProcessedFile {
35+
): Promise<ProcessedFile> {
3636
// eslint-disable-next-line no-console
3737
console.info(`Processing ${fullPath}`)
3838
const source = fs.readFileSync(fullPath)
3939
const dirName = path.dirname(fullPath) || process.cwd()
4040
const pathInfo = getPathInfo(fullPath, projectRoot, library)
4141

42-
const doc = parseDoc(fullPath, source, (err: Error) => {
42+
const doc = await parseDoc(fullPath, source, (err: Error) => {
4343
console.warn('Error when parsing ', fullPath, ":\n", err.stack)
4444
})
4545
const docData: ProcessedFile = { ...doc, ...pathInfo } as ProcessedFile

packages/__docs__/buildScripts/utils/getJSDoc.mts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@
2626
import jsdoc from 'jsdoc-api'
2727
import type { JsDocResult } from '../DataTypes.mjs'
2828

29-
export function getJSDoc(source: Buffer, error: (err: Error) => void) {
29+
export async function getJSDoc(source: Buffer, error: (err: Error) => void) {
3030
// note: JSDoc seems to be abandoned, we should use TypeScript:
3131
// https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
3232
let doc: Partial<JsDocResult> = {}
3333
try {
3434
// JSDoc only creates these sections if the file has a @module or @namespace annotation
35-
let sections: JsDocResult[] = jsdoc
36-
.explainSync({
35+
let sections: JsDocResult[] = await jsdoc
36+
.explain({
3737
// note: Do not use cache:true here, its buggy
3838
configure: './jsdoc.config.json',
39-
source
40-
})
41-
sections = sections.filter((section) => {
42-
return (
43-
section.undocumented !== true &&
44-
section.access !== 'private' &&
45-
section.kind !== 'package'
46-
)
39+
source: source.toString()
4740
})
41+
42+
sections = sections.filter((section) => {
43+
return (
44+
section.undocumented !== true &&
45+
section.access !== 'private' &&
46+
section.kind !== 'package'
47+
)
48+
})
4849
const module =
4950
sections.filter((section) => section.kind === 'module')[0] ||
5051
sections[0] ||

packages/__docs__/buildScripts/utils/getReactDoc.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function getReactDoc(
3333
error: (err: Error) => void
3434
) {
3535
let doc: Documentation | undefined = undefined
36+
3637
try {
3738
const parsed = parse(
3839
source,
@@ -42,6 +43,7 @@ export function getReactDoc(
4243
importer: makeFsImporter()
4344
}
4445
)
46+
4547
if (parsed.length > 1) {
4648
// If a file has multiple exports this will choose the one that has the
4749
// same name in its path.

packages/__docs__/buildScripts/utils/parseDoc.mts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,28 @@ import path from 'path'
2929
import type { JsDocResult, YamlMetaInfo } from '../DataTypes.mjs'
3030
import type { Documentation } from 'react-docgen'
3131

32-
export function parseDoc(
32+
export async function parseDoc(
3333
resourcePath: string,
3434
source: Buffer,
3535
errorHandler: (err: Error) => void
36-
): Documentation & YamlMetaInfo & Partial<JsDocResult> {
36+
): Promise<Documentation & YamlMetaInfo & Partial<JsDocResult>> {
3737
const extension = path.extname(resourcePath)
3838
const allowedExtensions = ['.js', '.ts', '.tsx']
3939
let doc: Documentation | undefined
4040

4141
if (extension === '.md') {
42-
doc = { description: source as unknown as string}
42+
doc = { description: source as unknown as string }
4343
} else if (allowedExtensions.includes(extension)) {
44+
4445
doc = getReactDoc(source, resourcePath, errorHandler)
46+
4547
if (!doc || !doc.props) {
46-
doc = getJSDoc(source, errorHandler)
48+
doc = await getJSDoc(source, errorHandler)
4749
}
50+
4851
} else {
4952
errorHandler(new Error('not allowed extension ' + extension))
50-
doc = { description: source as unknown as string}
53+
doc = { description: source as unknown as string }
5154
}
5255
// the YAML description in a JSDoc comment at the top of some files
5356
let frontMatter: YamlMetaInfo

packages/__docs__/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"globby": "^14.0.2",
135135
"gray-matter": "^4.0.3",
136136
"html-webpack-plugin": "^5.6.3",
137-
"jsdoc-api": "^8.1.1",
137+
"jsdoc-api": "^9.3.4",
138138
"mkdirp": "^3.0.1",
139139
"raw-loader": "^4.0.2",
140140
"react-docgen": "^7.1.1",

packages/__docs__/webpack.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ const config = merge(baseConfig, {
5959
directory: outputPath,
6060
},
6161
host: '0.0.0.0',
62-
onListening: function () {
62+
onListening: async function () {
6363
// devServer is watching source files by default and hot reloading the docs page if they are changed
6464
// however markdown files (i.e. README.md) need to be recompiled hence the need for chokidar
6565
const paths = globbySync(['packages/**/*.md', 'docs/**/*.md'], { cwd: '../../' }).map(p => '../../' + p)
6666
chokidar
6767
.watch(paths)
68-
.on('change', (evt) => {
68+
.on('change', async (evt) => {
6969
const fullPath = resolvePath(import.meta.dirname, evt)
70-
processSingleFile(fullPath)
70+
await processSingleFile(fullPath)
7171
})
7272
},
7373
client: {

0 commit comments

Comments
 (0)