Skip to content

Commit 3581b43

Browse files
committed
Merge branch 'main' of https://github.com/prettier/prettier-cli into stdin-filepath-test-fixes
2 parents 12698fe + fbdab1e commit 3581b43

14 files changed

Lines changed: 344 additions & 351 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ on:
88

99
jobs:
1010
test:
11-
name: Build & Test
12-
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os:
15+
- "ubuntu-latest"
16+
- "macos-latest"
17+
- "windows-latest"
18+
runs-on: ${{ matrix.os }}
19+
name: Build & Test (${{ matrix.os }})
1320
steps:
1421
- uses: actions/checkout@v4
1522

package-lock.json

Lines changed: 280 additions & 297 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"repository": "github:prettier/prettier-cli",
44
"description": "A faster CLI for Prettier.",
55
"license": "MIT",
6-
"version": "0.7.1",
6+
"version": "0.8.0",
77
"type": "module",
88
"main": "dist/index.js",
99
"types": "./dist/index.d.ts",
@@ -13,7 +13,7 @@
1313
"exports": {
1414
".": "./dist/index.js",
1515
"./bin": "./dist/bin.js",
16-
"./package.json": "./package.json"
16+
"./*": "./*"
1717
},
1818
"files": [
1919
"dist"
@@ -37,44 +37,43 @@
3737
"dependencies": {
3838
"atomically": "^2.0.3",
3939
"fast-ignore": "^1.1.3",
40-
"find-up-json": "^2.0.4",
41-
"function-once": "^3.0.0",
40+
"find-up-json": "^2.0.5",
41+
"function-once": "^3.0.1",
4242
"import-meta-resolve": "^4.1.0",
43-
"is-binary-path": "^2.1.0",
43+
"is-binary-path": "^3.0.0",
4444
"js-yaml": "^4.1.0",
45-
"json-sorted-stringify": "^1.0.0",
45+
"json-sorted-stringify": "^1.0.1",
4646
"json5": "^2.2.3",
47-
"kasi": "^1.1.0",
48-
"lomemo": "^1.0.0",
49-
"pioppo": "^1.2.0",
50-
"promise-resolve-timeout": "^2.0.0",
51-
"smol-toml": "^1.3.1",
47+
"kasi": "^1.1.1",
48+
"lomemo": "^1.0.1",
49+
"pioppo": "^1.2.1",
50+
"promise-resolve-timeout": "^2.0.1",
51+
"smol-toml": "^1.3.4",
5252
"specialist": "^1.4.5",
5353
"tiny-editorconfig": "^1.0.0",
54-
"tiny-jsonc": "^1.0.1",
5554
"tiny-readdir": "^2.7.4",
56-
"tiny-readdir-glob": "^1.23.1",
57-
"tiny-spinner": "^2.0.4",
55+
"tiny-readdir-glob": "^1.23.2",
56+
"tiny-spinner": "^2.0.5",
5857
"worktank": "^2.7.3",
59-
"zeptomatch": "^2.0.0",
60-
"zeptomatch-escape": "^1.0.0",
61-
"zeptomatch-is-static": "^1.0.0"
58+
"zeptomatch": "^2.0.1",
59+
"zeptomatch-escape": "^1.0.1",
60+
"zeptomatch-is-static": "^1.0.1"
6261
},
6362
"devDependencies": {
64-
"@types/jest": "^29.5.12",
63+
"@types/jest": "^29.5.14",
6564
"@types/js-yaml": "^4.0.9",
66-
"@types/node": "^20.12.7",
65+
"@types/node": "^22.15.10",
6766
"cross-env": "^7.0.3",
6867
"dedent": "^1.5.3",
6968
"jest": "^29.7.0",
70-
"jest-snapshot-serializer-ansi": "^2.1.0",
69+
"jest-snapshot-serializer-ansi": "^2.2.1",
7170
"jest-snapshot-serializer-raw": "^2.0.0",
7271
"json-archive": "^2.1.0",
7372
"nanoexec": "^1.1.0",
74-
"prettier": "3.3.3",
75-
"radix64-encoding": "^2.0.1",
76-
"tiny-dirname": "^1.0.1",
77-
"typescript": "^5.4.5",
73+
"prettier": "3.5.3",
74+
"radix64-encoding": "^2.0.2",
75+
"tiny-dirname": "^1.0.2",
76+
"typescript": "^5.8.3",
7877
"zeptoid": "^1.0.2"
7978
}
8079
}

