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.
@@ -1,64 +1,71 @@
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
- let allFiles;
9
- let allFolders;
10
- /** Generate list of files in a directory. */
11
- function walk(init, root, folders, gitignores, regexIgnores) {
12
- // Initialise files and folders lists
13
- if (init) {
14
- allFiles = new Set();
15
- allFolders = new Set();
16
- }
17
- // Walk tree of a folder
18
- if (folders.length === 1) {
19
- const folder = folders[0];
20
- // Get list of files and folders inside this folder
21
- const files = fs_1.default.readdirSync(folder).map(file => {
22
- // Create path relative to root
23
- const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(root, '.');
24
- // Add trailing slash to mark directories
25
- const isDir = fs_1.default.lstatSync(path_1.default.resolve(root, base)).isDirectory();
26
- return isDir ? `${base}/` : base;
27
- });
28
- // Loop through files and folders
29
- for (const file of files) {
30
- // Create absolute path for disc operations
31
- const path = path_1.default.resolve(root, file).replace(/\\/g, '/');
32
- // Skip if nonexistant or ignored
33
- const nonExistant = !fs_1.default.existsSync(path);
34
- const isGitIgnored = gitignores.test(file.replace('./', '')).ignored;
35
- const isRegexIgnored = regexIgnores.find(match => file.replace('./', '').match(match));
36
- if (nonExistant || isGitIgnored || isRegexIgnored)
37
- continue;
38
- // Add absolute folder path to list
39
- allFolders.add(path_1.default.resolve(folder).replace(/\\/g, '/'));
40
- // Check if this is a folder or file
41
- if (file.endsWith('/')) {
42
- // Recurse into subfolders
43
- allFolders.add(path);
44
- walk(false, root, [path], gitignores, regexIgnores);
45
- }
46
- else {
47
- // Add relative file path to list
48
- allFiles.add(path);
49
- }
50
- }
51
- }
52
- // Recurse into all folders
53
- else {
54
- for (const path of folders) {
55
- walk(false, root, [path], gitignores, regexIgnores);
56
- }
57
- }
58
- // Return absolute files and folders lists
59
- return {
60
- files: [...allFiles].map(file => file.replace(/^\./, root)),
61
- folders: [...allFolders],
62
- };
63
- }
64
- exports.default = walk;
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
+ let allFiles;
9
+ let allFolders;
10
+ ;
11
+ ;
12
+ /** Generate list of files in a directory. */
13
+ function walk(data) {
14
+ const { init, commonRoot, folderRoots, folders, ignored } = data;
15
+ // Initialise files and folders lists
16
+ if (init) {
17
+ allFiles = new Set();
18
+ allFolders = new Set();
19
+ }
20
+ // Walk tree of a folder
21
+ if (folders.length === 1) {
22
+ const folder = folders[0];
23
+ const localRoot = folderRoots[0].replace(commonRoot, '').replace(/^\//, '');
24
+ // Get list of files and folders inside this folder
25
+ const files = fs_1.default.readdirSync(folder).map(file => {
26
+ // Create path relative to root
27
+ const base = path_1.default.resolve(folder, file).replace(/\\/g, '/').replace(commonRoot, '.');
28
+ // Add trailing slash to mark directories
29
+ const isDir = fs_1.default.lstatSync(path_1.default.resolve(commonRoot, base)).isDirectory();
30
+ return isDir ? `${base}/` : base;
31
+ });
32
+ // Loop through files and folders
33
+ for (const file of files) {
34
+ // Create absolute path for disc operations
35
+ const path = path_1.default.resolve(commonRoot, file).replace(/\\/g, '/');
36
+ const localPath = localRoot ? file.replace(`./${localRoot}/`, '') : file.replace('./', '');
37
+ // Skip if nonexistant
38
+ const nonExistant = !fs_1.default.existsSync(path);
39
+ if (nonExistant)
40
+ continue;
41
+ // Skip if marked as ignored
42
+ const isIgnored = ignored.test(localPath).ignored;
43
+ if (isIgnored)
44
+ continue;
45
+ // Add absolute folder path to list
46
+ allFolders.add(path_1.default.resolve(folder).replace(/\\/g, '/'));
47
+ // Check if this is a folder or file
48
+ if (file.endsWith('/')) {
49
+ // Recurse into subfolders
50
+ allFolders.add(path);
51
+ walk({ init: false, commonRoot, folderRoots, folders: [path], ignored });
52
+ }
53
+ else {
54
+ // Add file path to list
55
+ allFiles.add(path);
56
+ }
57
+ }
58
+ }
59
+ // Recurse into all folders
60
+ else {
61
+ for (const i in folders) {
62
+ walk({ init: false, commonRoot, folderRoots: [folderRoots[i]], folders: [folders[i]], ignored });
63
+ }
64
+ }
65
+ // Return absolute files and folders lists
66
+ return {
67
+ files: [...allFiles].map(file => file.replace(/^\./, commonRoot)),
68
+ folders: [...allFolders],
69
+ };
70
+ }
71
+ exports.default = walk;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as T from './types';
2
- declare function analyse(path?: string, opts?: T.Options): Promise<T.Results>;
3
- declare function analyse(paths?: string[], opts?: T.Options): Promise<T.Results>;
4
- export = analyse;
1
+ import * as T from './types';
2
+ declare function analyse(path?: string, opts?: T.Options): Promise<T.Results>;
3
+ declare function analyse(paths?: string[], opts?: T.Options): Promise<T.Results>;
4
+ export = analyse;