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.
Files changed (124) hide show
  1. package/bin/index.js +1 -1
  2. package/dist/analyser/classifiers/byAttributes.d.ts +3 -0
  3. package/dist/analyser/classifiers/byAttributes.js +13 -0
  4. package/dist/analyser/classifiers/byExtension.d.ts +3 -0
  5. package/dist/analyser/classifiers/byExtension.js +31 -0
  6. package/dist/analyser/classifiers/byFilename.d.ts +3 -0
  7. package/dist/analyser/classifiers/byFilename.js +10 -0
  8. package/dist/analyser/classifiers/byHeuristics.d.ts +3 -0
  9. package/dist/analyser/classifiers/byHeuristics.js +67 -0
  10. package/dist/analyser/classifiers/byModeline.d.ts +3 -0
  11. package/dist/analyser/classifiers/byModeline.js +22 -0
  12. package/dist/analyser/classifiers/byShebang.d.ts +3 -0
  13. package/dist/analyser/classifiers/byShebang.js +27 -0
  14. package/dist/analyser/index.d.ts +3 -0
  15. package/dist/analyser/index.js +12 -0
  16. package/dist/analyser/pipeline/aggregate.d.ts +4 -0
  17. package/dist/analyser/pipeline/aggregate.js +98 -0
  18. package/dist/analyser/pipeline/classify.d.ts +3 -0
  19. package/dist/analyser/pipeline/classify.js +32 -0
  20. package/dist/analyser/pipeline/filter.d.ts +2 -0
  21. package/dist/analyser/pipeline/filter.js +14 -0
  22. package/dist/analyser/pipeline/heuristics.d.ts +3 -0
  23. package/dist/analyser/pipeline/heuristics.js +12 -0
  24. package/dist/analyser/pipeline/normalise.d.ts +2 -0
  25. package/dist/analyser/pipeline/normalise.js +9 -0
  26. package/dist/cli/output/default.d.ts +3 -0
  27. package/dist/cli/output/default.js +106 -0
  28. package/dist/cli/output/tree.d.ts +3 -0
  29. package/dist/cli/output/tree.js +11 -0
  30. package/dist/cli/runCliAnalysis.d.ts +2 -0
  31. package/dist/cli/runCliAnalysis.js +26 -0
  32. package/dist/cli/utils.d.ts +2 -0
  33. package/dist/cli/utils.js +9 -0
  34. package/dist/cli.js +14 -143
  35. package/dist/entry/analyseFs.d.ts +2 -0
  36. package/dist/entry/analyseFs.js +11 -0
  37. package/dist/entry/analyseRaw.d.ts +4 -0
  38. package/dist/entry/analyseRaw.js +11 -0
  39. package/dist/index.d.ts +19 -4
  40. package/dist/index.js +18 -483
  41. package/dist/input/fromFilesystem.d.ts +4 -0
  42. package/dist/input/fromFilesystem.js +115 -0
  43. package/dist/input/fromRawContent.d.ts +2 -0
  44. package/dist/input/fromRawContent.js +19 -0
  45. package/dist/input/normaliseOpts.d.ts +2 -0
  46. package/dist/input/normaliseOpts.js +13 -0
  47. package/dist/program/classes/attributes.d.ts +11 -0
  48. package/dist/program/classes/attributes.js +37 -0
  49. package/dist/program/data/loadDataFiles.d.ts +4 -0
  50. package/dist/program/data/loadDataFiles.js +32 -0
  51. package/dist/program/data/retrieveData.d.ts +12 -0
  52. package/dist/program/data/retrieveData.js +27 -0
  53. package/dist/program/fs/normalisedPath.d.ts +3 -0
  54. package/dist/program/fs/normalisedPath.js +17 -0
  55. package/dist/program/fs/readFile.js +17 -0
  56. package/dist/program/fs/walkTree.d.ts +20 -0
  57. package/dist/program/fs/walkTree.js +82 -0
  58. package/dist/program/parsing/parseGitattributes.d.ts +17 -0
  59. package/dist/program/parsing/parseGitattributes.js +33 -0
  60. package/dist/program/parsing/parseGitignore.js +9 -0
  61. package/dist/program/processFiles.d.ts +9 -0
  62. package/dist/program/processFiles.js +111 -0
  63. package/dist/program/utils/pcre.js +35 -0
  64. package/dist/src/cli/output/default.d.ts +3 -0
  65. package/dist/src/cli/output/default.js +106 -0
  66. package/dist/src/cli/output/tree.d.ts +3 -0
  67. package/dist/src/cli/output/tree.js +11 -0
  68. package/dist/src/cli/runCliAnalysis.d.ts +2 -0
  69. package/dist/src/cli/runCliAnalysis.js +25 -0
  70. package/dist/src/cli/utils.d.ts +2 -0
  71. package/dist/src/cli/utils.js +9 -0
  72. package/dist/src/cli.d.ts +1 -0
  73. package/dist/src/cli.js +56 -0
  74. package/dist/src/helpers/convert-pcre.d.ts +2 -0
  75. package/dist/src/helpers/parse-gitignore.d.ts +1 -0
  76. package/dist/src/helpers/read-file.d.ts +5 -0
  77. package/dist/{helpers → src/helpers}/read-file.js +1 -1
  78. package/dist/src/index.d.ts +5 -0
  79. package/dist/src/index.js +470 -0
  80. package/dist/src/program/data/loadData.d.ts +4 -0
  81. package/dist/src/program/data/loadData.js +32 -0
  82. package/dist/src/program/fs/normalisedPath.d.ts +2 -0
  83. package/dist/src/program/fs/normalisedPath.js +7 -0
  84. package/dist/src/program/fs/readFile.d.ts +5 -0
  85. package/dist/src/program/fs/readFile.js +17 -0
  86. package/dist/src/program/fs/walkTree.d.ts +20 -0
  87. package/dist/src/program/fs/walkTree.js +82 -0
  88. package/dist/src/program/parsing/parseGitattributes.d.ts +17 -0
  89. package/dist/src/program/parsing/parseGitattributes.js +33 -0
  90. package/dist/src/program/parsing/parseGitignore.d.ts +1 -0
  91. package/dist/src/program/parsing/parseGitignore.js +9 -0
  92. package/dist/src/program/utils/pcre.d.ts +2 -0
  93. package/dist/src/program/utils/pcre.js +35 -0
  94. package/dist/src/types/schema.d.ts +37 -0
  95. package/dist/src/types/schema.js +1 -0
  96. package/dist/src/types/types.d.ts +65 -0
  97. package/dist/src/types/types.js +1 -0
  98. package/dist/types/schema.d.ts +37 -0
  99. package/dist/types/schema.js +1 -0
  100. package/dist/types/types.d.ts +84 -0
  101. package/dist/types/types.js +1 -0
  102. package/ext/generated.rb +6 -0
  103. package/ext/heuristics.yml +102 -11
  104. package/ext/languages.yml +526 -88
  105. package/ext/vendor.yml +1 -0
  106. package/package.json +14 -13
  107. package/readme.md +99 -111
  108. /package/dist/{helpers/read-file.d.ts → program/fs/readFile.d.ts} +0 -0
  109. /package/dist/{helpers/parse-gitignore.d.ts → program/parsing/parseGitignore.d.ts} +0 -0
  110. /package/dist/{helpers/convert-pcre.d.ts → program/utils/pcre.d.ts} +0 -0
  111. /package/dist/{helpers → src/helpers}/convert-pcre.js +0 -0
  112. /package/dist/{helpers → src/helpers}/load-data.d.ts +0 -0
  113. /package/dist/{helpers → src/helpers}/load-data.js +0 -0
  114. /package/dist/{helpers → src/helpers}/norm-path.d.ts +0 -0
  115. /package/dist/{helpers → src/helpers}/norm-path.js +0 -0
  116. /package/dist/{helpers → src/helpers}/parse-gitattributes.d.ts +0 -0
  117. /package/dist/{helpers → src/helpers}/parse-gitattributes.js +0 -0
  118. /package/dist/{helpers → src/helpers}/parse-gitignore.js +0 -0
  119. /package/dist/{helpers → src/helpers}/walk-tree.d.ts +0 -0
  120. /package/dist/{helpers → src/helpers}/walk-tree.js +0 -0
  121. /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
  122. /package/dist/{schema.js → src/schema.js} +0 -0
  123. /package/dist/{types.d.ts → src/types.d.ts} +0 -0
  124. /package/dist/{types.js → src/types.js} +0 -0
