Skip to content

Commit

Permalink
Merge pull request #703 from oBusk/app-directory
Browse files Browse the repository at this point in the history
Next.js 13 - App directory
  • Loading branch information
oBusk authored Apr 16, 2023
2 parents 397f8bc + 14d0b76 commit 00439c4
Show file tree
Hide file tree
Showing 153 changed files with 1,794 additions and 1,439 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.next
.vscode/.chrome
coverage/
static/media/
7 changes: 7 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import "@testing-library/jest-dom/extend-expect";

// Override the react.cache method to avoid caching in tests
jest.mock("react", () => {
const React = jest.requireActual("react");
React.cache = (fn) => fn;
return React;
});
14 changes: 12 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
compiler: {
emotion: true,
// Does not work with appDir
// https://beta.nextjs.org/docs/styling/css-in-js
// compiler: {
// emotion: true,
// },
experimental: {
serverComponentsExternalPackages: [
"libnpmdiff",
"npm-package-arg",
"pacote",
],
appDir: true,
},
};
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@emotion/styled": "^11.10.6",
"@vercel/analytics": "^0.1.11",
"downshift": "^7.6.0",
"gitdiff-parser": "^0.3.1",
"jest": "^29.5.0",
"libnpmdiff": "^5.0.15",
"next": "^13.3.0",
Expand Down
Binary file removed public/favicon-16x16.png
Binary file not shown.
Binary file removed public/favicon-32x32.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Code, forwardRef } from "@chakra-ui/react";
import BorderBox, { BorderBoxProps } from "./theme/BorderBox";
import { Code, forwardRef, VStack } from "@chakra-ui/react";
import BorderBox, { BorderBoxProps } from "^/components/BorderBox";

export interface ErrorBoxProps extends BorderBoxProps {}

