linguist-js 2.9.2 → 3.0.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.
- package/bin/index.js +1 -1
- package/dist/analyser/classifiers/byAttributes.d.ts +3 -0
- package/dist/analyser/classifiers/byAttributes.js +13 -0
- package/dist/analyser/classifiers/byExtension.d.ts +3 -0
- package/dist/analyser/classifiers/byExtension.js +31 -0
- package/dist/analyser/classifiers/byFilename.d.ts +3 -0
- package/dist/analyser/classifiers/byFilename.js +10 -0
- package/dist/analyser/classifiers/byHeuristics.d.ts +3 -0
- package/dist/analyser/classifiers/byHeuristics.js +67 -0
- package/dist/analyser/classifiers/byModeline.d.ts +3 -0
- package/dist/analyser/classifiers/byModeline.js +22 -0
- package/dist/analyser/classifiers/byShebang.d.ts +3 -0
- package/dist/analyser/classifiers/byShebang.js +27 -0
- package/dist/analyser/index.d.ts +3 -0
- package/dist/analyser/index.js +12 -0
- package/dist/analyser/pipeline/aggregate.d.ts +4 -0
- package/dist/analyser/pipeline/aggregate.js +98 -0
- package/dist/analyser/pipeline/classify.d.ts +3 -0
- package/dist/analyser/pipeline/classify.js +32 -0
- package/dist/analyser/pipeline/filter.d.ts +2 -0
- package/dist/analyser/pipeline/filter.js +14 -0
- package/dist/analyser/pipeline/heuristics.d.ts +3 -0
- package/dist/analyser/pipeline/heuristics.js +12 -0
- package/dist/analyser/pipeline/normalise.d.ts +2 -0
- package/dist/analyser/pipeline/normalise.js +9 -0
- package/dist/cli/output/default.d.ts +3 -0
- package/dist/cli/output/default.js +106 -0
- package/dist/cli/output/tree.d.ts +3 -0
- package/dist/cli/output/tree.js +11 -0
- package/dist/cli/runCliAnalysis.d.ts +2 -0
- package/dist/cli/runCliAnalysis.js +26 -0
- package/dist/cli/utils.d.ts +2 -0
- package/dist/cli/utils.js +9 -0
- package/dist/cli.js +14 -143
- package/dist/entry/analyseFs.d.ts +2 -0
- package/dist/entry/analyseFs.js +11 -0
- package/dist/entry/analyseRaw.d.ts +4 -0
- package/dist/entry/analyseRaw.js +11 -0
- package/dist/index.d.ts +19 -4
- package/dist/index.js +18 -483
- package/dist/input/fromFilesystem.d.ts +4 -0
- package/dist/input/fromFilesystem.js +115 -0
- package/dist/input/fromRawContent.d.ts +2 -0
- package/dist/input/fromRawContent.js +19 -0
- package/dist/input/normaliseOpts.d.ts +2 -0
- package/dist/input/normaliseOpts.js +13 -0
- package/dist/program/classes/attributes.d.ts +11 -0
- package/dist/program/classes/attributes.js +37 -0
- package/dist/program/data/loadDataFiles.d.ts +4 -0
- package/dist/program/data/loadDataFiles.js +32 -0
- package/dist/program/data/retrieveData.d.ts +12 -0
- package/dist/program/data/retrieveData.js +27 -0
- package/dist/program/fs/normalisedPath.d.ts +3 -0
- package/dist/program/fs/normalisedPath.js +17 -0
- package/dist/program/fs/readFile.js +17 -0
- package/dist/program/fs/walkTree.d.ts +20 -0
- package/dist/program/fs/walkTree.js +82 -0
- package/dist/program/parsing/parseGitattributes.d.ts +17 -0
- package/dist/program/parsing/parseGitattributes.js +33 -0
- package/dist/program/parsing/parseGitignore.js +9 -0
- package/dist/program/processFiles.d.ts +9 -0
- package/dist/program/processFiles.js +111 -0
- package/dist/program/utils/pcre.js +35 -0
- package/dist/src/cli/output/default.d.ts +3 -0
- package/dist/src/cli/output/default.js +106 -0
- package/dist/src/cli/output/tree.d.ts +3 -0
- package/dist/src/cli/output/tree.js +11 -0
- package/dist/src/cli/runCliAnalysis.d.ts +2 -0
- package/dist/src/cli/runCliAnalysis.js +25 -0
- package/dist/src/cli/utils.d.ts +2 -0
- package/dist/src/cli/utils.js +9 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.js +56 -0
- package/dist/src/helpers/convert-pcre.d.ts +2 -0
- package/dist/src/helpers/parse-gitignore.d.ts +1 -0
- package/dist/src/helpers/read-file.d.ts +5 -0
- package/dist/{helpers → src/helpers}/read-file.js +1 -1
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +470 -0
- package/dist/src/program/data/loadData.d.ts +4 -0
- package/dist/src/program/data/loadData.js +32 -0
- package/dist/src/program/fs/normalisedPath.d.ts +2 -0
- package/dist/src/program/fs/normalisedPath.js +7 -0
- package/dist/src/program/fs/readFile.d.ts +5 -0
- package/dist/src/program/fs/readFile.js +17 -0
- package/dist/src/program/fs/walkTree.d.ts +20 -0
- package/dist/src/program/fs/walkTree.js +82 -0
- package/dist/src/program/parsing/parseGitattributes.d.ts +17 -0
- package/dist/src/program/parsing/parseGitattributes.js +33 -0
- package/dist/src/program/parsing/parseGitignore.d.ts +1 -0
- package/dist/src/program/parsing/parseGitignore.js +9 -0
- package/dist/src/program/utils/pcre.d.ts +2 -0
- package/dist/src/program/utils/pcre.js +35 -0
- package/dist/src/types/schema.d.ts +37 -0
- package/dist/src/types/schema.js +1 -0
- package/dist/src/types/types.d.ts +65 -0
- package/dist/src/types/types.js +1 -0
- package/dist/types/schema.d.ts +37 -0
- package/dist/types/schema.js +1 -0
- package/dist/types/types.d.ts +84 -0
- package/dist/types/types.js +1 -0
- package/ext/generated.rb +6 -0
- package/ext/heuristics.yml +102 -11
- package/ext/languages.yml +526 -88
- package/ext/vendor.yml +1 -0
- package/package.json +14 -13
- package/readme.md +99 -111
- /package/dist/{helpers/read-file.d.ts → program/fs/readFile.d.ts} +0 -0
- /package/dist/{helpers/parse-gitignore.d.ts → program/parsing/parseGitignore.d.ts} +0 -0
- /package/dist/{helpers/convert-pcre.d.ts → program/utils/pcre.d.ts} +0 -0
- /package/dist/{helpers → src/helpers}/convert-pcre.js +0 -0
- /package/dist/{helpers → src/helpers}/load-data.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/load-data.js +0 -0
- /package/dist/{helpers → src/helpers}/norm-path.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/norm-path.js +0 -0
- /package/dist/{helpers → src/helpers}/parse-gitattributes.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/parse-gitattributes.js +0 -0
- /package/dist/{helpers → src/helpers}/parse-gitignore.js +0 -0
- /package/dist/{helpers → src/helpers}/walk-tree.d.ts +0 -0
- /package/dist/{helpers → src/helpers}/walk-tree.js +0 -0
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
package/ext/vendor.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linguist-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Analyse languages used in a folder
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Analyse the programming languages used in a folder or from raw content, using the same rules that GitHub Linguist does.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"bin": {
|
|
7
8
|
"linguist-js": "bin/index.js",
|
|
8
9
|
"linguist": "bin/index.js"
|
|
9
10
|
},
|
|
10
11
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
12
|
-
"npm": ">=
|
|
12
|
+
"node": ">=26",
|
|
13
|
+
"npm": ">=10"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"download-files": "
|
|
16
|
+
"download-files": "node build/download-files.ts",
|
|
16
17
|
"pre-publish": "npm run download-files && npm test && npm run perf",
|
|
17
18
|
"perf": "tsc && node test/perf",
|
|
18
19
|
"test": "tsc && node test/folder && node test/unit"
|
|
@@ -39,19 +40,19 @@
|
|
|
39
40
|
},
|
|
40
41
|
"homepage": "https://github.com/Nixinova/Linguist#readme",
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"binary-extensions": "^
|
|
43
|
-
"commander": "^
|
|
43
|
+
"binary-extensions": "^3.1.0",
|
|
44
|
+
"commander": "^14.0.3",
|
|
44
45
|
"common-path-prefix": "^3.0.0",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"js-yaml": "^4.1.0",
|
|
46
|
+
"ignore": "^7.0.5",
|
|
47
|
+
"isbinaryfile": "^6.0.0",
|
|
48
|
+
"js-yaml": "^4.1.1",
|
|
49
49
|
"node-cache": "^5.1.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/js-yaml": "^4.0.9",
|
|
53
|
-
"@types/node": "
|
|
53
|
+
"@types/node": "^25.9.1",
|
|
54
54
|
"deep-object-diff": "^1.1.9",
|
|
55
|
-
"
|
|
55
|
+
"prettier": "^3.8.3",
|
|
56
|
+
"typescript": "~6.0.3"
|
|
56
57
|
}
|
|
57
58
|
}
|
package/readme.md
CHANGED
|
@@ -29,7 +29,7 @@ linguist-js --help
|
|
|
29
29
|
|
|
30
30
|
## Usage
|
|
31
31
|
|
|
32
|
-
LinguistJS
|
|
32
|
+
LinguistJS analyses a folder, or a dictionary of already-read file content, and determines what programming languages are used within.
|
|
33
33
|
|
|
34
34
|
As an example, take the following file structure:
|
|
35
35
|
|
|
@@ -38,89 +38,66 @@ As an example, take the following file structure:
|
|
|
38
38
|
| src
|
|
39
39
|
| | cli.js 1kB
|
|
40
40
|
| | index.ts 2kB
|
|
41
|
-
|
|
|
41
|
+
| info.md 3kB
|
|
42
42
|
| no-lang 10B
|
|
43
|
-
| x.pluginspec 10B
|
|
44
43
|
```
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
This may be represented in object form as a mapping of file path to file content.
|
|
46
|
+
|
|
47
|
+
Running LinguistJS on this will return the following JSON:
|
|
47
48
|
|
|
48
49
|
```json
|
|
49
50
|
{
|
|
50
51
|
"files": {
|
|
51
|
-
"count":
|
|
52
|
-
"bytes":
|
|
53
|
-
"lines": {
|
|
54
|
-
"total": 100,
|
|
55
|
-
"content": 90,
|
|
56
|
-
"code": 80,
|
|
57
|
-
},
|
|
52
|
+
"count": 4,
|
|
53
|
+
"bytes": 31,
|
|
54
|
+
"lines": { "total": 8, "content": 4, "code": 4 },
|
|
58
55
|
"results": {
|
|
59
|
-
"/
|
|
60
|
-
"/src/cli.js": "JavaScript",
|
|
61
|
-
"/readme.md": "Markdown",
|
|
56
|
+
"/info.md": "Markdown",
|
|
62
57
|
"/no-lang": null,
|
|
63
|
-
"/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"/x.pluginspec": ["XML"],
|
|
67
|
-
},
|
|
58
|
+
"/src/cli.js": "JavaScript",
|
|
59
|
+
"/src/index.ts": "TypeScript"
|
|
60
|
+
}
|
|
68
61
|
},
|
|
69
62
|
"languages": {
|
|
70
63
|
"count": 3,
|
|
71
|
-
"bytes":
|
|
72
|
-
"lines": {
|
|
73
|
-
"total": 90,
|
|
74
|
-
"content": 80,
|
|
75
|
-
"code": 70,
|
|
76
|
-
},
|
|
64
|
+
"bytes": 18,
|
|
65
|
+
"lines": { "total": 6, "content": 3, "code": 3 },
|
|
77
66
|
"results": {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"type": "programming",
|
|
98
|
-
"bytes": 2000,
|
|
99
|
-
"lines": { "total": 30, "content": 25, "code": 20 },
|
|
100
|
-
"color": "#2b7489"
|
|
101
|
-
},
|
|
102
|
-
},
|
|
67
|
+
"Markdown": {
|
|
68
|
+
"type": "prose",
|
|
69
|
+
"bytes": 6,
|
|
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
|
+
}
|
|
85
|
+
}
|
|
103
86
|
},
|
|
104
87
|
"unknown": {
|
|
105
88
|
"count": 1,
|
|
106
|
-
"bytes":
|
|
107
|
-
"lines": {
|
|
108
|
-
"total": 10,
|
|
109
|
-
"content": 10,
|
|
110
|
-
"code": 10,
|
|
111
|
-
},
|
|
112
|
-
"filenames": {
|
|
113
|
-
"no-lang": 10,
|
|
114
|
-
},
|
|
89
|
+
"bytes": 13,
|
|
90
|
+
"lines": { "total": 2, "content": 1, "code": 1 },
|
|
115
91
|
"extensions": {},
|
|
116
|
-
|
|
92
|
+
"filenames": { "no-lang": 13 }
|
|
93
|
+
}
|
|
117
94
|
}
|
|
118
95
|
```
|
|
119
96
|
|
|
120
97
|
### Notes
|
|
121
98
|
|
|
122
99
|
- File paths in the output use only forward slashes as delimiters, even on Windows.
|
|
123
|
-
- Unless running in offline mode
|
|
100
|
+
- Unless running in offline mode: do not rely on any language classification output from LinguistJS being unchanged between runs.
|
|
124
101
|
Language data is fetched each run from the latest classifications of [`github-linguist`](https://github.com/github/linguist).
|
|
125
102
|
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.
|
|
126
103
|
|
|
@@ -129,75 +106,86 @@ Running LinguistJS on this folder will return the following JSON:
|
|
|
129
106
|
### Node
|
|
130
107
|
|
|
131
108
|
```js
|
|
132
|
-
|
|
109
|
+
import linguist from 'linguist-js';
|
|
133
110
|
|
|
134
111
|
// Analyse folder on disc
|
|
135
|
-
const
|
|
112
|
+
const folders = ['./src'];
|
|
136
113
|
const options = { keepVendored: false, quick: false };
|
|
137
|
-
const { files, languages, unknown } = await linguist(folder, options);
|
|
114
|
+
const { files, languages, unknown, repository } = await linguist.analyseFolders(folder, options);
|
|
138
115
|
|
|
139
116
|
// Analyse file content from raw input
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
117
|
+
const fileContent = {
|
|
118
|
+
['file1.ts']: '#!/usr/bin/env node',
|
|
119
|
+
['file2.ts']: 'console.log("Example");',
|
|
120
|
+
['ignoreme.js']: 'ignored!',
|
|
121
|
+
}
|
|
122
|
+
const options = { ignoredFiles: ['ignoreme.*'] };
|
|
123
|
+
const { files, languages, unknown, repository } = await linguist.analyseRawContent(fileContent, options);
|
|
144
124
|
```
|
|
145
125
|
|
|
146
|
-
|
|
126
|
+
**Exports:**
|
|
127
|
+
|
|
128
|
+
- `analyseFolders(folders?, opts?)`:
|
|
129
|
+
Analyse the language of all files found in a folder or folders.
|
|
130
|
+
- `folders` (optional; string array):
|
|
131
|
+
A list of folders to analyse (defaults to `['./']`).
|
|
132
|
+
- `opts` (optional; object):
|
|
133
|
+
An object containing analyser options.
|
|
134
|
+
- `analyseRawContent(folders?, opts?)`:
|
|
147
135
|
Analyse the language of all files found in a folder or folders.
|
|
148
136
|
- `entry` (optional; string or string array):
|
|
149
|
-
|
|
137
|
+
A list of folders to analyse (defaults to `['./']`).
|
|
150
138
|
- `opts` (optional; object):
|
|
151
139
|
An object containing analyser options.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
140
|
+
|
|
141
|
+
**Analyser options:**
|
|
142
|
+
- `ignoredFiles` (string array):
|
|
143
|
+
A list of file path globs to explicitly ignore.
|
|
144
|
+
- `ignoredLanguages` (string array):
|
|
145
|
+
A list of languages to ignore.
|
|
146
|
+
- `categories` (string array):
|
|
147
|
+
A list of programming language categories that should be included in the results.
|
|
148
|
+
Defaults to `['data', 'markup', 'programming', 'prose']`.
|
|
149
|
+
- `childLanguages` (boolean):
|
|
150
|
+
Whether to display sub-languages instead of their parents when possible (defaults to `false`).
|
|
151
|
+
- `quick` (boolean):
|
|
152
|
+
Whether to skip complex language analysis such as the checking of heuristics and gitattributes statements (defaults to `false`).
|
|
153
|
+
Alias for `checkAttributes:false, checkIgnored:false, checkDetected:false, checkHeuristics:false, checkShebang:false, checkModeline:false`.
|
|
154
|
+
- `offline` (boolean):
|
|
155
|
+
Whether to use pre-packaged metadata files instead of fetching them from GitHub at runtime (defaults to `false`).
|
|
156
|
+
- `calculateLines` (boolean):
|
|
157
|
+
Whether to calculate line of code totals (defaults to `true`).
|
|
158
|
+
- `keepVendored` (boolean):
|
|
159
|
+
Whether to keep vendored files (dependencies, etc) (defaults to `false`).
|
|
160
|
+
Does nothing when `fileContent` is set.
|
|
161
|
+
- `keepBinary` (boolean):
|
|
162
|
+
Whether binary files should be included in the output (defaults to `false`).
|
|
163
|
+
- `relativePaths` (boolean):
|
|
164
|
+
Change the absolute file paths in the output to be relative to the current working directory (defaults to `false`).
|
|
165
|
+
- `checkAttributes` (boolean):
|
|
166
|
+
Force the checking of `.gitattributes` files (defaults to `true` unless `quick` is set).
|
|
167
|
+
Does nothing when `fileContent` is set.
|
|
168
|
+
- `checkIgnored` (boolean):
|
|
169
|
+
Force the checking of `.gitignore` files (defaults to `true` unless `quick` is set).
|
|
170
|
+
Does nothing when `fileContent` is set.
|
|
171
|
+
- `checkDetected` (boolean):
|
|
172
|
+
Force files marked with `linguist-detectable` to show up in the output, even if the file is not part of the declared `categories`.
|
|
173
|
+
- `checkHeuristics` (boolean):
|
|
174
|
+
Apply heuristics to ambiguous languages (defaults to `true` unless `quick` is set).
|
|
175
|
+
- `checkShebang` (boolean):
|
|
176
|
+
Check shebang (`#!`) lines for explicit language classification (defaults to `true` unless `quick` is set).
|
|
177
|
+
- `checkModeline` (boolean):
|
|
178
|
+
Check modelines for explicit language classification (defaults to `true` unless `quick` is set).
|
|
191
179
|
|
|
192
180
|
### Command-line
|
|
193
181
|
|
|
194
182
|
```
|
|
195
|
-
linguist --
|
|
183
|
+
linguist --analyse [<folders...>] [<options...>]
|
|
196
184
|
linguist --help
|
|
197
185
|
linguist --version
|
|
198
186
|
```
|
|
199
187
|
|
|
200
|
-
- `--
|
|
188
|
+
- `--analyse`:
|
|
201
189
|
Analyse the language of all files found in a folder or folders.
|
|
202
190
|
- `[<folders...>]`:
|
|
203
191
|
The folders to analyse (defaults to `./`).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|