Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

linguist-js

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linguist-js - npm Package Compare versions

Comparing version 2.6.0 to 2.6.1

dist/helpers/convert-pcre.d.ts

0

dist/cli.d.ts
export {};

2

dist/cli.js

@@ -13,3 +13,3 @@ "use strict";

.name('linguist')
.usage('--analyze [<folder>] [<options...>]')
.usage('--analyze [<folders...>] [<options...>]')
.option('-a|--analyze|--analyse [folders...]', 'Analyse the languages of all files in a folder')

@@ -16,0 +16,0 @@ .option('-i|--ignoredFiles <files...>', `A list of file path globs to ignore`)

@@ -0,0 +0,0 @@ "use strict";

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.parseGeneratedDataFile = void 0;
const fs_1 = __importDefault(require("fs"));

@@ -28,2 +29,8 @@ const path_1 = __importDefault(require("path"));

}
/** Nukes unused `generated.rb` file content. */
async function parseGeneratedDataFile(fileContent) {
var _a;
return [...(_a = fileContent.match(/(?<=name\.match\(\/).+?(?=(?<!\\)\/)/gm)) !== null && _a !== void 0 ? _a : []];
}
exports.parseGeneratedDataFile = parseGeneratedDataFile;
/** Load a data file from github-linguist. */

@@ -30,0 +37,0 @@ async function loadFile(file, offline = false) {

@@ -0,0 +0,0 @@ "use strict";

@@ -10,4 +10,7 @@ "use strict";

let allFolders;
;
;
/** Generate list of files in a directory. */
function walk(init, root, folders, gitignores, regexIgnores) {
function walk(data) {
const { init, commonRoot, folderRoots, folders, gitignores, regexIgnores } = data;
// Initialise files and folders lists

@@ -21,8 +24,9 @@ if (init) {

const folder = folders[0];
const localRoot = folderRoots[0].replace(commonRoot, '').replace(/^\//, '');
// Get list of files and folders inside this folder
const files = fs_1.default.readdirSync(folder).map(file => {
// Create path relative to root
const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(root, '.');
const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(commonRoot, '.');
// Add trailing slash to mark directories
const isDir = fs_1.default.lstatSync(path_1.default.resolve(root, base)).isDirectory();
const isDir = fs_1.default.lstatSync(path_1.default.resolve(commonRoot, base)).isDirectory();
return isDir ? `${base}/` : base;

@@ -33,7 +37,8 @@ });

// Create absolute path for disc operations
const path = path_1.default.resolve(root, file).replace(/\\/g, '/');
const path = path_1.default.resolve(commonRoot, file).replace(/\\/g, '/');
const localPath = localRoot ? file.replace(`./${localRoot}/`, '') : file.replace('./', '');
// Skip if nonexistant or ignored
const nonExistant = !fs_1.default.existsSync(path);
const isGitIgnored = gitignores.test(file.replace('./', '')).ignored;
const isRegexIgnored = regexIgnores.find(match => file.replace('./', '').match(match));
const isGitIgnored = gitignores.test(localPath).ignored;
const isRegexIgnored = regexIgnores.find(match => localPath.match(match));
if (nonExistant || isGitIgnored || isRegexIgnored)

@@ -47,6 +52,6 @@ continue;

allFolders.add(path);
walk(false, root, [path], gitignores, regexIgnores);
walk({ init: false, commonRoot: commonRoot, folderRoots, folders: [path], gitignores, regexIgnores });
}
else {
// Add relative file path to list
// Add file path to list
allFiles.add(path);

@@ -58,4 +63,4 @@ }

else {
for (const path of folders) {
walk(false, root, [path], gitignores, regexIgnores);
for (const i in folders) {
walk({ init: false, commonRoot: commonRoot, folderRoots: [folderRoots[i]], folders: [folders[i]], gitignores, regexIgnores });
}

@@ -65,3 +70,3 @@ }

return {
files: [...allFiles].map(file => file.replace(/^\./, root)),
files: [...allFiles].map(file => file.replace(/^\./, commonRoot)),
folders: [...allFolders],

@@ -68,0 +73,0 @@ };

@@ -0,0 +0,0 @@ import * as T from './types';

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -13,3 +36,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const walk_tree_1 = __importDefault(require("./helpers/walk-tree"));
const load_data_1 = __importDefault(require("./helpers/load-data"));
const load_data_1 = __importStar(require("./helpers/load-data"));
const read_file_1 = __importDefault(require("./helpers/read-file"));

@@ -28,3 +51,3 @@ const convert_pcre_1 = __importDefault(require("./helpers/convert-pcre"));

const heuristicsData = await (0, load_data_1.default)('heuristics.yml', opts.offline).then(js_yaml_1.default.load);
const generatedData = await (0, load_data_1.default)('generated.rb', opts.offline).then(text => { var _a; return (_a = text.match(/(?<=name\.match\(\/).+?(?=(?<!\\)\/)/gm)) !== null && _a !== void 0 ? _a : []; });
const generatedData = await (0, load_data_1.default)('generated.rb', opts.offline).then(load_data_1.parseGeneratedDataFile);
const vendorPaths = [...vendorData, ...docData, ...generatedData];

@@ -43,3 +66,3 @@ // Setup main variables

const regexIgnores = [];
gitignores.add('/.git');
gitignores.add('.git');
if (!opts.keepVendored)

@@ -50,6 +73,9 @@ regexIgnores.push(...vendorPaths.map(path => RegExp(path, 'i')));

// Set a common root path so that vendor paths do not incorrectly match parent folders
const resolvedInput = input.map(path => path_1.default.resolve(path).replace(/\\/g, '/'));
const normPath = (file) => file.replace(/\\/g, '/');
const resolvedInput = input.map(path => normPath(path_1.default.resolve(path)));
const commonRoot = (input.length > 1 ? (0, common_path_prefix_1.default)(resolvedInput) : resolvedInput[0]).replace(/\/?$/, '');
const relPath = (file) => path_1.default.relative(commonRoot, file).replace(/\\/g, '/');
const unRelPath = (file) => path_1.default.resolve(commonRoot, file).replace(/\\/g, '/');
const localRoot = (folder) => folder.replace(commonRoot, '').replace(/^\//, '');
const relPath = (file) => normPath(path_1.default.relative(commonRoot, file));
const unRelPath = (file) => normPath(path_1.default.resolve(commonRoot, file));
const localPath = (file) => localRoot(unRelPath(file));
// Load file paths and folders

@@ -64,3 +90,3 @@ let files, folders;

// Uses directory on disc
const data = (0, walk_tree_1.default)(true, commonRoot, input, gitignores, regexIgnores);
const data = (0, walk_tree_1.default)({ init: true, commonRoot, folderRoots: resolvedInput, folders: resolvedInput, gitignores, regexIgnores });
files = data.files;

@@ -92,2 +118,4 @@ folders = data.folders;

for (const folder of folders) {
// TODO FIX: this is absolute when only 1 path given
const localFilePath = (path) => localRoot(folder) ? localRoot(folder) + '/' + localPath(path) : path;
// Skip if folder is marked in gitattributes

@@ -101,3 +129,4 @@ if (relPath(folder) && gitignores.ignores(relPath(folder))) {

const ignoresData = await (0, read_file_1.default)(ignoresFile);
gitignores.add(ignoresData);
const localIgnoresData = ignoresData.replace(/^[\/\\]/g, localRoot(folder) + '/');
gitignores.add(localIgnoresData);
}

@@ -112,6 +141,6 @@ // Parse gitattributes

if (['text', '-binary'].includes(type)) {
customText.add(path);
customText.add(localFilePath(path));
}
if (['-text', 'binary'].includes(type)) {
customBinary.add(path);
customBinary.add(localFilePath(path));
}

@@ -122,3 +151,3 @@ }

for (const [_line, path] of vendorMatches) {
gitignores.add(path);
gitignores.add(localFilePath(path));
}

@@ -149,3 +178,3 @@ // Custom file associations

else {
files = gitignores.filter(files.map(relPath)).map(unRelPath);
files = gitignores.filter(files.map(localPath)).map(unRelPath);
}

@@ -152,0 +181,0 @@ }

@@ -36,3 +36,3 @@ import { Category, Language } from './types';

}
export declare type VendorSchema = string[];
export type VendorSchema = string[];
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -1,7 +0,7 @@

export declare type LanguageResult = string | null;
export declare type Language = string;
export declare type Category = 'data' | 'markup' | 'programming' | 'prose';
export declare type FilePath = string;
export declare type Bytes = Integer;
export declare type Integer = number;
export type LanguageResult = string | null;
export type Language = string;
export type Category = 'data' | 'markup' | 'programming' | 'prose';
export type FilePath = string;
export type Bytes = Integer;
export type Integer = number;
export interface Options {

@@ -8,0 +8,0 @@ fileContent?: string | string[];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
{
"name": "linguist-js",
"version": "2.6.0",
"version": "2.6.1",
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",

@@ -21,4 +21,3 @@ "main": "dist/index.js",

"bin/",
"dist/**/*.js",
"dist/*.d.ts",
"dist/",
"ext/"

@@ -46,3 +45,3 @@ ],

"common-path-prefix": "^3.0.0",
"cross-fetch": "^3.1.6",
"cross-fetch": "^3.1.8 <4",
"ignore": "^5.2.4",

@@ -49,0 +48,0 @@ "isbinaryfile": "^4.0.10 <5",

@@ -7,3 +7,3 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/Linguist?label=latest%20version&style=flat-square)](https://github.com/Nixinova/Linguist/releases)

Analyses the languages of all files in a given folder and collates the results.
Analyses the languages of all files in a given folder or folders and collates the results.

@@ -14,3 +14,4 @@ Powered by [github-linguist](https://github.com/github/linguist), although it doesn't need to be installed.

[Node.js](https://nodejs.org) must be installed to be able to use this.
[Node.js](https://nodejs.org) must be installed to be able to use LinguistJS.
LinguistJS is available [on npm](https://npmjs.com/package/linguist-js) as `linguist-js`.

@@ -24,6 +25,7 @@

Or install globally using `npm install -g linguist-js` and run using the CLI command `linguist`.
Or install globally using `npm install -g linguist-js` and run using the CLI command `linguist` or `linguist-js`.
```
linguist --help
linguist-js --help
```

@@ -33,3 +35,3 @@

LinguistJS contains one function which analyses a given folder.
LinguistJS contains one function which analyses a given folder or folders.

@@ -63,3 +65,3 @@ As an example, take the following file structure:

"alternatives": {
".pluginspec": ["XML"],
"/x.pluginspec": ["XML"],
},

@@ -107,3 +109,3 @@ },

- `linguist(entry?, opts?)` (default export):
Analyse the language of all files found in a folder.
Analyse the language of all files found in a folder or folders.
- `entry` (optional; string or string array):

@@ -152,19 +154,20 @@ The folder(s) to analyse (defaults to `./`).

```
linguist --analyze [<folder>] [<...options>]
linguist --analyze [<folders...>] [<options...>]
linguist --help
linguist --version
```
- `--analyze`:
Analyse the language of all files found in a folder.
- `<folders...>`:
Analyse the language of all files found in a folder or folders.
- `[<folders...>]`:
The folders to analyse (defaults to `./`).
- `--ignoredFiles <glob1> [[--ignoredFiles] <glob2> ...]`:
- `--ignoredFiles <globs...>`:
A list of file path globs to ignore.
When specifying more than one glob, this option can either be called with multiple values given (e.g., `--ignoredFiles *.txt *.json`) or be called multiple times (e.g., `--ignoredFiles *.txt --ignoredFiles *.json`). Both ways are equivalent.
- `--ignoredLanguages`:
A list of languages to ignore.
- `--ignoredLanguages <languages...>`:
A list of languages to exclude from the output.
- `--categories <categories...>`:
A list of space-delimited categories that should be displayed in the output.
A list of language categories that should be displayed in the output.
Must be one or more of `data`, `prose`, `programming`, `markup`.
- `--childLanguages`:
Whether to display sub-languages instead of their parents, when possible.
Display sub-languages instead of their parents, when possible.
- `--json`:

@@ -176,3 +179,3 @@ Display the outputted language data as JSON.

- `--quick`:
Whether to skip the checking of `.gitattributes` and `.gitignore` files for manual language classifications.
Skip the checking of `.gitattributes` and `.gitignore` files for manual language classifications.
Alias for `--checkAttributes=false --checkIgnored=false --checkHeuristics=false --checkShebang=false --checkModeline=false`.

@@ -182,20 +185,25 @@ - `--offline`:

- `--keepVendored`:
Whether to include vendored files (auto-generated files, dependencies folder, etc).
Include vendored files (auto-generated files, dependencies folder, etc) in the output.
- `--keepBinary`:
Whether binary files should be excluded from the output.
Include binary files in the output.
- `--relativePaths`:
Change the absolute file paths in the output to be relative to the current working directory.
- `--checkAttributes`:
Force the checking of `.gitatributes` files (use alongside `--quick` to overwrite).
Force the checking of `.gitatributes` files.
Use alongside `--quick` to override it disabling this option.
- `--checkIgnored`:
Force the checking of `.gitignore` files (use alongside `--quick` to overwrite).
Force the checking of `.gitignore` files.
Use alongside `--quick` to override it disabling this option.
- `--checkHeuristics`:
Apply heuristics to ambiguous languages (use alongside `--quick` to overwrite).
Apply heuristics to ambiguous languages.
Use alongside `--quick` to override it disabling this option.
- `--checkShebang`:
Check shebang (`#!`) lines for explicit classification (use alongside `--quick` to overwrite).
Check shebang (`#!`) lines for explicit classification.
Use alongside `--quick` to override it disabling this option.
- `--checkModeline`:
Check modelines for explicit classification (use alongside `--quick` to overwrite).
Check modelines for explicit classification.
Use alongside `--quick` to override it disabling this option.
- `--help`:
Display a help message.
Display the help message.
- `--version`:
Display the current version of linguist-js.
Display the current installed version of LinguistJS.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc