Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 4 additions & 37 deletions app/about/license/ThirdPartyLicenses.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
"use client";

import { FallbackPre } from "@/markdown/styledSyntaxHighlighter";
import { LicenseEntry } from "next-license-list";
import { useState } from "react";

export interface LicenseEntry {
name: string;
version: string;
author?: string;
repository?: string;
source?: string;
license: string;
licenseText?: string;
}

export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
const [expanded, setExpanded] = useState<string | null>(null);

Expand All @@ -21,30 +12,6 @@ export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
{licenses.map((pkg) => {
const key = `${pkg.name}@${pkg.version}`;
const isOpen = expanded === key;
let repositoryURL: string | undefined = undefined;
if (pkg.repository?.startsWith("http")) {
repositoryURL = pkg.repository;
} else if (pkg.repository?.startsWith("git+http")) {
repositoryURL = pkg.repository?.slice(4);
} else if (pkg.repository?.startsWith("git@")) {
repositoryURL =
"https://" +
pkg.repository
.slice(4)
.replace(":", "/")
.replace(/\.git$/, "");
} else if (
pkg.repository &&
/github:[\w-]+\/[\w-]+/.test(pkg.repository)
) {
repositoryURL = `https://github.com/${pkg.repository.slice(7)}`;
} else if (pkg.repository && /[\w-]+\/[\w-]+/.test(pkg.repository)) {
// assume github username/repository
repositoryURL = `https://github.com/${pkg.repository}`;
} else {
// fallback to source url
// repositoryURL = pkg.source ?? "";
}
return (
<div key={key} className="collapse collapse-arrow bg-base-200">
<input
Expand All @@ -66,15 +33,15 @@ export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
{pkg.author}
</p>
)}
{repositoryURL && (
{pkg.repository && (
<p className="mb-1">
<span className="opacity-60">Repository: </span>
<a
className="link link-info break-all"
href={repositoryURL}
href={pkg.repository}
target="_blank"
>
{repositoryURL}
{pkg.repository}
</a>
</p>
)}
Expand Down
30 changes: 5 additions & 25 deletions app/about/license/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Metadata } from "next";
import licenseText from "@/../LICENSE?raw";
import { LicenseEntry, ThirdPartyLicenses } from "./ThirdPartyLicenses";
import { isCloudflare } from "@/lib/detectCloudflare";
import { getCloudflareContext } from "@opennextjs/cloudflare";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ThirdPartyLicenses } from "./ThirdPartyLicenses";
import { StyledMarkdown } from "@/markdown/markdown";
import { getLicenses, LicenseEntry } from "next-license-list";
import { headers } from "next/headers";

export const metadata: Metadata = {
title: "ライセンス",
Expand All @@ -30,26 +28,8 @@ my.code(); は以下のオープンソースライブラリを使用していま
`;

export default async function LicensePage() {
let licenses: LicenseEntry[];
if (isCloudflare()) {
const cfAssets = getCloudflareContext().env.ASSETS;
const res = await cfAssets!.fetch(
`https://assets.local/_next/static/oss-licenses.json`
);
licenses = await res.json();
} else {
licenses = JSON.parse(
await readFile(
join(
process.cwd(),
process.env.NODE_ENV === "development"
? ".next/dev/static/oss-licenses.json"
: ".next/static/oss-licenses.json"
),
"utf-8"
)
);
}
await headers();
const licenses: LicenseEntry[] = await getLicenses();

return (
<div className="p-4 pb-16 w-full max-w-docs mx-auto">
Expand Down
46 changes: 20 additions & 26 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { NextConfig } from "next";
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
import { PyodidePlugin } from "@pyodide/webpack-plugin";
import { version as pyodideVersion } from "pyodide/package.json";
import LicensePlugin from "webpack-license-plugin";
import { dirname } from "node:path";
import { withSentryConfig } from "@sentry/nextjs";
import { withLicense } from "next-license-list/config";

initOpenNextCloudflareForDev();

const nextConfig: NextConfig = {
let nextConfig: NextConfig = {
/* config options here */
output: "standalone",
experimental: {
Expand Down Expand Up @@ -59,7 +59,7 @@ const nextConfig: NextConfig = {
},
];
},
webpack: (config, { isServer }) => {
webpack: (config) => {
config.plugins.push(
new PyodidePlugin({
// public/ 以下に書き出すと404
Expand All @@ -85,28 +85,6 @@ const nextConfig: NextConfig = {
resourceQuery: /raw/,
type: "asset/source",
});
// クライアントビルドのみサードパーティライセンスを /_next/static/oss-licenses.json に出力
if (!isServer) {
config.plugins.push(
new LicensePlugin({
outputFilename: "static/oss-licenses.json",
includeNoticeText: true,
excludedPackageTest: (packageName /*, version*/) => {
return (
packageName.startsWith("@my-code") || packageName === "my-code"
);
},
licenseOverrides: {
"@better-auth/core@1.4.20": "MIT",
"@better-fetch/fetch@1.1.21": "MIT",
},
includePackages: () =>
["tailwindcss", "daisyui", "@fontsource/m-plus-rounded-1c"].map(
(pkg) => dirname(import.meta.resolve(`${pkg}/package.json`))
),
})
);
}
return config;
},
async redirects() {
Expand Down Expand Up @@ -183,7 +161,21 @@ const nextConfig: NextConfig = {
},
};

export default withSentryConfig(nextConfig, {
nextConfig = withLicense(nextConfig, {
includeNoticeText: true,
excludedPackageTest: (packageName /*, version*/) => {
return packageName.startsWith("@my-code") || packageName === "my-code";
},
licenseOverrides: {
"@better-auth/core@1.4.20": "MIT",
"@better-fetch/fetch@1.1.21": "MIT",
},
includePackages: () =>
["tailwindcss", "daisyui", "@fontsource/m-plus-rounded-1c"].map((pkg) =>
dirname(import.meta.resolve(`${pkg}/package.json`))
),
});
nextConfig = withSentryConfig(nextConfig, {
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
sentryUrl: process.env.SENTRY_URL,
Expand All @@ -210,3 +202,5 @@ export default withSentryConfig(nextConfig, {
excludeReplayWorker: true,
},
});

export default nextConfig;
Loading
Loading