const ErrorBox = forwardRef<ErrorBoxProps, typeof BorderBox>((props, ref) => {
return (
<BorderBox
as={Code}
as={VStack}
backgroundColor="red.200"
_dark={{
backgroundColor: "red.700",
Expand Down
97 changes: 97 additions & 0 deletions src/app/[...parts]/_page/BundlephobiaDiff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import bundlephobia from "^/lib/api/bundlephobia";
import TIMED_OUT from "^/lib/api/TimedOut";
import { Bundlephobia } from "^/lib/Services";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import measuredPromise from "^/lib/utils/measuredPromise";
import BundlephobiaFlags, {
BundlephobiaFlagsSkeleton,
} from "./DiffIntro/BundlePhobiaFlags";
import SizeComparison, { SizeComparisonSkeleton } from "./SizeComparison";

export interface BundlephobiaDiffProps {
a: SimplePackageSpec;
b: SimplePackageSpec;
specs: [string, string];
}

const { name } = Bundlephobia;

const BundlephobiaDiff = async ({ specs, a, b }: BundlephobiaDiffProps) => {
const { result, time } = await measuredPromise(bundlephobia(specs));

if (result == null) {
console.warn(`${name} result is null`, { specs });
return null;
}

if (result === TIMED_OUT) {
console.warn(`${name} timed out`, { specs });
return null;
}

console.log(name, { specs, time });

return (
<SizeComparison
serviceName={name}
flags={<BundlephobiaFlags data={result} />}
a={a}
b={b}
sizeRows={[
{
name: "Size",
a: {
bytes: result.a.size,
},
b: {
bytes: result.b.size,
},
},
{
name: "Gzip",
a: {
bytes: result.a.gzip,
},
b: {
bytes: result.b.gzip,
},
},
{
name: "Dependencies",
a: {
count: result.a.dependencyCount,
},
b: {
count: result.b.dependencyCount,
},
},
]}
/>
);
};

export default BundlephobiaDiff;

export const BundlephobiaDiffSkeleton = () => (
<SizeComparisonSkeleton
serviceName={name}
flags={<BundlephobiaFlagsSkeleton />}
sizeRows={[
{
name: "Size",
a: 42,
b: 84,
},
{
name: "Gzip",
a: 42,
b: 84,
},
{
name: "Dependencies",
a: 16,
b: 32,
},
]}
/>
);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { Code, forwardRef, HStack, StackProps, Text } from "@chakra-ui/react";
import { ReactNode } from "react";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use client";

import { HStack } from "@chakra-ui/react";
import { FlagSkeleton } from "./Flag";

const BundlephobiaFlagsSkeleton = () => (
<HStack>
<FlagSkeleton />
<FlagSkeleton />
</HStack>
);

export default BundlephobiaFlagsSkeleton;
55 changes: 55 additions & 0 deletions src/app/[...parts]/_page/DiffIntro/BundlePhobiaFlags/Flag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
forwardRef,
Skeleton,
Tag,
TagLabel,
TagLeftIcon,
TagProps,
} from "@chakra-ui/react";
import { ElementType, ReactNode } from "react";
import Tooltip from "^/components/Tooltip";
import TreeshakeIcon from "./assets/TreeshakeIcon";

interface FlagProps extends TagProps {
icon: ElementType;
label: string;
tooltip?: ReactNode;
colorScheme?: undefined | "green" | "red";
}

const Flag = forwardRef<FlagProps, "div">(
({ label, icon, tooltip, colorScheme, ...props }, ref) => {
const tag = (
<Tag
colorScheme={colorScheme}
cursor="help"
margin="10px 0"
{...props}
ref={ref}
>
<TagLeftIcon boxSize="16px" as={icon} fill="currentColor" />
<TagLabel>{label}</TagLabel>
</Tag>
);

if (tooltip == null) {
return tag;
}

return (
<Tooltip
label={tooltip}
closeOnClick={false}
shouldWrapChildren={true}
>
{tag}
</Tooltip>
);
},
);

export default Flag;

export const FlagSkeleton = () => (
<Skeleton margin="10px 0" width="130px" height="24px" />
);
5 changes: 5 additions & 0 deletions src/app/[...parts]/_page/DiffIntro/BundlePhobiaFlags/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BundlephobiaFlags, { BundlephobiaFlagsProps } from "./BundlePhobiaFlags";
import BundlephobiaFlagsSkeleton from "./BundlePhobiaFlagsSkeleton";

export default BundlephobiaFlags;
export { BundlephobiaFlagsSkeleton, type BundlephobiaFlagsProps };
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Code } from "@chakra-ui/react";
import { forwardRef } from "@chakra-ui/system";
import DiffOptions from "^/lib/DiffOptions";
import { NpmDiffOptions } from "^/lib/npmDiff";

export interface CommandProps {
aName: string;
aVersion: string;
bName: string;
bVersion: string;
options: DiffOptions;
options: NpmDiffOptions;
}

function toKebabCase(input: string): string {
Expand Down
81 changes: 81 additions & 0 deletions src/app/[...parts]/_page/DiffIntro/DiffIntro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"use client";

import {
Box,
Code,
Flex,
FlexProps,
forwardRef,
Heading,
Text,
} from "@chakra-ui/react";
import { ReactNode } from "react";
import { NpmDiffOptions } from "^/lib/npmDiff";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import contentVisibility from "^/lib/utils/contentVisibility";
import Halfs from "./Halfs";
import Options from "./Options";
import SpecBox from "./SpecBox";

export interface DiffIntroProps extends FlexProps {
a: SimplePackageSpec;
b: SimplePackageSpec;
services: ReactNode;
options: NpmDiffOptions;
}

const DiffIntro = forwardRef<DiffIntroProps, "h2">(
({ a, b, services, options, ...props }, ref) => {
if (a.name == null) {
a.name = "ERROR";
}
if (b.name == null) {
b.name = "ERROR";
}

return (
<Flex
direction="column"
alignItems="center"
css={{
label: "DiffIntro",
...contentVisibility("700px"),
}}
{...props}
ref={ref}
>
<Heading
as="h2"
size="sm"
width="100%"
textAlign="center"
marginBottom="1.5em"
>
<Text>Comparing </Text>
<Halfs
left={<SpecBox pkg={a} />}
center={
<Box>
{/* Center column */}
<Code>...</Code>
</Box>
}
right={<SpecBox pkg={b} />}
/>
</Heading>
{services}
<Heading size="l">npm diff</Heading>
<Options options={options} />
{/* <Command
aName={aName}
aVersion={aVersion}
bName={bName}
bVersion={bVersion}
options={options}
/> */}
</Flex>
);
},
);

export default DiffIntro;
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Flex } from "@chakra-ui/react";
import { Flex, FlexProps } from "@chakra-ui/react";
import { forwardRef } from "@chakra-ui/system";
import { ReactNode } from "react";

interface ComparisonViewProps {
export interface HalfsProps
extends Omit<FlexProps, "children" | "left" | "right"> {
left: ReactNode;
center?: ReactNode;
right: ReactNode;
}

const Halfs = forwardRef<ComparisonViewProps, typeof Flex>(
const Halfs = forwardRef<HalfsProps, typeof Flex>(
({ left, center, right, ...props }, ref) => (
<Flex {...props} ref={ref}>
<Flex flex="1 0 0px" justifyContent="flex-end">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Code, Heading, Text } from "@chakra-ui/react";
import { forwardRef } from "@chakra-ui/system";
import { BorderBox } from "^/components/theme";
import DiffOptions from "^/lib/DiffOptions";
import BorderBox from "^/components/BorderBox";
import { NpmDiffOptions } from "^/lib/npmDiff";

interface OptionsProps {
options: DiffOptions;
options: NpmDiffOptions;
}

const Options = forwardRef<OptionsProps, typeof BorderBox>(
Expand Down
Loading

1 comment on commit 00439c4

@vercel
Copy link

@vercel vercel bot commented on 00439c4 Apr 16, 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.