Skip to content

Commit

Permalink
feat: upgrade prettier to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 6, 2023
2 parents f222333 + 25f3d27 commit 639bce1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
21 changes: 11 additions & 10 deletions compile-to-definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ const glob = require("glob");
const findCommonDir = require("commondir");
const { compile } = require("json-schema-to-typescript");

const prettierConfig = prettier.resolveConfig.sync(
path.resolve(root, outputFolder, "result.d.ts")
);
const style = {
printWidth: prettierConfig.printWidth,
useTabs: prettierConfig.useTabs,
tabWidth: prettierConfig.tabWidth,
};

const makeSchemas = () => {
const schemas = glob.sync(schemasGlob, { cwd: root, absolute: true });
const commonDir = path.resolve(findCommonDir(schemas));
Expand All @@ -31,7 +22,7 @@ const makeSchemas = () => {
}
};

const makeDefinitionsForSchema = (absSchemaPath, schemasDir) => {
const makeDefinitionsForSchema = async (absSchemaPath, schemasDir) => {
if (path.basename(absSchemaPath).startsWith("_")) return;
const relPath = path.relative(schemasDir, absSchemaPath);
const directory = path.dirname(relPath);
Expand All @@ -44,6 +35,16 @@ const makeDefinitionsForSchema = (absSchemaPath, schemasDir) => {
const schema = JSON.parse(fs.readFileSync(absSchemaPath, "utf-8"));
const keys = Object.keys(schema);
if (keys.length === 1 && keys[0] === "$ref") return;

const prettierConfig = await prettier.resolveConfig(
path.resolve(root, outputFolder, "result.d.ts")
);
const style = {
printWidth: prettierConfig.printWidth,
useTabs: prettierConfig.useTabs,
tabWidth: prettierConfig.tabWidth,
};

preprocessSchema(schema);
compile(schema, basename, {
bannerComment:
Expand Down
6 changes: 3 additions & 3 deletions format-schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ const processJson = processSchema.bind(null, {
},
});

const formatSchema = (schemaPath) => {
const formatSchema = async (schemaPath) => {
const json = require(schemaPath);
const processedJson = processJson(json, {
schema: json,
definitions: json.definitions,
importPrefix: "../".repeat(schemaPath.split(/[\\/]/).length - minSlashes),
});
const rawString = JSON.stringify(processedJson, null, 2);
const config = prettier.resolveConfig.sync(schemaPath);
const prettyString = prettier.format(rawString, config);
const config = await prettier.resolveConfig(schemaPath);
const prettyString = await prettier.format(rawString, config);
let normalizedContent = "";
try {
const content = fs.readFileSync(schemaPath, "utf-8");
Expand Down
2 changes: 1 addition & 1 deletion generate-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ const printError = (diagnostic) => {
return;
}

source = prettier.format(source, prettierOptions);
source = await prettier.format(source, prettierOptions);
} catch (e) {
exitCode = 1;
console.error(e.message);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@types/node": "^14.14.14",
"@types/yargs": "^15.0.12",
"prettier": "^2.7.1",
"prettier": "^3.0.1",
"typescript": "^5.0.4"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ prettier@^2.0.5:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.0.tgz#8a03c7777883b29b37fb2c4348c66a78e980418b"
integrity sha512-yYerpkvseM4iKD/BXLYUkQV5aKt4tQPqaGW6EsZjzyu0r7sVZZNPJW4Y8MyKmicp6t42XUPcBVA+H6sB3gqndw==

prettier@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
prettier@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.1.tgz#65271fc9320ce4913c57747a70ce635b30beaa40"
integrity sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==

punycode@^2.1.0:
version "2.1.1"
Expand Down

0 comments on commit 639bce1

Please sign in to comment.