@servicetitan/component-usage
Advanced tools
Comparing version
#!/usr/bin/env node | ||
declare const argv: any; | ||
declare const run: any; | ||
export {}; | ||
//# sourceMappingURL=cli.d.ts.map |
#!/usr/bin/env node | ||
"use strict"; | ||
const argv = require('yargs') | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const yargs_1 = __importDefault(require("yargs")); | ||
const _1 = require("."); | ||
const argv = yargs_1.default | ||
.usage('Usage: $0 [mode] [-b branchName]') | ||
@@ -56,3 +62,3 @@ .options({ | ||
.implies('sendToDataDog', 'dataDogApplicationKey') | ||
.check((argv) => { | ||
.check(argv => { | ||
if (!argv.sendToDataDog && !argv.outputDir && !argv.teamCityOutput) { | ||
@@ -73,4 +79,3 @@ throw new Error('You must specify at least one mode (--sendToDataDog, --outputDir, or --teamCityOutput)'); | ||
} | ||
const { run } = require('./index.js'); | ||
run(argv); | ||
_1.run(argv); | ||
//# sourceMappingURL=cli.js.map |
@@ -1,2 +0,2 @@ | ||
declare const DependencyReport: any; | ||
import DependencyReport from '@segment/dependency-report'; | ||
interface Options { | ||
@@ -10,11 +10,2 @@ outputDir: string; | ||
} | ||
interface DependencyReportEntry { | ||
name: string; | ||
files: number; | ||
filepaths: string[]; | ||
} | ||
declare type DependencyReportGroup = DependencyReportEntry[]; | ||
declare type DependencyReport = DependencyReportGroup[] & { | ||
getPackages(list: string[]): PackageObject[]; | ||
}; | ||
interface DataDogMetric { | ||
@@ -26,8 +17,2 @@ metric: string; | ||
} | ||
interface PackageObject { | ||
name: string; | ||
filepathsForExports: { | ||
[key: string]: string[]; | ||
}; | ||
} | ||
interface FoamTree { | ||
@@ -34,0 +19,0 @@ label: string; |
@@ -35,3 +35,3 @@ "use strict"; | ||
exports.sendMetrics = exports.convertTreeToFoamTree = exports.collapseTree = exports.convertReportToTreemap = exports.generateMetrics = exports.generateDependencyReport = exports.run = void 0; | ||
const DependencyReport = require('@segment/dependency-report'); | ||
const dependency_report_1 = __importDefault(require("@segment/dependency-report")); | ||
const dogapi = __importStar(require("dogapi")); | ||
@@ -42,3 +42,3 @@ const fs_1 = __importDefault(require("fs")); | ||
const metricPrefix = 'far.componentUsage'; | ||
const now = Math.floor(new Date().getTime() / 1000).toString(); | ||
const now = Math.floor(Date.now() / 1000).toString(); | ||
const statsFileName = 'componentUsageStats.json'; | ||
@@ -105,3 +105,3 @@ // TODO: accept cli list or check github for uikit packages? | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const report = new DependencyReport({ | ||
const report = new dependency_report_1.default({ | ||
files: ['**/*.tsx'], | ||
@@ -127,2 +127,3 @@ parser: 'typescript', | ||
const reportByPackageName = report.getPackages(packageList); | ||
console.info('packagepreport looks like ', JSON.stringify(reportByPackageName, null, 2)); | ||
const metrics = []; | ||
@@ -129,0 +130,0 @@ const countByPackage = {}; |
{ | ||
"name": "@servicetitan/component-usage", | ||
"version": "0.0.17", | ||
"version": "9.4.0", | ||
"description": "Usage metrics of @servicetitan components", | ||
@@ -20,3 +20,4 @@ "homepage": "https://docs.st.dev/docs/frontend/component-usage", | ||
"devDependencies": { | ||
"@types/dogapi": "~2.8.3" | ||
"@types/dogapi": "~2.8.3", | ||
"@types/yargs": "~15.0.4" | ||
}, | ||
@@ -33,3 +34,4 @@ "dependencies": { | ||
"webpack": false | ||
} | ||
}, | ||
"gitHead": "3dd3a1312a72ea0af49e1e1643b2136cff5e3220" | ||
} |
@@ -1,3 +0,26 @@ | ||
'use strict'; | ||
import { | ||
generateDependencyReport, | ||
convertTreeToFoamTree, | ||
convertReportToTreemap, | ||
collapseTree, | ||
generateMetrics, | ||
sendMetrics, | ||
} from '..'; | ||
import dogapi from 'dogapi'; | ||
import { mocked } from 'ts-jest/utils'; | ||
jest.mock('dogapi'); | ||
const mockedDogapi = mocked(dogapi, true); | ||
jest.mock('@segment/dependency-report', () => { | ||
return jest | ||
.fn() | ||
.mockImplementation(() => { | ||
return { run: jest.fn(() => Promise.resolve()) }; | ||
}) | ||
.mockImplementationOnce(() => { | ||
return { run: jest.fn(() => Promise.reject()) }; | ||
}); | ||
}); | ||
describe('@servicetitan/component-usage', () => { | ||
@@ -24,13 +47,5 @@ const realProcess = process; | ||
describe('generateDependencyReport', () => { | ||
it('should process.exit(2) on error', () => { | ||
jest.mock('@segment/dependency-report', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return Promise.reject(); | ||
}); | ||
}); | ||
const { generateDependencyReport } = require('../index'); | ||
it('should swallow error and call process.exit(2)', () => { | ||
expect.assertions(1); | ||
return generateDependencyReport().catch(() => { | ||
return generateDependencyReport().then(() => { | ||
expect(exitMock).toHaveBeenCalledWith(2); | ||
@@ -43,5 +58,4 @@ }); | ||
it('should convert the report format to a treemap', () => { | ||
const { convertReportToTreemap } = require('../index'); | ||
const report = { | ||
const report = Object.assign([], { | ||
run: jest.fn(), | ||
getPackages: () => { | ||
@@ -51,11 +65,17 @@ return [ | ||
name: 'mockPackageOne', | ||
filepathsForExports: { export1: ['path1'], export2: ['path2'] }, | ||
filepathsForExports: { | ||
export1: ['path1', 'path2'], | ||
export2: ['path3', 'path4'], | ||
}, | ||
}, | ||
{ | ||
name: 'mockPackageTwo', | ||
filepathsForExports: { export10: ['path10', 'path20'] }, | ||
filepathsForExports: { | ||
export1: ['path5', 'path6'], | ||
export2: ['path7', 'path8'], | ||
}, | ||
}, | ||
]; | ||
}, | ||
}; | ||
}); | ||
@@ -66,12 +86,18 @@ const treemap = { | ||
path1: {}, | ||
path2: {}, | ||
}, | ||
export2: { | ||
path2: {}, | ||
path3: {}, | ||
path4: {}, | ||
}, | ||
}, | ||
mockPackageTwo: { | ||
export10: { | ||
path10: {}, | ||
path20: {}, | ||
export1: { | ||
path5: {}, | ||
path6: {}, | ||
}, | ||
export2: { | ||
path7: {}, | ||
path8: {}, | ||
}, | ||
}, | ||
@@ -86,3 +112,2 @@ }; | ||
it('should convert a simple tree to the right format', () => { | ||
const { convertTreeToFoamTree } = require('../index'); | ||
const tree = { a: { b: {}, c: {} } }; | ||
@@ -118,4 +143,2 @@ const foamTree = { | ||
it('should collapse a simple tree correctly', () => { | ||
const { collapseTree } = require('../index'); | ||
const tree = { | ||
@@ -151,5 +174,4 @@ a: { | ||
it('should generate the right metrics and output to TeamCity log', () => { | ||
const { generateMetrics } = require('../index'); | ||
const report = { | ||
const report = Object.assign([], { | ||
run: jest.fn(), | ||
getPackages: () => { | ||
@@ -163,3 +185,3 @@ return [ | ||
}, | ||
}; | ||
}); | ||
@@ -204,11 +226,10 @@ const options = { | ||
describe('sendMetrics', () => { | ||
beforeEach(() => { | ||
mockedDogapi.metric.send_all.mockClear(); | ||
}); | ||
it('should initialize the data dog api', () => { | ||
jest.mock('dogapi'); | ||
const dogMock = require('dogapi'); | ||
const { sendMetrics } = require('../index'); | ||
sendMetrics([], 'mockApiKey', 'mockAppKey'); | ||
expect(dogMock.initialize).toHaveBeenCalledWith({ | ||
expect(mockedDogapi.initialize).toHaveBeenCalledWith({ | ||
api_key: 'mockApiKey', // eslint-disable-line @typescript-eslint/naming-convention | ||
@@ -220,13 +241,18 @@ app_key: 'mockAppKey', // eslint-disable-line @typescript-eslint/naming-convention | ||
it('should send the metrics', () => { | ||
jest.mock('dogapi'); | ||
const dogMock = require('dogapi'); | ||
const mockMetric = [ | ||
{ | ||
metric: 'mockMetricName', | ||
points: [], | ||
tags: ['mockTag'], | ||
metric_type: 'mockType', // eslint-disable-line @typescript-eslint/naming-convention | ||
}, | ||
]; | ||
const { sendMetrics } = require('../index'); | ||
sendMetrics(['mockMetric'], 'mockApiKey', 'mockAppKey'); | ||
sendMetrics(mockMetric, 'mockApiKey', 'mockAppKey'); | ||
// first and only call should have the metrics as the first arg | ||
expect(dogMock.metric.send_all).toHaveBeenCalledTimes(1); | ||
expect(dogMock.metric.send_all.mock.calls[0][0]).toEqual(['mockMetric']); | ||
expect(mockedDogapi.metric.send_all).toHaveBeenCalledTimes(1); | ||
expect(mockedDogapi.metric.send_all.mock.calls[0][0]).toEqual(mockMetric); | ||
}); | ||
}); | ||
}); |
#!/usr/bin/env node | ||
const argv = require('yargs') | ||
import yargs from 'yargs'; | ||
import { run } from '.'; | ||
const argv = yargs | ||
.usage('Usage: $0 [mode] [-b branchName]') | ||
@@ -56,3 +59,3 @@ .options({ | ||
.implies('sendToDataDog', 'dataDogApplicationKey') | ||
.check((argv: { sendToDataDog: string; outputDir: string; teamCityOutput: string }) => { | ||
.check(argv => { | ||
if (!argv.sendToDataDog && !argv.outputDir && !argv.teamCityOutput) { | ||
@@ -77,3 +80,2 @@ throw new Error( | ||
const { run } = require('./index.js'); | ||
run(argv); |
@@ -1,2 +0,2 @@ | ||
const DependencyReport = require('@segment/dependency-report'); | ||
import DependencyReport from '@segment/dependency-report'; | ||
import * as dogapi from 'dogapi'; | ||
@@ -8,3 +8,3 @@ import fs from 'fs'; | ||
const metricPrefix = 'far.componentUsage'; | ||
const now: string = Math.floor(new Date().getTime() / 1000).toString(); | ||
const now = Math.floor(Date.now() / 1000).toString(); | ||
@@ -22,10 +22,2 @@ const statsFileName = 'componentUsageStats.json'; | ||
interface DependencyReportEntry { | ||
name: string; | ||
files: number; | ||
filepaths: string[]; | ||
} | ||
type DependencyReportGroup = DependencyReportEntry[]; | ||
type DependencyReport = DependencyReportGroup[] & { getPackages(list: string[]): PackageObject[] }; | ||
interface DataDogMetric { | ||
@@ -40,4 +32,5 @@ metric: string; | ||
name: string; | ||
filepathsForExports: { [key: string]: string[] }; | ||
filepathsForExports: Record<string, string[]>; | ||
} | ||
interface FoamTree { | ||
@@ -121,3 +114,3 @@ label: string; | ||
*/ | ||
export async function generateDependencyReport(): Promise<DependencyReport> { | ||
export async function generateDependencyReport() { | ||
const report = new DependencyReport({ | ||
@@ -145,5 +138,6 @@ files: ['**/*.tsx'], | ||
const reportByPackageName = report.getPackages(packageList); | ||
console.info('packagepreport looks like ', JSON.stringify(reportByPackageName, null, 2)); | ||
const metrics: DataDogMetric[] = []; | ||
const countByPackage: { [key: string]: number } = {}; | ||
const countByPackage: Record<string, number> = {}; | ||
reportByPackageName.forEach((packageObj: PackageObject) => { | ||
@@ -150,0 +144,0 @@ const packageDisplayName: string = packages[packageObj.name] || packageObj.name; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
190246
0.37%16
6.67%1542
2.39%0
-100%2
100%1
Infinity%