Skip to content

Commit 1703029

Browse files
committed
restore findPluginsInNodeModules
1 parent a1270a2 commit 1703029

3 files changed

Lines changed: 19 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"find-project-root": "1.1.1",
3838
"flow-parser": "0.89.0",
3939
"get-stream": "5.1.0",
40+
"glob": "7.1.5",
4041
"globby": "10.0.1",
4142
"graphql": "14.5.8",
4243
"html-element-attributes": "2.2.0",

src/common/load-plugins.js

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const uniqBy = require("lodash.uniqby");
44
const fs = require("fs");
5-
const globby = require("globby");
5+
const glob = require("glob");
66
const path = require("path");
77
const resolve = require("resolve");
88
const thirdParty = require("./third-party");
@@ -94,42 +94,12 @@ function loadPlugins(plugins, pluginSearchDirs) {
9494
}
9595

9696
function findPluginsInNodeModules(nodeModulesDir) {
97-
// all dirs
98-
const dirs = globby.sync(["*"], {
99-
cwd: nodeModulesDir,
100-
expandDirectories: false,
101-
deep: 1,
102-
onlyDirectories: true
103-
});
104-
105-
const scopedPackagePattern = "prettier-plugin-*";
106-
107-
const pluginPackages = Array.prototype.concat.apply(
108-
// `prettier-plugin-*` package
109-
dirs.filter(dir => dir.startsWith("prettier-plugin-")),
110-
111-
// scoped plugins
112-
dirs
113-
.filter(dir => dir[0] === "@")
114-
.map(scope => {
115-
const pattern =
116-
scope === "@prettier"
117-
? [scopedPackagePattern, "plugin-*"]
118-
: scopedPackagePattern;
119-
const dir = path.join(nodeModulesDir, scope);
120-
121-
return globby
122-
.sync(pattern, {
123-
cwd: dir,
124-
expandDirectories: false,
125-
deep: 1,
126-
onlyDirectories: true
127-
})
128-
.map(dir => scope + "/" + dir);
129-
})
97+
// `node-glob` is faster in this case
98+
const pluginPackageJsonPaths = glob.sync(
99+
"{prettier-plugin-*,@*/prettier-plugin-*,@prettier/plugin-*}/package.json",
100+
{ cwd: nodeModulesDir }
130101
);
131-
132-
return pluginPackages.sort((a, b) => a.localeCompare(b));
102+
return pluginPackageJsonPaths.map(path.dirname);
133103
}
134104

135105
function isDirectory(dir) {

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,6 +3467,18 @@ glob-parent@^5.1.0:
34673467
dependencies:
34683468
is-glob "^4.0.1"
34693469

3470+
3471+
version "7.1.5"
3472+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.5.tgz#6714c69bee20f3c3e64c4dd905553e532b40cdc0"
3473+
integrity sha512-J9dlskqUXK1OeTOYBEn5s8aMukWMwWfs+rPTn/jn50Ux4MNXVhubL1wu/j2t+H4NVI+cXEcCaYellqaPVGXNqQ==
3474+
dependencies:
3475+
fs.realpath "^1.0.0"
3476+
inflight "^1.0.4"
3477+
inherits "2"
3478+
minimatch "^3.0.4"
3479+
once "^1.3.0"
3480+
path-is-absolute "^1.0.0"
3481+
34703482
glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
34713483
version "7.1.2"
34723484
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"

0 commit comments

Comments
 (0)