linguist-js
Advanced tools
Comparing version 2.4.1 to 2.4.2
@@ -8,6 +8,11 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const allFiles = new Set(); | ||
const allFolders = new Set(); | ||
let allFiles; | ||
let allFolders; | ||
/** Generate list of files in a directory. */ | ||
function walk(root, folders, gitignores, regexIgnores) { | ||
function walk(init, root, folders, gitignores, regexIgnores) { | ||
// Initialise files and folders lists | ||
if (init) { | ||
allFiles = new Set(); | ||
allFolders = new Set(); | ||
} | ||
// Walk tree of a folder | ||
@@ -40,3 +45,3 @@ if (folders.length === 1) { | ||
allFolders.add(path); | ||
walk(root, [path], gitignores, regexIgnores); | ||
walk(false, root, [path], gitignores, regexIgnores); | ||
} | ||
@@ -52,3 +57,3 @@ else { | ||
for (const path of folders) { | ||
walk(root, [path], gitignores, regexIgnores); | ||
walk(false, root, [path], gitignores, regexIgnores); | ||
} | ||
@@ -55,0 +60,0 @@ } |
@@ -61,3 +61,3 @@ "use strict"; | ||
// Uses directory on disc | ||
const data = (0, walk_tree_1.default)(commonRoot, input, gitignores, regexIgnores); | ||
const data = (0, walk_tree_1.default)(true, commonRoot, input, gitignores, regexIgnores); | ||
files = data.files; | ||
@@ -90,3 +90,3 @@ folders = data.folders; | ||
// Skip if folder is marked in gitattributes | ||
if (relPath(folder) && gitignores.test(relPath(folder)).ignored) | ||
if (relPath(folder) && gitignores.ignores(relPath(folder))) | ||
continue; | ||
@@ -195,3 +195,3 @@ // Parse gitignores | ||
if (!useRawContent && !opts.quick && opts.checkAttributes) { | ||
const isOverridden = (path) => (0, ignore_1.default)().add(path).test(relPath(file)).ignored; | ||
const isOverridden = (path) => (0, ignore_1.default)().add(path).ignores(relPath(file)); | ||
const match = overridesArray.find(item => isOverridden(item[0])); | ||
@@ -235,4 +235,4 @@ if (match) { | ||
if (!useRawContent && !opts.keepBinary) { | ||
const isCustomText = customText.test(relPath(file)).ignored; | ||
const isCustomBinary = customBinary.test(relPath(file)).ignored; | ||
const isCustomText = customText.ignores(relPath(file)); | ||
const isCustomBinary = customBinary.ignores(relPath(file)); | ||
const isBinaryExt = binary_extensions_1.default.some(ext => file.endsWith('.' + ext)); | ||
@@ -270,3 +270,3 @@ if (!isCustomText && (isCustomBinary || isBinaryExt || await (0, isbinaryfile_1.isBinaryFile)(file))) { | ||
// Check file contents and apply heuristic patterns | ||
const fileContent = await (0, read_file_1.default)(file).catch(() => null); | ||
const fileContent = opts.fileContent ? opts.fileContent[files.indexOf(file)] : await (0, read_file_1.default)(file).catch(() => null); | ||
if (fileContent === null) | ||
@@ -273,0 +273,0 @@ continue; |
{ | ||
"name": "linguist-js", | ||
"version": "2.4.1", | ||
"version": "2.4.2", | ||
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.", | ||
@@ -15,3 +15,3 @@ "main": "dist/index.js", | ||
"perf": "tsc && node test/perf", | ||
"test": "tsc && node test/test" | ||
"test": "tsc && node test/folder && echo --- && node test/unit" | ||
}, | ||
@@ -41,3 +41,3 @@ "files": [ | ||
"binary-extensions": "^2.2.0", | ||
"commander": "^9.0.0", | ||
"commander": "^9.1.0", | ||
"common-path-prefix": "^3.0.0", | ||
@@ -55,4 +55,4 @@ "cross-fetch": "^3.1.5", | ||
"deep-object-diff": "^1.1.7", | ||
"typescript": "~4.6.1-rc" | ||
"typescript": "~4.6.2" | ||
} | ||
} |
@@ -5,3 +5,3 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/Linguist?label=latest%20version&style=flat-square)](https://github.com/Nixinova/Linguist/releases) | ||
# Linguist | ||
# LinguistJS | ||
@@ -15,3 +15,3 @@ Analyses the languages of all files in a given folder and collates the results. | ||
[Node.js](https://nodejs.org) must be installed to be able to use this. | ||
Linguist is available [on npm](https://npmjs.com/package/linguist-js) as `linguist-js`. | ||
LinguistJS is available [on npm](https://npmjs.com/package/linguist-js) as `linguist-js`. | ||
@@ -32,3 +32,3 @@ Install locally using `npm install linguist-js` and import it into your code like so: | ||
Linguist contains one function which analyses a given folder. | ||
LinguistJS contains one function which analyses a given folder. | ||
@@ -46,3 +46,3 @@ As an example, take the following file structure: | ||
Running Linguist on this folder will return the following JSON: | ||
Running LinguistJS on this folder will return the following JSON: | ||
@@ -85,3 +85,3 @@ ```json | ||
- This tool does not work when offline. | ||
- Do not rely on any language classification output from Linguist being unchanged between runs. | ||
- Do not rely on any language classification output from LinguistJS being unchanged between runs. | ||
Language data is fetched each run from the latest classifications of [`github-linguist`](https://github.com/github/linguist). | ||
@@ -88,0 +88,0 @@ 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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41381
674
Updatedcommander@^9.1.0