prettify-bru 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/format.mjs +31 -0
  2. package/package.json +1 -1
package/lib/format.mjs CHANGED
@@ -48,6 +48,16 @@ export async function format(originalContents, only = null) {
48
48
  }
49
49
  }
50
50
 
51
+ if (only === null) {
52
+ const fileBodyBlockOutcome = formatFilePaths(fileOutcome.newContents)
53
+ if (fileBodyBlockOutcome.errorMessage !== null) {
54
+ fileOutcome.errorMessages.push(fileBodyBlockOutcome.errorMessage)
55
+ } else if (fileBodyBlockOutcome.changeable) {
56
+ fileOutcome.changeable = true
57
+ fileOutcome.newContents = fileBodyBlockOutcome.fileContents
58
+ }
59
+ }
60
+
51
61
  const overallOutcome = formatOverallStructure(fileOutcome.newContents)
52
62
  if (overallOutcome.changeable) {
53
63
  fileOutcome.changeable = true
@@ -109,6 +119,27 @@ async function formatBlock(fileContents, blockName, parser) {
109
119
  return outcome
110
120
  }
111
121
 
122
+ /**
123
+ * @param {string} fileContents
124
+ * @returns {fileContents: string, changeable: boolean, errorMessage: ?string}
125
+ */
126
+ function formatFilePaths(fileContents) {
127
+ let changeable = false
128
+
129
+ const matches = fileContents.matchAll(/file: @file\(([^)]+)\)/g)
130
+
131
+ matches.forEach(match => {
132
+ const path = match[1]
133
+ if (path.match(/\\/) !== null) {
134
+ const newPath = path.replaceAll('\\', '/')
135
+ changeable = true
136
+ fileContents = fileContents.replace(path, newPath)
137
+ }
138
+ })
139
+
140
+ return {fileContents, changeable, errorMessage: null}
141
+ }
142
+
112
143
  /**
113
144
  * @param {string} fileContents
114
145
  * @returns {fileContents: string, changeable: boolean}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettify-bru",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Prettifies JSON and JavaScript blocks in Bruno .bru files",
5
5
  "keywords": [
6
6
  "bruno",