linguist-js 2.3.0 → 2.3.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.
- package/dist/helpers/convert-pcre.js +7 -4
- package/dist/index.js +16 -14
- package/package.json +1 -1
|
@@ -3,23 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/** Convert a PCRE regex into JS. */
|
|
4
4
|
function pcre(regex) {
|
|
5
5
|
let finalRegex = regex;
|
|
6
|
+
const replace = (search, replace) => finalRegex = finalRegex.replace(search, replace);
|
|
6
7
|
const finalFlags = new Set();
|
|
7
8
|
// Convert inline flag declarations
|
|
8
9
|
const inlineMatches = regex.matchAll(/\?([a-z]):/g);
|
|
9
10
|
const startMatches = regex.matchAll(/\(\?([a-z]+)\)/g);
|
|
10
11
|
for (const [match, flags] of [...inlineMatches, ...startMatches]) {
|
|
11
|
-
|
|
12
|
+
replace(match, '');
|
|
12
13
|
[...flags].forEach(flag => finalFlags.add(flag));
|
|
13
14
|
}
|
|
14
|
-
// Remove invalid
|
|
15
|
-
|
|
15
|
+
// Remove invalid syntax
|
|
16
|
+
replace(/([*+]){2}/g, '$1');
|
|
17
|
+
replace(/\(\?>/g, '(?:');
|
|
16
18
|
// Remove start/end-of-file markers
|
|
17
19
|
if (/\\[AZ]/.test(finalRegex)) {
|
|
18
|
-
|
|
20
|
+
replace(/\\A/g, '^').replace(/\\Z/g, '$');
|
|
19
21
|
finalFlags.delete('m');
|
|
20
22
|
}
|
|
21
23
|
else
|
|
22
24
|
finalFlags.add('m');
|
|
25
|
+
// Return final regex
|
|
23
26
|
return RegExp(finalRegex, [...finalFlags].join(''));
|
|
24
27
|
}
|
|
25
28
|
exports.default = pcre;
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,9 @@ const read_file_1 = __importDefault(require("./helpers/read-file"));
|
|
|
14
14
|
const convert_pcre_1 = __importDefault(require("./helpers/convert-pcre"));
|
|
15
15
|
const convert_glob_1 = __importDefault(require("./helpers/convert-glob"));
|
|
16
16
|
async function analyse(input, opts = {}) {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
18
|
-
var
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
18
|
+
var _s, _t, _u;
|
|
19
|
+
const useRawContent = opts.fileContent !== undefined;
|
|
19
20
|
const langData = await (0, load_data_1.default)('languages.yml').then(js_yaml_1.default.load);
|
|
20
21
|
const vendorData = await (0, load_data_1.default)('vendor.yml').then(js_yaml_1.default.load);
|
|
21
22
|
const heuristicsData = await (0, load_data_1.default)('heuristics.yml').then(js_yaml_1.default.load);
|
|
@@ -59,7 +60,7 @@ async function analyse(input, opts = {}) {
|
|
|
59
60
|
const customIgnored = [];
|
|
60
61
|
const customBinary = [];
|
|
61
62
|
const customText = [];
|
|
62
|
-
if (!
|
|
63
|
+
if (!useRawContent && !opts.quick) {
|
|
63
64
|
for (const folder of folders) {
|
|
64
65
|
// Skip if folder is marked in gitattributes
|
|
65
66
|
if (customIgnored.some(path => (0, convert_glob_1.default)(path).test(folder)))
|
|
@@ -106,7 +107,7 @@ async function analyse(input, opts = {}) {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
// Check vendored files
|
|
109
|
-
if (!
|
|
110
|
+
if (!useRawContent && !opts.keepVendored) {
|
|
110
111
|
// Filter out any files that match a vendor file path
|
|
111
112
|
const matcher = (match) => RegExp(match.replace(/\/$/, '/.+$').replace(/^\.\//, ''));
|
|
112
113
|
files = files.filter(file => !customIgnored.some(pattern => matcher(pattern).test(file)));
|
|
@@ -119,7 +120,7 @@ async function analyse(input, opts = {}) {
|
|
|
119
120
|
}
|
|
120
121
|
const parent = !opts.childLanguages && result && langData[result].group || false;
|
|
121
122
|
fileAssociations[file].push(parent || result);
|
|
122
|
-
extensions[file] = path_1.default.extname(file);
|
|
123
|
+
extensions[file] = path_1.default.extname(file).toLowerCase();
|
|
123
124
|
};
|
|
124
125
|
const overridesArray = Object.entries(overrides);
|
|
125
126
|
// List all languages that could be associated with a given file
|
|
@@ -147,7 +148,7 @@ async function analyse(input, opts = {}) {
|
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
// Check override for manual language classification
|
|
150
|
-
if (!
|
|
151
|
+
if (!useRawContent && !opts.quick && opts.checkAttributes) {
|
|
151
152
|
const match = overridesArray.find(item => RegExp(item[0]).test(file));
|
|
152
153
|
if (match) {
|
|
153
154
|
const forcedLang = match[1];
|
|
@@ -179,7 +180,7 @@ async function analyse(input, opts = {}) {
|
|
|
179
180
|
// Narrow down file associations to the best fit
|
|
180
181
|
for (const file in fileAssociations) {
|
|
181
182
|
// Skip binary files
|
|
182
|
-
if (!
|
|
183
|
+
if (!useRawContent && !opts.keepBinary) {
|
|
183
184
|
const isCustomText = customText.some(path => RegExp(path).test(file));
|
|
184
185
|
const isCustomBinary = customBinary.some(path => RegExp(path).test(file));
|
|
185
186
|
const isBinaryExt = binary_extensions_1.default.some(ext => file.endsWith('.' + ext));
|
|
@@ -201,8 +202,9 @@ async function analyse(input, opts = {}) {
|
|
|
201
202
|
heuristic.language = heuristic.language[0];
|
|
202
203
|
}
|
|
203
204
|
// Make sure the results includes this language
|
|
205
|
+
const languageGroup = (_j = langData[heuristic.language]) === null || _j === void 0 ? void 0 : _j.group;
|
|
204
206
|
const matchesLang = fileAssociations[file].includes(heuristic.language);
|
|
205
|
-
const matchesParent =
|
|
207
|
+
const matchesParent = languageGroup && fileAssociations[file].includes(languageGroup);
|
|
206
208
|
if (!matchesLang && !matchesParent)
|
|
207
209
|
continue;
|
|
208
210
|
// Normalise heuristic data
|
|
@@ -223,10 +225,10 @@ async function analyse(input, opts = {}) {
|
|
|
223
225
|
}
|
|
224
226
|
}
|
|
225
227
|
// If no heuristics, assign a language
|
|
226
|
-
(
|
|
228
|
+
(_k = (_s = results.files.results)[file]) !== null && _k !== void 0 ? _k : (_s[file] = fileAssociations[file][0]);
|
|
227
229
|
}
|
|
228
230
|
// Skip specified categories
|
|
229
|
-
if ((
|
|
231
|
+
if ((_l = opts.categories) === null || _l === void 0 ? void 0 : _l.length) {
|
|
230
232
|
const categories = ['data', 'markup', 'programming', 'prose'];
|
|
231
233
|
const hiddenCategories = categories.filter(cat => !opts.categories.includes(cat));
|
|
232
234
|
for (const [file, lang] of Object.entries(results.files.results)) {
|
|
@@ -244,7 +246,7 @@ async function analyse(input, opts = {}) {
|
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
// Convert paths to relative
|
|
247
|
-
if (!
|
|
249
|
+
if (!useRawContent && opts.relativePaths) {
|
|
248
250
|
const newMap = {};
|
|
249
251
|
for (const [file, lang] of Object.entries(results.files.results)) {
|
|
250
252
|
let relPath = path_1.default.relative(process.cwd(), file).replace(/\\/g, '/');
|
|
@@ -258,21 +260,21 @@ async function analyse(input, opts = {}) {
|
|
|
258
260
|
for (const [file, lang] of Object.entries(results.files.results)) {
|
|
259
261
|
if (lang && !langData[lang])
|
|
260
262
|
continue;
|
|
261
|
-
const fileSize = (
|
|
263
|
+
const fileSize = (_p = (_o = (_m = opts.fileContent) === null || _m === void 0 ? void 0 : _m[files.indexOf(file)]) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : fs_1.default.statSync(file).size;
|
|
262
264
|
results.files.bytes += fileSize;
|
|
263
265
|
// If no language found, add extension in other section
|
|
264
266
|
if (!lang) {
|
|
265
267
|
const ext = path_1.default.extname(file);
|
|
266
268
|
const unknownType = ext === '' ? 'filenames' : 'extensions';
|
|
267
269
|
const name = ext === '' ? path_1.default.basename(file) : ext;
|
|
268
|
-
(
|
|
270
|
+
(_q = (_t = results.unknown[unknownType])[name]) !== null && _q !== void 0 ? _q : (_t[name] = 0);
|
|
269
271
|
results.unknown[unknownType][name] += fileSize;
|
|
270
272
|
results.unknown.bytes += fileSize;
|
|
271
273
|
continue;
|
|
272
274
|
}
|
|
273
275
|
// Add language and bytes data to corresponding section
|
|
274
276
|
const { type } = langData[lang];
|
|
275
|
-
(
|
|
277
|
+
(_r = (_u = results.languages.results)[lang]) !== null && _r !== void 0 ? _r : (_u[lang] = { type, bytes: 0, color: langData[lang].color });
|
|
276
278
|
if (opts.childLanguages)
|
|
277
279
|
results.languages.results[lang].parent = langData[lang].group;
|
|
278
280
|
results.languages.results[lang].bytes += fileSize;
|