turtb 0.5.0 → 0.5.2
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.
- package/lib/utils/fileTransformer.js +2 -2
- package/package.json +1 -1
- package/src/proxyFolder.js +10 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const textFileExtensions = ['js', 'html', 'css', 'txt', 'gitignore']
|
|
1
|
+
export const textFileExtensions = ['js', 'html', 'css', 'txt', 'gitignore', 'svg', 'env', 'node_repl_history', 'LICENSE', 'webmanifest']
|
|
2
2
|
export const jsonFileExtensions = ['json']
|
|
3
3
|
|
|
4
4
|
export const TEXT_FILE = 'text file'
|
|
@@ -6,7 +6,7 @@ export const JSON_FILE = 'json file'
|
|
|
6
6
|
export const BINARY_FILE = 'binary file'
|
|
7
7
|
|
|
8
8
|
export const pathToType = path => {
|
|
9
|
-
const extension = path.split(
|
|
9
|
+
const extension = path.split(/\b/).pop()
|
|
10
10
|
if (textFileExtensions.includes(extension)) return TEXT_FILE
|
|
11
11
|
if (jsonFileExtensions.includes(extension)) return JSON_FILE
|
|
12
12
|
return BINARY_FILE
|
package/package.json
CHANGED
package/src/proxyFolder.js
CHANGED
|
@@ -4,9 +4,7 @@ import { logError } from '../lib/utils/logger.js'
|
|
|
4
4
|
import { deepEqual } from '../lib/utils/deepEqual.js'
|
|
5
5
|
import { Recaller } from '../lib/utils/Recaller.js'
|
|
6
6
|
import { subscribe } from '@parcel/watcher'
|
|
7
|
-
|
|
8
|
-
export const isLinesOfTextExtension = path => path.match(/\.(html|css|js|svg|txt|gitignore|env|node_repl_history)$/)
|
|
9
|
-
export const isJSONExtension = path => path.match(/\.(json)$/)
|
|
7
|
+
import { BINARY_FILE, JSON_FILE, pathToType } from '../lib/utils/fileTransformer.js'
|
|
10
8
|
|
|
11
9
|
export const encodeTextFile = object => {
|
|
12
10
|
if (!object || typeof object !== 'object') throw new Error('encodeFile requires an object')
|
|
@@ -17,18 +15,18 @@ export const encodeTextFile = object => {
|
|
|
17
15
|
const decodeBufferAsFileObject = (buffer, path) => {
|
|
18
16
|
if (!buffer?.isBuffer?.() && !(buffer instanceof Uint8Array)) return buffer
|
|
19
17
|
const uint8Array = new Uint8Array(buffer)
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
if (!isLinesOfText && !isJSON) return uint8Array
|
|
18
|
+
const type = pathToType(path)
|
|
19
|
+
if (type === BINARY_FILE) return uint8Array
|
|
23
20
|
const decoder = new TextDecoder('utf-8')
|
|
24
21
|
const str = decoder.decode(uint8Array)
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
if (type === JSON_FILE) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(str)
|
|
25
|
+
} catch (err) {
|
|
26
|
+
logError(() => console.error(`error parsing (file:${path})`))
|
|
27
|
+
}
|
|
31
28
|
}
|
|
29
|
+
return str.split(/\r?\n/)
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export const equalFileObjects = (a, b, path) => {
|