@korioinc/next-conf 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"with-config.d.ts","sourceRoot":"","sources":["../../src/plugin/with-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA2BvC,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,UAAU,GAAE,UAAe,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAmFxG"}
1
+ {"version":3,"file":"with-config.d.ts","sourceRoot":"","sources":["../../src/plugin/with-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA+BvC,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA4FD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,UAAU,GAAE,UAAe,EAAE,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAsFxG"}
@@ -1,4 +1,77 @@
1
+ import * as fs from 'fs';
2
+ import { createRequire } from 'node:module';
1
3
  import * as path from 'path';
4
+ const requireForConfig = createRequire(import.meta.url);
5
+ function readLocalesFromConfig({ cwd, linguiConfigFileName }) {
6
+ const linguiConfigPath = path.resolve(cwd, linguiConfigFileName);
7
+ if (!fs.existsSync(linguiConfigPath))
8
+ return [];
9
+ try {
10
+ const linguiConfig = requireForConfig(linguiConfigPath);
11
+ return linguiConfig?.locales ?? [];
12
+ }
13
+ catch (err) {
14
+ console.warn('[withNextKitConf] Unable to read lingui.config; falling back to lang/*.po scan:', err);
15
+ return [];
16
+ }
17
+ }
18
+ function readLocalesFromPoFiles({ cwd, linguiLoaderDir }) {
19
+ const dir = path.resolve(cwd, linguiLoaderDir);
20
+ if (!fs.existsSync(dir))
21
+ return [];
22
+ try {
23
+ return fs
24
+ .readdirSync(dir, { withFileTypes: true })
25
+ .filter((d) => d.isFile() && d.name.endsWith('.po'))
26
+ .map((d) => d.name.replace(/\.po$/, ''));
27
+ }
28
+ catch (err) {
29
+ console.warn('[withNextKitConf] Unable to scan lang/*.po files:', err);
30
+ return [];
31
+ }
32
+ }
33
+ function ensureLinguiLoader(options) {
34
+ const { cwd, linguiConfigFileName, linguiLoaderDir } = options;
35
+ const loaderDir = linguiLoaderDir.startsWith('.') || linguiLoaderDir.startsWith('/') ? linguiLoaderDir : `./${linguiLoaderDir}`;
36
+ const loaderPath = path.resolve(cwd, loaderDir, 'index.ts');
37
+ const signature = '// Generated by withNextKitConf';
38
+ const noTypecheck = '// @ts-nocheck';
39
+ const localesFromConfig = readLocalesFromConfig({ cwd, linguiConfigFileName, linguiLoaderDir });
40
+ const locales = localesFromConfig.length > 0
41
+ ? localesFromConfig
42
+ : readLocalesFromPoFiles({ cwd, linguiConfigFileName, linguiLoaderDir });
43
+ const resolvedLocales = locales?.length ? locales : ['en'];
44
+ const defaultLocale = resolvedLocales.includes('en') ? 'en' : resolvedLocales[0];
45
+ const importLines = resolvedLocales
46
+ .map((locale) => {
47
+ const key = /^[A-Za-z_$][\w$]*$/.test(locale) ? locale : JSON.stringify(locale);
48
+ // Use dynamic `import()` so apps don't need CommonJS `require` shims.
49
+ // Next's webpack config handles `.po` via @lingui/loader at runtime.
50
+ return ` ${key}: async () => import('./${locale}.po'),`;
51
+ })
52
+ .join('\n');
53
+ const contents = `${signature}
54
+ ${noTypecheck}
55
+ import type { Messages } from '@lingui/core';
56
+
57
+ const loaders = {
58
+ ${importLines}
59
+ } satisfies Record<string, () => Promise<unknown>>;
60
+
61
+ export const supportedLocales = Object.keys(loaders);
62
+
63
+ export async function load(locale: string): Promise<Messages> {
64
+ const loader = loaders[locale as keyof typeof loaders] ?? loaders['${defaultLocale}'];
65
+ const mod = (await loader()) as { messages?: Messages; default?: Messages };
66
+
67
+ return mod.messages ?? (mod.default as Messages) ?? {};
68
+ }
69
+ `;
70
+ const langDir = path.dirname(loaderPath);
71
+ fs.mkdirSync(langDir, { recursive: true });
72
+ fs.writeFileSync(loaderPath, contents);
73
+ console.log(`[withNextKitConf] Generated lingui loader at ${path.relative(cwd, loaderPath)}`);
74
+ }
2
75
  /**
3
76
  * Next.js configuration plugin that injects webpack aliases
4
77
  * Maps the default config to the actual user config file
@@ -19,6 +92,8 @@ import * as path from 'path';
19
92
  */
20
93
  export function withNextKitConf(nextConfig = {}, options = {}) {
21
94
  const { configFileName = 'next-kit.config.ts', linguiConfigFileName = 'lingui.config.ts', linguiLoaderDir = './lang', } = options;
95
+ // Auto-generate a minimal Lingui loader if missing (avoids per-app scripts)
96
+ ensureLinguiLoader({ cwd: process.cwd(), linguiConfigFileName, linguiLoaderDir });
22
97
  return {
23
98
  ...nextConfig,
24
99
  // Turbopack configuration for development
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@korioinc/next-conf",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Configuration management for Next.js applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "LICENSE"
28
28
  ],
29
29
  "peerDependencies": {
30
- "next": ">=15"
30
+ "next": ">=16"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "next": {
@@ -35,6 +35,7 @@
35
35
  }
36
36
  },
37
37
  "devDependencies": {
38
+ "@lingui/conf": "5.6.1",
38
39
  "@types/node": "^24.10.0",
39
40
  "typescript": "^5.9.3",
40
41
  "vitest": "^2.1.9"