diff --git a/lib/configuration.js b/lib/configuration.js index 5d21f2c..2a2d303 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -84,7 +84,7 @@ import assert from 'node:assert/strict' import path from 'node:path' -import {pathToFileURL} from 'node:url' +import {fileURLToPath, pathToFileURL} from 'node:url' import structuredClone from '@ungap/structured-clone' import createDebug from 'debug' import isPlainObj from 'is-plain-obj' @@ -421,11 +421,11 @@ async function merge(target, raw, options) { */ async function addModule(id, value) { /** @type {string} */ - let fp + let fileUrl try { - fp = await resolvePlugin(id, { - cwd: options.root, + fileUrl = await resolvePlugin(id, { + from: pathToFileURL(options.root) + '/', prefix: options.prefix }) } catch (error) { @@ -435,7 +435,7 @@ async function merge(target, raw, options) { return } - const result = await loadFromAbsolutePath(fp, options.root) + const result = await loadFromAbsolutePath(fileUrl, options.root) try { if (typeof result === 'function') { @@ -445,14 +445,17 @@ async function merge(target, raw, options) { } else { // Assume preset. const preset = /** @type {Preset} */ (result) - await merge(target, preset, {...options, root: path.dirname(fp)}) + await merge(target, preset, { + ...options, + root: path.dirname(fileURLToPath(fileUrl)) + }) } } catch (error) { throw new Error( 'Expected preset or plugin, not `' + result + '`, at `' + - path.relative(options.root, fp) + + path.relative(options.root, fileURLToPath(fileUrl)) + '`', {cause: error} ) @@ -518,17 +521,17 @@ function find(entries, plugin) { } /** - * @param {string} fp + * @param {string} fileUrl * Specifier. * @param {string} base * Base. * @returns {Promise} * Result. */ -async function loadFromAbsolutePath(fp, base) { +async function loadFromAbsolutePath(fileUrl, base) { try { /** @type {ImportResult} */ - const result = await import(pathToFileURL(fp).href) + const result = await import(fileUrl) if (!('default' in result)) { throw new Error( @@ -538,8 +541,9 @@ async function loadFromAbsolutePath(fp, base) { return result.default } catch (error) { - throw new Error('Cannot import `' + path.relative(base, fp) + '`', { - cause: error - }) + throw new Error( + 'Cannot import `' + path.relative(base, fileURLToPath(fileUrl)) + '`', + {cause: error} + ) } } diff --git a/lib/file-set-pipeline/log.js b/lib/file-set-pipeline/log.js index 775b5f0..df8c9d9 100644 --- a/lib/file-set-pipeline/log.js +++ b/lib/file-set-pipeline/log.js @@ -6,6 +6,7 @@ * @typedef {import('../index.js').VFileReporter} VFileReporter */ +import {pathToFileURL} from 'node:url' import {loadPlugin} from 'load-plugin' import {reporter} from 'vfile-reporter' @@ -35,7 +36,7 @@ export async function log(context, settings) { // Assume a valid reporter. const result = /** @type {VFileReporter} */ ( await loadPlugin(settings.reporter, { - cwd: settings.cwd, + from: pathToFileURL(settings.cwd) + '/', prefix: 'vfile-reporter' }) ) diff --git a/package.json b/package.json index d636fbe..1e87d03 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "ignore": "^5.0.0", "is-empty": "^1.0.0", "is-plain-obj": "^4.0.0", - "load-plugin": "^5.0.0", + "load-plugin": "^6.0.0", "parse-json": "^7.0.0", "trough": "^2.0.0", "unist-util-inspect": "^8.0.0",