linguist-js 2.4.1 → 2.4.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/dist/helpers/walk-tree.js +10 -5
- package/dist/index.js +6 -6
- package/package.json +4 -4
- package/readme.md +5 -5
|
@@ -5,10 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let allFiles;
|
|
9
|
+
let allFolders;
|
|
10
10
|
/** Generate list of files in a directory. */
|
|
11
|
-
function walk(root, folders, gitignores, regexIgnores) {
|
|
11
|
+
function walk(init, root, folders, gitignores, regexIgnores) {
|
|
12
|
+
// Initialise files and folders lists
|
|
13
|
+
if (init) {
|
|
14
|
+
allFiles = new Set();
|
|
15
|
+
allFolders = new Set();
|
|
16
|
+
}
|
|
12
17
|
// Walk tree of a folder
|
|
13
18
|
if (folders.length === 1) {
|
|
14
19
|
const folder = folders[0];
|
|
@@ -36,7 +41,7 @@ function walk(root, folders, gitignores, regexIgnores) {
|
|
|
36
41
|
if (file.endsWith('/')) {
|
|
37
42
|
// Recurse into subfolders
|
|
38
43
|
allFolders.add(path);
|
|
39
|
-
walk(root, [path], gitignores, regexIgnores);
|
|
44
|
+
walk(false, root, [path], gitignores, regexIgnores);
|
|
40
45
|
}
|
|
41
46
|
else {
|
|
42
47
|
// Add relative file path to list
|
|
@@ -47,7 +52,7 @@ function walk(root, folders, gitignores, regexIgnores) {
|
|
|
47
52
|
// Recurse into all folders
|
|
48
53
|
else {
|
|
49
54
|
for (const path of folders) {
|
|
50
|
-
walk(root, [path], gitignores, regexIgnores);
|
|
55
|
+
walk(false, root, [path], gitignores, regexIgnores);
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
// Return absolute files and folders lists
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,7 @@ async function analyse(input, opts = {}) {
|
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
60
|
// Uses directory on disc
|
|
61
|
-
const data = (0, walk_tree_1.default)(commonRoot, input, gitignores, regexIgnores);
|
|
61
|
+
const data = (0, walk_tree_1.default)(true, commonRoot, input, gitignores, regexIgnores);
|
|
62
62
|
files = data.files;
|
|
63
63
|
folders = data.folders;
|
|
64
64
|
}
|
|
@@ -86,7 +86,7 @@ async function analyse(input, opts = {}) {
|
|
|
86
86
|
if (!useRawContent && opts.checkAttributes) {
|
|
87
87
|
for (const folder of folders) {
|
|
88
88
|
// Skip if folder is marked in gitattributes
|
|
89
|
-
if (relPath(folder) && gitignores.
|
|
89
|
+
if (relPath(folder) && gitignores.ignores(relPath(folder)))
|
|
90
90
|
continue;
|
|
91
91
|
// Parse gitignores
|
|
92
92
|
const ignoresFile = path_1.default.join(folder, '.gitignore');
|
|
@@ -190,7 +190,7 @@ async function analyse(input, opts = {}) {
|
|
|
190
190
|
}
|
|
191
191
|
// Check override for manual language classification
|
|
192
192
|
if (!useRawContent && !opts.quick && opts.checkAttributes) {
|
|
193
|
-
const isOverridden = (path) => (0, ignore_1.default)().add(path).
|
|
193
|
+
const isOverridden = (path) => (0, ignore_1.default)().add(path).ignores(relPath(file));
|
|
194
194
|
const match = overridesArray.find(item => isOverridden(item[0]));
|
|
195
195
|
if (match) {
|
|
196
196
|
const forcedLang = match[1];
|
|
@@ -229,8 +229,8 @@ async function analyse(input, opts = {}) {
|
|
|
229
229
|
}
|
|
230
230
|
// Skip binary files
|
|
231
231
|
if (!useRawContent && !opts.keepBinary) {
|
|
232
|
-
const isCustomText = customText.
|
|
233
|
-
const isCustomBinary = customBinary.
|
|
232
|
+
const isCustomText = customText.ignores(relPath(file));
|
|
233
|
+
const isCustomBinary = customBinary.ignores(relPath(file));
|
|
234
234
|
const isBinaryExt = binary_extensions_1.default.some(ext => file.endsWith('.' + ext));
|
|
235
235
|
if (!isCustomText && (isCustomBinary || isBinaryExt || await (0, isbinaryfile_1.isBinaryFile)(file))) {
|
|
236
236
|
continue;
|
|
@@ -263,7 +263,7 @@ async function analyse(input, opts = {}) {
|
|
|
263
263
|
if (heuristic.named_pattern)
|
|
264
264
|
normalise(heuristicsData.named_patterns[heuristic.named_pattern]);
|
|
265
265
|
// Check file contents and apply heuristic patterns
|
|
266
|
-
const fileContent = await (0, read_file_1.default)(file).catch(() => null);
|
|
266
|
+
const fileContent = opts.fileContent ? opts.fileContent[files.indexOf(file)] : await (0, read_file_1.default)(file).catch(() => null);
|
|
267
267
|
if (fileContent === null)
|
|
268
268
|
continue;
|
|
269
269
|
if (!patterns.length || patterns.some(pattern => (0, convert_pcre_1.default)(pattern).test(fileContent))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linguist-js",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepare": "npm test && npm run perf",
|
|
14
14
|
"perf": "tsc && node test/perf",
|
|
15
|
-
"test": "tsc && node test/test"
|
|
15
|
+
"test": "tsc && node test/folder && echo --- && node test/unit"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"bin/",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"homepage": "https://github.com/Nixinova/Linguist#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"binary-extensions": "^2.2.0",
|
|
40
|
-
"commander": "^9.
|
|
40
|
+
"commander": "^9.1.0",
|
|
41
41
|
"common-path-prefix": "^3.0.0",
|
|
42
42
|
"cross-fetch": "^3.1.5",
|
|
43
43
|
"ignore": "^5.2.0",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"@types/js-yaml": "ts4.6",
|
|
51
51
|
"@types/node": "ts4.6",
|
|
52
52
|
"deep-object-diff": "^1.1.7",
|
|
53
|
-
"typescript": "~4.6.
|
|
53
|
+
"typescript": "~4.6.2"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://github.com/Nixinova/Linguist/releases)
|
|
3
3
|
[](https://www.npmjs.com/package/linguist-js)
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# LinguistJS
|
|
6
6
|
|
|
7
7
|
Analyses the languages of all files in a given folder and collates the results.
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ Powered by [github-linguist](https://github.com/github/linguist), although it do
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
[Node.js](https://nodejs.org) must be installed to be able to use this.
|
|
14
|
-
|
|
14
|
+
LinguistJS is available [on npm](https://npmjs.com/package/linguist-js) as `linguist-js`.
|
|
15
15
|
|
|
16
16
|
Install locally using `npm install linguist-js` and import it into your code like so:
|
|
17
17
|
|
|
@@ -27,7 +27,7 @@ linguist --help
|
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
LinguistJS contains one function which analyses a given folder.
|
|
31
31
|
|
|
32
32
|
As an example, take the following file structure:
|
|
33
33
|
|
|
@@ -40,7 +40,7 @@ As an example, take the following file structure:
|
|
|
40
40
|
| no-lang 10B
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Running
|
|
43
|
+
Running LinguistJS on this folder will return the following JSON:
|
|
44
44
|
|
|
45
45
|
```json
|
|
46
46
|
{
|
|
@@ -78,7 +78,7 @@ Running Linguist on this folder will return the following JSON:
|
|
|
78
78
|
|
|
79
79
|
- File paths in the output use only forward slashes as delimiters, even on Windows.
|
|
80
80
|
- This tool does not work when offline.
|
|
81
|
-
- Do not rely on any language classification output from
|
|
81
|
+
- Do not rely on any language classification output from LinguistJS being unchanged between runs.
|
|
82
82
|
Language data is fetched each run from the latest classifications of [`github-linguist`](https://github.com/github/linguist).
|
|
83
83
|
This data is subject to change at any time and may change the results of a run even when using the same version of Linguist.
|
|
84
84
|
|