Skip to content

Commit 34a5ba4

Browse files
committed
Refactor to use @imports
1 parent 6b2533a commit 34a5ba4

File tree

43 files changed

+188
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+188
-175
lines changed

index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* @typedef {import('./lib/configuration.js').ConfigResult} ConfigResult
33
* @typedef {import('./lib/file-set.js').Completer} Completer
44
* @typedef {import('./lib/index.js').Callback} Callback
5-
* @typedef {import('./lib/index.js').ConfigTransform} ConfigTransform
5+
* @typedef {import('./lib/configuration.js').ConfigTransform} ConfigTransform
66
* @typedef {import('./lib/index.js').Context} Context
7-
* @typedef {import('./lib/index.js').FileSet} FileSet
7+
* @typedef {import('./lib/file-set.js').FileSet} FileSet
88
* @typedef {import('./lib/index.js').Options} Options
9-
* @typedef {import('./lib/index.js').PresetSupportingSpecifiers} Preset
10-
* @typedef {import('./lib/index.js').ResolveFrom} ResolveFrom
9+
* @typedef {import('./lib/configuration.js').PresetSupportingSpecifiers} Preset
10+
* @typedef {import('./lib/ignore.js').ResolveFrom} ResolveFrom
1111
* @typedef {import('./lib/index.js').VFileReporter} VFileReporter
1212
*/
1313

lib/configuration.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
2-
* @typedef {import('unified').Plugin<Array<unknown>>} Plugin
3-
* @typedef {import('unified').PluginTuple<Array<unknown>>} PluginTuple
4-
* @typedef {import('unified').Preset} Preset
5-
* @typedef {import('unified').Settings} Settings
2+
* @import {PluginTuple, Plugin, Preset, Settings} from 'unified'
63
*/
74