src/bin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ const makeWarnedPluggableBin = async (): Promise<Bin> => {
322322

323323
const runBin = async (): Promise<void> => {
324324
const bin = await makeWarnedPluggableBin();
325-
bin.run();
325+
await bin.run();
326326
};
327327

328-
runBin();
328+
// Exposed for test, we can also consider use TLA someday
329+
export const __promise = runBin();

src/config_prettier.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import JSONC from "tiny-jsonc";
3+
import url from "node:url";
44
import zeptomatch from "zeptomatch";
55
import Known from "./known.js";
66
import { fastJoinedPath, fastRelativeChildPath, getModulePath } from "./utils.js";
@@ -15,19 +15,14 @@ const Loaders = {
1515
return loader(filePath);
1616
},
1717
js: async (filePath: string): Promise<unknown> => {
18-
const module = await import(filePath);
18+
const module = await import(url.pathToFileURL(filePath).href);
1919
return module.default || module.exports || module.prettier || module;
2020
},
2121
json: async (filePath: string): Promise<unknown> => {
2222
const fileContent = fs.readFileSync(filePath, "utf8");
2323
const config = JSON.parse(fileContent);
2424
return config;
2525
},
26-
jsonc: async (filePath: string): Promise<unknown> => {
27-
const fileContent = fs.readFileSync(filePath, "utf8");
28-
const config = JSONC.parse(fileContent);
29-
return config;
30-
},
3126
json5: async (filePath: string): Promise<unknown> => {
3227
const fileContent = fs.readFileSync(filePath, "utf8");
3328
const JSON5 = (await import("json5")).default;
@@ -70,7 +65,6 @@ const File2Loader: Record<string, (filePath: string) => Promise<unknown>> = {
7065
".prettierrc.yml": Loaders.yaml,
7166
".prettierrc.yaml": Loaders.yaml,
7267
".prettierrc.json": Loaders.json,
73-
".prettierrc.jsonc": Loaders.jsonc,
7468
".prettierrc.json5": Loaders.json5,
7569
".prettierrc.toml": Loaders.toml,
7670
".prettierrc.js": Loaders.js,
@@ -86,7 +80,6 @@ const Ext2Loader: Record<string, (filePath: string) => Promise<unknown>> = {
8680
yml: Loaders.yaml,
8781
yaml: Loaders.yaml,
8882
json: Loaders.json,
89-
jsonc: Loaders.jsonc,
9083
json5: Loaders.json5,
9184
toml: Loaders.toml,
9285
js: Loaders.js,

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const DEFAULT_PARSERS = [
2121
"scss",
2222
"json",
2323
"json5",
24+
"jsonc",
2425
"json-stringify",
2526
"graphql",
2627
"markdown",

src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Known from "./known.js";
1212
import Logger from "./logger.js";
1313
import { makePrettier } from "./prettier.js";
1414
import { castArray, getExpandedFoldersPaths, getFoldersChildrenPaths, getPluginsVersions, getProjectPath, getStdin, getTargetsPaths } from "./utils.js";
15-
import { fastRelativePath, isNull, isString, isUndefined, negate, pluralize, trimFinalNewline, uniq, without } from "./utils.js";
15+
import { fastRelativePath, isNull, isString, isUndefined, negate, pluralize, trimFinalNewline, uniq, without, normalizeToPosix } from "./utils.js";
1616
import type { FormatOptions, Options, PluginsOptions } from "./types.js";
1717

1818
async function run(options: Options, pluginsDefaultOptions: PluginsOptions, pluginsCustomOptions: PluginsOptions): Promise<void> {
@@ -194,11 +194,11 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions,
194194
} else {
195195
totalUnformatted += 1;
196196
const filePath = filesPathsTargets[i];
197-
const fileRelativePath = fastRelativePath(rootPath, filePath);
197+
const fileNameToDisplay = normalizeToPosix(fastRelativePath(rootPath, filePath));
198198
if (options.check) {
199-
stderr.prefixed.warn(fileRelativePath);
199+
stderr.prefixed.warn(fileNameToDisplay);
200200
} else if (options.list || options.write) {
201-
stdout.warn(fileRelativePath);
201+
stdout.warn(fileNameToDisplay);
202202
}
203203
}
204204
}
@@ -212,12 +212,12 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions,
212212
totalErrored += 1;
213213
pathsErrored.push(filesPathsTargets[i]);
214214
const filePath = filesPathsTargets[i];
215-
const fileRelativePath = fastRelativePath(rootPath, filePath);
215+
const fileNameToDisplay = normalizeToPosix(fastRelativePath(rootPath, filePath));
216216
//TODO: Make sure the error is syntax-highlighted when possible
217217
if (options.check || options.write) {
218-
stderr.prefixed.error(`${fileRelativePath}: ${error}`);
218+
stderr.prefixed.error(`${fileNameToDisplay}: ${error}`);
219219
} else if (options.list) {
220-
stderr.error(fileRelativePath);
220+
stderr.error(fileNameToDisplay);
221221
}
222222
}
223223
}
@@ -229,9 +229,9 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions,
229229
stdout.prefixed.debug(`Files formatted: ${totalFormatted}`);
230230
stdout.prefixed.debug(`Files unformatted: ${totalUnformatted}`);
231231
stdout.prefixed.debug(`Files unknown: ${totalUnknown}`);
232-
stdout.prefixed.debug(() => pathsUnknown.map((filePath) => fastRelativePath(rootPath, filePath)).join("\n"));
232+
stdout.prefixed.debug(() => pathsUnknown.map((filePath) => normalizeToPosix(fastRelativePath(rootPath, filePath))).join("\n"));
233233
stdout.prefixed.debug(`Files errored: ${totalErrored}`);
234-
stdout.prefixed.debug(() => pathsErrored.map((filePath) => fastRelativePath(rootPath, filePath)).join("\n"));
234+
stdout.prefixed.debug(() => pathsErrored.map((filePath) => normalizeToPosix(fastRelativePath(rootPath, filePath))).join("\n"));
235235

236236
if (!totalMatched && !totalIgnored) {
237237
if (options.errorOnUnmatchedPattern) {

src/prettier_serial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFile, writeFile } from "atomically";
22
import process from "node:process";
3-
import prettier from "prettier/standalone";
3+
import * as prettier from "prettier/standalone";
44
import { getPluginsOrExit, getPluginsBuiltin, resolve } from "./utils.js";
55
import type { ContextOptions, LazyFormatOptions, PluginsOptions } from "./types.js";
66

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type FormatOptions = {
2020
insertPragma?: boolean;
2121
jsxSingleQuote?: boolean;
2222
objectWrap?: "preserve" | "collapse";
23-
parser?: "flow" | "babel" | "babel-flow" | "babel-ts" | "typescript" | "acorn" | "espree" | "meriyah" | "css" | "less" | "scss" | "json" | "json5" | "json-stringify" | "graphql" | "markdown" | "mdx" | "vue" | "yaml" | "glimmer" | "html" | "angular" | "lwc"; // prettier-ignore
23+
parser?: "flow" | "babel" | "babel-flow" | "babel-ts" | "typescript" | "acorn" | "espree" | "meriyah" | "css" | "less" | "scss" | "json" | "jsonc" | "json5" | "json-stringify" | "graphql" | "markdown" | "mdx" | "vue" | "yaml" | "glimmer" | "html" | "angular" | "lwc"; // prettier-ignore
2424
plugins?: string[];
2525
printWidth?: number;
2626
proseWrap?: "always" | "never" | "preserve";

0 commit comments

Comments
 (0)