Skip to content

Commit

Permalink
Merge pull request #946 from Accenture/bugfix/945-queries-not-correct…
Browse files Browse the repository at this point in the history
…ly-formatted-when-other-types-were-retrieved-first

Bugfix/945 queries not correctly formatted when other types were retrieved first
  • Loading branch information
JoernBerkefeld committed May 30, 2023
2 parents bea555f + 575554d commit e098cb2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Asset extends MetadataType {
static async retrieve(retrieveDir, _, subTypeArr, key) {
const items = [];
subTypeArr ||= this._getSubTypes();
await File.initPrettier();
if (retrieveDir) {
await File.initPrettier();
}
// loop through subtypes and return results of each subType for caching (saving is handled per subtype)
for (const subType of subTypeArr) {
// each subtype contains multiple different specific types (images contains jpg and png for example)
Expand Down
8 changes: 5 additions & 3 deletions lib/util/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ const File = {
* @param {string} [filetype='html'] filetype ie. JSON or SSJS
* @returns {Promise.<boolean>} success of config load
*/
async initPrettier(filetype) {
if (FileFs.prettierConfig === null) {
filetype ||= 'html';
async initPrettier(filetype = 'html') {
if (FileFs.prettierConfig === null || FileFs.prettierConfigFileType !== filetype) {
// run this if no config was yet found or if the filetype previously used to initialize it differs (because it results in a potentially different config!)
FileFs.prettierConfigFileType = filetype;
try {
// pass in project dir with fake index.html to avoid "no parser" error
// by using process.cwd we are limiting ourselves to a config in the project root
Expand Down Expand Up @@ -547,5 +548,6 @@ const File = {
};
const FileFs = { ...fs, ...File };
FileFs.prettierConfig = null;
FileFs.prettierConfigFileType = null;

module.exports = FileFs;
2 changes: 1 addition & 1 deletion test/resources/9999999/query/build-expected.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT
SubscriberKey as testField
SubscriberKey AS testField
FROM
_Subscribers
WHERE
Expand Down
2 changes: 1 addition & 1 deletion test/resources/9999999/query/get-expected.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT
SubscriberKey as testField
SubscriberKey AS testField
FROM
_Subscribers
WHERE
Expand Down
2 changes: 1 addition & 1 deletion test/resources/9999999/query/patch-expected.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT
SubscriberKey as testField
SubscriberKey AS testField
FROM
_Subscribers
WHERE
Expand Down
2 changes: 1 addition & 1 deletion test/resources/9999999/query/post-expected.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SELECT
SubscriberKey as testField
SubscriberKey AS testField
FROM
_Subscribers
2 changes: 1 addition & 1 deletion test/resources/9999999/query/template-expected.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT
SubscriberKey as testField
SubscriberKey AS testField
FROM
_Subscribers
WHERE
Expand Down

0 comments on commit e098cb2

Please sign in to comment.