package/ext/vendor.yml CHANGED
@@ -165,3 +165,4 @@
165
165
  - (^|/)\.github/
166
166
  - (^|/)\.obsidian/
167
167
  - (^|/)\.teamcity/
168
+ - (^|/)xvba_modules/
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "linguist-js",
3
- "version": "2.9.2",
4
- "description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
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",
12
- "npm": ">=8"
12
+ "node": ">=26",
13
+ "npm": ">=10"
13
14
  },
14
15
  "scripts": {
15
- "download-files": "npx tsx@3 build/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": "^2.3.0 <3",
43
- "commander": "^9.5.0 <10",
43
+ "binary-extensions": "^3.1.0",
44
+ "commander": "^14.0.3",
44
45
  "common-path-prefix": "^3.0.0",
45
- "cross-fetch": "^3.2.0 <4",
46
- "ignore": "^7.0.4",
47
- "isbinaryfile": "^4.0.10 <5",
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": "ts5.0",
53
+ "@types/node": "^25.9.1",
54
54
  "deep-object-diff": "^1.1.9",
55
- "typescript": "~5.0.4 <5.1"
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 contains one function which analyses a given folder or folders.
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
- | readme.md 3kB
41
+ | info.md 3kB
42
42
  | no-lang 10B
43
- | x.pluginspec 10B
44
43
  ```
45
44
 
46
- Running LinguistJS on this folder will return the following JSON:
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": 5,
52
- "bytes": 6020,
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
- "/src/index.ts": "TypeScript",
60
- "/src/cli.js": "JavaScript",
61
- "/readme.md": "Markdown",
56
+ "/info.md": "Markdown",
62
57
  "/no-lang": null,
63
- "/x.pluginspec": "Ruby",
64
- },
65
- "alternatives": {
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": 6010,
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
- "JavaScript": {
79
- "type": "programming",
80
- "bytes": 1000,
81
- "lines": { "total": 49, "content": 49, "code": 44 },
82
- "color": "#f1e05a"
83
- },
84
- "Markdown": {
85
- "type": "prose",
86
- "bytes": 3000,
87
- "lines": { "total": 10, "content": 5, "code": 5 },
88
- "color": "#083fa1"
89
- },
90
- "Ruby": {
91
- "type": "programming",
92
- "bytes": 10,
93
- "lines": { "total": 1, "content": 1, "code": 1 },
94
- "color": "#701516"
95
- },
96
- "TypeScript": {
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": 10,
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, do not rely on any language classification output from LinguistJS being unchanged between runs.
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
- const linguist = require('linguist-js');
109
+ import linguist from 'linguist-js';
133
110
 
134
111
  // Analyse folder on disc
135
- const folder = './src';
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 fileNames = ['file1.ts', 'file2.ts', 'ignoreme.js'];
141
- const fileContent = ['#!/usr/bin/env node', 'console.log("Example");', '"ignored"'];
142
- const options = { ignoredFiles: ['ignore*'] };
143
- const { files, languages, unknown } = await linguist(fileNames, { fileContent, ...options });
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
- - `linguist(entry?, opts?)` (default export):
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
- The folder(s) to analyse (defaults to `./`).
137
+ A list of folders to analyse (defaults to `['./']`).
150
138
  - `opts` (optional; object):
151
139
  An object containing analyser options.
152
- - `fileContent` (string or string array):
153
- Provides the file content associated with the file name(s) given as `entry` to analyse instead of reading from a folder on disk.
154
- - `ignoredFiles` (string array):
155
- A list of file path globs to explicitly ignore.
156
- - `ignoredLanguages` (string array):
157
- A list of languages to ignore.
158
- - `categories` (string array):
159
- A list of programming language categories that should be included in the results.
160
- Defaults to `['data', 'markup', 'programming', 'prose']`.
161
- - `childLanguages` (boolean):
162
- Whether to display sub-languages instead of their parents when possible (defaults to `false`).
163
- - `quick` (boolean):
164
- Whether to skip complex language analysis such as the checking of heuristics and gitattributes statements (defaults to `false`).
165
- Alias for `checkAttributes:false, checkIgnored:false, checkDetected:false, checkHeuristics:false, checkShebang:false, checkModeline:false`.
166
- - `offline` (boolean):
167
- Whether to use pre-packaged metadata files instead of fetching them from GitHub at runtime (defaults to `false`).
168
- - `calculateLines` (boolean):
169
- Whether to calculate line of code totals (defaults to `true`).
170
- - `keepVendored` (boolean):
171
- Whether to keep vendored files (dependencies, etc) (defaults to `false`).
172
- Does nothing when `fileContent` is set.
173
- - `keepBinary` (boolean):
174
- Whether binary files should be included in the output (defaults to `false`).
175
- - `relativePaths` (boolean):
176
- Change the absolute file paths in the output to be relative to the current working directory (defaults to `false`).
177
- - `checkAttributes` (boolean):
178
- Force the checking of `.gitattributes` files (defaults to `true` unless `quick` is set).
179
- Does nothing when `fileContent` is set.
180
- - `checkIgnored` (boolean):
181
- Force the checking of `.gitignore` files (defaults to `true` unless `quick` is set).
182
- Does nothing when `fileContent` is set.
183
- - `checkDetected` (boolean):
184
- Force files marked with `linguist-detectable` to show up in the output, even if the file is not part of the declared `categories`.
185
- - `checkHeuristics` (boolean):
186
- Apply heuristics to ambiguous languages (defaults to `true` unless `quick` is set).
187
- - `checkShebang` (boolean):
188
- Check shebang (`#!`) lines for explicit language classification (defaults to `true` unless `quick` is set).
189
- - `checkModeline` (boolean):
190
- Check modelines for explicit language classification (defaults to `true` unless `quick` is set).
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 --analyze [<folders...>] [<options...>]
183
+ linguist --analyse [<folders...>] [<options...>]
196
184
  linguist --help
197
185
  linguist --version
198
186
  ```
199
187
 
200
- - `--analyze`:
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