diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba1d4ac0..ec0832349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to the "prettier-vscode" extension will be documented in thi +## [9.12.0] + +- Support Prettier v3 + ## [9.11.0] - Prettier 2.8.7 diff --git a/package.json b/package.json index 221a29dfd..4a4ff34a7 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "scripts": { "clean": "node ./scripts/clean.js", "lint": "eslint -c .eslintrc.js --ext .ts .", - "pretest": "yarn test-compile && cd test-fixtures/plugins && yarn install && cd ../plugins-pnpm && pnpm i && cd ../outdated && yarn install && cd ../module && yarn install && cd ../specific-version && yarn install && cd ../explicit-dep && yarn install && cd implicit-dep && yarn install", + "pretest": "yarn test-compile && cd test-fixtures/plugins && yarn install && cd ../plugins-pnpm && pnpm i && cd ../outdated && yarn install && cd ../module && yarn install && cd ../specific-version && yarn install && cd ../explicit-dep && yarn install && cd implicit-dep && yarn install && cd ../../v3 && yarn install", "prettier": "prettier --write '**/*.{ts,json,md,hbs,yml,js}'", "test-compile": "yarn clean && tsc -p ./ && yarn webpack", "test": "node ./out/test/runTests.js", diff --git a/src/ModuleResolver.ts b/src/ModuleResolver.ts index 410a359d2..9c0c69abf 100644 --- a/src/ModuleResolver.ts +++ b/src/ModuleResolver.ts @@ -324,7 +324,7 @@ export class ModuleResolver implements ModuleResolverInterface { * Clears the module and config cache */ public async dispose() { - prettier.clearConfigCache(); + await prettier.clearConfigCache(); this.path2Module.forEach((module) => { try { module.clearConfigCache(); diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index 250980df8..1e60acc06 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -255,7 +255,7 @@ export default class PrettierEditService implements Disposable { prettierInstance: PrettierModule, uri?: Uri ): Promise => { - const { languages } = prettierInstance.getSupportInfo(); + const { languages } = await prettierInstance.getSupportInfo(); languages.forEach((lang) => { if (lang && lang.vscodeLanguageIds) { @@ -442,7 +442,7 @@ export default class PrettierEditService implements Disposable { this.loggingService.logWarning( `Parser not inferred, trying VS Code language.` ); - const languages = prettierInstance.getSupportInfo().languages; + const { languages } = await prettierInstance.getSupportInfo(); parser = getParserFromLanguageId(languages, uri, languageId); } @@ -465,7 +465,11 @@ export default class PrettierEditService implements Disposable { this.loggingService.logInfo("Prettier Options:", prettierOptions); try { - const formattedText = prettierInstance.format(text, prettierOptions); + // Since Prettier v3, `format` returns Promise. + const formattedText = await prettierInstance.format( + text, + prettierOptions + ); this.statusBar.update(FormatterStatus.Success); return formattedText; diff --git a/src/TemplateService.ts b/src/TemplateService.ts index 4fc7741db..25173b11d 100644 --- a/src/TemplateService.ts +++ b/src/TemplateService.ts @@ -20,7 +20,7 @@ export class TemplateService { useTabs: settings.useTabs, }; - const templateSource = this.prettierModule.format( + const templateSource = await this.prettierModule.format( JSON.stringify(settings, null, 2), formatterOptions ); diff --git a/src/test/suite/format.test.ts b/src/test/suite/format.test.ts index 10bb941d9..4ad5b2ec5 100644 --- a/src/test/suite/format.test.ts +++ b/src/test/suite/format.test.ts @@ -92,7 +92,7 @@ async function formatSameAsPrettier( }, }; const { actual, source } = await format("project", file); - const prettierFormatted = prettier.format(source, prettierOptions); + const prettierFormatted = await prettier.format(source, prettierOptions); assert.equal(actual, prettierFormatted); } diff --git a/src/test/suite/v3.test.ts b/src/test/suite/v3.test.ts new file mode 100644 index 000000000..50c23ea29 --- /dev/null +++ b/src/test/suite/v3.test.ts @@ -0,0 +1,11 @@ +import * as assert from "assert"; +import { format, getText } from "./format.test"; + +suite("Tests for Prettier v3", function () { + this.timeout(10000); + test("it formats by Prettier v3", async () => { + const { actual } = await format("v3", "index.ts"); + const expected = await getText("v3", "index.result.ts"); + assert.equal(actual, expected); + }); +}); diff --git a/test-fixtures/test.code-workspace b/test-fixtures/test.code-workspace index b6dbeeb5d..53748ac1c 100644 --- a/test-fixtures/test.code-workspace +++ b/test-fixtures/test.code-workspace @@ -35,6 +35,9 @@ }, { "path": "explicit-dep" + }, + { + "path": "v3" } ], "settings": { diff --git a/test-fixtures/v3/index.result.ts b/test-fixtures/v3/index.result.ts new file mode 100644 index 000000000..b4c2a2204 --- /dev/null +++ b/test-fixtures/v3/index.result.ts @@ -0,0 +1,6 @@ +const Counter = decorator("my-counter")((props: { + initialCount?: number; + label?: string; +}) => { + // ... +}); diff --git a/test-fixtures/v3/index.ts b/test-fixtures/v3/index.ts new file mode 100644 index 000000000..3174ca3c6 --- /dev/null +++ b/test-fixtures/v3/index.ts @@ -0,0 +1,5 @@ +const Counter = decorator("my-counter")( + (props: { initialCount?: number; label?: string }) => { + // ... + } +); diff --git a/test-fixtures/v3/package.json b/test-fixtures/v3/package.json new file mode 100644 index 000000000..a4f5ff9cf --- /dev/null +++ b/test-fixtures/v3/package.json @@ -0,0 +1,15 @@ +{ + "name": "v3", + "version": "1.0.0", + "description": "Test folder for Prettier v3", + "private": true, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Prettier", + "license": "MIT", + "devDependencies": { + "prettier": "3.0.0-alpha.6" + }, + "dependencies": {} +} diff --git a/test-fixtures/v3/yarn.lock b/test-fixtures/v3/yarn.lock new file mode 100644 index 000000000..849f35251 --- /dev/null +++ b/test-fixtures/v3/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +prettier@3.0.0-alpha.6: + version "3.0.0-alpha.6" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.0-alpha.6.tgz#c562f9f54966aff792c6920e6a29fbffd1ae07b6" + integrity sha512-AdbQSZ6Oo+iy9Ekzmsgno05P1uX2vqPkjOMJqRfP8hTe+m6iDw4Nt7bPFpWZ/HYCU+3f0P5U0o2ghxQwwkLH7A==