Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/update docs tests failing on master #1442

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/NODE_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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&#x20;(optional, default `[]`)
* `args.access` **[Array][17]<[string][18]>** an array of access levels
to output in documentation (optional, default `[]`)
to output in documentation&#x20;(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&#x20;(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.
Expand Down Expand Up @@ -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.&#x20;(optional, default `'default_theme'`)

### Examples

Expand Down Expand Up @@ -181,7 +181,7 @@ documentation.build(['index.js'])
});
```

Returns **[Promise][21]<[string][18]>**
Returns **[Promise][21]<[string][18]>**&#x20;

[1]: #lint

Expand Down
216 changes: 108 additions & 108 deletions src/input/moduleDeps.js
Original file line number Diff line number Diff line change
@@ -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)));
}