Skip to content

Commit fafcd21

Browse files
committed
Bump to v1.0.5, strict type checks, generate types
Though a lot of changes, each one is relatively small, they're all thematically related, and all tests still pass. Note a lot of these descriptions also come from mbland/test-page-opener#23 or commit mbland/test-page-opener@01a79f6. - Added `settings.jsdoc.preferredTypes.Object = "object"` to .eslintrc to enable "Object.<..., ...>" syntax in a JSDoc `@typedef`. Got rid of some extra whitespaces in .eslintrc, too. - https://github.com/gajus/eslint-plugin-jsdoc/blob/b60cbb027b03b4f6d509933b0dca8681dbe47206/docs/rules/check-types.md#why-not-capital-case-everything - https://github.com/gajus/eslint-plugin-jsdoc/blob/b60cbb027b03b4f6d509933b0dca8681dbe47206/docs/settings.md#settings-to-configure-check-types-and-no-undefined-types - Updated jsconfig.json to specify: ```json "lib": [ "ES2022" ], "module": "node16", "target": "es2020", "strict": true, "exclude": [ "node_modules/**", "coverage*/**", "jsdoc/**" ] ``` The "lib", "modules", and "target" lines are to ensure compatibility with Node v18, and there's no more disabling `strictNullChecks` and `noImplicitAny` after `"strict": true`. Most of the changes in this commit are a result of removing those two options. - Added @types/{chai,node} to devDependencies and added a `pnpm typecheck` command. Now the whole project and its dependencies pass strict type checking. - Updated everything under test/ to be strictly TypeScript compliant. - Updated `pnpm test:ci` to incorporate `pnpm jsdoc` and `pnpm typecheck`. Added 'jsdoc' to devDependencies to enable this. - Added a `pnpm prepack` script to generate types and a package.json `"types"` entry. - Updated all local import paths to add '.js' or 'index.js' and added JSDoc comments everywhere reqired by `pnpm typecheck`. - Added null checks and corresponding tests everywhere reqired by `pnpm typecheck`.
1 parent 03e3ea5 commit fafcd21

17 files changed

+583
-293
lines changed

