diff --git a/apps/oxfmt/src-js/index.ts b/apps/oxfmt/src-js/index.ts index e8e5b96145f58..10c39478bcd15 100644 --- a/apps/oxfmt/src-js/index.ts +++ b/apps/oxfmt/src-js/index.ts @@ -84,7 +84,7 @@ export type FormatOptions = { experimentalSortImports?: SortImportsOptions; /** Experimental: Sort `package.json` keys. (Default: `true`) */ experimentalSortPackageJson?: boolean; -}; +} & Record; // Also allow additional options for we don't have typed yet. /** * Configuration options for sort imports. diff --git a/apps/oxfmt/test/__snapshots__/external_formatter_with_config.test.ts.snap b/apps/oxfmt/test/__snapshots__/external_formatter_with_config.test.ts.snap index e6e27c06a23ba..3d5e502da9338 100644 --- a/apps/oxfmt/test/__snapshots__/external_formatter_with_config.test.ts.snap +++ b/apps/oxfmt/test/__snapshots__/external_formatter_with_config.test.ts.snap @@ -26,19 +26,19 @@ export default {name:"Test",data(){return {foo:"bar",baz:123}}} --------------------" diff --git a/apps/oxfmt/test/api.test.ts b/apps/oxfmt/test/api.test.ts index 8468c6a8ed4e7..479d24ffa6893 100644 --- a/apps/oxfmt/test/api.test.ts +++ b/apps/oxfmt/test/api.test.ts @@ -39,4 +39,35 @@ describe("API Tests", () => { }); expect(errors.length).toBe(1); }); + + test("should `format()` with options work", async () => { + const pkgJSON = JSON.stringify({ + version: "1.0.0", + name: "my-package", + }); + const result1 = await format("package.json", pkgJSON); + expect(result1.code).toBe(`{\n "name": "my-package",\n "version": "1.0.0"\n}\n`); + expect(result1.errors).toStrictEqual([]); + + const result2 = await format("package.json", pkgJSON, { experimentalSortPackageJson: false }); + expect(result2.code).toBe(`{\n "version": "1.0.0",\n "name": "my-package"\n}\n`); + expect(result2.errors).toStrictEqual([]); + + const vueCode = ` + + +`.trim(); + const result3 = await format("Component.vue", vueCode, { + vueIndentScriptAndStyle: true, + }); + expect(result3.code).toBe( + ` + + +`.trimStart(), + ); + expect(result3.errors).toStrictEqual([]); + }); }); diff --git a/apps/oxfmt/test/fixtures/external_formatter_with_config/.oxfmtrc.json b/apps/oxfmt/test/fixtures/external_formatter_with_config/.oxfmtrc.json index d5ca6842b8179..e4880ab3ebcb0 100644 --- a/apps/oxfmt/test/fixtures/external_formatter_with_config/.oxfmtrc.json +++ b/apps/oxfmt/test/fixtures/external_formatter_with_config/.oxfmtrc.json @@ -2,5 +2,6 @@ "printWidth": 40, "useTabs": true, "singleQuote": true, - "embeddedLanguageFormatting": "auto" + "embeddedLanguageFormatting": "auto", + "vueIndentScriptAndStyle": true }