Skip to content

Commit b135659

Browse files
committedJul 2, 2021
Update dependencies
* Update to [`vfile@5`](https://github.com/vfile/vfile/releases/tag/5.0.0). Notable: Rename `vfile.contents` -> `vfile.value` * Update to [`load-plugin@4`](https://github.com/wooorm/load-plugin/releases/tag/4.0.0) Notable: Node’s new module resolution is now used: before you could use `x` to load `x.js` or `x/index.js`, now you must be explicit. * Update to [`unist-util-inspect@6`](https://github.com/syntax-tree/unist-util-inspect/releases/tag/6.0.0) and [`unist-util-inspect@7`](https://github.com/syntax-tree/unist-util-inspect/releases/tag/7.0.0) Notable: Using `inspect: true` now gives improved insights
1 parent 8595952 commit b135659

File tree

47 files changed

+155
-161
lines changed

Some content is hidden

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

47 files changed

+155
-161
lines changed
 

‎lib/configuration.js

+39-49
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import path from 'path'
22
import jsYaml from 'js-yaml'
33
import parseJson from 'parse-json'
44
import createDebug from 'debug'
5-
import loadPlugin from 'load-plugin'
5+
import {resolvePlugin} from 'load-plugin'
66
import isPlainObj from 'is-plain-obj'
7-
import fault from 'fault'
7+
import {fault} from 'fault'
88
import {FindUp} from './find-up.js'
99

1010
const debug = createDebug('unified-engine:configuration')
@@ -81,26 +81,26 @@ async function create(buf, filePath) {
8181
const fn = (filePath && loaders[path.extname(filePath)]) || defaultLoader
8282
const options = {prefix: this.pluginPrefix, cwd: this.cwd}
8383
const result = {settings: {}, plugins: []}
84-
let contents
84+
let value
8585

8686
if (filePath) {
87-
contents = await Reflect.apply(fn, this, arguments)
87+
value = await fn.call(this, buf, filePath)
8888
}
8989

90-
if (this.configTransform && contents !== undefined) {
91-
contents = this.configTransform(contents, filePath)
90+
if (this.configTransform && value !== undefined) {
91+
value = this.configTransform(value, filePath)
9292
}
9393

9494
// Exit if we did find a `package.json`, but it does not have configuration.
9595
if (
9696
buf &&
97-
contents === undefined &&
97+
value === undefined &&
9898
path.basename(filePath) === 'package.json'
9999
) {
100100
return
101101
}
102102

103-
if (contents === undefined) {
103+
if (value === undefined) {
104104
if (this.defaultConfig) {
105105
await merge(
106106
result,
@@ -111,7 +111,7 @@ async function create(buf, filePath) {
111111
} else {
112112
await merge(
113113
result,
114-
contents,
114+
value,
115115
Object.assign({}, options, {root: path.dirname(filePath)})
116116
)
117117
}
@@ -126,7 +126,7 @@ function loadScriptOrModule(_, filePath) {
126126
}
127127

128128
function loadYaml(buf, filePath) {
129-
return jsYaml.safeLoad(buf, {filename: path.basename(filePath)})
129+
return jsYaml.load(buf, {filename: path.basename(filePath)})
130130
}
131131

132132
function loadJson(buf, filePath) {
@@ -201,34 +201,37 @@ async function merge(target, raw, options) {
201201
}
202202

203203
async function addModule(id, value) {
204-
let fp = loadPlugin.resolve(id, {cwd: options.root, prefix: options.prefix})
205-
let result
206-
207-
if (fp) {
208-
result = await loadFromAbsolutePath(fp, options.root)
209-
210-
try {
211-
if (typeof result === 'function') {
212-
addPlugin(result, value)
213-
} else {
214-
await merge(
215-
target,
216-
result,
217-
Object.assign({}, options, {root: path.dirname(fp)})
218-
)
219-
}
220-
} catch {
221-
throw fault(
222-
'Error: Expected preset or plugin, not %s, at `%s`',
204+
let fp
205+
206+
try {
207+
fp = await resolvePlugin(id, {
208+
cwd: options.root,
209+
prefix: options.prefix
210+
})
211+
} catch (error) {
212+
addPlugin(() => {
213+
throw fault('Could not find module `%s`\n%s', id, error.stack)
214+
}, value)
215+
return
216+
}
217+
218+
const result = await loadFromAbsolutePath(fp, options.root)
219+
220+
try {
221+
if (typeof result === 'function') {
222+
addPlugin(result, value)
223+
} else {
224+
await merge(
225+
target,
223226
result,
224-
path.relative(options.root, fp)
227+
Object.assign({}, options, {root: path.dirname(fp)})
225228
)
226229
}
227-
} else {
228-
fp = path.relative(options.cwd, path.resolve(options.root, id))
229-
addPlugin(
230-
failingModule(fp, new Error('Could not find module `' + id + '`')),
231-
value
230+
} catch {
231+
throw fault(
232+
'Error: Expected preset or plugin, not %s, at `%s`',
233+
result,
234+
path.relative(options.root, fp)
232235
)
233236
}
234237
}
@@ -262,26 +265,13 @@ function find(entries, plugin) {
262265
}
263266
}
264267

265-
function failingModule(id, error) {
266-
const cache = failingModule.cache || (failingModule.cache = {})
267-
const submodule = own.call(cache, id) ? cache[id] : (cache[id] = fail)
268-
return submodule
269-
function fail() {
270-
throw error
271-
}
272-
}
273-
274268
async function loadFromAbsolutePath(fp, base) {
275269
let result
276270

277271
try {
278272
result = (await import(fp)).default
279273
} catch (error) {
280-
throw fault(
281-
'Cannot parse script `%s`\n%s',
282-
path.relative(base, fp),
283-
error.stack
284-
)
274+
throw fault('Cannot import `%s`\n%s', path.relative(base, fp), error.stack)
285275
}
286276

287277
if (result && typeof result === 'object' && result.__esModule) {

‎lib/file-pipeline/configure.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import createDebug from 'debug'
2-
import statistics from 'vfile-statistics'
2+
import {statistics} from 'vfile-statistics'
33
import isEmpty from 'is-empty'
44

55
const debug = createDebug('unified-engine:file-pipeline:configure')

0 commit comments

Comments
 (0)
Please sign in to comment.