.eslintrc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"env" : {
2+
"env": {
33
"node": true,
4-
"es2023" : true
4+
"es2023": true
55
},
66
"parserOptions": {
77
"ecmaVersion": "latest",
@@ -25,7 +25,7 @@
2525
]
2626
}
2727
],
28-
"rules" : {
28+
"rules": {
2929
"@stylistic/js/comma-dangle": [
3030
"error", "never"
3131
],
@@ -50,5 +50,12 @@
5050
"no-console": [
5151
"error", { "allow": [ "warn", "error" ]}
5252
]
53+
},
54+
"settings": {
55+
"jsdoc": {
56+
"preferredTypes": {
57+
"Object": "object"
58+
}
59+
}
5360
}
5461
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ node_modules/
1010
out/
1111
pnpm-debug.log
1212
tmp/
13+
types/
1314
*.log
15+
*.tgz

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Running the wrapper will generate the local `file://` URL to the generated
5555
`index.html` file, e.g.:
5656

5757
```text
58-
file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.4/index.html
58+
file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.5/index.html
5959
```
6060

6161
You can click on or copy this link to open it in your browser. You can also open
@@ -99,10 +99,10 @@ This wrapper resolves both of these minor annoyances.
9999
```sh
100100
$ pnpm jsdoc
101101

102-
> [email protected].4 jsdoc /path/to/jsdoc-cli-wrapper
102+
> [email protected].5 jsdoc /path/to/jsdoc-cli-wrapper
103103
> node index.js -c jsdoc.json .
104104

105-
file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.4/index.html
105+
file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.5/index.html
106106
```
107107

108108
Of course, your own project would use `jsdoc-cli-wrapper` instead of `node

ci/vitest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
import { defineConfig, mergeConfig } from 'vitest/config'
23
import baseConfig from '../vitest.config'
34

jsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"checkJs": true,
4+
"lib": [
5+
"ES2022"
6+
],
7+
"module": "node16",
8+
"target": "es2020",
9+
"strict": true
10+
},
11+
"exclude": [
12+
"node_modules/**",
13+
"coverage/**",
14+
"jsdoc/**"
15+
]
16+
}

lib/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,32 @@ import { spawn } from 'node:child_process'
88
import { access, readdir, readFile, rm } from 'node:fs/promises'
99
import path from 'node:path'
1010

11+
export const INSTALL_HINT = 'Run \'pnpm add [-g|-D] jsdoc\' ' +
12+
'to install JSDoc: https://jsdoc.app'
13+
1114
/**
1215
* Result of the `jsdoc` execution
1316
* @typedef {object} RunJsdocResults
1417
* @property {number} exitCode - 0 on success, nonzero on failure
15-
* @property {string} indexHtml - path to the generated index.html file
18+
* @property {string} [indexHtml] - path to the generated index.html file
1619
*/
1720

1821
/**
1922
* Removes the existing JSDoc directory, runs `jsdoc`, and emits the result path
2023
* @param {string[]} argv - JSDoc command line interface arguments
21-
* @param {object} env - environment variables, presumably process.env
24+
* @param {EnvVars} env - environment variables, presumably process.env
2225
* @param {string} platform - the process.platform string
2326
* @returns {Promise<RunJsdocResults>} result of `jsdoc` execution
2427
* @throws if `jsdoc` isn't found or can't execute
2528
*/
2629
export async function runJsdoc(argv, env, platform) {
30+
/** @type {string} */
2731
let jsdocPath
2832

2933
try {
3034
jsdocPath = await getPath('jsdoc', env, platform)
31-
} catch {
32-
return Promise.reject(
33-
'Run \'pnpm add -g jsdoc\' to install JSDoc: https://jsdoc.app'
34-
)
35+
} catch (err) {
36+
return Promise.reject(err instanceof Error ? err : INSTALL_HINT)
3537
}
3638

3739
const {destination, willGenerate} = await analyzeArgv(argv)
@@ -62,22 +64,26 @@ export async function runJsdoc(argv, env, platform) {
6264
*/
6365
export const pathKey = platform => platform !== 'win32' ? 'PATH' : 'Path'
6466

67+
/** @typedef {Object<string,string|undefined>} EnvVars */
68+
6569
/**
6670
* Returns the full path to the specified command
6771
* @param {string} cmdName - command to find in env[pathKey(platform)]
68-
* @param {object} env - environment variables, presumably process.env
72+
* @param {EnvVars} env - environment variables, presumably process.env
6973
* @param {string} platform - the process.platform string
7074
* @returns {Promise<string>} path to the command
7175
* @throws if `jsdoc` isn't found
7276
*/
7377
export async function getPath(cmdName, env, platform) {
7478
const pk = pathKey(platform)
79+
const pathVar = env[pk]
80+
if (!pathVar) throw new Error(`"${pk}" environment variable not defined`)
7581

7682
// pnpm will install both the original script and versions ending with .CMD
7783
// and .ps1. We'll just default to .CMD.
7884
if (platform === 'win32') cmdName += '.CMD'
7985

80-
for (const p of env[pk].split(path.delimiter)) {
86+
for (const p of pathVar.split(path.delimiter)) {
8187
try {
8288
const candidate = path.join(p, cmdName)
8389
await access(candidate)
@@ -103,7 +109,11 @@ export async function getPath(cmdName, env, platform) {
103109
* @returns {Promise<ArgvResults>} analysis results
104110
*/
105111
export async function analyzeArgv(argv) {
106-
const validArg = nextArg => nextArg !== undefined && !nextArg.startsWith('-')
112+
/**
113+
* @param {(string|undefined)} nextArg - next argument after current one
114+
* @returns {boolean} true if defined and not another flag, false otherwise
115+
*/
116+
function validArg(nextArg) { return !!nextArg && !nextArg.startsWith('-') }
107117
let destination, cmdLineDest, willGenerate = true
108118

109119
for (let i = 0; i !== argv.length; ++i) {
@@ -178,7 +188,8 @@ export async function analyzeArgv(argv) {
178188
* @returns {string} str with comments, trailing commas replaced by space
179189
*/
180190
export function stripJsonComments(str) {
181-
let inString, escaped, comment, comma, result = []
191+
let inString = false, escaped = false, comment = null, comma = null
192+
let result = []
182193

183194
for (let i = 0; i !== str.length; ++i) {
184195
let c = str[i]

package.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
{
22
"name": "jsdoc-cli-wrapper",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "JSDoc command line interface wrapper",
55
"main": "index.js",
66
"bin": "./index.js",
7+
"types": "./types/index.d.ts",
78
"scripts": {
89
"lint": "eslint --color --max-warnings 0 .",
910
"test": "vitest",
10-
"test:ci": "eslint --color --max-warnings 0 . && vitest run -c ci/vitest.config.js",
11-
"jsdoc": "node index.js -c jsdoc.json ."
11+
"test:ci": "pnpm lint && pnpm typecheck && vitest run -c ci/vitest.config.js && pnpm jsdoc",
12+
"typecheck": "npx -p typescript tsc -p jsconfig.json --noEmit --pretty",
13+
"jsdoc": "node index.js -c jsdoc.json .",
14+
"prepack": "npx -p typescript tsc ./index.js --allowJs --declaration --declarationMap --emitDeclarationOnly --outDir types"
1215
},
13-
"files": [ "lib/**" ],
16+
"files": [
17+
"lib/**",
18+
"types/**"
19+
],
1420
"keywords": [
1521
"jsdoc",
1622
"JavaScript"
@@ -25,13 +31,17 @@
2531
"repository": "https://github.com/mbland/jsdoc-cli-wrapper",
2632
"bugs": "https://github.com/mbland/jsdoc-cli-wrapper/issues",
2733
"devDependencies": {
28-
"@stylistic/eslint-plugin-js": "^1.5.1",
29-
"@vitest/coverage-istanbul": "^1.1.0",
30-
"@vitest/coverage-v8": "^1.1.0",
31-
"@vitest/ui": "^1.1.0",
34+
"@stylistic/eslint-plugin-js": "^1.5.3",
35+
"@types/chai": "^4.3.11",
36+
"@types/node": "^20.10.7",
37+
"@vitest/coverage-istanbul": "^1.1.3",
38+
"@vitest/coverage-v8": "^1.1.3",
39+
"@vitest/ui": "^1.1.3",
3240
"eslint": "^8.56.0",
33-
"eslint-plugin-jsdoc": "^46.9.1",
41+
"eslint-plugin-jsdoc": "^46.10.1",
3442
"eslint-plugin-vitest": "^0.3.20",
35-
"vitest": "^1.1.0"
43+
"jsdoc": "^4.0.2",
44+
"typescript": "^5.3.3",
45+
"vitest": "^1.1.3"
3646
}
3747
}

0 commit comments

Comments
 (0)