mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
42
test/markdownlint-test-parallel.mjs
Normal file
42
test/markdownlint-test-parallel.mjs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// @ts-check
|
||||
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
||||
import { availableParallelism } from "node:os";
|
||||
import { Worker } from "node:worker_threads";
|
||||
import { __filename } from "./esm-helpers.mjs";
|
||||
import markdownlint from "../lib/markdownlint.mjs";
|
||||
const markdownlintSync = markdownlint.sync;
|
||||
|
||||
/**
|
||||
* Lint specified Markdown files (using multiple threads).
|
||||
*
|
||||
* @param {import("../lib/markdownlint.mjs").Options} options Configuration options.
|
||||
* @returns {Promise<import("../lib/markdownlint.mjs").LintResults>} Results object.
|
||||
*/
|
||||
export function markdownlintParallel(options) {
|
||||
const workerCount = availableParallelism();
|
||||
const files = options.files || [];
|
||||
const chunkSize = Math.ceil(files.length / workerCount);
|
||||
const promises = [];
|
||||
for (let i = 0; i < workerCount; i++) {
|
||||
promises.push(new Promise((resolve, reject) => {
|
||||
const workerData = {
|
||||
...options,
|
||||
"files": files.slice(i * chunkSize, (i + 1) * chunkSize)
|
||||
};
|
||||
const worker = new Worker(__filename(import.meta).replace(/parallel\.mjs$/, "worker.mjs"), { workerData });
|
||||
worker.on("message", resolve);
|
||||
worker.on("error", reject);
|
||||
}));
|
||||
}
|
||||
return Promise.all(promises).then((workerResults) => {
|
||||
const combinedResults = markdownlintSync(null);
|
||||
for (const workerResult of workerResults) {
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const result in workerResult) {
|
||||
combinedResults[result] = workerResult[result];
|
||||
}
|
||||
}
|
||||
return combinedResults;
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue