Skip to content

Commit

Permalink
fix: extract sloc info if component.sources false
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 9, 2021
1 parent c75d859 commit c06c9b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/instrument/src/babel/extract-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ export const extractComponent = async (
component.loc = follow.loc;
}
const { fileInfo = true } = components || {};

if (fileInfo) {
component.fileInfo = await getFileIinfo(follow.filePath, saveSource);
component.fileInfo = await getFileIinfo(follow.filePath, follow.source);
}
if (components && typeof components.resolvePropsFile === 'function') {
const propsFile = components.resolvePropsFile(
Expand Down
7 changes: 6 additions & 1 deletion core/instrument/src/misc/file-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import fs from 'fs';
import path from 'path';
import gitlog, { GitlogOptions } from 'gitlog';
import slocAPI from 'sloc';
import { createHash } from 'crypto';
import { findUpFile } from '@component-controls/core/node-utils';
import { FileInfo } from '@component-controls/core';
import { CachedFileResource } from './chached-file';
export const getFileIinfo = async (
filePath: string,
source?: string,
): Promise<FileInfo> => {
const fileHash = createHash('md5')
.update(source || '')
.digest('hex');

const cached = new CachedFileResource<FileInfo>(
'file-stats',
filePath,
`${filePath}-${fileHash}`,
filePath,
);
let result: FileInfo | undefined;
Expand Down

0 comments on commit c06c9b6

Please sign in to comment.