openapi-jsonrpc-jsdoc 1.5.5 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +50 -3
  2. package/package.json +2 -2
package/index.mjs CHANGED
@@ -1,5 +1,52 @@
1
+ import { stripTypeScriptTypes } from 'node:module';
2
+ import { readFileSync } from 'node:fs';
3
+ import { glob } from 'node:fs/promises';
4
+ import path from 'node:path';
1
5
  import jsdoc from 'jsdoc-api';
2
6
 
7
+ async function collectJsdocDocuments(options) {
8
+ const allFiles = [];
9
+ for (const pattern of options.files || []) {
10
+ for await (const file of glob(pattern)) {
11
+ allFiles.push(file);
12
+ }
13
+ }
14
+
15
+ const { files: _f, package: _p, cache: _c, ...baseOptions } = options;
16
+
17
+ const allResults = [];
18
+
19
+ if (!options.cache && options.package) {
20
+ try {
21
+ const pkg = JSON.parse(readFileSync(options.package, options.encoding || 'utf8'));
22
+ allResults.push({
23
+ kind: 'package',
24
+ name: pkg.name,
25
+ version: pkg.version,
26
+ description: pkg.description,
27
+ });
28
+ } catch {}
29
+ }
30
+
31
+ for (const file of allFiles) {
32
+ const raw = readFileSync(file, options.encoding || 'utf8');
33
+ const source = /\.tsx?$/.test(file) ? stripTypeScriptTypes(raw) : raw;
34
+ const results = await jsdoc.explain({ ...baseOptions, source });
35
+
36
+ const basenameNoExt = path.basename(file, path.extname(file));
37
+ const dirname = path.dirname(file);
38
+ for (const item of results) {
39
+ if (item.meta) {
40
+ item.meta.filename = basenameNoExt;
41
+ item.meta.path = dirname;
42
+ }
43
+ }
44
+ allResults.push(...results);
45
+ }
46
+
47
+ return allResults;
48
+ }
49
+
3
50
  function extractName(name) {
4
51
  try {
5
52
  return name.match(/\.(.+)/i)[1]; //eslint-disable-line
@@ -200,9 +247,9 @@ export default async function openapiJsonrpcJsdoc({
200
247
  }
201
248
  let documents;
202
249
  if (options.cache) {
203
- documents = await jsdoc.explain(options);
250
+ documents = await collectJsdocDocuments(options);
204
251
  } else {
205
- const allData = await jsdoc.explain(options);
252
+ const allData = await collectJsdocDocuments(options);
206
253
  documents = allData.filter(item => item.kind !== 'package');
207
254
  const package_ = allData.find(item => item.kind === 'package');
208
255
  info.version = package_.version;
@@ -276,7 +323,7 @@ export default async function openapiJsonrpcJsdoc({
276
323
  continue prepare;
277
324
  }
278
325
  const {filename} = module.meta;
279
- const apiName = filename.replace(/\.js$/, '');
326
+ const apiName = path.parse(filename).name || filename.replace(/\.[^.]+$/, '');
280
327
 
281
328
  let resultValues;
282
329
  switch (module.returns?.[0]?.description) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-jsonrpc-jsdoc",
3
- "version": "1.5.5",
3
+ "version": "1.6.0",
4
4
  "description": "Transform JSDoc-annotated JSON-RPC 2.0 methods into OpenAPI specifications.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/qertis/openapi-jsonrpc-jsdoc#readme",
31
31
  "dependencies": {
32
- "jsdoc-api": "~9.3.5"
32
+ "jsdoc-api": "~9.3.6"
33
33
  },
34
34
  "devDependencies": {
35
35
  "ava": "~6.4.1",