diff --git a/docs/NODE_API.md b/docs/NODE_API.md index c5716e70b..a53e49df6 100644 --- a/docs/NODE_API.md +++ b/docs/NODE_API.md @@ -34,7 +34,7 @@ of lint information intended for human-readable output. that defines what external modules will be whitelisted and included in the generated documentation. * `args.shallow` **[boolean][20]** whether to avoid dependency parsing - even in JavaScript code. (optional, default `false`) + even in JavaScript code. (optional, default `false`) * `args.inferPrivate` **[string][18]?** a valid regular expression string to infer whether a code element should be private, given its naming structure. For instance, you can specify `inferPrivate: '^_'` to automatically treat @@ -71,14 +71,14 @@ comments, given a root file as a path. that defines what external modules will be whitelisted and included in the generated documentation. * `args.shallow` **[boolean][20]** whether to avoid dependency parsing - even in JavaScript code. (optional, default `false`) + even in JavaScript code. (optional, default `false`) * `args.order` **[Array][17]<([string][18] | [Object][19])>** optional array that - defines sorting order of documentation (optional, default `[]`) + defines sorting order of documentation (optional, default `[]`) * `args.access` **[Array][17]<[string][18]>** an array of access levels - to output in documentation (optional, default `[]`) + to output in documentation (optional, default `[]`) * `args.hljs` **[Object][19]?** hljs optional args - * `args.hljs.highlightAuto` **[boolean][20]** hljs automatically detect language (optional, default `false`) + * `args.hljs.highlightAuto` **[boolean][20]** hljs automatically detect language (optional, default `false`) * `args.hljs.languages` **[Array][17]?** languages for hljs to choose from * `args.inferPrivate` **[string][18]?** a valid regular expression string to infer whether a code element should be private, given its naming structure. @@ -120,7 +120,7 @@ Formats documentation as HTML. * `comments` **[Array][17]<[Comment][22]>** parsed comments * `config` **[Object][19]** Options that can customize the output - * `config.theme` **[string][18]** Name of a module used for an HTML theme. (optional, default `'default_theme'`) + * `config.theme` **[string][18]** Name of a module used for an HTML theme. (optional, default `'default_theme'`) ### Examples @@ -181,7 +181,7 @@ documentation.build(['index.js']) }); ``` -Returns **[Promise][21]<[string][18]>** +Returns **[Promise][21]<[string][18]>** [1]: #lint diff --git a/src/input/moduleDeps.js b/src/input/moduleDeps.js index b2e8479fd..78cc28ee3 100644 --- a/src/input/moduleDeps.js +++ b/src/input/moduleDeps.js @@ -1,108 +1,108 @@ -import path from 'path'; -import util from 'util'; -import r from 'resolve'; -import readFileCode from './readFileCode.js'; -import konan from 'konan'; -import { parseToAst } from '../parsers/parse_to_ast.js'; - -// const parseExst = ['.js', '.mjs', '.jsx', '.vue', '.ts', '.tsx']; -const resolveExst = ['.json', '.css', '.less', '.sass']; -const resolve = util.promisify(r); - -class Deps { - constructor(opts = {}) { - this.fileCache = opts.fileCache || {}; - this.visited = {}; - this.res = []; - - this.options = { ...opts }; - } - - async flush(input) { - const promises = input.map(file => { - const dir = path.dirname(file); - return this.walk(file, { - basedir: dir, - filename: 'root' - }); - }); - await Promise.all(promises); - - return this.res; - } - - async readFile(file) { - if (this.fileCache[file]) { - return this.fileCache[file]; - } - - return readFileCode(file); - } - - async walk(id, parent) { - const extensions = this.options.extensions; - const sortKey = parent.sortKey || ''; - let file = null; - - try { - file = await resolve(id, { ...parent, extensions }); - } catch (err) { - if (err.code === 'MODULE_NOT_FOUND') { - console.warn(`module not found: "${id}" from file ${parent.filename}`); - return; - } - throw err; - } - - if (this.visited[file] || resolveExst.includes(path.extname(file))) { - return file; - } - this.visited[file] = true; - - const source = await this.readFile(file); - const depsArray = this.parseDeps(file, source); - if (!depsArray) { - return file; - } - - const deps = {}; - const promises = depsArray.map(async (id, i) => { - const filter = this.options.filter; - if (filter && !filter(id)) { - deps[id] = false; - return; - } - const number = i.toString().padStart(8, '0'); - deps[id] = await this.walk(id, { - filename: file, - basedir: path.dirname(file), - sortKey: sortKey + '!' + file + ':' + number - }); - }); - - await Promise.all(promises); - - this.res.push({ - id: file, - source, - deps, - file, - sortKey: sortKey + '!' + file - }); - return file; - } - - parseDeps(file, src) { - try { - const ast = parseToAst(src, file); - return konan(ast).strings; - } catch (ex) { - console.error(`Parsing file ${file}: ${ex}`); - } - } -} - -export default async function (input = [], opts = {}) { - const dep = new Deps(opts); - return dep.flush(Array.from(new Set(input))); -} +import path from 'path'; +import util from 'util'; +import r from 'resolve'; +import readFileCode from './readFileCode.js'; +import konan from 'konan'; +import { parseToAst } from '../parsers/parse_to_ast.js'; + +// const parseExst = ['.js', '.mjs', '.jsx', '.vue', '.ts', '.tsx']; +const resolveExst = ['.json', '.css', '.less', '.sass']; +const resolve = util.promisify(r); + +class Deps { + constructor(opts = {}) { + this.fileCache = opts.fileCache || {}; + this.visited = {}; + this.res = []; + + this.options = { ...opts }; + } + + async flush(input) { + const promises = input.map(file => { + const dir = path.dirname(file); + return this.walk(file, { + basedir: dir, + filename: 'root' + }); + }); + await Promise.all(promises); + + return this.res; + } + + async readFile(file) { + if (this.fileCache[file]) { + return this.fileCache[file]; + } + + return readFileCode(file); + } + + async walk(id, parent) { + const extensions = this.options.extensions; + const sortKey = parent.sortKey || ''; + let file = null; + + try { + file = await resolve(id, { ...parent, extensions }); + } catch (err) { + if (err.code === 'MODULE_NOT_FOUND') { + console.warn(`module not found: "${id}" from file ${parent.filename}`); + return; + } + throw err; + } + + if (this.visited[file] || resolveExst.includes(path.extname(file))) { + return file; + } + this.visited[file] = true; + + const source = await this.readFile(file); + const depsArray = this.parseDeps(file, source); + if (!depsArray) { + return file; + } + + const deps = {}; + const promises = depsArray.map(async (id, i) => { + const filter = this.options.filter; + if (filter && !filter(id)) { + deps[id] = false; + return; + } + const number = i.toString().padStart(8, '0'); + deps[id] = await this.walk(id, { + filename: file, + basedir: path.dirname(file), + sortKey: sortKey + '!' + file + ':' + number + }); + }); + + await Promise.all(promises); + + this.res.push({ + id: file, + source, + deps, + file, + sortKey: sortKey + '!' + file + }); + return file; + } + + parseDeps(file, src) { + try { + const ast = parseToAst(src, file); + return konan(ast, { dynamicImport: false }).strings; + } catch (ex) { + console.error(`Parsing file ${file}: ${ex}`); + } + } +} + +export default async function (input = [], opts = {}) { + const dep = new Deps(opts); + return dep.flush(Array.from(new Set(input))); +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy