Skip to content

Commit

Permalink
Always use absolute paths in output
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 1, 2021
1 parent 97547ca commit 8fa0410
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.3
*2021-08-01*
- Changed outputted file paths to always be absolute regardless of input.

## 1.4.2
*2021-08-01*
- Fixed crash occurring when checking named patterns.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linguist-js",
"version": "1.4.2",
"version": "1.4.3",
"description": "Analyse languages used in a folder. Powered by GitHub Linguist, although it doesn't need to be installed.",
"main": "dist/index.js",
"bin": {
Expand Down
14 changes: 11 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const VERSION = require('../package.json').version;

import linguist from './index.js';
import path from 'path';
import yargs from 'yargs-parser';

import linguist from './index';
import * as T from './types';

const indent = (n: number) => ' '.repeat(n * 4);
Expand Down Expand Up @@ -55,7 +56,9 @@ else if (args.analyse) {
if (args.A) opts.checkAttributes = args.A;
if (args.I) opts.checkIgnored = args.I;
if (args.H) opts.checkHeuristics = args.H;
const { count, languages, results } = await linguist(args._[0], opts);

const root = args._[0] ?? '.';
const { count, languages, results } = await linguist(root, opts);
if (args.summary) {
const { data, markup, programming, prose, total: { bytes: totalBytes } } = languages;
const languageData = { data, markup, programming, prose };
Expand All @@ -69,7 +72,12 @@ else if (args.analyse) {
console.log(`Total: ${totalBytes.toLocaleString()} bytes`);
}
else {
console.log(args.files ? { results, count, languages } : { count, languages });
const relResults: Record<T.FilePath, T.Language> = {};
for (const [file, lang] of Object.entries(results)) {
const relFile = file.replace(path.resolve(root).replace(/\\/g, '/'), '.');
relResults[relFile] = lang;
}
console.log(args.files ? { results: relResults, count, languages } : { count, languages });
}
})();
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import path from 'path';
import fetch from 'node-fetch';
import yaml from 'js-yaml';
import glob from 'glob';
Expand Down Expand Up @@ -31,7 +32,7 @@ export = async function analyse(root = '.', opts: T.Options = {}) {
total: { unique: 0, bytes: 0, unknownBytes: 0 },
};

const sourceFiles = glob.sync(root + '/**/*', {});
const sourceFiles = glob.sync(path.resolve(root) + '/**/*', {});
const folders = new Set<string>();

// Apply aliases
Expand Down
2 changes: 1 addition & 1 deletion test/perf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const linguist = require('../dist/index.js');
const linguist = require('..');

async function perfTest() {
let times = [];
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const linguist = require('../dist/index.js');
const linguist = require('..');

async function test() {
const samplesFolder = __dirname.replace(/\\/g, '/') + '/samples';
Expand Down

0 comments on commit 8fa0410

Please sign in to comment.