Support URL in plugins options (#17166)
This commit is contained in:
1 parent
14fd0f6caf
commit
e830ad36a7
5 files changed
+94
-5
No files matched your search
Vendored
+3
-3
@@ -398,7 +398,7 @@ export interface RequiredOptions extends doc.printer.Options {
|
||||
/**
|
||||
* Provide ability to support new languages to prettier.
|
||||
*/
|
||||
plugins: Array<string | Plugin>;
|
||||
plugins: Array<string | URL | Plugin>;
|
||||
/**
|
||||
* How to handle whitespaces in HTML.
|
||||
* @default "css"
|
||||
@@ -801,7 +801,7 @@ export interface SupportInfo {
|
||||
export interface FileInfoOptions {
|
||||
ignorePath?: string | URL | (string | URL)[] | undefined;
|
||||
withNodeModules?: boolean | undefined;
|
||||
plugins?: Array<string | Plugin> | undefined;
|
||||
plugins?: Array<string | URL | Plugin> | undefined;
|
||||
resolveConfig?: boolean | undefined;
|
||||
}
|
||||
|
||||
@@ -816,7 +816,7 @@ export function getFileInfo(
|
||||
): Promise<FileInfoResult>;
|
||||
|
||||
export interface SupportInfoOptions {
|
||||
plugins?: Array<string | Plugin> | undefined;
|
||||
plugins?: Array<string | URL | Plugin> | undefined;
|
||||
showDeprecated?: boolean | undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { isUrl } from "url-or-path";
|
||||
import importFromDirectory from "../../utils/import-from-directory.js";
|
||||
|
||||
/**
|
||||
@param {string | URL} name
|
||||
@param {string} cwd
|
||||
*/
|
||||
async function importPlugin(name, cwd) {
|
||||
if (isUrl(name)) {
|
||||
// @ts-expect-error -- Pass `URL` to `import()` works too
|
||||
return import(name);
|
||||
}
|
||||
|
||||
if (path.isAbsolute(name)) {
|
||||
return import(pathToFileURL(name).href);
|
||||
}
|
||||
@@ -23,7 +33,7 @@ async function loadPluginWithoutCache(plugin, cwd) {
|
||||
|
||||
const cache = new Map();
|
||||
function loadPlugin(plugin) {
|
||||
if (typeof plugin !== "string") {
|
||||
if (typeof plugin !== "string" && !(plugin instanceof URL)) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user