linguist-js 3.0.0 → 3.0.1
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import YAML from 'js-yaml';
|
|
1
2
|
import Cache from 'node-cache';
|
|
2
3
|
import FS from 'node:fs';
|
|
3
4
|
import Path from 'node:path';
|
|
@@ -14,8 +15,15 @@ async function loadWebFile(file) {
|
|
|
14
15
|
// Load file content, falling back to the local file if the request fails
|
|
15
16
|
const fileContent = await fetch(dataUrl(file))
|
|
16
17
|
.then((data) => data.text())
|
|
17
|
-
.catch(async () =>
|
|
18
|
+
.catch(async (x) => void x);
|
|
19
|
+
if (!fileContent) {
|
|
20
|
+
return await loadLocalFile(file);
|
|
21
|
+
}
|
|
18
22
|
cache.set(file, fileContent);
|
|
23
|
+
// Clean up lengthy files
|
|
24
|
+
if (file === 'generated.rb') {
|
|
25
|
+
return YAML.dump(parseGeneratedDataFile(fileContent));
|
|
26
|
+
}
|
|
19
27
|
return fileContent;
|
|
20
28
|
}
|
|
21
29
|
async function loadLocalFile(file) {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { HeuristicsSchema, LanguagesScema
|
|
1
|
+
import { HeuristicsSchema, LanguagesScema } from '../../types/schema.js';
|
|
2
2
|
type LoadedData = {
|
|
3
3
|
langData: LanguagesScema;
|
|
4
|
-
vendorData: VendorSchema;
|
|
5
|
-
docData: VendorSchema;
|
|
6
4
|
heuristicsData: HeuristicsSchema;
|
|
7
|
-
generatedData: string[];
|
|
8
5
|
vendorPaths: string[];
|
|
9
6
|
};
|
|
10
7
|
/** Load data from github-linguist web repo or cached local file. */
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import YAML from 'js-yaml';
|
|
2
|
-
import { loadFile
|
|
2
|
+
import { loadFile } from './loadDataFiles.js';
|
|
3
3
|
let data = null;
|
|
4
4
|
async function initRetrieveData(offline) {
|
|
5
|
-
// Only load the data on
|
|
5
|
+
// Only load the data on mount
|
|
6
6
|
if (data)
|
|
7
7
|
return;
|
|
8
8
|
const langData = (await loadFile('languages.yml', offline).then(YAML.load));
|
|
9
9
|
const vendorData = (await loadFile('vendor.yml', offline).then(YAML.load));
|
|
10
10
|
const docData = (await loadFile('documentation.yml', offline).then(YAML.load));
|
|
11
11
|
const heuristicsData = (await loadFile('heuristics.yml', offline).then(YAML.load));
|
|
12
|
-
const generatedData = (await loadFile('generated.rb', offline).then(
|
|
12
|
+
const generatedData = (await loadFile('generated.rb', offline).then(YAML.load));
|
|
13
13
|
const vendorPaths = [...vendorData, ...docData, ...generatedData];
|
|
14
14
|
data = {
|
|
15
15
|
langData,
|
|
16
|
-
vendorData,
|
|
17
|
-
docData,
|
|
18
16
|
heuristicsData,
|
|
19
|
-
generatedData,
|
|
20
17
|
vendorPaths,
|
|
21
18
|
};
|
|
22
19
|
}
|
|
@@ -14,6 +14,7 @@ export default function pcre(regex) {
|
|
|
14
14
|
// Remove PCRE-only syntax
|
|
15
15
|
replace(/([*+]){2}/g, '$1');
|
|
16
16
|
replace(/\(\?>/g, '(?:');
|
|
17
|
+
replace(/\\g\<[^>]+\>/g, '.*?'); // referenced named groups not supported
|
|
17
18
|
// Remove start/end-of-file markers
|
|
18
19
|
if (/\\[AZ]/.test(finalRegex)) {
|
|
19
20
|
replace(/\\A/g, '^');
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -50,8 +50,8 @@ Running LinguistJS on this will return the following JSON:
|
|
|
50
50
|
{
|
|
51
51
|
"files": {
|
|
52
52
|
"count": 4,
|
|
53
|
-
"bytes":
|
|
54
|
-
"lines": { "total":
|
|
53
|
+
"bytes": 6010,
|
|
54
|
+
"lines": { "total": 150, "content": 75 },
|
|
55
55
|
"results": {
|
|
56
56
|
"/info.md": "Markdown",
|
|
57
57
|
"/no-lang": null,
|
|
@@ -61,35 +61,25 @@ Running LinguistJS on this will return the following JSON:
|
|
|
61
61
|
},
|
|
62
62
|
"languages": {
|
|
63
63
|
"count": 3,
|
|
64
|
-
"bytes":
|
|
65
|
-
"lines": { "total":
|
|
64
|
+
"bytes": 6000,
|
|
65
|
+
"lines": { "total": 147, "content": 74 },
|
|
66
66
|
"results": {
|
|
67
|
-
"Markdown": {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"lines": { "total": 2, "content": 1, "code": 1 },
|
|
71
|
-
"color": "#083fa1"
|
|
72
|
-
},
|
|
73
|
-
"JavaScript": {
|
|
74
|
-
"type": "programming",
|
|
75
|
-
"bytes": 6,
|
|
76
|
-
"lines": { "total": 2, "content": 1, "code": 1 },
|
|
77
|
-
"color": "#f1e05a"
|
|
78
|
-
},
|
|
79
|
-
"TypeScript": {
|
|
80
|
-
"type": "programming",
|
|
81
|
-
"bytes": 6,
|
|
82
|
-
"lines": { "total": 2, "content": 1, "code": 1 },
|
|
83
|
-
"color": "#3178c6"
|
|
84
|
-
}
|
|
67
|
+
"Markdown": { "count": 1, "bytes": 3000, "lines": { "total": 10, "content": 5 } },
|
|
68
|
+
"JavaScript": { "count": 1, "bytes": 1000, "lines": { "total": 46, "content": 23 } },
|
|
69
|
+
"TypeScript": { "count": 1, "bytes": 2000, "lines": { "total": 91, "content": 46 } }
|
|
85
70
|
}
|
|
86
71
|
},
|
|
87
72
|
"unknown": {
|
|
88
73
|
"count": 1,
|
|
89
|
-
"bytes":
|
|
90
|
-
"lines": { "total":
|
|
74
|
+
"bytes": 10,
|
|
75
|
+
"lines": { "total": 3, "content": 1 },
|
|
91
76
|
"extensions": {},
|
|
92
|
-
"filenames": { "no-lang":
|
|
77
|
+
"filenames": { "no-lang": 10 }
|
|
78
|
+
},
|
|
79
|
+
"repository": {
|
|
80
|
+
"Markdown": { "type": "prose", "color": "#083fa1" },
|
|
81
|
+
"JavaScript": { "type": "programming", "color": "#f1e05a" },
|
|
82
|
+
"TypeScript": { "type": "programming", "color": "#3178c6" }
|
|
93
83
|
}
|
|
94
84
|
}
|
|
95
85
|
```
|