85
/**
@@ -19,7 +16,7 @@
1916
* Resolved configuration.
2017
* @property {string | undefined} filePath
2118
* File path of found configuration.
22-
* @property {Array<PluginTuple>} plugins
19+
* @property {Array<PluginTuple<Array<unknown>>>} plugins
2320
* Resolved plugins.
2421
* @property {Settings} settings
2522
* Resolved settings.
@@ -61,10 +58,10 @@
6158
* @typedef {PluginSupportingSpecifiers | PluginTupleSupportingSpecifiers | Preset} PluggableSupportingSpecifiers
6259
* Usable values, with support for specifiers.
6360
*
64-
* @typedef {Plugin | string} PluginSupportingSpecifiers
61+
* @typedef {Plugin<Array<unknown>> | string} PluginSupportingSpecifiers
6562
* A plugin, or a specifier to one.
6663
*
67-
* @typedef {[plugin: string, ...parameters: Array<unknown>] | PluginTuple} PluginTupleSupportingSpecifiers
64+
* @typedef {[plugin: string, ...parameters: Array<unknown>] | PluginTuple<Array<unknown>>} PluginTupleSupportingSpecifiers
6865
* A plugin with configuration, with support for specifiers.
6966
*
7067
* @typedef PresetSupportingSpecifiers
@@ -439,7 +436,7 @@ async function merge(target, raw, options) {
439436
try {
440437
if (typeof result === 'function') {
441438
// Assume plugin.
442-
const plugin = /** @type {Plugin} */ (result)
439+
const plugin = /** @type {Plugin<Array<unknown>>} */ (result)
443440
addPlugin(plugin, value)
444441
} else {
445442
// Assume preset.
@@ -462,7 +459,7 @@ async function merge(target, raw, options) {
462459
}
463460

464461
/**
465-
* @param {Plugin} plugin
462+
* @param {Plugin<Array<unknown>>} plugin
466463
* Plugin.
467464
* @param {unknown} value
468465
* Primary parameter.
@@ -485,7 +482,7 @@ async function merge(target, raw, options) {
485482
}
486483

487484
/**
488-
* @param {PluginTuple} entry
485+
* @param {PluginTuple<Array<unknown>>} entry
489486
* Tuple.
490487
* @param {unknown} value
491488
* Primary value.
@@ -501,11 +498,11 @@ function reconfigure(entry, value) {
501498
}
502499

503500
/**
504-
* @param {Array<PluginTuple>} entries
501+
* @param {Array<PluginTuple<Array<unknown>>>} entries
505502
* Tuples.
506-
* @param {Plugin} plugin
503+
* @param {Plugin<Array<unknown>>} plugin
507504
* Plugin.
508-
* @returns {PluginTuple | undefined}
505+
* @returns {PluginTuple<Array<unknown>> | undefined}
509506
* Tuple.
510507
*/
511508
function find(entries, plugin) {

lib/file-pipeline/configure.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import createDebug from 'debug'

lib/file-pipeline/copy.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import fs from 'node:fs'

lib/file-pipeline/file-system.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import fs from 'node:fs'

lib/file-pipeline/index.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2-
* @typedef {import('trough').Pipeline} Pipeline
3-
*
4-
* @typedef {import('unified').Processor} Processor
5-
*
6-
* @typedef {import('unist').Node} Node
7-
*
8-
* @typedef {import('vfile').VFile} VFile
9-
*
10-
* @typedef {import('vfile-message').VFileMessage} VFileMessage
11-
*
12-
* @typedef {import('../configuration.js').Configuration} Configuration
13-
* @typedef {import('../file-set.js').FileSet} FileSet
14-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Pipeline} from 'trough'
3+
* @import {Processor} from 'unified'
4+
* @import {Node} from 'unist'
5+
* @import {VFileMessage} from 'vfile-message'
6+
* @import {VFile} from 'vfile'
7+
* @import {Configuration} from '../configuration.js'
8+
* @import {Settings} from '../index.js'
9+
* @import {FileSet} from '../file-set.js'
1510
*/
1611

1712
/**

lib/file-pipeline/parse.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('unist').Node} Node
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Node} from 'unist'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import createDebug from 'debug'

lib/file-pipeline/queue.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import createDebug from 'debug'

lib/file-pipeline/read.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import fs from 'node:fs'

lib/file-pipeline/stdout.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import createDebug from 'debug'

lib/file-pipeline/stringify.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
2-
* @typedef {import('vfile').VFile} VFile
3-
*
4-
* @typedef {import('./index.js').Context} Context
2+
* @import {VFile} from 'vfile'
3+
* @import {Context} from './index.js'
54
*/
65

76
import assert from 'node:assert/strict'
87
import createDebug from 'debug'
98
import {inspectColor, inspectNoColor} from 'unist-util-inspect'
109
import {statistics} from 'vfile-statistics'
1110

11+
// To do: next major: do not use `inspectColor`, `inspectNoColor`, directly.
12+
1213
const debug = createDebug('unified-engine:file-pipeline:stringify')
1314

1415
/**

lib/file-pipeline/transform.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('./index.js').Context} Context
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Context} from './index.js'
75
*/
86

97
import assert from 'node:assert/strict'

lib/file-set-pipeline/configure.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Settings} from '../index.js'
33
*/
44

55
/**

lib/file-set-pipeline/file-system.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('../configuration.js').Configuration} Configuration
7-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Configuration} from '../configuration.js'
5+
* @import {Settings} from '../index.js'
86
*/
97

