unified-engine
Advanced tools
+3
-26
@@ -38,3 +38,3 @@ /** | ||
| import {pathToFileURL} from 'node:url' | ||
| import jsYaml from 'js-yaml' | ||
| import yaml from 'yaml' | ||
| import parseJson from 'parse-json' | ||
@@ -203,4 +203,2 @@ import createDebug from 'debug' | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 2 */ | ||
| return result | ||
@@ -212,4 +210,2 @@ } | ||
| async function loadScriptOrModule(_, filePath) { | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 4 */ | ||
| // @ts-expect-error: Assume it matches config. | ||
@@ -221,7 +217,4 @@ // type-coverage:ignore-next-line | ||
| /** @type {Loader} */ | ||
| async function loadYaml(buf, filePath) { | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 4 */ | ||
| // @ts-expect-error: Assume it matches config. | ||
| return jsYaml.load(String(buf), {filename: path.basename(filePath)}) | ||
| async function loadYaml(buf) { | ||
| return yaml.parse(String(buf)) | ||
| } | ||
@@ -234,4 +227,2 @@ | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 8 */ | ||
| // @ts-expect-error: Assume it matches config. | ||
@@ -259,4 +250,2 @@ return path.basename(filePath) === 'package.json' | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 6 */ | ||
| return target | ||
@@ -281,4 +270,2 @@ | ||
| target.settings = Object.assign({}, target.settings, result.settings) | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 6 */ | ||
| } | ||
@@ -302,4 +289,2 @@ | ||
| } | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 6 */ | ||
| } | ||
@@ -321,4 +306,2 @@ | ||
| } | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 7 */ | ||
| } | ||
@@ -338,4 +321,2 @@ | ||
| } | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 7 */ | ||
| } | ||
@@ -383,4 +364,2 @@ | ||
| } | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 8 */ | ||
| } | ||
@@ -455,4 +434,2 @@ | ||
| return result.default | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 9 */ | ||
| } catch (error) { | ||
@@ -459,0 +436,0 @@ const exception = /** @type {Error} */ (error) |
@@ -24,3 +24,6 @@ /** | ||
| if (file.value || file.data.unifiedEngineStreamIn) { | ||
| if ( | ||
| (file.value !== null && file.value !== undefined) || | ||
| file.data.unifiedEngineStreamIn | ||
| ) { | ||
| debug('Not reading file `%s` with `value`', filePath) | ||
@@ -27,0 +30,0 @@ next() |
@@ -47,3 +47,3 @@ export class FileSet extends EventEmitter { | ||
| set: FileSet, | ||
| callback: (error?: Error | null | undefined) => void | ||
| callback: (error?: Error | null) => void | ||
| ) => void | ||
@@ -50,0 +50,0 @@ export type CompleterAsync = (set: FileSet) => Promise<void> |
+5
-5
@@ -233,4 +233,2 @@ /** | ||
| file.fail('Cannot process specified file: it’s ignored') | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 1 */ | ||
| } catch {} | ||
@@ -244,4 +242,2 @@ } | ||
| ) | ||
| // C8 bug on Node@12 | ||
| /* c8 ignore next 1 */ | ||
| } catch {} | ||
@@ -290,3 +286,7 @@ } | ||
| if (typeof file === 'string' || !file.value) { | ||
| if ( | ||
| typeof file === 'string' || | ||
| file.value === null || | ||
| file.value === undefined | ||
| ) { | ||
| expected++ | ||
@@ -293,0 +293,0 @@ fs.stat(fp, (error, value) => { |
+4
-4
@@ -31,4 +31,4 @@ /** | ||
| processor: Options['processor'] | ||
| cwd: Exclude<Options['cwd'], undefined> | ||
| files: Exclude<Options['files'], undefined> | ||
| cwd: Exclude<Options['cwd'], undefined | URL> | ||
| files: Array<string | VFile> | ||
| extensions: Exclude<Options['extensions'], undefined> | ||
@@ -81,7 +81,7 @@ streamIn: Exclude<Options['streamIn'], undefined> | ||
| */ | ||
| cwd?: string | undefined | ||
| cwd?: string | URL | undefined | ||
| /** | ||
| * Paths or globs to files and directories, or virtual files, to process. | ||
| */ | ||
| files?: (string | import('vfile').VFile)[] | undefined | ||
| files?: (string | import('vfile').VFile | URL)[] | undefined | ||
| /** | ||
@@ -88,0 +88,0 @@ * If `files` matches directories, include `files` with `extensions` |
+15
-7
@@ -24,4 +24,4 @@ /** | ||
| * @property {Options['processor']} processor | ||
| * @property {Exclude<Options['cwd'], undefined>} cwd | ||
| * @property {Exclude<Options['files'], undefined>} files | ||
| * @property {Exclude<Options['cwd'], undefined | URL>} cwd | ||
| * @property {Array<string|VFile>} files | ||
| * @property {Exclude<Options['extensions'], undefined>} extensions | ||
@@ -66,6 +66,6 @@ * @property {Exclude<Options['streamIn'], undefined>} streamIn | ||
| * Unified processor to transform files | ||
| * @property {string} [cwd] | ||
| * @property {string|URL} [cwd] | ||
| * Directory to search files in, load plugins from, and more. | ||
| * Defaults to `process.cwd()`. | ||
| * @property {Array<string|VFile>} [files] | ||
| * @property {Array<string|URL|VFile>} [files] | ||
| * Paths or globs to files and directories, or virtual files, to process. | ||
@@ -177,2 +177,3 @@ * @property {Array<string>} [extensions] | ||
| import {PassThrough} from 'node:stream' | ||
| import {fileURLToPath} from 'node:url' | ||
| import {statistics} from 'vfile-statistics' | ||
@@ -220,6 +221,13 @@ import {fileSetPipeline} from './file-set-pipeline/index.js' | ||
| // Path to run as. | ||
| settings.cwd = options.cwd || process.cwd() | ||
| settings.cwd = | ||
| typeof options.cwd === 'object' | ||
| ? fileURLToPath(options.cwd) | ||
| : options.cwd || process.cwd() | ||
| // Input. | ||
| settings.files = options.files || [] | ||
| settings.files = (options.files || []).map((d) => { | ||
| return typeof d === 'object' && 'href' in d && !('path' in d) | ||
| ? fileURLToPath(d) | ||
| : d | ||
| }) | ||
| settings.extensions = (options.extensions || []).map((ext) => | ||
@@ -341,3 +349,3 @@ ext.charAt(0) === '.' ? ext : '.' + ext | ||
| // Process. | ||
| fileSetPipeline.run({files: options.files || []}, settings, next) | ||
| fileSetPipeline.run({files: settings.files}, settings, next) | ||
@@ -344,0 +352,0 @@ /** |
+6
-7
| { | ||
| "name": "unified-engine", | ||
| "version": "9.1.0", | ||
| "version": "10.0.0", | ||
| "description": "Engine to process multiple files with unified", | ||
@@ -35,3 +35,2 @@ "license": "MIT", | ||
| "@types/is-empty": "^1.0.0", | ||
| "@types/js-yaml": "^4.0.0", | ||
| "@types/node": "^17.0.0", | ||
@@ -42,3 +41,3 @@ "@types/unist": "^2.0.0", | ||
| "fault": "^2.0.0", | ||
| "glob": "^7.0.0", | ||
| "glob": "^8.0.0", | ||
| "ignore": "^5.0.0", | ||
@@ -48,4 +47,3 @@ "is-buffer": "^2.0.0", | ||
| "is-plain-obj": "^4.0.0", | ||
| "js-yaml": "^4.0.0", | ||
| "load-plugin": "^4.0.0", | ||
| "load-plugin": "^5.0.0", | ||
| "parse-json": "^6.0.0", | ||
@@ -57,3 +55,4 @@ "to-vfile": "^7.0.0", | ||
| "vfile-reporter": "^7.0.0", | ||
| "vfile-statistics": "^2.0.0" | ||
| "vfile-statistics": "^2.0.0", | ||
| "yaml": "^2.0.0" | ||
| }, | ||
@@ -78,3 +77,3 @@ "devDependencies": { | ||
| "vfile-reporter-pretty": "^6.0.0", | ||
| "xo": "^0.48.0" | ||
| "xo": "^0.50.0" | ||
| }, | ||
@@ -81,0 +80,0 @@ "scripts": { |
+124
-75
@@ -10,22 +10,48 @@ # unified-engine | ||
| Engine to process multiple files with [**unified**][unified], allowing users to | ||
| [configure][] from the file system. | ||
| **[unified][]** engine to process multiple files, lettings users [configure][] | ||
| from the file system. | ||
| ## Projects | ||
| ## Contents | ||
| The following projects wrap the engine: | ||
| * [What is this?](#what-is-this) | ||
| * [When should I use this?](#when-should-i-use-this) | ||
| * [Install](#install) | ||
| * [Use](#use) | ||
| * [API](#api) | ||
| * [`engine(options, callback)`](#engineoptions-callback) | ||
| * [Plugins](#plugins) | ||
| * [Configuration](#configuration) | ||
| * [Ignoring](#ignoring) | ||
| * [Types](#types) | ||
| * [Compatibility](#compatibility) | ||
| * [Security](#security) | ||
| * [Contribute](#contribute) | ||
| * [License](#license) | ||
| * [`unified-args`][args] — Create CLIs for processors | ||
| * [`unified-engine-gulp`][gulp] — Create Gulp plugins | ||
| * [`unified-engine-atom`][atom] — Create Atom Linters for processors | ||
| * [`unified-language-server`][language-server] — Create language servers for | ||
| processors | ||
| ## What is this? | ||
| This package is the engine. | ||
| It’s what you use underneath when you use [`remark-cli`][remark-cli] or a | ||
| language server. | ||
| Compared to unified, this deals with multiple files, often from the file | ||
| system, and with configuration files and ignore files. | ||
| ## When should I use this? | ||
| You typically use something that wraps this, such as: | ||
| * [`unified-args`][args] | ||
| — create CLIs | ||
| * [`unified-engine-gulp`][gulp] | ||
| — create Gulp plugins | ||
| * [`unified-language-server`][language-server] | ||
| — create language servers | ||
| You can use this to make such things. | ||
| ## Install | ||
| This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
| Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
| This package is [ESM only][esm]. | ||
| In Node.js (version 14.14+, 16.0+, or 18.0+), install with [npm][]: | ||
| [npm][]: | ||
| ```sh | ||
@@ -38,3 +64,3 @@ npm install unified-engine | ||
| The following example processes all files in the current directory with a | ||
| Markdown extension with [**remark**][remark], allows [configuration][configure] | ||
| markdown extension with **[remark][]**, allows [configuration][configure] | ||
| from `.remarkrc` and `package.json` files, ignoring files from `.remarkignore` | ||
@@ -44,2 +70,6 @@ files, and more. | ||
| ```js | ||
| /** | ||
| * @typedef {import('unified-engine').Callback} Callback | ||
| */ | ||
| import {engine} from 'unified-engine' | ||
@@ -62,2 +92,3 @@ import {remark} from 'remark' | ||
| /** @type {Callback} */ | ||
| function done(error) { | ||
@@ -68,16 +99,5 @@ if (error) throw error | ||
| ## Contents | ||
| * [API](#api) | ||
| * [`engine(options, callback)`](#engineoptions-callback) | ||
| * [Plugins](#plugins) | ||
| * [Configuration](#configuration) | ||
| * [Ignoring](#ignoring) | ||
| * [Security](#security) | ||
| * [Contribute](#contribute) | ||
| * [License](#license) | ||
| ## API | ||
| This package exports the following identifiers: `engine`. | ||
| This package exports the identifier `engine`. | ||
| There is no default export. | ||
@@ -94,91 +114,92 @@ | ||
| — unified processor to transform files | ||
| * [`cwd`][cwd] (`string`, default: `process.cwd()`) | ||
| — Directory to search files in, load plugins from, and more | ||
| * [`files`][files] (`Array<string|VFile>`, optional) | ||
| — Paths or globs to files and directories, or virtual files, to process | ||
| * [`cwd`][cwd] (`string` or `URL`, default: `process.cwd()`) | ||
| — directory to search files in, load plugins from, and more | ||
| * [`files`][files] (`Array<string|URL|VFile>`, optional) | ||
| — paths or globs to files and directories, virtual files, or URLs, to | ||
| process | ||
| * [`extensions`][extensions] (`Array<string>`, optional) | ||
| — If `files` matches directories, include files with `extensions` | ||
| — if `files` matches directories, include files with `extensions` | ||
| * [`streamIn`][stream-in] (`ReadableStream`, default: `process.stdin`) | ||
| — Stream to read from if no files are found or given | ||
| — stream to read from if no files are found or given | ||
| * [`filePath`][file-path] (`string`, optional) | ||
| — File path to process the given file on `streamIn` as | ||
| — file path to process the given file on `streamIn` as | ||
| * [`streamOut`][stream-out] (`WritableStream`, default: `process.stdout`) | ||
| — Stream to write processed files to | ||
| — stream to write processed files to | ||
| * [`streamError`][stream-error] (`WritableStream`, default: `process.stderr`) | ||
| — Stream to write the report (if any) to | ||
| — stream to write the report (if any) to | ||
| * [`out`][out] (`boolean`, default: depends) | ||
| — Whether to write the processed file to `streamOut` | ||
| — whether to write the processed file to `streamOut` | ||
| * [`output`][output] (`boolean` or `string`, default: `false`) | ||
| — Whether to write successfully processed files, and where to | ||
| — whether to write successfully processed files, and where to | ||
| * [`alwaysStringify`][always-stringify] (`boolean`, default: `false`) | ||
| — Whether to always serialize successfully processed files | ||
| — whether to always serialize successfully processed files | ||
| * [`tree`][tree] (`boolean`, default: `false`) | ||
| — Whether to treat both input and output as a syntax tree | ||
| — whether to treat both input and output as a syntax tree | ||
| * [`treeIn`][tree-in] (`boolean`, default: `tree`) | ||
| — Whether to treat input as a syntax tree | ||
| — whether to treat input as a syntax tree | ||
| * [`treeOut`][tree-out] (`boolean`, default: `tree`) | ||
| — Whether to treat output as a syntax tree | ||
| — whether to treat output as a syntax tree | ||
| * [`inspect`][inspect] (`boolean`, default: `false`) | ||
| — Whether to output a formatted syntax tree | ||
| — whether to output a formatted syntax tree | ||
| * [`rcName`][rc-name] (`string`, optional) | ||
| — Name of configuration files to load | ||
| — wame of configuration files to load | ||
| * [`packageField`][package-field] (`string`, optional) | ||
| — Property at which configuration can be found in `package.json` files | ||
| — property at which configuration can be found in `package.json` files | ||
| * [`detectConfig`][detect-config] (`boolean`, default: whether `rcName` or | ||
| `packageField` is given) | ||
| — Whether to search for configuration files | ||
| — whether to search for configuration files | ||
| * [`rcPath`][rc-path] (`string`, optional) | ||
| — Filepath to a configuration file to load | ||
| — filepath to a configuration file to load | ||
| * [`settings`][settings] (`Object`, optional) | ||
| — Configuration for the parser and compiler of the processor | ||
| — configuration for the parser and compiler of the processor | ||
| * [`ignoreName`][ignore-name] (`string`, optional) | ||
| — Name of ignore files to load | ||
| — name of ignore files to load | ||
| * [`detectIgnore`][detect-ignore] (`boolean`, default: whether `ignoreName` | ||
| is given) | ||
| — Whether to search for ignore files | ||
| — whether to search for ignore files | ||
| * [`ignorePath`][ignore-path] (`string`, optional) | ||
| — Filepath to an ignore file to load | ||
| — filepath to an ignore file to load | ||
| * [`ignorePathResolveFrom`][ignore-path-resolve-from] (`'dir'` or `'cwd'`, | ||
| default: `'dir'`) | ||
| — Resolve patterns in `ignorePath` from the current working directory or the | ||
| — resolve patterns in `ignorePath` from the current working directory or the | ||
| file’s directory | ||
| * [`ignorePatterns`][ignore-patterns] (`Array<string>`, optional) | ||
| — Patterns to ignore in addition to ignore files, if any | ||
| — patterns to ignore in addition to ignore files, if any | ||
| * [`ignoreUnconfigured`][ignore-unconfigured] (`boolean`, default: `false`) | ||
| — Ignore files that do not have an associated detected configuration file | ||
| — ignore files that do not have an associated detected configuration file | ||
| * [`silentlyIgnore`][silently-ignore] (`boolean`, default: `false`) | ||
| — Skip given files if they are ignored | ||
| — skip given files if they are ignored | ||
| * [`plugins`][options-plugins] (`Array|Object`, optional) | ||
| — Plugins to use | ||
| — plugins to use | ||
| * [`pluginPrefix`][plugin-prefix] (`string`, optional) | ||
| — Optional prefix to use when searching for plugins | ||
| — optional prefix to use when searching for plugins | ||
| * [`configTransform`][config-transform] (`Function`, optional) | ||
| — Transform config files from a different schema | ||
| — transform config files from a different schema | ||
| * [`reporter`][reporter] (`string` or `function`, default: | ||
| `import {reporter} from 'vfile-reporter'`) | ||
| — Reporter to use | ||
| — reporter to use | ||
| * [`reporterOptions`][reporteroptions] (`Object?`, optional) | ||
| — Config to pass to the used reporter | ||
| — config to pass to the used reporter | ||
| * [`color`][color] (`boolean`, default: `false`) | ||
| — Whether to report with ANSI color sequences | ||
| — whether to report with ANSI color sequences | ||
| * [`silent`][silent] (`boolean`, default: `false`) | ||
| — Report only fatal errors | ||
| — report only fatal errors | ||
| * [`quiet`][quiet] (`boolean`, default: `silent`) | ||
| — Do not report successful files | ||
| — do not report successful files | ||
| * [`frail`][frail] (`boolean`, default: `false`) | ||
| — Call back with an unsuccessful (`1`) code on warnings as well as errors | ||
| — call back with an unsuccessful (`1`) code on warnings as well as errors | ||
| #### `function callback(error[, code, context])` | ||
| Called when processing is complete, either with a fatal error if processing went | ||
| horribly wrong (probably due to incorrect configuration), or a status code and | ||
| the processing context. | ||
| Called when processing is complete, either with a fatal error if processing | ||
| went horribly wrong (probably due to incorrect configuration on your part as a | ||
| developer), or a status code and the processing context. | ||
| ###### Parameters | ||
| * `error` (`Error`) — Fatal error | ||
| * `code` (`number`) — Either `0` if successful, or `1` if unsuccessful. | ||
| The latter occurs if [fatal][] errors happen when processing individual | ||
| * `error` (`Error`) — fatal error | ||
| * `code` (`number`) — either `0` if successful, or `1` if unsuccessful, | ||
| the latter occurs if [fatal][] errors happen when processing individual | ||
| files, or if [`frail`][frail] is set and warnings occur | ||
| * `context` (`Object`) — Processing context, containing internally used | ||
| * `context` (`Object`) — processing context, containing internally used | ||
| information and a `files` array with the processed files | ||
@@ -200,2 +221,26 @@ | ||
| ## Types | ||
| This package is fully typed with [TypeScript][]. | ||
| It additionally exports the following types: | ||
| * `VFileReporterOptions` — models options passed to vfile reporters | ||
| * `VFileReporter` — models the signature accepted as a vfile reporter | ||
| * `FileSet` — models what is passed to plugins as a second parameter | ||
| * `Completer` — models file set plugins | ||
| * `ResolveFrom` — models the enum allowed for `options.ignorePathResolveFrom` | ||
| * `ConfigTransform` — models the signature of `options.configTransform` | ||
| * `Preset` — models a preset, like `Preset` from `unified` but accepts | ||
| strings | ||
| * `Options` — models configuration | ||
| * `Context` — models the third parameter to `callback` | ||
| * `Callback` — models the signature of `callback` | ||
| ## Compatibility | ||
| Projects maintained by the unified collective are compatible with all maintained | ||
| versions of Node.js. | ||
| As of now, that is Node.js 14.14+, 16.0+, and 18.0+. | ||
| Our projects sometimes work with older versions, but this is not guaranteed. | ||
| ## Security | ||
@@ -249,9 +294,13 @@ | ||
| [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
| [typescript]: https://www.typescriptlang.org | ||
| [health]: https://github.com/unifiedjs/.github | ||
| [contributing]: https://github.com/unifiedjs/.github/blob/HEAD/contributing.md | ||
| [contributing]: https://github.com/unifiedjs/.github/blob/main/contributing.md | ||
| [support]: https://github.com/unifiedjs/.github/blob/HEAD/support.md | ||
| [support]: https://github.com/unifiedjs/.github/blob/main/support.md | ||
| [coc]: https://github.com/unifiedjs/.github/blob/HEAD/code-of-conduct.md | ||
| [coc]: https://github.com/unifiedjs/.github/blob/main/code-of-conduct.md | ||
@@ -352,4 +401,2 @@ [license]: license | ||
| [atom]: https://github.com/unifiedjs/unified-engine-atom | ||
| [gulp]: https://github.com/unifiedjs/unified-engine-gulp | ||
@@ -360,1 +407,3 @@ | ||
| [args]: https://github.com/unifiedjs/unified-args | ||
| [remark-cli]: https://github.com/remarkjs/remark/tree/main/packages/remark-cli#readme |
107877
1.05%22
-4.35%400
13.96%3007
-0.4%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated