linguist-js
Advanced tools
Comparing version 2.7.0-pre to 2.7.0
@@ -13,3 +13,4 @@ "use strict"; | ||
const output = []; | ||
for (const line of content.split('\n')) { | ||
for (const rawLine of content.split('\n')) { | ||
const line = rawLine.replace(/#.*/, '').trim(); | ||
if (!line) | ||
@@ -16,0 +17,0 @@ continue; |
@@ -40,7 +40,7 @@ "use strict"; | ||
const convert_pcre_1 = __importDefault(require("./helpers/convert-pcre")); | ||
async function analyse(rawInput, opts = {}) { | ||
async function analyse(rawPaths, opts = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
var _r, _s; | ||
const useRawContent = opts.fileContent !== undefined; | ||
const input = [rawInput !== null && rawInput !== void 0 ? rawInput : []].flat(); | ||
const input = [rawPaths !== null && rawPaths !== void 0 ? rawPaths : []].flat(); | ||
const manualFileContent = [(_a = opts.fileContent) !== null && _a !== void 0 ? _a : []].flat(); | ||
@@ -105,13 +105,17 @@ // Normalise input option arguments | ||
// Load gitignore data and apply ignores rules | ||
if (!useRawContent) { | ||
// TODO switch to be like the gitattributes code | ||
for (const folder of folders) { | ||
if (!useRawContent && opts.checkIgnored) { | ||
const nestedIgnoreFiles = files.filter(file => file.endsWith('.gitignore')); | ||
for (const ignoresFile of nestedIgnoreFiles) { | ||
const relIgnoresFile = relPath(ignoresFile); | ||
const relIgnoresFolder = path_1.default.dirname(relIgnoresFile); | ||
// Parse gitignores | ||
const ignoresFile = path_1.default.join(folder, '.gitignore'); | ||
if (opts.checkIgnored && fs_1.default.existsSync(ignoresFile)) { | ||
const ignoresData = await (0, read_file_1.default)(ignoresFile); | ||
const localIgnoresData = ignoresData.replace(/^[\/\\]/g, localRoot(folder) + '/'); | ||
ignored.add(localIgnoresData); | ||
files = filterOutIgnored(files, ignored); | ||
} | ||
const ignoresDataRaw = await (0, read_file_1.default)(ignoresFile); | ||
const ignoresData = ignoresDataRaw.replace(/#.+|\s+$/gm, ''); | ||
const absoluteIgnoresData = ignoresData | ||
// '.file' -> 'root/*/.file' | ||
.replace(/^(?=[^\s\/\\])/gm, localRoot(relIgnoresFolder) + '/*/') | ||
// '/folder' -> 'root/folder' | ||
.replace(/^[\/\\]/gm, localRoot(relIgnoresFolder) + '/'); | ||
ignored.add(absoluteIgnoresData); | ||
files = filterOutIgnored(files, ignored); | ||
} | ||
@@ -142,3 +146,4 @@ } | ||
// Set up glob ignore object to use for expanding globs to match files | ||
const vendorOverrides = (0, ignore_1.default)().add(vendorFalseGlobs); | ||
const vendorTrueIgnore = (0, ignore_1.default)().add(vendorTrueGlobs); | ||
const vendorFalseIgnore = (0, ignore_1.default)().add(vendorFalseGlobs); | ||
// Remove all files marked as vendored by default | ||
@@ -148,7 +153,6 @@ const excludedFiles = files.filter(file => vendorPaths.some(pathPtn => RegExp(pathPtn, 'i').test(relPath(file)))); | ||
// Re-add removed files that are overridden manually in gitattributes | ||
const overriddenExcludedFiles = excludedFiles.filter(file => vendorOverrides.ignores(relPath(file))); | ||
const overriddenExcludedFiles = excludedFiles.filter(file => vendorFalseIgnore.ignores(relPath(file))); | ||
files.push(...overriddenExcludedFiles); | ||
// Remove files explicitly marked as vendored in gitattributes | ||
// TODO change globs.includes(file) to parse the glob using ignore() | ||
files = files.filter(file => !vendorTrueGlobs.includes(relPath(file))); | ||
files = files.filter(file => !vendorTrueIgnore.ignores(relPath(file))); | ||
} | ||
@@ -164,3 +168,2 @@ // Filter out binary files | ||
const binaryUnignored = (0, ignore_1.default)().add(getFlaggedGlobs('binary', false)); | ||
// TODO parse the globs using ignore() | ||
const unignoredList = filterOutIgnored(files, binaryUnignored); | ||
@@ -167,0 +170,0 @@ files.push(...unignoredList); |
{ | ||
"name": "linguist-js", | ||
"version": "2.7.0-pre", | ||
"version": "2.7.0", | ||
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -98,5 +98,13 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/Linguist?label=latest%20version&style=flat-square)](https://github.com/Nixinova/Linguist/releases) | ||
const linguist = require('linguist-js'); | ||
let folder = './src'; | ||
let options = { keepVendored: false, quick: false }; | ||
const { files, languages, unknown } = linguist(folder, options); | ||
// Analyse folder on disc | ||
const folder = './src'; | ||
const options = { keepVendored: false, quick: false }; | ||
const { files, languages, unknown } = await linguist(folder, options); | ||
// Analyse file content from raw input | ||
const fileNames = ['file1.ts', 'file2.ts', 'ignoreme.js']; | ||
const fileContent = ['#!/usr/bin/env node', 'console.log("Example");', '"ignored"']; | ||
const options = { ignoredFiles: ['ignore*'] }; | ||
const { files, languages, unknown } = await linguist(fileNames, { fileContent, ...options }); | ||
``` | ||
@@ -126,3 +134,3 @@ | ||
Whether to use pre-packaged metadata files instead of fetching them from GitHub at runtime (defaults to `false`). | ||
- `keepVendored` (boolean): | ||
- `keepVendored` (boolean): | ||
Whether to keep vendored files (dependencies, etc) (defaults to `false`). | ||
@@ -129,0 +137,0 @@ Does nothing when `fileContent` is set. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
225664
928
0
215