Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Thumbs.db

/dist
/node_modules
/test/__fixtures__/.temp-*
145 changes: 78 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"find-up-json": "^2.0.5",
"function-once": "^3.0.1",
"import-meta-resolve": "^4.1.0",
"is-binary-path": "^3.0.0",
"is-binary-path": "^2.0.0",
"js-yaml": "^4.1.0",
"json-sorted-stringify": "^1.0.1",
"json5": "^2.2.3",
Expand All @@ -54,7 +54,7 @@
"tiny-readdir": "^2.7.4",
"tiny-readdir-glob": "^1.23.2",
"tiny-spinner": "^2.0.5",
"worktank": "^2.7.3",
"worktank": "^3.0.2",
"zeptomatch": "^2.0.1",
"zeptomatch-escape": "^1.0.1",
"zeptomatch-is-static": "^1.0.1"
Expand Down
14 changes: 10 additions & 4 deletions src/prettier_parallel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import os from "node:os";
import process from "node:process";
import WorkTank from "worktank";
import { resolve } from "./utils.js";
import type { Options, Prettier } from "./types.js";

function makeParallel(options: Options): Prettier {
const pool = new WorkTank<Prettier>({
name: "prettier",
size: options.parallelWorkers || Math.max(1, os.cpus().length - 1),
methods: new URL("./prettier_serial.js", import.meta.url),
warmup: true,
pool: {
name: "prettier",
size: options.parallelWorkers || Math.max(1, os.cpus().length - 1),
},
worker: {
autoInstantiate: true,
env: process.env,
methods: new URL("./prettier_serial.js", import.meta.url),
},
});

return {
Expand Down
11 changes: 9 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,15 @@ async function getTargetsPaths(
}

const filesExplicitPaths = targetFiles;
const filesFoundPaths = globResult.filesFound;
const foldersFoundPaths = [rootPath, ...globResult.directoriesFound];

const globFilesFoundPaths = globResult.filesFound;
const directoryFilesFoundPaths = directoriesResultsFiles.flat();
const filesFoundPaths = [...globFilesFoundPaths, ...directoryFilesFoundPaths];

const globFoldersFoundPaths = globResult.directoriesFound;
const directoryFoldersFoundPaths = directoriesResults.flatMap((result) => result.directories);
const foldersFoundPaths = [rootPath, ...globFoldersFoundPaths, ...directoryFoldersFoundPaths];

return [filesPaths, filesNames, filesNamesToPaths, filesExplicitPaths, filesFoundPaths, foldersFoundPaths];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
overrides: [
{
files: ["dir/*.foo"],
options: {
plugins: ["../plugin-extensions/plugin.cjs"]
}
},
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.foo
3 changes: 3 additions & 0 deletions test/__fixtures__/infer-plugins-ext-dir-with-config/foo.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
plugins: ["../plugin-extensions/plugin.cjs"],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
plugins: ["../plugin-default-options/plugin.cjs"]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main() {
console.log("Hello, World!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
overrides: [
{
// TODO (43081j): in prettier, this was `*.foo` and would successfully
// match `src/*.foo`. In prettier CLI, this is not the case
files: ["**/*.foo"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@fabiospampinato this one seems like something we should discuss/decide before we merge these tests

it seems prettier treats *.foo as if it was **/*.foo, whereas we treat it as ./*.foo

i think we're correct, but this means a whole bunch of prettier configs may fail with our CLI. maybe we should do a special case that transforms "*.ext" into "**/*.ext"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I think so, no need to break the world here. The problem is that this is a bit tricky, what is the actual logic that we want? Worth checking what v3 is actually doing, because there are many potential ways to implement something like this.

I imagine we should try to explode the glob and do something with that in some cases 🤔

I think we can skip this test for now and fix it later if it's the only blocker for this test suite.

Is everything else basically just copy/pasted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pretty much, just the paths changed to the mock/fixture extensions. The rest should be the same

options: {
plugins: ["../plugin-default-options/plugin.cjs"]
}
}
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contents
Loading