Преглед изворни кода

refactor: update next.config and utils for TypeScript compatibility and improve code formatting

Yuki Takei пре 1 месец
родитељ
комит
628bca6c76

+ 9 - 5
apps/app/next.config.ts

@@ -5,14 +5,19 @@
  * See: https://github.com/vercel/next.js/discussions/35969#discussioncomment-2522954
  * See: https://github.com/vercel/next.js/discussions/35969#discussioncomment-2522954
  */
  */
 
 
+import type { NextConfig } from 'next';
+import {
+  PHASE_PRODUCTION_BUILD,
+  PHASE_PRODUCTION_SERVER,
+} from 'next/constants';
 import path from 'node:path';
 import path from 'node:path';
-
 import bundleAnalyzer from '@next/bundle-analyzer';
 import bundleAnalyzer from '@next/bundle-analyzer';
-import type { NextConfig } from 'next';
-import { PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } from 'next/constants';
 
 
-import { createChunkModuleStatsPlugin, listPrefixedPackages } from './src/utils/next.config.utils';
 import nextI18nConfig from './config/next-i18next.config';
 import nextI18nConfig from './config/next-i18next.config';
+import {
+  createChunkModuleStatsPlugin,
+  listPrefixedPackages,
+} from './src/utils/next.config.utils';
 
 
 const { i18n, localePath } = nextI18nConfig;
 const { i18n, localePath } = nextI18nConfig;
 
 
@@ -158,7 +163,6 @@ export default (phase: string): NextConfig => {
 
 
       // setup i18next-hmr
       // setup i18next-hmr
       if (!options.isServer && options.dev) {
       if (!options.isServer && options.dev) {
-        // biome-ignore lint/suspicious/noRequireImports: lazy load dev-only plugin
         const { I18NextHMRPlugin } = require('i18next-hmr/webpack');
         const { I18NextHMRPlugin } = require('i18next-hmr/webpack');
         config.plugins!.push(new I18NextHMRPlugin({ localesDir: localePath }));
         config.plugins!.push(new I18NextHMRPlugin({ localesDir: localePath }));
       }
       }

+ 22 - 6
apps/app/src/utils/next.config.utils.ts

@@ -14,7 +14,10 @@ interface Opts {
 
 
 const defaultOpts: Opts = { ignorePackageNames: [] };
 const defaultOpts: Opts = { ignorePackageNames: [] };
 
 
-export const listScopedPackages = (scopes: string[], opts: Opts = defaultOpts): string[] => {
+export const listScopedPackages = (
+  scopes: string[],
+  opts: Opts = defaultOpts,
+): string[] => {
   const scopedPackages: string[] = [];
   const scopedPackages: string[] = [];
 
 
   nodeModulesPaths.forEach((nodeModulesPath) => {
   nodeModulesPaths.forEach((nodeModulesPath) => {
@@ -31,7 +34,9 @@ export const listScopedPackages = (scopes: string[], opts: Opts = defaultOpts):
               'package.json',
               'package.json',
             );
             );
             if (fs.existsSync(packageJsonPath)) {
             if (fs.existsSync(packageJsonPath)) {
-              const { name } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as { name: string };
+              const { name } = JSON.parse(
+                fs.readFileSync(packageJsonPath, 'utf-8'),
+              ) as { name: string };
               if (!opts.ignorePackageNames.includes(name)) {
               if (!opts.ignorePackageNames.includes(name)) {
                 scopedPackages.push(name);
                 scopedPackages.push(name);
               }
               }
@@ -91,7 +96,11 @@ export const createChunkModuleStatsPlugin = () => ({
           (id) => !initialModuleIds.has(id),
           (id) => !initialModuleIds.has(id),
         );
         );
 
 
-        const analyzeModuleSet = (moduleIds: Set<string> | string[], title: string, filename: string): void => {
+        const analyzeModuleSet = (
+          moduleIds: Set<string> | string[],
+          title: string,
+          filename: string,
+        ): void => {
           const packageCounts: Record<string, number> = {};
           const packageCounts: Record<string, number> = {};
           const appModules: string[] = [];
           const appModules: string[] = [];
           for (const rawId of moduleIds) {
           for (const rawId of moduleIds) {
@@ -114,7 +123,9 @@ export const createChunkModuleStatsPlugin = () => ({
             (a, b) => b[1] - a[1],
             (a, b) => b[1] - a[1],
           );
           );
           const lines = [`# ${title}`, ''];
           const lines = [`# ${title}`, ''];
-          const totalCount = Array.isArray(moduleIds) ? moduleIds.length : moduleIds.size;
+          const totalCount = Array.isArray(moduleIds)
+            ? moduleIds.length
+            : moduleIds.size;
           lines.push(`Total modules: ${totalCount}`);
           lines.push(`Total modules: ${totalCount}`);
           lines.push(`App modules (non-node_modules): ${appModules.length}`);
           lines.push(`App modules (non-node_modules): ${appModules.length}`);
           lines.push(`node_modules packages: ${sorted.length}`);
           lines.push(`node_modules packages: ${sorted.length}`);
@@ -154,7 +165,10 @@ export const createChunkModuleStatsPlugin = () => ({
   },
   },
 });
 });
 
 
-export const listPrefixedPackages = (prefixes: string[], opts: Opts = defaultOpts): string[] => {
+export const listPrefixedPackages = (
+  prefixes: string[],
+  opts: Opts = defaultOpts,
+): string[] => {
   const prefixedPackages: string[] = [];
   const prefixedPackages: string[] = [];
 
 
   nodeModulesPaths.forEach((nodeModulesPath) => {
   nodeModulesPaths.forEach((nodeModulesPath) => {
@@ -168,7 +182,9 @@ export const listPrefixedPackages = (prefixes: string[], opts: Opts = defaultOpt
           'package.json',
           'package.json',
         );
         );
         if (fs.existsSync(packageJsonPath)) {
         if (fs.existsSync(packageJsonPath)) {
-          const { name } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as { name: string };
+          const { name } = JSON.parse(
+            fs.readFileSync(packageJsonPath, 'utf-8'),
+          ) as { name: string };
           if (!opts.ignorePackageNames.includes(name)) {
           if (!opts.ignorePackageNames.includes(name)) {
             prefixedPackages.push(name);
             prefixedPackages.push(name);
           }
           }

+ 2 - 5
apps/app/src/utils/superjson-ssr-loader.ts

@@ -31,8 +31,5 @@ function superjsonSsrLoader(source: string): string {
   );
   );
 }
 }
 
 
-// Webpack loaders require CommonJS exports.
-// ts-node (configured in tsconfig.json with module: CommonJS) handles CJS compilation at runtime.
-module.exports = superjsonSsrLoader;
-
-export {};
+// biome-ignore lint/style/noDefaultExport: webpack loaders require a default export
+export default superjsonSsrLoader;