From 8a3fed2a11a4add374159eabbb1d5f006db6b599 Mon Sep 17 00:00:00 2001 From: Blake Date: Fri, 16 Aug 2024 16:22:36 -0400 Subject: [PATCH] #1574 Fix overwriting parser --- @types/lib/util/file.d.ts.map | 2 +- lib/util/file.js | 102 ++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/@types/lib/util/file.d.ts.map b/@types/lib/util/file.d.ts.map index 8bbbbba9d..732257fc7 100644 --- a/@types/lib/util/file.d.ts.map +++ b/@types/lib/util/file.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../lib/util/file.js"],"names":[],"mappings":";yBAUa,OAAO,wBAAwB,EAAE,UAAU;uBAC3C,OAAO,wBAAwB,EAAE,QAAQ;oBACzC,OAAO,wBAAwB,EAAE,KAAK;0BACtC,OAAO,wBAAwB,EAAE,WAAW;8BAC5C,OAAO,wBAAwB,EAAE,eAAe;2BAChD,OAAO,wBAAwB,EAAE,YAAY;sBAC7C,OAAO,wBAAwB,EAAE,OAAO;+BACxC,OAAO,wBAAwB,EAAE,gBAAgB;mCACjD,OAAO,wBAAwB,EAAE,oBAAoB;kCACrD,OAAO,wBAAwB,EAAE,mBAAmB;8BACpD,OAAO,wBAAwB,EAAE,eAAe;iCAChD,OAAO,wBAAwB,EAAE,kBAAkB;oCACnD,OAAO,wBAAwB,EAAE,qBAAqB;mCACtD,OAAO,wBAAwB,EAAE,oBAAoB;gCACrD,OAAO,wBAAwB,EAAE,iBAAiB;0BAClD,OAAO,wBAAwB,EAAE,WAAW;2BAC5C,OAAO,wBAAwB,EAAE,YAAY;AAqiB1D;;;IAnhBI;;;;;;OAMG;yBAHQ,MAAM,MACN,MAAM,GACJ,OAAO,CAAE;QAAC,MAAM,EAAC,IAAI,GAAC,SAAS,GAAC,QAAQ,CAAC;QAAC,aAAa,EAAC,MAAM,CAAC;QAAC,IAAI,EAAC,MAAM,CAAA;KAAC,CAAC;IAkB1F;;;;;OAKG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/util/file.js index c47a19826..23e7eeff4 100644 --- a/lib/util/file.js +++ b/lib/util/file.js @@ -260,57 +260,61 @@ const File = { // will throw an error falsely assuming bad syntax return await this.beautify_beautyAmp(content, true); } - // load the right prettier config relative to our file - switch (filetype) { - case 'htm': - case 'html': { - FileFs.prettierConfig.parser = 'html'; - break; - } - case 'ssjs': - case 'js': { - FileFs.prettierConfig.parser = 'babel'; - break; - } - case 'json': { - FileFs.prettierConfig.parser = 'json'; - break; - } - case 'yaml': - case 'yml': { - FileFs.prettierConfig.parser = 'yaml'; - break; - } - case 'ts': { - FileFs.prettierConfig.parser = 'babel-ts'; - break; - } - case 'css': { - FileFs.prettierConfig.parser = 'css'; - break; - } - case 'less': { - FileFs.prettierConfig.parser = 'less'; - break; - } - case 'sass': - case 'scss': { - FileFs.prettierConfig.parser = 'scss'; - break; - } - case 'md': { - FileFs.prettierConfig.parser = 'markdown'; - break; - } - case 'sql': { - FileFs.prettierConfig.parser = 'sql'; - FileFs.prettierConfig.plugins = ['prettier-plugin-sql']; - break; - } - default: { - FileFs.prettierConfig.parser = 'babel'; + + if (!FileFs.prettierConfig.parser) { + // load the right prettier config relative to our file + switch (filetype) { + case 'htm': + case 'html': { + FileFs.prettierConfig.parser = 'html'; + break; + } + case 'ssjs': + case 'js': { + FileFs.prettierConfig.parser = 'babel'; + break; + } + case 'json': { + FileFs.prettierConfig.parser = 'json'; + break; + } + case 'yaml': + case 'yml': { + FileFs.prettierConfig.parser = 'yaml'; + break; + } + case 'ts': { + FileFs.prettierConfig.parser = 'babel-ts'; + break; + } + case 'css': { + FileFs.prettierConfig.parser = 'css'; + break; + } + case 'less': { + FileFs.prettierConfig.parser = 'less'; + break; + } + case 'sass': + case 'scss': { + FileFs.prettierConfig.parser = 'scss'; + break; + } + case 'md': { + FileFs.prettierConfig.parser = 'markdown'; + break; + } + case 'sql': { + FileFs.prettierConfig.parser = 'sql'; + FileFs.prettierConfig.plugins = ['prettier-plugin-sql']; + break; + } + default: { + FileFs.prettierConfig.parser = 'babel'; + } } } + formatted = await prettier.format(content, FileFs.prettierConfig); } catch (ex) { // save prettier errror into log file