diff --git a/packages/crypto-frontmatter/src/cli.ts b/packages/crypto-frontmatter/src/cli.ts index 4250b830b..e1800eaad 100644 --- a/packages/crypto-frontmatter/src/cli.ts +++ b/packages/crypto-frontmatter/src/cli.ts @@ -12,7 +12,7 @@ export class MirrorCommand extends Command { async execute(): Promise { await mkdir(this.target, { recursive: true }); - const collections = await getInstalledFrontmatterCollection(); + const collections = getInstalledFrontmatterCollection(); for (const collection of collections) { let count = 0; const indexArray = await getFrontmatterIndexArray(collection.caip2, collection.namespace); diff --git a/packages/crypto-frontmatter/src/index.ts b/packages/crypto-frontmatter/src/index.ts index 0d41c961f..e0c1ea0c2 100644 --- a/packages/crypto-frontmatter/src/index.ts +++ b/packages/crypto-frontmatter/src/index.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto'; -import { readdir, readFile, stat } from 'node:fs/promises'; +import { existsSync, readdirSync, readFileSync } from 'node:fs'; +import { readFile, stat } from 'node:fs/promises'; import { join } from 'node:path'; export interface FrontmatterLink { @@ -40,6 +41,7 @@ export interface FrontmatterContent extends FrontmatterIndex { } export interface FrontmatterCollection { + name: string; caip2: string; namespace: string; } @@ -92,19 +94,23 @@ export function getNodeModulesPath(caip2: string, namespace: string, file: strin ); } -export async function getInstalledFrontmatterCollection(): Promise { +export function getInstalledFrontmatterCollection(): FrontmatterCollection[] { const scopePath = join('node_modules', '@crypto-frontmatter'); const collections: FrontmatterCollection[] = []; - for (const dir of await readdir(scopePath)) { + for (const dir of readdirSync(scopePath)) { const packagePath = join(scopePath, dir, 'package.json'); - if (!(await hasFile(packagePath))) { + if (!existsSync(packagePath)) { continue; } - const contents = await readFile(packagePath, { + const contents = readFileSync(packagePath, { encoding: 'utf-8', }); - collections.push(JSON.parse(contents).config); + const packageJson = JSON.parse(contents); + collections.push({ + name: packageJson.name, + ...packageJson.config, + }); } return collections; } diff --git a/packages/crypto-frontmatter/src/index.unit.ts b/packages/crypto-frontmatter/src/index.unit.ts index 45cd321a4..39dd3ba6f 100644 --- a/packages/crypto-frontmatter/src/index.unit.ts +++ b/packages/crypto-frontmatter/src/index.unit.ts @@ -55,19 +55,63 @@ it('should getFrontmatterContent of eip155:1/erc20:0', async () => { expect(frontmatterContent).toBeUndefined(); }); -it('should getInstalledFrontmatterCollection', async () => { - const collections = await getInstalledFrontmatterCollection(); +it('should getInstalledFrontmatterCollection()', async () => { + const collections = getInstalledFrontmatterCollection(); expect(collections).toStrictEqual([ - { caip2: 'eip155:1', namespace: 'erc20' }, - { caip2: 'eip155:10', namespace: 'erc20' }, - { caip2: 'eip155:1313161554', namespace: 'erc20' }, - { caip2: 'eip155:137', namespace: 'erc20' }, - { caip2: 'eip155:42161', namespace: 'erc20' }, - { caip2: 'eip155:42220', namespace: 'erc20' }, - { caip2: 'eip155:43114', namespace: 'erc20' }, - { caip2: 'eip155:56', namespace: 'erc20' }, - { caip2: 'eip155:8453', namespace: 'erc20' }, - { caip2: 'tip474:728126428', namespace: 'trc10' }, - { caip2: 'tip474:728126428', namespace: 'trc20' }, + { + caip2: 'eip155:1', + name: '@crypto-frontmatter/eip155-1-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:10', + name: '@crypto-frontmatter/eip155-10-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:1313161554', + name: '@crypto-frontmatter/eip155-1313161554-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:137', + name: '@crypto-frontmatter/eip155-137-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:42161', + name: '@crypto-frontmatter/eip155-42161-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:42220', + name: '@crypto-frontmatter/eip155-42220-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:43114', + name: '@crypto-frontmatter/eip155-43114-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:56', + name: '@crypto-frontmatter/eip155-56-erc20', + namespace: 'erc20', + }, + { + caip2: 'eip155:8453', + name: '@crypto-frontmatter/eip155-8453-erc20', + namespace: 'erc20', + }, + { + caip2: 'tip474:728126428', + name: '@crypto-frontmatter/tip474-728126428-trc10', + namespace: 'trc10', + }, + { + caip2: 'tip474:728126428', + name: '@crypto-frontmatter/tip474-728126428-trc20', + namespace: 'trc20', + }, ]); }); diff --git a/packages/crypto-frontmatter/src/require.ts b/packages/crypto-frontmatter/src/require.ts index fca4ea60e..a3ad27849 100644 --- a/packages/crypto-frontmatter/src/require.ts +++ b/packages/crypto-frontmatter/src/require.ts @@ -6,6 +6,7 @@ * if you want to use it. * For example, you must install @crypto-frontmatter/eip155-1-erc20 if you want to use eip155:1/erc frontmatter. * + * @deprecated scheduled for removal * @param caip2 {string} * @param type {string} * @param path {string} diff --git a/website/next.config.mjs b/website/next.config.mjs index 2eb2352b1..08aa2901b 100644 --- a/website/next.config.mjs +++ b/website/next.config.mjs @@ -1,8 +1,13 @@ +import { getInstalledFrontmatterCollection } from 'crypto-frontmatter'; + /** @type {import('next').NextConfig} */ const nextConfig = { env: { BASE_URL: process.env.NEXT_PUBLIC_URL ?? `https://${process.env.VERCEL_URL}` ?? 'https://frontmatter.levain.tech', }, + experimental: { + serverComponentsExternalPackages: getInstalledFrontmatterCollection().map((collection) => collection.name), + }, trailingSlash: false, reactStrictMode: true, swcMinify: true,