linguist-js 2.6.0 → 2.7.0-pre

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/cli.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/dist/cli.js CHANGED
@@ -1,107 +1,141 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const VERSION = require('../package.json').version;
7
- const commander_1 = require("commander");
8
- const index_1 = __importDefault(require("./index"));
9
- const colouredMsg = ([r, g, b], msg) => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
10
- const hexToRgb = (hex) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
11
- commander_1.program
12
- .name('linguist')
13
- .usage('--analyze [<folder>] [<options...>]')
14
- .option('-a|--analyze|--analyse [folders...]', 'Analyse the languages of all files in a folder')
15
- .option('-i|--ignoredFiles <files...>', `A list of file path globs to ignore`)
16
- .option('-l|--ignoredLanguages <languages...>', `A list of languages to ignore`)
17
- .option('-c|--categories <categories...>', 'Language categories to include in output')
18
- .option('-C|--childLanguages [bool]', 'Display child languages instead of their parents', false)
19
- .option('-j|--json [bool]', 'Display the output as JSON', false)
20
- .option('-t|--tree <traversal>', 'Which part of the output JSON to display (dot-delimited)')
21
- .option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
22
- .option('-o|--offline [bool]', 'Use packaged data files instead of fetching latest from GitHub', false)
23
- .option('-V|--keepVendored [bool]', 'Prevent skipping over vendored/generated files', false)
24
- .option('-B|--keepBinary [bool]', 'Prevent skipping over binary files', false)
25
- .option('-r|--relativePaths [bool]', 'Convert absolute file paths to relative', false)
26
- .option('-A|--checkAttributes [bool]', 'Force the checking of gitattributes files', true)
27
- .option('-I|--checkIgnored [bool]', 'Force the checking of gitignore files', true)
28
- .option('-H|--checkHeuristics [bool]', 'Apply heuristics to ambiguous languages', true)
29
- .option('-S|--checkShebang [bool]', 'Check shebang lines for explicit classification', true)
30
- .option('-M|--checkModeline [bool]', 'Check modelines for explicit classification', true)
31
- .helpOption(`-h|--help`, 'Display this help message')
32
- .version(VERSION, '-v|--version', 'Display the installed version of linguist-js');
33
- commander_1.program.parse(process.argv);
34
- const args = commander_1.program.opts();
35
- // Normalise arguments
36
- for (const arg in args) {
37
- const normalise = (val) => {
38
- if (typeof val !== 'string')
39
- return val;
40
- val = val.replace(/^=/, '');
41
- if (val.match(/true$|false$/))
42
- val = val === 'true';
43
- return val;
44
- };
45
- if (Array.isArray(args[arg]))
46
- args[arg] = args[arg].map(normalise);
47
- else
48
- args[arg] = normalise(args[arg]);
49
- }
50
- // Run Linguist
51
- if (args.analyze)
52
- (async () => {
53
- // Fetch language data
54
- const root = args.analyze === true ? '.' : args.analyze;
55
- const data = await (0, index_1.default)(root, args);
56
- const { files, languages, unknown } = data;
57
- // Print output
58
- if (!args.json) {
59
- const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
60
- const totalBytes = languages.bytes;
61
- console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
62
- console.log(`\n Language analysis results:`);
63
- let count = 0;
64
- if (sortedEntries.length === 0)
65
- console.log(` None`);
66
- // List parsed results
67
- for (const [lang, { bytes, color }] of sortedEntries) {
68
- const fmtd = {
69
- index: (++count).toString().padStart(2, ' '),
70
- lang: lang.padEnd(24, ' '),
71
- percent: (bytes / (totalBytes || 1) * 100).toFixed(2).padStart(5, ' '),
72
- bytes: bytes.toLocaleString().padStart(10, ' '),
73
- icon: colouredMsg(hexToRgb(color !== null && color !== void 0 ? color : '#ededed'), '\u2588'),
74
- };
75
- console.log(` ${fmtd.index}. ${fmtd.icon} ${fmtd.lang} ${fmtd.percent}% ${fmtd.bytes} B`);
76
- }
77
- console.log(` Total: ${totalBytes.toLocaleString()} B`);
78
- // List unknown files/extensions
79
- if (unknown.bytes > 0) {
80
- console.log(`\n Unknown files and extensions:`);
81
- for (const [name, bytes] of Object.entries(unknown.filenames)) {
82
- console.log(` '${name}': ${bytes.toLocaleString()} B`);
83
- }
84
- for (const [ext, bytes] of Object.entries(unknown.extensions)) {
85
- console.log(` '*${ext}': ${bytes.toLocaleString()} B`);
86
- }
87
- console.log(` Total: ${unknown.bytes.toLocaleString()} B`);
88
- }
89
- }
90
- else if (args.tree) {
91
- const treeParts = args.tree.split('.');
92
- let nestedData = data;
93
- for (const part of treeParts) {
94
- if (!nestedData[part])
95
- throw Error(`TraversalError: Key '${part}' cannot be found on output object.`);
96
- nestedData = nestedData[part];
97
- }
98
- console.log(nestedData);
99
- }
100
- else {
101
- console.dir(data, { depth: null });
102
- }
103
- })();
104
- else {
105
- console.log(`Welcome to linguist-js, a JavaScript port of GitHub's language analyzer.`);
106
- console.log(`Type 'linguist --help' for a list of commands.`);
107
- }
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const VERSION = require('../package.json').version;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const commander_1 = require("commander");
10
+ const index_1 = __importDefault(require("./index"));
11
+ const colouredMsg = ([r, g, b], msg) => `\u001B[${38};2;${r};${g};${b}m${msg}${'\u001b[0m'}`;
12
+ const hexToRgb = (hex) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];
13
+ commander_1.program
14
+ .name('linguist')
15
+ .usage('--analyze [<folders...>] [<options...>]')
16
+ .option('-a|--analyze|--analyse [folders...]', 'Analyse the languages of all files in a folder')
17
+ .option('-i|--ignoredFiles <files...>', `A list of file path globs to ignore`)
18
+ .option('-l|--ignoredLanguages <languages...>', `A list of languages to ignore`)
19
+ .option('-c|--categories <categories...>', 'Language categories to include in output')
20
+ .option('-C|--childLanguages [bool]', 'Display child languages instead of their parents', false)
21
+ .option('-j|--json [bool]', 'Display the output as JSON', false)
22
+ .option('-t|--tree <traversal>', 'Which part of the output JSON to display (dot-delimited)')
23
+ .option('-F|--listFiles [bool]', 'Whether to list every matching file under the language results', false)
24
+ .option('-q|--quick [bool]', 'Skip complex language analysis (alias for -{A|I|H|S}=false)', false)
25
+ .option('-o|--offline [bool]', 'Use packaged data files instead of fetching latest from GitHub', false)
26
+ .option('-V|--keepVendored [bool]', 'Prevent skipping over vendored/generated files', false)
27
+ .option('-B|--keepBinary [bool]', 'Prevent skipping over binary files', false)
28
+ .option('-r|--relativePaths [bool]', 'Convert absolute file paths to relative', false)
29
+ .option('-A|--checkAttributes [bool]', 'Force the checking of gitattributes files', true)
30
+ .option('-I|--checkIgnored [bool]', 'Force the checking of gitignore files', true)
31
+ .option('-H|--checkHeuristics [bool]', 'Apply heuristics to ambiguous languages', true)
32
+ .option('-S|--checkShebang [bool]', 'Check shebang lines for explicit classification', true)
33
+ .option('-M|--checkModeline [bool]', 'Check modelines for explicit classification', true)
34
+ .helpOption(`-h|--help`, 'Display this help message')
35
+ .version(VERSION, '-v|--version', 'Display the installed version of linguist-js');
36
+ commander_1.program.parse(process.argv);
37
+ const args = commander_1.program.opts();
38
+ // Normalise arguments
39
+ for (const arg in args) {
40
+ const normalise = (val) => {
41
+ if (typeof val !== 'string')
42
+ return val;
43
+ val = val.replace(/^=/, '');
44
+ if (val.match(/true$|false$/))
45
+ val = val === 'true';
46
+ return val;
47
+ };
48
+ if (Array.isArray(args[arg]))
49
+ args[arg] = args[arg].map(normalise);
50
+ else
51
+ args[arg] = normalise(args[arg]);
52
+ }
53
+ // Run Linguist
54
+ if (args.analyze)
55
+ (async () => {
56
+ // Fetch language data
57
+ const root = args.analyze === true ? '.' : args.analyze;
58
+ const data = await (0, index_1.default)(root, args);
59
+ const { files, languages, unknown } = data;
60
+ // Print output
61
+ if (!args.json) {
62
+ const sortedEntries = Object.entries(languages.results).sort((a, b) => a[1].bytes < b[1].bytes ? +1 : -1);
63
+ const totalBytes = languages.bytes;
64
+ console.log(`\n Analysed ${files.bytes.toLocaleString()} B from ${files.count} files with linguist-js`);
65
+ console.log(`\n Language analysis results: \n`);
66
+ let count = 0;
67
+ if (sortedEntries.length === 0)
68
+ console.log(` None`);
69
+ // Collate files per language
70
+ const filesPerLanguage = {};
71
+ if (args.listFiles) {
72
+ for (const language of Object.keys(languages.results)) {
73
+ filesPerLanguage[language] = [];
74
+ }
75
+ for (const [file, lang] of Object.entries(files.results)) {
76
+ if (lang)
77
+ filesPerLanguage[lang].push(file);
78
+ }
79
+ }
80
+ // List parsed results
81
+ for (const [lang, { bytes, color }] of sortedEntries) {
82
+ const percent = (bytes) => bytes / (totalBytes || 1) * 100;
83
+ const fmtd = {
84
+ index: (++count).toString().padStart(2, ' '),
85
+ lang: lang.padEnd(24, ' '),
86
+ percent: percent(bytes).toFixed(2).padStart(5, ' '),
87
+ bytes: bytes.toLocaleString().padStart(10, ' '),
88
+ icon: colouredMsg(hexToRgb(color !== null && color !== void 0 ? color : '#ededed'), '\u2588'),
89
+ };
90
+ console.log(` ${fmtd.index}. ${fmtd.icon} ${fmtd.lang} ${fmtd.percent}% ${fmtd.bytes} B`);
91
+ // If using `listFiles` option, list all files tagged as this language
92
+ if (args.listFiles) {
93
+ console.log(); // padding
94
+ for (const file of filesPerLanguage[lang]) {
95
+ let relFile = path_1.default.relative(path_1.default.resolve('.'), file).replace(/\\/g, '/');
96
+ if (!relFile.startsWith('../'))
97
+ relFile = './' + relFile;
98
+ const bytes = (await fs_1.default.promises.stat(file)).size;
99
+ const fmtd2 = {
100
+ file: relFile.padEnd(42, ' '),
101
+ percent: percent(bytes).toFixed(2).padStart(5, ' '),
102
+ bytes: bytes.toLocaleString().padStart(10, ' '),
103
+ };
104
+ console.log(` ${fmtd.icon} ${fmtd2.file} ${fmtd2.percent}% ${fmtd2.bytes} B`);
105
+ }
106
+ console.log(); // padding
107
+ }
108
+ }
109
+ if (!args.listFiles)
110
+ console.log(); // padding
111
+ console.log(` Total: ${totalBytes.toLocaleString()} B`);
112
+ // List unknown files/extensions
113
+ if (unknown.bytes > 0) {
114
+ console.log(`\n Unknown files and extensions:`);
115
+ for (const [name, bytes] of Object.entries(unknown.filenames)) {
116
+ console.log(` '${name}': ${bytes.toLocaleString()} B`);
117
+ }
118
+ for (const [ext, bytes] of Object.entries(unknown.extensions)) {
119
+ console.log(` '*${ext}': ${bytes.toLocaleString()} B`);
120
+ }
121
+ console.log(` Total: ${unknown.bytes.toLocaleString()} B`);
122
+ }
123
+ }
124
+ else if (args.tree) {
125
+ const treeParts = args.tree.split('.');
126
+ let nestedData = data;
127
+ for (const part of treeParts) {
128
+ if (!nestedData[part])
129
+ throw Error(`TraversalError: Key '${part}' cannot be found on output object.`);
130
+ nestedData = nestedData[part];
131
+ }
132
+ console.log(nestedData);
133
+ }
134
+ else {
135
+ console.dir(data, { depth: null });
136
+ }
137
+ })();
138
+ else {
139
+ console.log(`Welcome to linguist-js, a JavaScript port of GitHub's language analyzer.`);
140
+ console.log(`Type 'linguist --help' for a list of commands.`);
141
+ }
@@ -0,0 +1,2 @@
1
+ /** Convert a PCRE regex into JS. */
2
+ export default function pcre(regex: string): RegExp;
@@ -1,38 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /** Convert a PCRE regex into JS. */
4
- function pcre(regex) {
5
- let finalRegex = regex;
6
- const replace = (search, replace) => finalRegex = finalRegex.replace(search, replace);
7
- const finalFlags = new Set();
8
- // Convert inline flag declarations
9
- const inlineMatches = regex.matchAll(/\?(-)?([a-z]):/g);
10
- const startMatches = regex.matchAll(/\(\?(-)?([a-z]+)\)/g);
11
- for (const [match, isNegative, flags] of [...inlineMatches, ...startMatches]) {
12
- replace(match, '');
13
- const func = (flag) => isNegative ? finalFlags.delete(flag) : finalFlags.add(flag);
14
- [...flags].forEach(func);
15
- }
16
- // Remove PCRE-only syntax
17
- replace(/([*+]){2}/g, '$1');
18
- replace(/\(\?>/g, '(?:');
19
- // Remove start/end-of-file markers
20
- if (/\\[AZ]/.test(finalRegex)) {
21
- replace(/\\A/g, '^');
22
- replace(/\\Z/g, '$');
23
- finalFlags.delete('m');
24
- }
25
- else {
26
- finalFlags.add('m');
27
- }
28
- // Reformat free-spacing mode
29
- if (finalFlags.has('x')) {
30
- finalFlags.delete('x');
31
- replace(/#.+/g, '');
32
- replace(/^\s+|\s+$|\n/gm, '');
33
- replace(/\s+/g, ' ');
34
- }
35
- // Return final regex
36
- return RegExp(finalRegex, [...finalFlags].join(''));
37
- }
38
- exports.default = pcre;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /** Convert a PCRE regex into JS. */
4
+ function pcre(regex) {
5
+ let finalRegex = regex;
6
+ const replace = (search, replace) => finalRegex = finalRegex.replace(search, replace);
7
+ const finalFlags = new Set();
8
+ // Convert inline flag declarations
9
+ const inlineMatches = regex.matchAll(/\?(-)?([a-z]):/g);
10
+ const startMatches = regex.matchAll(/\(\?(-)?([a-z]+)\)/g);
11
+ for (const [match, isNegative, flags] of [...inlineMatches, ...startMatches]) {
12
+ replace(match, '');
13
+ const func = (flag) => isNegative ? finalFlags.delete(flag) : finalFlags.add(flag);
14
+ [...flags].forEach(func);
15
+ }
16
+ // Remove PCRE-only syntax
17
+ replace(/([*+]){2}/g, '$1');
18
+ replace(/\(\?>/g, '(?:');
19
+ // Remove start/end-of-file markers
20
+ if (/\\[AZ]/.test(finalRegex)) {
21
+ replace(/\\A/g, '^');
22
+ replace(/\\Z/g, '$');
23
+ finalFlags.delete('m');
24
+ }
25
+ else {
26
+ finalFlags.add('m');
27
+ }
28
+ // Reformat free-spacing mode
29
+ if (finalFlags.has('x')) {
30
+ finalFlags.delete('x');
31
+ replace(/#.+/g, '');
32
+ replace(/^\s+|\s+$|\n/gm, '');
33
+ replace(/\s+/g, ' ');
34
+ }
35
+ // Return final regex
36
+ return RegExp(finalRegex, [...finalFlags].join(''));
37
+ }
38
+ exports.default = pcre;
@@ -0,0 +1,4 @@
1
+ /** Nukes unused `generated.rb` file content. */
2
+ export declare function parseGeneratedDataFile(fileContent: string): Promise<string[]>;
3
+ /** Load a data file from github-linguist. */
4
+ export default function loadFile(file: string, offline?: boolean): Promise<string>;
@@ -1,31 +1,38 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- const path_1 = __importDefault(require("path"));
8
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
- const node_cache_1 = __importDefault(require("node-cache"));
10
- const cache = new node_cache_1.default({});
11
- async function loadWebFile(file) {
12
- // Return cache if it exists
13
- const cachedContent = cache.get(file);
14
- if (cachedContent)
15
- return cachedContent;
16
- // Otherwise cache the request
17
- const dataUrl = (file) => `https://raw.githubusercontent.com/github/linguist/HEAD/lib/linguist/${file}`;
18
- // Load file content, falling back to the local file if the request fails
19
- const fileContent = await (0, cross_fetch_1.default)(dataUrl(file)).then(data => data.text()).catch(async () => await loadLocalFile(file));
20
- cache.set(file, fileContent);
21
- return fileContent;
22
- }
23
- async function loadLocalFile(file) {
24
- const filePath = path_1.default.resolve(__dirname, '../../ext', file);
25
- return fs_1.default.promises.readFile(filePath).then(buffer => buffer.toString());
26
- }
27
- /** Load a data file from github-linguist. */
28
- async function loadFile(file, offline = false) {
29
- return offline ? loadLocalFile(file) : loadWebFile(file);
30
- }
31
- exports.default = loadFile;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseGeneratedDataFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
10
+ const node_cache_1 = __importDefault(require("node-cache"));
11
+ const cache = new node_cache_1.default({});
12
+ async function loadWebFile(file) {
13
+ // Return cache if it exists
14
+ const cachedContent = cache.get(file);
15
+ if (cachedContent)
16
+ return cachedContent;
17
+ // Otherwise cache the request
18
+ const dataUrl = (file) => `https://raw.githubusercontent.com/github/linguist/HEAD/lib/linguist/${file}`;
19
+ // Load file content, falling back to the local file if the request fails
20
+ const fileContent = await (0, cross_fetch_1.default)(dataUrl(file)).then(data => data.text()).catch(async () => await loadLocalFile(file));
21
+ cache.set(file, fileContent);
22
+ return fileContent;
23
+ }
24
+ async function loadLocalFile(file) {
25
+ const filePath = path_1.default.resolve(__dirname, '../../ext', file);
26
+ return fs_1.default.promises.readFile(filePath).then(buffer => buffer.toString());
27
+ }
28
+ /** Nukes unused `generated.rb` file content. */
29
+ async function parseGeneratedDataFile(fileContent) {
30
+ var _a;
31
+ return [...(_a = fileContent.match(/(?<=name\.match\(\/).+?(?=(?<!\\)\/)/gm)) !== null && _a !== void 0 ? _a : []];
32
+ }
33
+ exports.parseGeneratedDataFile = parseGeneratedDataFile;
34
+ /** Load a data file from github-linguist. */
35
+ async function loadFile(file, offline = false) {
36
+ return offline ? loadLocalFile(file) : loadWebFile(file);
37
+ }
38
+ exports.default = loadFile;
@@ -0,0 +1,16 @@
1
+ import * as T from '../types';
2
+ export type FlagAttributes = {
3
+ 'vendored': boolean | null;
4
+ 'generated': boolean | null;
5
+ 'documentation': boolean | null;
6
+ 'binary': boolean | null;
7
+ 'language': T.LanguageResult;
8
+ };
9
+ export type ParsedGitattributes = Array<{
10
+ glob: T.FileGlob;
11
+ attrs: FlagAttributes;
12
+ }>;
13
+ /**
14
+ * Parses a gitattributes file.
15
+ */
16
+ export default function parseAttributes(content: string, folderRoot?: string): ParsedGitattributes;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ /**
8
+ * Parses a gitattributes file.
9
+ */
10
+ function parseAttributes(content, folderRoot = '.') {
11
+ var _a, _b;
12
+ const output = [];
13
+ for (const line of content.split('\n')) {
14
+ if (!line)
15
+ continue;
16
+ const parts = line.split(/\s+/g);
17
+ const fileGlob = parts[0];
18
+ const relFileGlob = path_1.default.join(folderRoot, fileGlob).replace(/\\/g, '/');
19
+ const attrParts = parts.slice(1);
20
+ const isTrue = (str) => !str.startsWith('-') && !str.endsWith('=false');
21
+ const isFalse = (str) => str.startsWith('-') || str.endsWith('=false');
22
+ const trueParts = (str) => attrParts.filter(part => part.includes(str) && isTrue(part));
23
+ const falseParts = (str) => attrParts.filter(part => part.includes(str) && isFalse(part));
24
+ const hasTrueParts = (str) => trueParts(str).length > 0;
25
+ const hasFalseParts = (str) => falseParts(str).length > 0;
26
+ const attrs = {
27
+ 'generated': hasTrueParts('linguist-generated') ? true : hasFalseParts('linguist-generated') ? false : null,
28
+ 'vendored': hasTrueParts('linguist-vendored') ? true : hasFalseParts('linguist-vendored') ? false : null,
29
+ 'documentation': hasTrueParts('linguist-documentation') ? true : hasFalseParts('linguist-documentation') ? false : null,
30
+ 'binary': hasTrueParts('binary') || hasFalseParts('text') ? true : hasFalseParts('binary') || hasTrueParts('text') ? false : null,
31
+ 'language': (_b = (_a = trueParts('linguist-language').at(-1)) === null || _a === void 0 ? void 0 : _a.split('=')[1]) !== null && _b !== void 0 ? _b : null,
32
+ };
33
+ output.push({ glob: relFileGlob, attrs });
34
+ }
35
+ return output;
36
+ }
37
+ exports.default = parseAttributes;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Read part of a file on disc.
3
+ * @throws 'EPERM' if the file is not readable.
4
+ */
5
+ export default function readFile(filename: string, onlyFirstLine?: boolean): Promise<string>;
@@ -1,23 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_1 = __importDefault(require("fs"));
7
- /**
8
- * Read part of a file on disc.
9
- * @throws 'EPERM' if the file is not readable.
10
- */
11
- async function readFile(filename, onlyFirstLine = false) {
12
- const chunkSize = 100;
13
- const stream = fs_1.default.createReadStream(filename, { highWaterMark: chunkSize });
14
- let content = '';
15
- for await (const data of stream) { // may throw
16
- content += data.toString();
17
- if (onlyFirstLine && content.includes('\n')) {
18
- return content.split(/\r?\n/)[0];
19
- }
20
- }
21
- return content;
22
- }
23
- exports.default = readFile;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ /**
8
+ * Read part of a file on disc.
9
+ * @throws 'EPERM' if the file is not readable.
10
+ */
11
+ async function readFile(filename, onlyFirstLine = false) {
12
+ const chunkSize = 100;
13
+ const stream = fs_1.default.createReadStream(filename, { highWaterMark: chunkSize });
14
+ let content = '';
15
+ for await (const data of stream) { // may throw
16
+ content += data.toString();
17
+ if (onlyFirstLine && content.includes('\n')) {
18
+ return content.split(/\r?\n/)[0];
19
+ }
20
+ }
21
+ return content;
22
+ }
23
+ exports.default = readFile;
@@ -0,0 +1,20 @@
1
+ import { Ignore } from 'ignore';
2
+ interface WalkInput {
3
+ /** Whether this is walking the tree from the root */
4
+ init: boolean;
5
+ /** The common root absolute path of all folders being checked */
6
+ commonRoot: string;
7
+ /** The absolute path that each folder is relative to */
8
+ folderRoots: string[];
9
+ /** The absolute path of folders being checked */
10
+ folders: string[];
11
+ /** An instantiated Ignore object listing ignored files */
12
+ ignored: Ignore;
13
+ }
14
+ interface WalkOutput {
15
+ files: string[];
16
+ folders: string[];
17
+ }
18
+ /** Generate list of files in a directory. */
19
+ export default function walk(data: WalkInput): WalkOutput;
20
+ export {};