Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js 13 - App directory #703

Merged
merged 131 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
b388516
Enable appDir in next configuration
oBusk Nov 2, 2022
f02ea0e
Disable emotion in compiler. It breaks app pages
oBusk Nov 2, 2022
9959fc6
Add dummy app dir page
oBusk Nov 2, 2022
bf7e8d3
Move about over to app directory. Not working.
oBusk Nov 2, 2022
cfdc3c2
Replace about/api into pages.
oBusk Nov 7, 2022
95d3c79
Migrate app/document into layout.tsx
oBusk Nov 7, 2022
6134a3a
remove dummy page, not needed anymore
oBusk Nov 7, 2022
e0e1a7f
Don't prefetch about/api pages
oBusk Nov 7, 2022
e1b47bb
Avoid warnings about next/image
oBusk Nov 7, 2022
4ccb1f2
Fix about not appearing as active in header
oBusk Nov 7, 2022
45bf884
Revert "Don't prefetch about/api pages"
oBusk Nov 7, 2022
3180bb8
Try to see if this fixes the various pre-loading issues.
oBusk Nov 7, 2022
f6e73f6
Move index page into /app directory.
oBusk Nov 8, 2022
e84b02a
This lint-ignore should not be needed any more
oBusk Nov 8, 2022
303faab
Move entire landing into app/
oBusk Nov 8, 2022
feb2678
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 12, 2022
5691460
Create a clone of about/api in appdir
oBusk Nov 12, 2022
6d5fadb
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 15, 2022
8e9ba00
Replace pages/about/api with app/about/api
oBusk Nov 15, 2022
360b7fb
Move diffpage into app dir - Step 1/2 - Rename
oBusk Nov 15, 2022
59773fe
Use npm lib packages as external packages
oBusk Nov 16, 2022
ed1cfc7
Migrate ViewTypeSwitch to use next/navigation
oBusk Nov 16, 2022
1e80705
Move diffpage into app dir - Stem 2/2 - Convert
oBusk Nov 16, 2022
17779de
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 16, 2022
49d4566
Remove middleware that should no longer be needed
oBusk Nov 16, 2022
1d780de
Delete pages/_app and pages/_document
oBusk Nov 16, 2022
9eef0b4
Set title and description
oBusk Nov 16, 2022
7047336
Move about page client code into app/
oBusk Nov 17, 2022
49ceb4b
Rename index page components directory to `(components)`
oBusk Nov 17, 2022
99489ef
Fix type of AboutPage
oBusk Nov 17, 2022
07ebe3d
Move diff page components into app dir
oBusk Nov 17, 2022
f6230be
Rename all page components into '_page'
oBusk Nov 17, 2022
4618198
Move layout components into './_layout'
oBusk Nov 17, 2022
1d0a141
Move component/theme -> components/
oBusk Nov 17, 2022
2b5dee1
Move diff type param name into related folder
oBusk Nov 17, 2022
bc0db4f
Move diff-view files into related folder
oBusk Nov 17, 2022
75d36dc
Move homepage and about page to edge
oBusk Nov 17, 2022
3ee5c11
Try what happens if I put diff page on edge
oBusk Nov 17, 2022
433a191
Revert "Try what happens if I put diff page on edge"
oBusk Nov 17, 2022
4fb396e
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 18, 2022
b76ddb0
Fix segment being encoded.
oBusk Nov 18, 2022
eaa5873
Rename diffView to page.client
oBusk Nov 19, 2022
1944e52
Move errors from diff page to separate error
oBusk Nov 19, 2022
70a5277
Convert external diff to use SERVER COMPONENTS 🤯
oBusk Nov 19, 2022
3cfc45d
Try to fix bug where "parts=..." is added to the query in redirect
oBusk Nov 19, 2022
f71be40
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 20, 2022
cb8e566
stop prefetching viewtype split/unified
oBusk Nov 20, 2022
1d9e8bc
Make diffIntro non-reliant on files and diff result
oBusk Nov 20, 2022
76e600b
Be more consistent how to pass name/version
oBusk Nov 20, 2022
629523c
Refactor NpmDiff to happen in server component
oBusk Nov 20, 2022
24c0918
Minor cleanup of diff page
oBusk Nov 20, 2022
31d6a9e
Use simplePackageSpec in place of ComparedPackage
oBusk Nov 20, 2022
11cc68d
Cleanup parsing to SimplePackageSpec a little
oBusk Nov 20, 2022
342d992
Move files used in NpmDiff into folder
oBusk Nov 20, 2022
9ea55f0
Still support changing viewType
oBusk Nov 20, 2022
e44dd79
Ensure to cache diff
oBusk Nov 20, 2022
01af43b
Cache canonicalSpec
oBusk Nov 20, 2022
5ea9f49
Ensure all pages are static
oBusk Nov 20, 2022
0ab09b7
Print timing inside cache
oBusk Nov 20, 2022
bd76786
Fix tests using React.cache()
oBusk Nov 20, 2022
d83aa21
Make caching of methods a bit more default
oBusk Nov 20, 2022
eea4daf
Fix wrong import in test
oBusk Nov 20, 2022
0881796
Use method name in console.log
oBusk Nov 20, 2022
6ea4771
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Nov 25, 2022
0eda2c9
Add static/media to gitignore
oBusk Nov 25, 2022
a8c187f
chore(deps): Bump all versions that does not break app
oBusk Feb 24, 2023
a14654a
Fix lint problem
oBusk Feb 23, 2023
2267c14
External service components should not Throw errors.
oBusk Feb 24, 2023
43a418e
Stop using edge-experimental for pages as it seems to break.
oBusk Feb 24, 2023
cfc234f
Upgrade react-diff-view and adjust for typing
oBusk Feb 23, 2023
dc692c9
chore(deps): Update react-diff-view
oBusk Feb 24, 2023
0bdb83a
Use exported types from react-diff-view
oBusk Feb 24, 2023
319149b
Fix build failing because missing diff parser
oBusk Feb 24, 2023
d70cd2c
Fix type failings
oBusk Feb 25, 2023
da2897d
fix: remove unwanted vertical scroll
oBusk Feb 25, 2023
289e3a0
Bump npm-package-arg in package.json
oBusk Feb 25, 2023
f62c3f1
chore(deps): Bump next to 13.1
oBusk Feb 25, 2023
930eb46
Edge runtime is no longer experimental
oBusk Feb 23, 2023
7d17243
Setup params for statically generated diff pages
oBusk Feb 25, 2023
7e7c565
chore(deps): Bump next.js to latest version
oBusk Feb 25, 2023
26683ae
Checkin automatic update to env.d.ts
oBusk Feb 25, 2023
f6dda7c
Fix type issues with updated searchParams
oBusk Feb 26, 2023
3053fe2
chode(deps): Bump some safer deps
oBusk Apr 9, 2023
cd3e2e4
chore: Remove wrong param
oBusk Apr 9, 2023
32820f4
chore(deps): Bump all versions except Next
oBusk Apr 9, 2023
d5b885a
chore(deps): Bump next.js
oBusk Apr 9, 2023
78cad5a
Use npm-package-arg as external package to allow build
oBusk Apr 9, 2023
c90a529
chore(deps): Bump all sub-dependencies
oBusk Apr 9, 2023
67adcb6
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 9, 2023
3780624
Remove workaround. (vercel/next.js#47930)
oBusk Apr 10, 2023
900a3ee
Just supress the hydration warnings for theme
oBusk Apr 10, 2023
04339a3
Migrate metadata to new file based metadata
oBusk Apr 10, 2023
48d3f5f
Add analytics
oBusk Apr 10, 2023
e51c63f
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 10, 2023
052bff1
Restructure diff page to investigate suspenses
oBusk Apr 10, 2023
4a0e4e3
Pass compiled styles from server to client.
oBusk Apr 11, 2023
d95a518
Disable analytics when running locally
oBusk Apr 11, 2023
060b794
Update launch script to match Next.js Documentation
oBusk Apr 11, 2023
366c574
Update diff method to actually cache.
oBusk Apr 11, 2023
b2f4eca
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 11, 2023
37148ad
Add first stab at skeleton for packagephobia diff
oBusk Apr 12, 2023
76191dd
Less jumpiness by flex 1 diff fallback
oBusk Apr 12, 2023
7cbbb87
Fix annoying props issues
oBusk Apr 12, 2023
10ade76
See if adding fallback to bundlephobia suspense makes any differance
oBusk Apr 12, 2023
6764024
Temporarily delay
oBusk Apr 12, 2023
705f0ab
Stop forcing static
oBusk Apr 12, 2023
a383335
Add loading page to see if it has any
oBusk Apr 12, 2023
70d1fa3
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 12, 2023
f8737b4
Wrap all usages of dynamic functions in Suspense
oBusk Apr 12, 2023
b1d66dd
Force caching on diff page
oBusk Apr 12, 2023
6e38f9f
Revert "Temporarily delay"
oBusk Apr 12, 2023
343fb7d
Artificially slow down diff to make caching more obvious
oBusk Apr 12, 2023
55642b7
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 13, 2023
681f6ec
Do we get caching if we set revalidate?
oBusk Apr 15, 2023
f954658
Go back to where we came from :(
oBusk Apr 15, 2023
2b8c7b0
Revert "Artificially slow down diff to make caching more obvious"
oBusk Apr 15, 2023
a501347
Full skeleton for bundle/packagephobia
oBusk Apr 16, 2023
836b5ad
Silly skeleton for NpmDiff
oBusk Apr 16, 2023
6c2fa44
Refactor viewtype to hook
oBusk Apr 16, 2023
92aff06
Migrate versions API to app route handler
oBusk Apr 16, 2023
04eed91
Migrate main API to app route handler
oBusk Apr 16, 2023
efa0f71
Fix forbidden exports from versions endpoint
oBusk Apr 16, 2023
68586a5
Move versions api endpoint into prefixed folder
oBusk Apr 16, 2023
cb223c0
Remove loading component
oBusk Apr 16, 2023
4832877
Refactor lib/npmDiff
oBusk Apr 16, 2023
50d0149
Restructure to move git diff parsing into lib
oBusk Apr 16, 2023
d26b12d
Fix some messed up imports
oBusk Apr 16, 2023
25c3bc0
Cleanup /lib a bit more
oBusk Apr 16, 2023
3ba1760
Use NextLink
oBusk Apr 16, 2023
4bc3fed
Merge branch 'main' of github.com:oBusk/npm-diff.app into app-directory
oBusk Apr 16, 2023
14d0b76
Remove underline on hover on viewtypeswitch
oBusk Apr 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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