Skip to content

Commit

Permalink
chore: dissociate the code that wraps Next.js calls of the Next.js co…
Browse files Browse the repository at this point in the history
…debase itself
  • Loading branch information
thomvaill committed Dec 14, 2024
1 parent 611b650 commit 4acbea6
Show file tree
Hide file tree
Showing 118 changed files with 138 additions and 89 deletions.
25 changes: 16 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ module.exports = {
sourceType: "module",
project: "./tsconfig.json"
},
ignorePatterns: ["**/*.js", "**/*.d.ts", "dist", "node_modules"],
ignorePatterns: [
"**/*.js",
"**/*.d.ts",
"**/*.stories.tsx", // temporary disabled
"dist",
"node_modules"
],
plugins: ["jest", "sonarjs", "promise", "@typescript-eslint", "react"],
extends: [
"eslint:recommended",
Expand Down Expand Up @@ -57,14 +63,15 @@ module.exports = {
"@typescript-eslint/explicit-module-boundary-types": "off" // @adr web/20200927-avoid-react-fc-type
}
},
{
files: ["src/**/*.stories.tsx"], // Storybook
rules: {
"import/no-extraneous-dependencies": "off",
"import/no-default-export": "off",
"react/function-component-definition": "off"
}
},
// Temporary disabled
// {
// files: ["src/**/*.stories.tsx"], // Storybook
// rules: {
// "import/no-extraneous-dependencies": "off",
// "import/no-default-export": "off",
// "react/function-component-definition": "off"
// }
// },
{
files: "*", // All non-React files
excludedFiles: "*.tsx",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typings/

# Next.js build output
.next
.next-export

# Nuxt.js build / generate output
.nuxt
Expand Down
16 changes: 2 additions & 14 deletions packages/web/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@ const path = require("path");

module.exports = {
env: {
browser: true,
node: true
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
project: path.join(__dirname, "tsconfig.dev.json")
project: path.join(__dirname, "tsconfig.json")
},
extends: ["../../.eslintrc"],
overrides: [
{
files: ["src/pages/**/*.tsx", "src/pages/api/**/*.ts"], // Next.js pages and api routes
rules: {
"import/no-default-export": "off"
}
}
]
extends: ["../../.eslintrc"]
};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import mkdirp from "mkdirp";
import { makeBadge } from "badge-maker";
import { promises as fsP } from "fs";
import type { AppConsole } from "@log4brains/cli-common";
import { getNextJsDir } from "../../lib/next";
import { Search } from "../../lib/search";
import { toAdrLight } from "../../types";
import { execNext, getL4bInstance } from "../utils";
import { Search } from "@lib-shared/search";
import { toAdrLight } from "@lib-shared/types";
import { execNext, getL4bInstance, getNextJsDir } from "../utils";

type Deps = {
appConsole: AppConsole;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import SocketIO from "socket.io";
import chalk from "chalk";
import open from "open";
import type { AppConsole } from "@log4brains/cli-common";
import { getNextJsDir } from "../../lib/next";
import { execNext, getL4bInstance } from "../utils";
import { execNext, getL4bInstance, getNextJsDir } from "../utils";

type Deps = {
appConsole: AppConsole;
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/web/src/cli/utils.ts → packages/web/cli/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from "chalk";
import { ConsoleCapturer } from "@log4brains/cli-common";
import { Log4brains } from "@log4brains/core";
import path from "path";

let l4bInstance: Log4brains;
export function getL4bInstance(): Log4brains {
Expand All @@ -10,6 +11,10 @@ export function getL4bInstance(): Log4brains {
return l4bInstance;
}

export function getNextJsDir(): string {
return path.resolve(path.join(__dirname, "../nextjs")); // only one level up because bundled with microbundle
}

/**
* #NEXTJS-HACK
* We want to hide the output of Next.js when we execute CLI commands.
Expand Down
1 change: 1 addition & 0 deletions packages/web/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./cli";
File renamed without changes.
23 changes: 23 additions & 0 deletions packages/web/nextjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require("path");

module.exports = {
env: {
browser: true,
node: true
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
project: path.join(__dirname, "tsconfig.dev.json")
},
extends: ["../../../.eslintrc"],
overrides: [
{
files: ["src/pages/**/*.tsx", "src/pages/api/**/*.ts"], // Next.js pages and api routes
rules: {
"import/no-default-export": "off"
}
}
]
};
4 changes: 4 additions & 0 deletions packages/web/nextjs/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.next-export
.storybook
jest.config.js
tsconfig.dev.json
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AdrDtoStatus } from "@log4brains/core";
import { Adr } from "../../src/types";
import { Adr } from "../../src/lib-shared/types";

export const adrMocks = [
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const base = require("../../jest.config.base");
const base = require("../../../jest.config.base");
const packageJson = require("./package");

module.exports = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ module.exports = withBundleAnalyzer({
},
future: {
excludeDefaultMomentLocales: true
},
typescript: {
// We check typescript errors only during the first build, not during "log4brains build",
// for performance purpose and to avoid importing @types/* packages as dependencies
ignoreBuildErrors: process.env.LOG4BRAINS_PHASE !== "initial-build"
}
});
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createStyles, makeStyles, Theme } from "@material-ui/core/styles";
import { GrDocumentText as AdrIcon } from "react-icons/gr";
import { useRouter } from "next/router";
import { SearchBar } from "./components/SearchBar";
import { SearchResult } from "../../lib/search";
import { SearchResult } from "../../lib-shared/search";

