Skip to content

Commit 4924dd8

Browse files
committed
Add --no-workers flag in @webdoc/cli to disable worker threads.
1 parent 0b21fbd commit 4924dd8

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build-next": "cd .. && webdoc && cd example",
2828
"build-pixi-api": "cd ../../pixi-api && webdoc --verbose && cd ../webdoc/example",
2929
"build-pixi-api-prod": "cd ../../pixi-api && webdoc --site-root pixi-api && cd ../webdoc/example",
30-
"build-pixi-api-gcp": "cd ../../pixi-api && node --inspect-brk ../webdoc/example/node_modules/@webdoc/cli/cli --tutorials ./projects/guides --verbose && cd ../webdoc/example",
30+
"build-pixi-api-gcp": "cd ../../pixi-api && webdoc --tutorials ./projects/guides --verbose && cd ../webdoc/example",
3131
"build-pixi-guides": "cd ../../guides && webdoc --tutorials docs && cd ../webdoc/example",
3232
"build-mongodb": "cd ../../node-mongodb-native && webdoc --verbose && cd ../webdoc/example"
3333
},

packages/webdoc-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ generate the `sitemap.xml`. This is useful if you want to integrate with [Algoli
1919
* `--site-root <path>`: If using absolute links in a template, this will set the basepath. The basepath should the directory in which the documentation is being stored relative to where the server is running. The site root is "/" by default - which means that you'll need to serve the documentation directory as top-level. Note that @webdoc/default-template uses absolute links.
2020
* `-c <config-path>`: This sets the path of the configuration file webdoc uses.
2121
* `-u <tutorials-directory>` - (optional) This should point to a directory containing tutorials written in Markdown (".md") or HTML ".html, ".htm". JSON files can be used to configure the hierarchy and naming of tutorials (see the Tutorial Configuration section).
22+
* `--no-workers` - Disables usage of worker threads to parallelize parsing.
2223

2324
### Configuration
2425

packages/webdoc-cli/src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ async function main(argv: yargs.Argv) {
6363
const config = loadConfig(argv.config);
6464
const tutorials = loadTutorials(argv.tutorials, config.template.routes.tutorials);
6565

66-
6766
if (argv.siteRoot) {
6867
config.template.siteRoot = argv.siteRoot;
6968
}
@@ -107,7 +106,10 @@ async function main(argv: yargs.Argv) {
107106
}
108107

109108
try {
110-
await parse(sourceFiles, documentTree);
109+
console.log(argv);
110+
await parse(sourceFiles, documentTree, {
111+
mainThread: !argv.workers,
112+
});
111113
} catch (e) {
112114
// Make sure we get that API structure out so the user can debug the problem!
113115
if (config.opts && config.opts.export) {
@@ -163,7 +165,9 @@ async function main(argv: yargs.Argv) {
163165
const argv = yargs.scriptName("@webdoc/cli")
164166
.usage("$0 -c <configFile> -u <tutorialDir> --verbose " +
165167
"--site-root <siteRoot> " +
166-
"--site-domain <siteDomain>")
168+
"--site-domain <siteDomain>" +
169+
"--no-workers")
170+
.default("workers", true)
167171
.default("config", path.join(process.cwd(), "webdoc.conf.json"), "webdoc config file")
168172
.alias("c", "config")
169173
.alias("u", "tutorials")
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
declare module "@webdoc/parser" {
2-
import type {Doc} from "@webdoc/types";
2+
import type {RootDoc} from "@webdoc/types";
33

4-
/**
5-
* The parser will accept:
6-
* + a file's contents
7-
* + an array of file contents
8-
+ + a map mapping file-names to file contents
9-
*/
10-
declare type ParserInput = string | string[] | Map<string, string>;
11-
12-
declare function parse(input: ParserInput): Doc;
4+
declare function parse(
5+
target: string | SourceFile[],
6+
root?: RootDoc,
7+
options?: $Shape<{ mainThread: boolean }>,
8+
): Promise<RootDoc>;
139
}

packages/webdoc-parser/src/indexer/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ export function register(lang: LanguageIntegration): void {
2828
}
2929
}
3030

31-
export async function run(files: SourceFile[], config: LanguageConfig): Promise<Symbol[]> {
31+
export async function run(
32+
files: SourceFile[],
33+
config: LanguageConfig,
34+
options?: $Shape<{
35+
mainThread: boolean,
36+
}>,
37+
): Promise<Symbol[]> {
3238
const startTime = Date.now();
3339
const maxThreads = Math.min(os.cpus().length, 1 + Math.floor(files.length / 125));
3440

3541
parserLogger.info(tag.Indexer, "Indexing " + files.length + " files");
3642

3743
const symbolTrees: Array<Symbol> = new Array(files.length);
3844

39-
if (maxThreads > 1) {
45+
if (maxThreads > 1 && !options?.mainThread) {
4046
const packages = _.keyBy(
4147
files.map((file) => file.package),
4248
(pkg) => pkg.id,

packages/webdoc-parser/src/parse.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ export function buildSymbolTree(
8080
*
8181
* @param {string | SourceFile[]} target
8282
* @param {RootDoc} root
83+
* @param {object}[options]
84+
* @param {boolean}[options.mainThread] - Force the indexer to run on the main thread.
8385
* @return {RootDoc}
8486
*/
8587
export async function parse(
8688
target: string | SourceFile[],
8789
root?: RootDoc = createRootDoc(),
90+
options?: $Shape<{
91+
mainThread: boolean
92+
}>,
8893
): Promise<RootDoc> {
8994
if (typeof target === "string") {
9095
target = [{
@@ -94,7 +99,7 @@ export async function parse(
9499
}];
95100
}
96101

97-
const perFileSymbolTrees = await Indexer.run(target, Webdoc.DEFAULT_LANG_CONFIG);
102+
const perFileSymbolTrees = await Indexer.run(target, Webdoc.DEFAULT_LANG_CONFIG, options);
98103
const fullSymbolTree = assemble(perFileSymbolTrees);
99104

100105
root.children = root.members;

0 commit comments

Comments
 (0)