Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC DRAFT WIP] globby@10 update (with fast-glob implementation) #6748

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
"parentless",
"parser's",
"pcss",
"pify",
"Pierzchała",
"Pieter",
"pomber",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"find-project-root": "1.1.1",
"flow-parser": "0.89.0",
"get-stream": "5.1.0",
"globby": "6.1.0",
"globby": "10.0.1",
"graphql": "14.5.8",
"html-element-attributes": "2.2.0",
"html-styles": "1.0.0",
Expand Down Expand Up @@ -78,6 +78,7 @@
"@babel/preset-env": "7.6.3",
"@rollup/plugin-replace": "2.2.0",
"babel-loader": "8.0.6",
"babel-plugin-transform-async-to-promises": "0.8.15",
"benchmark": "2.1.4",
"builtin-modules": "3.1.0",
"codecov": "codecov/codecov-node#e427d900309adb50746a39a50aa7d80071a5ddd0",
Expand All @@ -95,6 +96,7 @@
"jest-snapshot-serializer-raw": "1.1.0",
"jest-watch-typeahead": "0.4.0",
"mkdirp": "0.5.1",
"pify": "4.0.1",
"prettier": "1.18.2",
"prettylint": "1.0.0",
"rimraf": "3.0.0",
Expand Down
9 changes: 8 additions & 1 deletion scripts/build/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ function getBabelConfig(bundle) {
targets.browsers = [">0.25%", "not ie 11", "not op_mini all"];
}
config.presets = [
[require.resolve("@babel/preset-env"), { targets, modules: false }]
[
require.resolve("@babel/preset-env"),
{
targets,
exclude: ["transform-async-to-generator"],
modules: false
}
]
];
return config;
}
Expand Down
15 changes: 12 additions & 3 deletions scripts/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ const coreBundles = [
externals: [path.resolve("src/common/third-party.js")],
replace: {
// from @iarna/toml/parse-string
"eval(\"require('util').inspect\")": "require('util').inspect"
}
"eval(\"require('util').inspect\")": "require('util').inspect",

// `util.promisify` required by `globby` is not available until node 8
"const {promisify} = require('util')": "const promisify = require('pify')"
},
babelPlugins: ["babel-plugin-transform-async-to-promises"]
},
{
input: "src/doc/index.js",
Expand All @@ -173,7 +177,12 @@ const coreBundles = [
type: "core",
output: "bin-prettier.js",
target: "node",
externals: [path.resolve("src/common/third-party.js")]
externals: [path.resolve("src/common/third-party.js")],
replace: {
// `util.promisify` required by `globby` is not available until node 8
"const {promisify} = require('util')": "const promisify = require('pify')"
},
babelPlugins: ["babel-plugin-transform-async-to-promises"]
},
{
input: "src/common/third-party.js",
Expand Down
9 changes: 7 additions & 2 deletions src/cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ function createIgnorerFromContextOrDie(context) {
}

function eachFilename(context, patterns, callback) {
// workaround for fast-glob on Windows ref:
// https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
patterns = patterns.map(path => path.replace(/\\/g, "/"));

// The '!./' globs are due to https://github.com/prettier/prettier/issues/2110
const ignoreNodeModules = context.argv["with-node-modules"] !== true;
if (ignoreNodeModules) {
Expand All @@ -410,8 +414,9 @@ function eachFilename(context, patterns, callback) {

try {
const filePaths = globby
.sync(patterns, { dot: true, nodir: true })
.map(filePath => path.relative(process.cwd(), filePath));
.sync(patterns, { dot: true })
.map(filePath => path.relative(process.cwd(), filePath))
.sort();

if (filePaths.length === 0) {
context.logger.error(
Expand Down
20 changes: 12 additions & 8 deletions src/common/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ function loadPlugins(plugins, pluginSearchDirs) {
}

function findPluginsInNodeModules(nodeModulesDir) {
const pluginPackageJsonPaths = globby.sync(
[
"prettier-plugin-*/package.json",
"@*/prettier-plugin-*/package.json",
"@prettier/plugin-*/package.json"
],
{ cwd: nodeModulesDir }
return (
globby
.sync(
[
"prettier-plugin-*/package.json",
"@*/prettier-plugin-*/package.json",
"@prettier/plugin-*/package.json"
],
{ cwd: nodeModulesDir }
)
// post-processing:
.map(path.dirname)
);
return pluginPackageJsonPaths.map(path.dirname);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is not right here, you can work on this, restore this will pass all test, but very slow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fisker, I will take a look at this. I may need to ask for some more hints online (I will deal with the code changes if needed).

Sorry to hear about the troubles with your laptop. I am also having some troubles, using a virtual server to help with development on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its late in China, going to sleep now, will back online in 9 hours, I was trying to make this fast. maybe the slice is not right just need check the glob result. lets see how fast it will be


function isDirectory(dir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ function f() {
console.log(
\\"should have no semi\\"
)
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
console.log(
\\"jest/Component.js should not have semi\\"
)
console.log(
\\"jest/Component.test.js should have semi\\"
);
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
function js() {
console.log(
\\"js/file.js should have tab width 8 (1 if CLI)\\"
Expand Down Expand Up @@ -134,9 +134,9 @@ function f() {
)
}
console.log(\\"should have no semi\\")
console.log(\\"jest/__best-tests__/file.js should have semi\\");
console.log(\\"jest/Component.js should not have semi\\")
console.log(\\"jest/Component.test.js should have semi\\");
console.log(\\"jest/__best-tests__/file.js should have semi\\");
function js() {
console.log(\\"js/file.js should have tab width 8 (1 if CLI)\\");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
exports[`support relative paths (stderr) 1`] = `""`;

exports[`support relative paths (stdout) 1`] = `
"shouldNotBeIgnored.js
level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss
"level1-glob/level2-glob/level3-glob/shouldNotBeIgnored.scss
level1-glob/shouldNotBeIgnored.js
shouldNotBeIgnored.js
"
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ function f() {
console.log(
\\"should have no semi\\"
)
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
console.log(
\\"jest/Component.js should not have semi\\"
)
console.log(
\\"jest/Component.test.js should have semi\\"
);
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
function js() {
console.log(
\\"js/file.js should have tab width 8 (1 if CLI)\\"
Expand Down Expand Up @@ -197,15 +197,15 @@ function f() {
console.log(
\\"should have no semi\\"
)
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
console.log(
\\"jest/Component.js should not have semi\\"
)
console.log(
\\"jest/Component.test.js should have semi\\"
);
console.log(
\\"jest/__best-tests__/file.js should have semi\\"
);
function js() {
console.log(
\\"js/file.js should have tab width 8 (1 if CLI)\\"
Expand Down