mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Expose aggregate file sizes in FileStats
We're not sure that file counts are a good proxy for project size and this will give us more direct insight.
This commit is contained in:
@@ -123,11 +123,22 @@ namespace ts.server {
|
||||
|
||||
export interface FileStats {
|
||||
readonly js: number;
|
||||
readonly jsSize?: number;
|
||||
|
||||
readonly jsx: number;
|
||||
readonly jsxSize?: number;
|
||||
|
||||
readonly ts: number;
|
||||
readonly tsSize?: number;
|
||||
|
||||
readonly tsx: number;
|
||||
readonly tsxSize?: number;
|
||||
|
||||
readonly dts: number;
|
||||
readonly dtsSize?: number;
|
||||
|
||||
readonly deferred: number;
|
||||
readonly deferredSize?: number;
|
||||
}
|
||||
|
||||
export interface OpenFileInfo {
|
||||
@@ -1600,7 +1611,7 @@ namespace ts.server {
|
||||
setProjectOptionsUsed(project);
|
||||
const data: ProjectInfoTelemetryEventData = {
|
||||
projectId: this.host.createSHA256Hash(project.projectName),
|
||||
fileStats: countEachFileTypes(project.getScriptInfos()),
|
||||
fileStats: countEachFileTypes(project.getScriptInfos(), /*includeSizes*/ true),
|
||||
compilerOptions: convertCompilerOptionsForTelemetry(project.getCompilationSettings()),
|
||||
typeAcquisition: convertTypeAcquisition(project.getTypeAcquisition()),
|
||||
extends: projectOptions && projectOptions.configHasExtendsProperty,
|
||||
|
||||
@@ -10,26 +10,43 @@ namespace ts.server {
|
||||
export type Mutable<T> = { -readonly [K in keyof T]: T[K]; };
|
||||
|
||||
/* @internal */
|
||||
export function countEachFileTypes(infos: ScriptInfo[]): FileStats {
|
||||
const result: Mutable<FileStats> = { js: 0, jsx: 0, ts: 0, tsx: 0, dts: 0, deferred: 0 };
|
||||
export function countEachFileTypes(infos: ScriptInfo[], includeSizes = false): FileStats {
|
||||
const result: Mutable<FileStats> = {
|
||||
js: 0, jsSize: 0,
|
||||
jsx: 0, jsxSize: 0,
|
||||
ts: 0, tsSize: 0,
|
||||
tsx: 0, tsxSize: 0,
|
||||
dts: 0, dtsSize: 0,
|
||||
deferred: 0, deferredSize: 0,
|
||||
};
|
||||
for (const info of infos) {
|
||||
const fileSize = includeSizes ? info.getTelemetryFileSize() : 0;
|
||||
switch (info.scriptKind) {
|
||||
case ScriptKind.JS:
|
||||
result.js += 1;
|
||||
result.jsSize! += fileSize;
|
||||
break;
|
||||
case ScriptKind.JSX:
|
||||
result.jsx += 1;
|
||||
result.jsxSize! += fileSize;
|
||||
break;
|
||||
case ScriptKind.TS:
|
||||
fileExtensionIs(info.fileName, Extension.Dts)
|
||||
? result.dts += 1
|
||||
: result.ts += 1;
|
||||
if (fileExtensionIs(info.fileName, Extension.Dts)) {
|
||||
result.dts += 1;
|
||||
result.dtsSize! += fileSize;
|
||||
}
|
||||
else {
|
||||
result.ts += 1;
|
||||
result.tsSize! += fileSize;
|
||||
}
|
||||
break;
|
||||
case ScriptKind.TSX:
|
||||
result.tsx += 1;
|
||||
result.tsxSize! += fileSize;
|
||||
break;
|
||||
case ScriptKind.Deferred:
|
||||
result.deferred += 1;
|
||||
result.deferredSize! += fileSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,6 +316,11 @@ namespace ts.server {
|
||||
return this.textStorage.version;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
getTelemetryFileSize() {
|
||||
return this.textStorage.getTelemetryFileSize();
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
public isDynamicOrHasMixedContent() {
|
||||
return this.hasMixedContent || this.isDynamic;
|
||||
|
||||
Reference in New Issue
Block a user