|
2 | 2 |
|
3 | 3 | const uniqBy = require("lodash.uniqby"); |
4 | 4 | const fs = require("fs"); |
5 | | -const globby = require("globby"); |
| 5 | +const glob = require("glob"); |
6 | 6 | const path = require("path"); |
7 | 7 | const resolve = require("resolve"); |
8 | 8 | const thirdParty = require("./third-party"); |
@@ -94,42 +94,12 @@ function loadPlugins(plugins, pluginSearchDirs) { |
94 | 94 | } |
95 | 95 |
|
96 | 96 | 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 } |
130 | 101 | ); |
131 | | - |
132 | | - return pluginPackages.sort((a, b) => a.localeCompare(b)); |
| 102 | + return pluginPackageJsonPaths.map(path.dirname); |
133 | 103 | } |
134 | 104 |
|
135 | 105 | function isDirectory(dir) { |
|
0 commit comments