Support absolute path in config file (#15666)
This commit is contained in:
1 parent
ddf223a3ff
commit
44949eb5dc
4 files changed
+37
No files matched your search
@@ -0,0 +1,15 @@
|
||||
#### Support absolute path as plugin in config file (#15666 by @fisker)
|
||||
|
||||
```js
|
||||
// prettier.config.cjs
|
||||
module.exports = {
|
||||
plugins: [
|
||||
// posix style
|
||||
"/path/to/plugin.js",
|
||||
// Windows style
|
||||
"D:\\\\path\\to\\plugin.js",
|
||||
// Use `require.resolve`
|
||||
require.resolve("my-awesome-prettier-plugin"),
|
||||
],
|
||||
};
|
||||
```
|
||||
@@ -16,6 +16,10 @@ const loadPluginFromDirectory = mem(
|
||||
);
|
||||
|
||||
const importPlugin = mem(async (name) => {
|
||||
if (path.isAbsolute(name)) {
|
||||
return import(pathToFileURL(name).href);
|
||||
}
|
||||
|
||||
try {
|
||||
// try local files
|
||||
return await import(pathToFileURL(path.resolve(name)).href);
|
||||
|
||||
@@ -62,3 +62,14 @@ describe("loads --plugin by bespoke plugin name (assuming it is installed in cwd
|
||||
write: [],
|
||||
});
|
||||
});
|
||||
|
||||
describe.only("support absolute path in config file", () => {
|
||||
runCli("cli/config/plugins/absolute-path", ["--parser=uppercase-rocks"], {
|
||||
input: "prettier should be uppercase",
|
||||
}).test({
|
||||
stdout: "PRETTIER SHOULD BE UPPERCASE",
|
||||
stderr: "",
|
||||
status: 0,
|
||||
write: [],
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import path from 'node:path'
|
||||
|
||||
export default {
|
||||
plugins: [
|
||||
path.resolve('../../../../../config/prettier-plugins/prettier-plugin-uppercase-rocks/index.js')
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user