const useStyles = makeStyles((theme: Theme) => {
return createStyles({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { AdrLight } from "../../types";
import { AdrLight } from "../../lib-shared/types";

export type AdrNav = {
previousAdr?: AdrLight;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Meta, Story } from "@storybook/react";
import { AdrBrowserLayout, AdrBrowserLayoutProps } from "..";
import { adrMocks } from "../../../.storybook/mocks";
import { toAdrLight } from "../../types";
import { toAdrLight } from "../../lib-shared/types";

const Template: Story<AdrBrowserLayoutProps> = (args) => (
<AdrBrowserLayout {...args} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import clsx from "clsx";
import { AdrMenu } from "./components/AdrMenu";
import { CustomTheme } from "../../mui";
import { ConnectedSearchBox } from "./components/ConnectedSearchBox/ConnectedSearchBox";
import { AdrLight } from "../../types";
import { AdrLight } from "../../lib-shared/types";
import { AdrNav, AdrNavContext } from "../../contexts";
import { RoutingProgress } from "./components/RoutingProgress";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import Router, { useRouter } from "next/router";
// import io from "socket.io-client"; // loaded by _document.tsx so that we don't add this lib in the static mode bundle
import type { FileWatcherEvent } from "@log4brains/core";
import { Adr, AdrLight } from "../../types";
import { Adr, AdrLight } from "../../lib-shared/types";
import { Log4brainsMode, Log4brainsModeContext } from "../../contexts";
import { AdrBrowserLayout, AdrBrowserLayoutProps } from "./AdrBrowserLayout";
// eslint-disable-next-line import/no-cycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Link from "next/link";
import clsx from "clsx";
import { Log4brainsMode, Log4brainsModeContext } from "../../../../contexts";
import { AdrStatusChip } from "../../../../components";
import { AdrLight } from "../../../../types";
import { AdrLight } from "../../../../lib-shared/types";

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from "react";
import { SearchBox, SearchBoxProps } from "../../../../components/SearchBox";
import {
createSearchInstance,
Search,
SearchResult
} from "../../../../lib/search";
import { createSearchInstance } from "../../../../lib/search";
import { Search, SearchResult } from "../../../../lib-shared/search";
import { Log4brainsMode, Log4brainsModeContext } from "../../../../contexts";

export type ConnectedSearchBoxProps = Omit<
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/web/nextjs/src/lib-shared/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Search";
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Adr, AdrLight } from "../types";
import { Adr, AdrLight } from "../lib-shared/types";

export function buildAdrUrl(adr: AdrLight | Adr): string {
return `/adr/${adr.slug}`;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import path from "path";
import getNextConfig from "next/config";

export function getNextJsDir(): string {
// When built, there is no more "src/" directory
return path.resolve(path.join(__dirname, ".."));
}

export type L4bNextConfig = {
serverRuntimeConfig: {
PROJECT_ROOT: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./Search";
export * from "./instance";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Router from "next/router";
import { Log4brainsMode } from "../../contexts";
import { Search, SerializedIndex } from "./Search";
import { Search, SerializedIndex } from "../../lib-shared/search";

function isSerializedIndex(obj: unknown): obj is SerializedIndex {
return (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetStaticProps, GetStaticPaths } from "next";
import { getLog4brainsInstance } from "../../lib/core-api";
import { getConfig } from "../../lib/next";
import { AdrScene, AdrSceneProps } from "../../scenes";
import { toAdr } from "../../types";
import { toAdr } from "../../lib-shared/types";

export default AdrScene;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
import { getLog4brainsInstance } from "../../lib/core-api";
import { toAdrLight } from "../../types";
import { toAdrLight } from "../../lib-shared/types";

export default async (
req: NextApiRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
import { getLog4brainsInstance } from "../../lib/core-api";
import { Search } from "../../lib/search";
import { Search } from "../../lib-shared/search";

export default async (
req: NextApiRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetStaticProps } from "next";
import { getIndexPageMarkdown, getLog4brainsInstance } from "../lib/core-api";
import { getConfig } from "../lib/next";
import { IndexScene, IndexSceneProps } from "../scenes";
import { toAdrLight } from "../types";
import { toAdrLight } from "../lib-shared/types";

export default IndexScene;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Meta, Story } from "@storybook/react";
import { AdrScene, AdrSceneProps } from "./AdrScene";
import { adrMocks, getMockedAdrBySlug } from "../../../.storybook/mocks";
import { Log4brainsMode, Log4brainsModeContext } from "../../contexts";
import { toAdrLight } from "../../types";
import { toAdrLight } from "../../lib-shared/types";
import { AdrBrowserLayout } from "../../layouts";

const Template: Story<AdrSceneProps> = (args) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
Log4brainsMode,
Log4brainsModeContext
} from "../../contexts";
import { Adr } from "../../types";
import { Adr } from "../../lib-shared/types";
import { buildAdrUrl } from "../../lib/adr-utils";

const useStyles = makeStyles((theme: CustomTheme) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { FiLink as LinkRIcon } from "react-icons/fi";
import clsx from "clsx";
import { AdrStatusChip } from "../../../../components";
import { Adr } from "../../../../types";
import { Adr } from "../../../../lib-shared/types";

function capitalize(s: string): string {
return s.charAt(0).toUpperCase() + s.slice(1);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Meta, Story } from "@storybook/react";
import { IndexScene, IndexSceneProps } from "./IndexScene";
import { Log4brainsMode, Log4brainsModeContext } from "../../contexts";
import { adrMocks } from "../../../.storybook/mocks";
import { toAdrLight } from "../../types";
import { toAdrLight } from "../../lib-shared/types";
import { AdrBrowserLayout } from "../../layouts";

const markdown = `# Hello World
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions packages/web/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "src/**/*.ts", "src/**/*.tsx"],
"exclude": [
"node_modules",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.stories.tsx"
]
}
5 changes: 0 additions & 5 deletions packages/web/nodemon.json

This file was deleted.

Loading

0 comments on commit 4acbea6

Please sign in to comment.