108
/**
@@ -48,6 +46,9 @@ export function fileSystem(context, settings, next) {
4846
ignorePatterns: settings.ignorePatterns,
4947
silentlyIgnore: settings.silentlyIgnore
5048
},
49+
/**
50+
* @returns {undefined}
51+
*/
5152
function (error, result) {
5253
/* c8 ignore next 4 -- glob errors are unusual. */
5354
if (!result) {

lib/file-set-pipeline/log.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @typedef {import('vfile').VFile} VFile
3-
*
4-
* @typedef {import('../configuration.js').Configuration} Configuration
5-
* @typedef {import('../index.js').Settings} Settings
6-
* @typedef {import('../index.js').VFileReporter} VFileReporter
2+
* @import {VFile} from 'vfile'
3+
* @import {Configuration} from '../configuration.js'
4+
* @import {Settings, VFileReporter} from '../index.js'
75
*/
86

97
import {pathToFileURL} from 'node:url'

lib/file-set-pipeline/stdin.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Callback} from 'trough'
3+
* @import {Settings} from '../index.js'
54
*/
65

76
/**

lib/file-set-pipeline/transform.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/**
2-
* @typedef {import('trough').Callback} Callback
3-
*
4-
* @typedef {import('vfile').VFile} VFile
5-
*
6-
* @typedef {import('../configuration.js').Configuration} Configuration
7-
* @typedef {import('../index.js').Settings} Settings
2+
* @import {Callback} from 'trough'
3+
* @import {VFile} from 'vfile'
4+
* @import {Configuration} from '../configuration.js'
5+
* @import {Settings} from '../index.js'
86
*/
97

108
/**

lib/file-set.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('trough').Pipeline} Pipeline
2+
* @import {Pipeline} from 'trough'
33
*/
44

55
/**

lib/finder.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @typedef {import('node:fs').Stats} Stats
3-
* @typedef {import('ignore').Ignore} IgnorePackageClass
4-
* @typedef {import('./ignore.js').Ignore} Ignore
2+
* @import {Stats} from 'node:fs'
3+
* @import {Ignore as IgnorePackageClass} from 'ignore'
4+
* @import {Ignore} from './ignore.js'
55
*/
66

77
/**

lib/ignore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('ignore').Ignore} IgnorePackageClass
2+
* @import {Ignore as IgnorePackageClass} from 'ignore'
33
*/
44

55
/**

lib/index.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
/**
2-
* @typedef {import('unified').Processor<any, any, any, any, any>} Processor
3-
* @typedef {import('unified').Settings} UnifiedSettings
4-
*
5-
* @typedef {import('vfile').VFile} VFile
6-
*
7-
* @typedef {import('vfile-reporter').Options} VFileReporterKnownFields
8-
*
9-
* @typedef {import('./configuration.js').ConfigTransform} ConfigTransform
10-
* @typedef {import('./configuration.js').PresetSupportingSpecifiers} PresetSupportingSpecifiers
11-
* @typedef {import('./file-set.js').FileSet} FileSet
12-
* @typedef {import('./ignore.js').ResolveFrom} ResolveFrom
2+
* @import {Processor, Settings as UnifiedSettings} from 'unified'
3+
* @import {Options as VFileReporterKnownFields} from 'vfile-reporter'
4+
* @import {VFile} from 'vfile'
5+
* @import {ConfigTransform, PresetSupportingSpecifiers} from './configuration.js'
6+
* @import {FileSet} from './file-set.js'
7+
* @import {ResolveFrom} from './ignore.js'
8+
* @import {Context} from './index.js'
139
*/
1410

1511
/**
@@ -108,7 +104,7 @@
108104
* Prefix to use when searching for plugins (optional).
109105
* @property {PresetSupportingSpecifiers['plugins'] | undefined} [plugins]
110106
* Plugins to use (optional).
111-
* @property {() => Processor} processor
107+
* @property {() => Processor<any, any, any, any, any>} processor
112108
* Unified processor to transform files (required).
113109
* @property {boolean | undefined} [quiet=false]
114110
* Do not report successful files (default: `false`); given to the reporter.

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ files, and more.
120120

121121
```js
122122
/**
123-
* @typedef {import('unified-engine').Callback} Callback
123+
* @import {Callback} from 'unified-engine'
124124
*/
125125

126126
import process from 'node:process'

test/completers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('unified-engine').FileSet} FileSet
2+
* @import {FileSet} from 'unified-engine'
33
*/
44

55
import assert from 'node:assert/strict'

0 commit comments

Comments
 (0)