Skip to content

Commit

Permalink
fix: upgrade [email protected] and fix type import (#1022)
Browse files Browse the repository at this point in the history
- fix types by using explicit export and import (instead of implicit
global declarations)
- upgrade `[email protected]` 
- remove `test` in favor of native `node --test`
  • Loading branch information
styfle authored Nov 12, 2023
1 parent 80f74e3 commit bd03c28
Show file tree
Hide file tree
Showing 22 changed files with 82 additions and 1,098 deletions.
1,121 changes: 45 additions & 1,076 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"prettier": "prettier \"./**/*.ts\" \"./**/*.tsx\" --write",
"git-pre-commit": "npm run prettier && git add -A",
"lint": "npm run prettier && git diff --exit-code",
"test": "tsc && rm -f test/hardlink/link && ln test/hardlink/orig.txt test/hardlink/link && node--test dist/test/"
"test": "tsc && rm -f test/hardlink/link && ln test/hardlink/orig.txt test/hardlink/link && node --test dist/test/"
},
"repository": "styfle/packagephobia",
"author": "styfle",
Expand All @@ -21,14 +21,13 @@
"semver": "^7.5.2"
},
"devDependencies": {
"@types/node": "^18.15.3",
"@types/node": "^18.18.9",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@types/semver": "^7.3.10",
"npm": "^10.2.3",
"prettier": "^3.0.0",
"test": "^3.0.1",
"typescript": "^5.0.2"
"typescript": "^5.2.2"
},
"packageManager": "[email protected]"
}
1 change: 1 addition & 0 deletions src/components/BarGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { getReadableFileSize } from '../util/npm-parser';
import type { PkgSize } from '../types';
const stylesheet = `
.bar-graph{
height:55vh;
Expand Down
1 change: 1 addition & 0 deletions src/components/LinkedLogos.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { escape } from 'querystring';
import LinkedLogo from './LinkedLogo';
import type { PkgSize } from '../types';

interface Props {
pkgSize: PkgSize;
Expand Down
1 change: 1 addition & 0 deletions src/components/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import type { SizeWithUnit } from '../types';

interface Props {
publish: SizeWithUnit;
Expand Down
1 change: 1 addition & 0 deletions src/page-props/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { findOne, insert } from '../util/backend/db';
import { getAllDistTags, getAllVersions, getPublishDate } from '../util/npm-api';
import { calculatePackageSize } from '../util/backend/npm-stats';
import { versionUnknown } from '../util/constants';
import type { NpmManifest, PkgSize } from '../types';

export async function getPkgDetails(
manifest: NpmManifest | null,
Expand Down
1 change: 1 addition & 0 deletions src/page-props/compare.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetchManifest } from '../util/npm-api';
import { getPkgDetails } from './common';
import type { CompareProps, PackageVersion } from '../types';

export async function getCompareProps(
inputStr: string,
Expand Down
1 change: 1 addition & 0 deletions src/page-props/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { findAll } from '../util/backend/db';
import { getAllDistTags, getVersionsForChart, getPublishDate } from '../util/npm-api';
import { getPkgDetails } from './common';
import { NotFoundError } from '../util/not-found-error';
import type { NpmManifest, PackageVersion, ResultProps } from '../types';

export async function getResultProps(
inputStr: string,
Expand Down
1 change: 1 addition & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Logo from '../components/Logo';
import { fetchManifest } from '../util/npm-api';
import { parsePackageString } from '../util/npm-parser';
import { NotFoundError } from '../util/not-found-error';
import type { NpmManifest, PackageVersion, ParsedUrlQuery } from '../types';

const existingPaths = new Set(Object.values(pages));
const logoSize = 108;
Expand Down
1 change: 1 addition & 0 deletions src/pages/compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getBadgeUrl } from '../util/badge';
import { Stat } from '../components/Stats';
import SearchBar from '../components/SearchBar';
import Sponsors from '../components/Sponsors';
import type { CompareProps } from '../types';

export default ({ inputStr, results }: CompareProps) => {
const resultsToPrint = results.map(({ pkgSize, isLatest }) => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Sponsors from '../components/Sponsors';
import { pages, versionUnknown } from '../util/constants';
import { getReadableFileSize } from '../util/npm-parser';
import { getBadgeSvg, getBadgeMarkdown } from '../util/badge';
import type { PkgSize, ResultProps } from '../types';

const error: React.CSSProperties = {
fontSize: '2.3rem',
Expand Down
1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { parsePackageString } from './util/npm-parser';
import semver from 'semver';
import { fetchManifest } from './util/npm-api';
import { NotFoundError } from './util/not-found-error';
import type { ApiResponseV1, ApiResponseV2, PackageJson } from './types';

const { TMPDIR = '/tmp', GA_ID = '', NODE_ENV } = process.env;
process.env.HOME = TMPDIR;
Expand Down
24 changes: 12 additions & 12 deletions src/interfaces/types.d.ts → src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
interface PackageVersion {
export interface PackageVersion {
name: string;
version: string | null;
scoped: boolean;
}

interface SizeWithUnit {
export interface SizeWithUnit {
size: string;
unit: string;
pretty: string;
}

interface PkgSize {
export interface PkgSize {
name: string;
version: string;
publishDate: string;
Expand All @@ -21,49 +21,49 @@ interface PkgSize {
disabled?: boolean;
}

interface ApiResponseV1 {
export interface ApiResponseV1 {
publishSize: number;
installSize: number;
}

interface ApiResponseV2 {
export interface ApiResponseV2 {
name: string;
version: string;
publish: ApiResponseSize;
install: ApiResponseSize;
}

interface ApiResponseSize {
export interface ApiResponseSize {
bytes: number;
files: number;
pretty: string;
color: string;
}

interface ResultProps {
export interface ResultProps {
pkgSize: PkgSize;
readings: PkgSize[];
cacheResult: boolean;
isLatest: boolean;
inputStr: string;
}

interface ComparePackage {
export interface ComparePackage {
pkgSize: PkgSize;
cacheResult: boolean;
isLatest: boolean;
}

interface CompareProps {
export interface CompareProps {
inputStr: string;
results: ComparePackage[];
}

interface ParsedUrlQuery {
export interface ParsedUrlQuery {
[key: string]: string | string[] | undefined;
}

interface NpmManifest {
export interface NpmManifest {
name: string;
description: string;
versions: { [version: string]: any };
Expand All @@ -74,7 +74,7 @@ interface NpmManifest {
};
}

interface PackageJson {
export interface PackageJson {
dependencies: {
[key: string]: string;
};
Expand Down
1 change: 1 addition & 0 deletions src/util/backend/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Redis from 'ioredis';
import type { PkgSize } from '../../types';

const { REDIS_URL = '' } = process.env;
delete process.env.REDIS_URL;
Expand Down
1 change: 1 addition & 0 deletions src/util/backend/npm-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const mkdirAsync = promisify(mkdir);
const writeFileAsync = promisify(writeFile);
const execFileAsync = promisify(execFile);
import { npmInstall, packageString } from './npm-wrapper';
import type { PkgSize } from '../../types';

// TODO: Can this be optimized by changing sync to async?
export function getDirSize(root: string, seen: Set<number>): number {
Expand Down
1 change: 1 addition & 0 deletions src/util/badge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { badgen } from 'badgen';
import { getReadableFileSize, getHexColor, color } from './npm-parser';
import { pages, productionHostname } from '../util/constants';
import type { ApiResponseSize, PkgSize } from '../types';

export function getBadgeSvg(pkgSize: PkgSize) {
const { installSize } = pkgSize;
Expand Down
1 change: 1 addition & 0 deletions src/util/npm-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import https from 'https';
import semver from 'semver';
import { NotFoundError } from './not-found-error';
import type { NpmManifest } from '../types';

const { NPM_REGISTRY_URL = 'https://registry.npmjs.com' } = process.env;

Expand Down
2 changes: 2 additions & 0 deletions src/util/npm-parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PackageVersion, SizeWithUnit } from '../types';

export function parsePackageString(packageString: string): PackageVersion {
let name: string;
let version: string | null;
Expand Down
2 changes: 1 addition & 1 deletion test/npm-api-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as npmapi from '../src/util/npm-api';
import test from 'test';
import test from 'node:test';
import assert from 'assert/strict';

const manifest = {
Expand Down
2 changes: 1 addition & 1 deletion test/npm-parser-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as npmparser from '../src/util/npm-parser';
import test from 'test';
import test from 'node:test';
import assert from 'assert/strict';

const kilobyte = 1024;
Expand Down
2 changes: 1 addition & 1 deletion test/npm-stats-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDirSize } from '../src/util/backend/npm-stats';
import { join } from 'path';
import test from 'test';
import test from 'node:test';
import assert from 'assert/strict';

test('getDirSize top level', () => {
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./dist",
"module": "commonjs",
"target": "es2019",
"moduleResolution": "node",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"jsx": "react",
"sourceMap": true,
"strict": true,
Expand Down

1 comment on commit bd03c28

@vercel
Copy link

@vercel vercel bot commented on bd03c28 Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.