Skip to content

Commit 4d868a8

Browse files
committed
migrate to next-license-list
1 parent ea54970 commit 4d868a8

5 files changed

Lines changed: 65 additions & 173 deletions

File tree

app/about/license/ThirdPartyLicenses.tsx

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
"use client";
22

33
import { FallbackPre } from "@/markdown/styledSyntaxHighlighter";
4+
import { LicenseEntry } from "next-license-list";
45
import { useState } from "react";
56

6-
export interface LicenseEntry {
7-
name: string;
8-
version: string;
9-
author?: string;
10-
repository?: string;
11-
source?: string;
12-
license: string;
13-
licenseText?: string;
14-
}
15-
167
export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
178
const [expanded, setExpanded] = useState<string | null>(null);
189

@@ -21,30 +12,6 @@ export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
2112
{licenses.map((pkg) => {
2213
const key = `${pkg.name}@${pkg.version}`;
2314
const isOpen = expanded === key;
24-
let repositoryURL: string | undefined = undefined;
25-
if (pkg.repository?.startsWith("http")) {
26-
repositoryURL = pkg.repository;
27-
} else if (pkg.repository?.startsWith("git+http")) {
28-
repositoryURL = pkg.repository?.slice(4);
29-
} else if (pkg.repository?.startsWith("git@")) {
30-
repositoryURL =
31-
"https://" +
32-
pkg.repository
33-
.slice(4)
34-
.replace(":", "/")
35-
.replace(/\.git$/, "");
36-
} else if (
37-
pkg.repository &&
38-
/github:[\w-]+\/[\w-]+/.test(pkg.repository)
39-
) {
40-
repositoryURL = `https://github.com/${pkg.repository.slice(7)}`;
41-
} else if (pkg.repository && /[\w-]+\/[\w-]+/.test(pkg.repository)) {
42-
// assume github username/repository
43-
repositoryURL = `https://github.com/${pkg.repository}`;
44-
} else {
45-
// fallback to source url
46-
// repositoryURL = pkg.source ?? "";
47-
}
4815
return (
4916
<div key={key} className="collapse collapse-arrow bg-base-200">
5017
<input
@@ -66,15 +33,15 @@ export function ThirdPartyLicenses({ licenses }: { licenses: LicenseEntry[] }) {
6633
{pkg.author}
6734
</p>
6835
)}
69-
{repositoryURL && (
36+
{pkg.repository && (
7037
<p className="mb-1">
7138
<span className="opacity-60">Repository: </span>
7239
<a
7340
className="link link-info break-all"
74-
href={repositoryURL}
41+
href={pkg.repository}
7542
target="_blank"
7643
>
77-
{repositoryURL}
44+
{pkg.repository}
7845
</a>
7946
</p>
8047
)}

app/about/license/page.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { Metadata } from "next";
22
import licenseText from "@/../LICENSE?raw";
3-
import { LicenseEntry, ThirdPartyLicenses } from "./ThirdPartyLicenses";
4-
import { isCloudflare } from "@/lib/detectCloudflare";
5-
import { getCloudflareContext } from "@opennextjs/cloudflare";
6-
import { readFile } from "node:fs/promises";
7-
import { join } from "node:path";
3+
import { ThirdPartyLicenses } from "./ThirdPartyLicenses";
84
import { StyledMarkdown } from "@/markdown/markdown";
5+
import { getLicenses, LicenseEntry } from "next-license-list";
6+
import { headers } from "next/headers";
97

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

3230
export default async function LicensePage() {
33-
let licenses: LicenseEntry[];
34-
if (isCloudflare()) {
35-
const cfAssets = getCloudflareContext().env.ASSETS;
36-
const res = await cfAssets!.fetch(
37-
`https://assets.local/_next/static/oss-licenses.json`
38-
);
39-
licenses = await res.json();
40-
} else {
41-
licenses = JSON.parse(
42-
await readFile(
43-
join(
44-
process.cwd(),
45-
process.env.NODE_ENV === "development"
46-
? ".next/dev/static/oss-licenses.json"
47-
: ".next/static/oss-licenses.json"
48-
),
49-
"utf-8"
50-
)
51-
);
52-
}
31+
await headers();
32+
const licenses: LicenseEntry[] = await getLicenses();
5333

5434
return (
5535
<div className="p-4 pb-16 w-full max-w-docs mx-auto">

next.config.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { NextConfig } from "next";
22
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
33
import { PyodidePlugin } from "@pyodide/webpack-plugin";
44
import { version as pyodideVersion } from "pyodide/package.json";
5-
import LicensePlugin from "webpack-license-plugin";
65
import { dirname } from "node:path";
76
import { withSentryConfig } from "@sentry/nextjs";
7+
import { withLicense } from "next-license-list/config";
88

99
initOpenNextCloudflareForDev();
1010

11-
const nextConfig: NextConfig = {
11+
let nextConfig: NextConfig = {
1212
/* config options here */
1313
output: "standalone",
1414
experimental: {
@@ -59,7 +59,7 @@ const nextConfig: NextConfig = {
5959
},
6060
];
6161
},
62-
webpack: (config, { isServer }) => {
62+
webpack: (config) => {
6363
config.plugins.push(
6464
new PyodidePlugin({
6565
// public/ 以下に書き出すと404
@@ -85,28 +85,6 @@ const nextConfig: NextConfig = {
8585
resourceQuery: /raw/,
8686
type: "asset/source",
8787
});
88-
// クライアントビルドのみサードパーティライセンスを /_next/static/oss-licenses.json に出力
89-
if (!isServer) {
90-
config.plugins.push(
91-
new LicensePlugin({
92-
outputFilename: "static/oss-licenses.json",
93-
includeNoticeText: true,
94-
excludedPackageTest: (packageName /*, version*/) => {
95-
return (
96-
packageName.startsWith("@my-code") || packageName === "my-code"
97-
);
98-
},
99-
licenseOverrides: {
100-
"@better-auth/core@1.4.20": "MIT",
101-
"@better-fetch/fetch@1.1.21": "MIT",
102-
},
103-
includePackages: () =>
104-
["tailwindcss", "daisyui", "@fontsource/m-plus-rounded-1c"].map(
105-
(pkg) => dirname(import.meta.resolve(`${pkg}/package.json`))
106-
),
107-
})
108-
);
109-
}
11088
return config;
11189
},
11290
async redirects() {
@@ -183,7 +161,21 @@ const nextConfig: NextConfig = {
183161
},
184162
};
185163

186-
export default withSentryConfig(nextConfig, {
164+
nextConfig = withLicense(nextConfig, {
165+
includeNoticeText: true,
166+
excludedPackageTest: (packageName /*, version*/) => {
167+
return packageName.startsWith("@my-code") || packageName === "my-code";
168+
},
169+
licenseOverrides: {
170+
"@better-auth/core@1.4.20": "MIT",
171+
"@better-fetch/fetch@1.1.21": "MIT",
172+
},
173+
includePackages: () =>
174+
["tailwindcss", "daisyui", "@fontsource/m-plus-rounded-1c"].map((pkg) =>
175+
dirname(import.meta.resolve(`${pkg}/package.json`))
176+
),
177+
});
178+
nextConfig = withSentryConfig(nextConfig, {
187179
org: process.env.SENTRY_ORG,
188180
project: process.env.SENTRY_PROJECT,
189181
sentryUrl: process.env.SENTRY_URL,
@@ -210,3 +202,5 @@ export default withSentryConfig(nextConfig, {
210202
excludeReplayWorker: true,
211203
},
212204
});
205+
206+
export default nextConfig;

0 commit comments

Comments
 (0)