@intlayer/chokidar 9.0.0-canary.2 → 9.0.0-canary.4
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.
- package/dist/cjs/init/frameworkSetup/index.cjs +27 -0
- package/dist/cjs/init/frameworkSetup/index.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/detect.cjs +56 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/detect.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs +103 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/index.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs +147 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/templates.cjs +122 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/templates.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/transforms.cjs +211 -0
- package/dist/cjs/init/frameworkSetup/nextAppRouter/transforms.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/detect.cjs +31 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/detect.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs +74 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/index.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs +79 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/templates.cjs +104 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/templates.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/transforms.cjs +128 -0
- package/dist/cjs/init/frameworkSetup/tanstackStart/transforms.cjs.map +1 -0
- package/dist/cjs/init/frameworkSetup/types.cjs +0 -0
- package/dist/cjs/init/index.cjs +51 -21
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/utils/configManipulation.cjs +2 -1
- package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
- package/dist/cjs/init/utils/fileSystem.cjs +45 -0
- package/dist/cjs/init/utils/fileSystem.cjs.map +1 -1
- package/dist/cjs/init/utils/index.cjs +7 -1
- package/dist/cjs/init/utils/packageManager.cjs +84 -1
- package/dist/cjs/init/utils/packageManager.cjs.map +1 -1
- package/dist/esm/init/frameworkSetup/index.mjs +26 -0
- package/dist/esm/init/frameworkSetup/index.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/detect.mjs +52 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/detect.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs +100 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/index.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs +142 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/templates.mjs +113 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/templates.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/transforms.mjs +208 -0
- package/dist/esm/init/frameworkSetup/nextAppRouter/transforms.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/detect.mjs +28 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/detect.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs +71 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/index.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs +74 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/templates.mjs +100 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/templates.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/transforms.mjs +126 -0
- package/dist/esm/init/frameworkSetup/tanstackStart/transforms.mjs.map +1 -0
- package/dist/esm/init/frameworkSetup/types.mjs +0 -0
- package/dist/esm/init/index.mjs +52 -22
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/utils/configManipulation.mjs +2 -1
- package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
- package/dist/esm/init/utils/fileSystem.mjs +46 -2
- package/dist/esm/init/utils/fileSystem.mjs.map +1 -1
- package/dist/esm/init/utils/index.mjs +3 -3
- package/dist/esm/init/utils/packageManager.mjs +81 -3
- package/dist/esm/init/utils/packageManager.mjs.map +1 -1
- package/dist/types/init/frameworkSetup/index.d.ts +13 -0
- package/dist/types/init/frameworkSetup/index.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/detect.d.ts +25 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/detect.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/index.d.ts +12 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/index.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/restructure.d.ts +44 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/restructure.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/templates.d.ts +26 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/templates.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/transforms.d.ts +23 -0
- package/dist/types/init/frameworkSetup/nextAppRouter/transforms.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/tanstackStart/detect.d.ts +19 -0
- package/dist/types/init/frameworkSetup/tanstackStart/detect.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/tanstackStart/index.d.ts +13 -0
- package/dist/types/init/frameworkSetup/tanstackStart/index.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/tanstackStart/restructure.d.ts +35 -0
- package/dist/types/init/frameworkSetup/tanstackStart/restructure.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/tanstackStart/templates.d.ts +20 -0
- package/dist/types/init/frameworkSetup/tanstackStart/templates.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/tanstackStart/transforms.d.ts +17 -0
- package/dist/types/init/frameworkSetup/tanstackStart/transforms.d.ts.map +1 -0
- package/dist/types/init/frameworkSetup/types.d.ts +35 -0
- package/dist/types/init/frameworkSetup/types.d.ts.map +1 -0
- package/dist/types/init/index.d.ts +17 -0
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
- package/dist/types/init/utils/fileSystem.d.ts +30 -1
- package/dist/types/init/utils/fileSystem.d.ts.map +1 -1
- package/dist/types/init/utils/index.d.ts +3 -3
- package/dist/types/init/utils/packageManager.d.ts +52 -1
- package/dist/types/init/utils/packageManager.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_init_frameworkSetup_nextAppRouter_index = require('./nextAppRouter/index.cjs');
|
|
3
|
+
const require_init_frameworkSetup_tanstackStart_index = require('./tanstackStart/index.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/init/frameworkSetup/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Registered framework adapters, tried in order. The first one whose `detect`
|
|
8
|
+
* returns true handles the project. Add new adapters (Nuxt, Vite + React, …)
|
|
9
|
+
* here as they are implemented.
|
|
10
|
+
*/
|
|
11
|
+
const adapters = [require_init_frameworkSetup_nextAppRouter_index.nextAppRouterAdapter, require_init_frameworkSetup_tanstackStart_index.tanStackStartAdapter];
|
|
12
|
+
/**
|
|
13
|
+
* Runs framework-specific scaffolding (middleware/proxy, providers in
|
|
14
|
+
* layout/page, example content) for the first adapter that matches the project.
|
|
15
|
+
* No-ops when no adapter recognizes the project. Each adapter is idempotent and
|
|
16
|
+
* non-destructive, so this is safe to run on existing applications.
|
|
17
|
+
*/
|
|
18
|
+
const setupFramework = async (context) => {
|
|
19
|
+
for (const adapter of adapters) if (await adapter.detect(context)) {
|
|
20
|
+
await adapter.setup(context);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.setupFramework = setupFramework;
|
|
27
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["nextAppRouterAdapter","tanStackStartAdapter"],"sources":["../../../../src/init/frameworkSetup/index.ts"],"sourcesContent":["import { nextAppRouterAdapter } from './nextAppRouter';\nimport { tanStackStartAdapter } from './tanstackStart';\nimport type { FrameworkAdapter, FrameworkSetupContext } from './types';\n\nexport type { FrameworkAdapter, FrameworkSetupContext } from './types';\n\n/**\n * Registered framework adapters, tried in order. The first one whose `detect`\n * returns true handles the project. Add new adapters (Nuxt, Vite + React, …)\n * here as they are implemented.\n */\nconst adapters: FrameworkAdapter[] = [\n nextAppRouterAdapter,\n tanStackStartAdapter,\n];\n\n/**\n * Runs framework-specific scaffolding (middleware/proxy, providers in\n * layout/page, example content) for the first adapter that matches the project.\n * No-ops when no adapter recognizes the project. Each adapter is idempotent and\n * non-destructive, so this is safe to run on existing applications.\n */\nexport const setupFramework = async (\n context: FrameworkSetupContext\n): Promise<void> => {\n for (const adapter of adapters) {\n if (await adapter.detect(context)) {\n await adapter.setup(context);\n return;\n }\n }\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAM,WAA+B,CACnCA,sEACAC,qEACD;;;;;;;AAQD,MAAa,iBAAiB,OAC5B,YACkB;AAClB,MAAK,MAAM,WAAW,SACpB,KAAI,MAAM,QAAQ,OAAO,QAAQ,EAAE;AACjC,QAAM,QAAQ,MAAM,QAAQ;AAC5B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_init_utils_fileSystem = require('../../utils/fileSystem.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
|
|
6
|
+
//#region src/init/frameworkSetup/nextAppRouter/detect.ts
|
|
7
|
+
/** Script extensions probed when locating an App Router convention file. */
|
|
8
|
+
const SCRIPT_EXTENSIONS = [
|
|
9
|
+
"tsx",
|
|
10
|
+
"jsx",
|
|
11
|
+
"ts",
|
|
12
|
+
"js"
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Detects the Next.js App Router directory, preferring `src/app` over `app`.
|
|
16
|
+
* Returns `null` when neither exists (e.g. a Pages Router project).
|
|
17
|
+
*/
|
|
18
|
+
const detectNextAppDir = async (rootDir) => {
|
|
19
|
+
if (await require_init_utils_fileSystem.exists(rootDir, (0, node_path.join)("src", "app"))) return {
|
|
20
|
+
appDir: (0, node_path.join)("src", "app"),
|
|
21
|
+
srcDir: "src"
|
|
22
|
+
};
|
|
23
|
+
if (await require_init_utils_fileSystem.exists(rootDir, "app")) return {
|
|
24
|
+
appDir: "app",
|
|
25
|
+
srcDir: ""
|
|
26
|
+
};
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Finds an existing App Router convention file (e.g. `layout`, `page`) within
|
|
31
|
+
* `dir`, trying each known script extension. Returns the matching relative path
|
|
32
|
+
* or `null`.
|
|
33
|
+
*/
|
|
34
|
+
const findAppFile = async (rootDir, dir, baseName) => {
|
|
35
|
+
for (const extension of SCRIPT_EXTENSIONS) {
|
|
36
|
+
const candidate = (0, node_path.join)(dir, `${baseName}.${extension}`);
|
|
37
|
+
if (await require_init_utils_fileSystem.exists(rootDir, candidate)) return candidate;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Returns true when the dependency `version` range targets a major >= `major`.
|
|
43
|
+
* Tolerant of leading range characters, e.g. `^16.0.0`, `~16`, `16.1.0`.
|
|
44
|
+
*/
|
|
45
|
+
const isVersionAtLeast = (version, major) => {
|
|
46
|
+
if (!version || typeof version !== "string") return false;
|
|
47
|
+
const match = version.match(/(\d+)/);
|
|
48
|
+
if (!match?.[1]) return false;
|
|
49
|
+
return parseInt(match[1], 10) >= major;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.detectNextAppDir = detectNextAppDir;
|
|
54
|
+
exports.findAppFile = findAppFile;
|
|
55
|
+
exports.isVersionAtLeast = isVersionAtLeast;
|
|
56
|
+
//# sourceMappingURL=detect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.cjs","names":["exists"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/detect.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { exists } from '../../utils/fileSystem';\n\n/** Script extensions probed when locating an App Router convention file. */\nconst SCRIPT_EXTENSIONS = ['tsx', 'jsx', 'ts', 'js'] as const;\n\n/** Location of the Next.js App Router directory within the project. */\nexport type NextAppDirInfo = {\n /** App Router directory relative to the root, e.g. `src/app` or `app`. */\n appDir: string;\n /** `src` when the project uses a `src/` directory, otherwise `''`. */\n srcDir: string;\n};\n\n/**\n * Detects the Next.js App Router directory, preferring `src/app` over `app`.\n * Returns `null` when neither exists (e.g. a Pages Router project).\n */\nexport const detectNextAppDir = async (\n rootDir: string\n): Promise<NextAppDirInfo | null> => {\n if (await exists(rootDir, join('src', 'app'))) {\n return { appDir: join('src', 'app'), srcDir: 'src' };\n }\n if (await exists(rootDir, 'app')) {\n return { appDir: 'app', srcDir: '' };\n }\n return null;\n};\n\n/**\n * Finds an existing App Router convention file (e.g. `layout`, `page`) within\n * `dir`, trying each known script extension. Returns the matching relative path\n * or `null`.\n */\nexport const findAppFile = async (\n rootDir: string,\n dir: string,\n baseName: string\n): Promise<string | null> => {\n for (const extension of SCRIPT_EXTENSIONS) {\n const candidate = join(dir, `${baseName}.${extension}`);\n if (await exists(rootDir, candidate)) {\n return candidate;\n }\n }\n return null;\n};\n\n/**\n * Returns true when the dependency `version` range targets a major >= `major`.\n * Tolerant of leading range characters, e.g. `^16.0.0`, `~16`, `16.1.0`.\n */\nexport const isVersionAtLeast = (\n version: string | undefined,\n major: number\n): boolean => {\n if (!version || typeof version !== 'string') return false;\n const match = version.match(/(\\d+)/);\n if (!match?.[1]) return false;\n return parseInt(match[1], 10) >= major;\n};\n"],"mappings":";;;;;;;AAIA,MAAM,oBAAoB;CAAC;CAAO;CAAO;CAAM;CAAK;;;;;AAcpD,MAAa,mBAAmB,OAC9B,YACmC;AACnC,KAAI,MAAMA,qCAAO,6BAAc,OAAO,MAAM,CAAC,CAC3C,QAAO;EAAE,4BAAa,OAAO,MAAM;EAAE,QAAQ;EAAO;AAEtD,KAAI,MAAMA,qCAAO,SAAS,MAAM,CAC9B,QAAO;EAAE,QAAQ;EAAO,QAAQ;EAAI;AAEtC,QAAO;;;;;;;AAQT,MAAa,cAAc,OACzB,SACA,KACA,aAC2B;AAC3B,MAAK,MAAM,aAAa,mBAAmB;EACzC,MAAM,gCAAiB,KAAK,GAAG,SAAS,GAAG,YAAY;AACvD,MAAI,MAAMA,qCAAO,SAAS,UAAU,CAClC,QAAO;;AAGX,QAAO;;;;;;AAOT,MAAa,oBACX,SACA,UACY;AACZ,KAAI,CAAC,WAAW,OAAO,YAAY,SAAU,QAAO;CACpD,MAAM,QAAQ,QAAQ,MAAM,QAAQ;AACpC,KAAI,CAAC,QAAQ,GAAI,QAAO;AACxB,QAAO,SAAS,MAAM,IAAI,GAAG,IAAI"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_init_utils_fileSystem = require('../../utils/fileSystem.cjs');
|
|
4
|
+
const require_init_frameworkSetup_nextAppRouter_detect = require('./detect.cjs');
|
|
5
|
+
const require_init_frameworkSetup_nextAppRouter_restructure = require('./restructure.cjs');
|
|
6
|
+
const require_init_frameworkSetup_nextAppRouter_templates = require('./templates.cjs');
|
|
7
|
+
const require_init_frameworkSetup_nextAppRouter_transforms = require('./transforms.cjs');
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
11
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
12
|
+
|
|
13
|
+
//#region src/init/frameworkSetup/nextAppRouter/index.ts
|
|
14
|
+
/**
|
|
15
|
+
* Creates the locale-detection proxy (Next >= 16) or middleware (Next < 16),
|
|
16
|
+
* but only when neither already exists, so a user's custom file is never
|
|
17
|
+
* touched. Placed next to the app directory's parent (`src/` when present).
|
|
18
|
+
*/
|
|
19
|
+
const ensureProxyOrMiddleware = async (rootDir, srcDir, isNext16) => {
|
|
20
|
+
const baseDir = srcDir || ".";
|
|
21
|
+
for (const candidate of [
|
|
22
|
+
"proxy.ts",
|
|
23
|
+
"proxy.js",
|
|
24
|
+
"middleware.ts",
|
|
25
|
+
"middleware.js"
|
|
26
|
+
]) if (await require_init_utils_fileSystem.exists(rootDir, (0, node_path.join)(baseDir, candidate))) {
|
|
27
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} ${(0, _intlayer_config_logger.colorizePath)((0, node_path.join)(baseDir, candidate))} already exists, leaving it untouched`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const fileName = isNext16 ? "proxy.ts" : "middleware.ts";
|
|
31
|
+
const content = isNext16 ? require_init_frameworkSetup_nextAppRouter_templates.PROXY_TEMPLATE : require_init_frameworkSetup_nextAppRouter_templates.MIDDLEWARE_TEMPLATE;
|
|
32
|
+
const targetPath = (0, node_path.join)(baseDir, fileName);
|
|
33
|
+
if (srcDir) await require_init_utils_fileSystem.ensureDirectory(rootDir, srcDir);
|
|
34
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, targetPath, content);
|
|
35
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Created ${(0, _intlayer_config_logger.colorizePath)(targetPath)} for locale detection`);
|
|
36
|
+
};
|
|
37
|
+
/** Logs the outcome of a layout/page provider-wrap transform. */
|
|
38
|
+
const logTransformOutcome = (filePath, result) => {
|
|
39
|
+
switch (result.status) {
|
|
40
|
+
case "wrapped":
|
|
41
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Added Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)}`);
|
|
42
|
+
break;
|
|
43
|
+
case "already":
|
|
44
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} ${(0, _intlayer_config_logger.colorizePath)(filePath)} already wraps the Intlayer provider`);
|
|
45
|
+
break;
|
|
46
|
+
case "skipped-client":
|
|
47
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} ${(0, _intlayer_config_logger.colorizePath)(filePath)} is a client component — add the Intlayer provider manually.`, { level: "warn" });
|
|
48
|
+
break;
|
|
49
|
+
case "skipped":
|
|
50
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.x} Could not safely add the Intlayer provider to ${(0, _intlayer_config_logger.colorizePath)(filePath)} — please wire it manually.`, { level: "warn" });
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/** Transforms an existing file in place, writing it back only when changed. */
|
|
55
|
+
const transformExistingFile = async (rootDir, filePath, transform) => {
|
|
56
|
+
const result = transform(await require_init_utils_fileSystem.readFileFromRoot(rootDir, filePath));
|
|
57
|
+
if (result.status === "wrapped") await require_init_utils_fileSystem.writeFileToRoot(rootDir, filePath, result.code);
|
|
58
|
+
logTransformOutcome(filePath, result);
|
|
59
|
+
};
|
|
60
|
+
/** Creates a file from a template only when it does not already exist. */
|
|
61
|
+
const createIfMissing = async (rootDir, filePath, content, description) => {
|
|
62
|
+
if (await require_init_utils_fileSystem.exists(rootDir, filePath)) return false;
|
|
63
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, filePath, content);
|
|
64
|
+
(0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Created ${description} ${(0, _intlayer_config_logger.colorizePath)(filePath)}`);
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Next.js App Router adapter. Scaffolds the locale proxy/middleware, restructures
|
|
69
|
+
* the app into a `[locale]` segment, and wraps the layout/page with the Intlayer
|
|
70
|
+
* providers — all idempotently and without overwriting recognizable user code.
|
|
71
|
+
*/
|
|
72
|
+
const nextAppRouterAdapter = {
|
|
73
|
+
name: "Next.js App Router",
|
|
74
|
+
detect: async ({ rootDir, allDeps }) => {
|
|
75
|
+
if (!allDeps.next) return false;
|
|
76
|
+
return await require_init_frameworkSetup_nextAppRouter_detect.detectNextAppDir(rootDir) !== null;
|
|
77
|
+
},
|
|
78
|
+
setup: async ({ rootDir, allDeps, useTypeScript }) => {
|
|
79
|
+
const appDirInfo = await require_init_frameworkSetup_nextAppRouter_detect.detectNextAppDir(rootDir);
|
|
80
|
+
if (!appDirInfo) return;
|
|
81
|
+
const { appDir, srcDir } = appDirInfo;
|
|
82
|
+
const isNext16 = require_init_frameworkSetup_nextAppRouter_detect.isVersionAtLeast(allDeps.next, 16);
|
|
83
|
+
const scriptExtension = useTypeScript ? "tsx" : "jsx";
|
|
84
|
+
(0, _intlayer_config_logger.logger)((0, _intlayer_config_logger.colorize)("Setting up Next.js App Router integration...", _intlayer_config_colors.CYAN));
|
|
85
|
+
await ensureProxyOrMiddleware(rootDir, srcDir, isNext16);
|
|
86
|
+
const restructureResult = await require_init_frameworkSetup_nextAppRouter_restructure.restructureAppIntoLocale(rootDir, appDir);
|
|
87
|
+
if (restructureResult.status === "moved") (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} Restructured app routes under ${(0, _intlayer_config_logger.colorizePath)((0, node_path.join)(appDir, "[locale]"))}: ${restructureResult.movedEntries.map((entry) => (0, _intlayer_config_logger.colorize)(entry, _intlayer_config_colors.MAGENTA)).join(", ")}`);
|
|
88
|
+
else if (restructureResult.status === "already-structured") (0, _intlayer_config_logger.logger)(`${_intlayer_config_logger.v} ${(0, _intlayer_config_logger.colorizePath)((0, node_path.join)(appDir, "[locale]"))} already exists, skipping restructure`);
|
|
89
|
+
const localeDir = (0, node_path.join)(appDir, "[locale]");
|
|
90
|
+
await require_init_utils_fileSystem.ensureDirectory(rootDir, localeDir);
|
|
91
|
+
await createIfMissing(rootDir, (0, node_path.join)(appDir, `layout.${scriptExtension}`), useTypeScript ? require_init_frameworkSetup_nextAppRouter_templates.ROOT_LAYOUT_TEMPLATE_TS : require_init_frameworkSetup_nextAppRouter_templates.ROOT_LAYOUT_TEMPLATE_JS, "root layout");
|
|
92
|
+
const existingLayout = await require_init_frameworkSetup_nextAppRouter_detect.findAppFile(rootDir, localeDir, "layout");
|
|
93
|
+
if (existingLayout) await transformExistingFile(rootDir, existingLayout, require_init_frameworkSetup_nextAppRouter_transforms.wrapLayoutWithProvider);
|
|
94
|
+
else await createIfMissing(rootDir, (0, node_path.join)(localeDir, `layout.${scriptExtension}`), useTypeScript ? require_init_frameworkSetup_nextAppRouter_templates.LOCALE_LAYOUT_TEMPLATE_TS : require_init_frameworkSetup_nextAppRouter_templates.LOCALE_LAYOUT_TEMPLATE_JS, "locale layout");
|
|
95
|
+
const existingPage = await require_init_frameworkSetup_nextAppRouter_detect.findAppFile(rootDir, localeDir, "page");
|
|
96
|
+
if (existingPage) await transformExistingFile(rootDir, existingPage, require_init_frameworkSetup_nextAppRouter_transforms.wrapPageWithProvider);
|
|
97
|
+
else await createIfMissing(rootDir, (0, node_path.join)(localeDir, `page.${scriptExtension}`), useTypeScript ? require_init_frameworkSetup_nextAppRouter_templates.LOCALE_PAGE_TEMPLATE_TS : require_init_frameworkSetup_nextAppRouter_templates.LOCALE_PAGE_TEMPLATE_JS, "locale page");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.nextAppRouterAdapter = nextAppRouterAdapter;
|
|
103
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["exists","v","PROXY_TEMPLATE","MIDDLEWARE_TEMPLATE","ensureDirectory","writeFileToRoot","x","readFileFromRoot","detectNextAppDir","isVersionAtLeast","ANSIColors","restructureAppIntoLocale","ROOT_LAYOUT_TEMPLATE_TS","ROOT_LAYOUT_TEMPLATE_JS","findAppFile","wrapLayoutWithProvider","LOCALE_LAYOUT_TEMPLATE_TS","LOCALE_LAYOUT_TEMPLATE_JS","wrapPageWithProvider","LOCALE_PAGE_TEMPLATE_TS","LOCALE_PAGE_TEMPLATE_JS"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/index.ts"],"sourcesContent":["import { join } from 'node:path';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, logger, v, x } from '@intlayer/config/logger';\nimport {\n ensureDirectory,\n exists,\n readFileFromRoot,\n writeFileToRoot,\n} from '../../utils/fileSystem';\nimport type { FrameworkAdapter, FrameworkSetupContext } from '../types';\nimport { detectNextAppDir, findAppFile, isVersionAtLeast } from './detect';\nimport { restructureAppIntoLocale } from './restructure';\nimport {\n LOCALE_LAYOUT_TEMPLATE_JS,\n LOCALE_LAYOUT_TEMPLATE_TS,\n LOCALE_PAGE_TEMPLATE_JS,\n LOCALE_PAGE_TEMPLATE_TS,\n MIDDLEWARE_TEMPLATE,\n PROXY_TEMPLATE,\n ROOT_LAYOUT_TEMPLATE_JS,\n ROOT_LAYOUT_TEMPLATE_TS,\n} from './templates';\nimport {\n type TransformResult,\n wrapLayoutWithProvider,\n wrapPageWithProvider,\n} from './transforms';\n\n/**\n * Creates the locale-detection proxy (Next >= 16) or middleware (Next < 16),\n * but only when neither already exists, so a user's custom file is never\n * touched. Placed next to the app directory's parent (`src/` when present).\n */\nconst ensureProxyOrMiddleware = async (\n rootDir: string,\n srcDir: string,\n isNext16: boolean\n): Promise<void> => {\n const baseDir = srcDir || '.';\n const proxyCandidates = [\n 'proxy.ts',\n 'proxy.js',\n 'middleware.ts',\n 'middleware.js',\n ];\n\n for (const candidate of proxyCandidates) {\n if (await exists(rootDir, join(baseDir, candidate))) {\n logger(\n `${v} ${colorizePath(join(baseDir, candidate))} already exists, leaving it untouched`\n );\n return;\n }\n }\n\n const fileName = isNext16 ? 'proxy.ts' : 'middleware.ts';\n const content = isNext16 ? PROXY_TEMPLATE : MIDDLEWARE_TEMPLATE;\n const targetPath = join(baseDir, fileName);\n\n if (srcDir) await ensureDirectory(rootDir, srcDir);\n await writeFileToRoot(rootDir, targetPath, content);\n logger(`${v} Created ${colorizePath(targetPath)} for locale detection`);\n};\n\n/** Logs the outcome of a layout/page provider-wrap transform. */\nconst logTransformOutcome = (\n filePath: string,\n result: TransformResult\n): void => {\n switch (result.status) {\n case 'wrapped':\n logger(`${v} Added Intlayer provider to ${colorizePath(filePath)}`);\n break;\n case 'already':\n logger(\n `${v} ${colorizePath(filePath)} already wraps the Intlayer provider`\n );\n break;\n case 'skipped-client':\n logger(\n `${x} ${colorizePath(filePath)} is a client component — add the Intlayer provider manually.`,\n { level: 'warn' }\n );\n break;\n case 'skipped':\n logger(\n `${x} Could not safely add the Intlayer provider to ${colorizePath(filePath)} — please wire it manually.`,\n { level: 'warn' }\n );\n break;\n }\n};\n\n/** Transforms an existing file in place, writing it back only when changed. */\nconst transformExistingFile = async (\n rootDir: string,\n filePath: string,\n transform: (code: string) => TransformResult\n): Promise<void> => {\n const code = await readFileFromRoot(rootDir, filePath);\n const result = transform(code);\n if (result.status === 'wrapped') {\n await writeFileToRoot(rootDir, filePath, result.code);\n }\n logTransformOutcome(filePath, result);\n};\n\n/** Creates a file from a template only when it does not already exist. */\nconst createIfMissing = async (\n rootDir: string,\n filePath: string,\n content: string,\n description: string\n): Promise<boolean> => {\n if (await exists(rootDir, filePath)) return false;\n await writeFileToRoot(rootDir, filePath, content);\n logger(`${v} Created ${description} ${colorizePath(filePath)}`);\n return true;\n};\n\n/**\n * Next.js App Router adapter. Scaffolds the locale proxy/middleware, restructures\n * the app into a `[locale]` segment, and wraps the layout/page with the Intlayer\n * providers — all idempotently and without overwriting recognizable user code.\n */\nexport const nextAppRouterAdapter: FrameworkAdapter = {\n name: 'Next.js App Router',\n\n detect: async ({ rootDir, allDeps }) => {\n if (!allDeps.next) return false;\n return (await detectNextAppDir(rootDir)) !== null;\n },\n\n setup: async ({ rootDir, allDeps, useTypeScript }: FrameworkSetupContext) => {\n const appDirInfo = await detectNextAppDir(rootDir);\n if (!appDirInfo) return;\n\n const { appDir, srcDir } = appDirInfo;\n const isNext16 = isVersionAtLeast(allDeps.next, 16);\n const scriptExtension = useTypeScript ? 'tsx' : 'jsx';\n\n logger(\n colorize('Setting up Next.js App Router integration...', ANSIColors.CYAN)\n );\n\n // 1. Locale detection proxy / middleware (create only when absent).\n await ensureProxyOrMiddleware(rootDir, srcDir, isNext16);\n\n // 2. Move routable files under a `[locale]` segment (idempotent).\n const restructureResult = await restructureAppIntoLocale(rootDir, appDir);\n if (restructureResult.status === 'moved') {\n logger(\n `${v} Restructured app routes under ${colorizePath(join(appDir, '[locale]'))}: ${restructureResult.movedEntries\n .map((entry) => colorize(entry, ANSIColors.MAGENTA))\n .join(', ')}`\n );\n } else if (restructureResult.status === 'already-structured') {\n logger(\n `${v} ${colorizePath(join(appDir, '[locale]'))} already exists, skipping restructure`\n );\n }\n\n const localeDir = join(appDir, '[locale]');\n await ensureDirectory(rootDir, localeDir);\n\n // 3. Minimal pass-through root layout (the `[locale]` layout owns `<html>`).\n await createIfMissing(\n rootDir,\n join(appDir, `layout.${scriptExtension}`),\n useTypeScript ? ROOT_LAYOUT_TEMPLATE_TS : ROOT_LAYOUT_TEMPLATE_JS,\n 'root layout'\n );\n\n // 4. Locale layout — transform an existing one, else scaffold from template.\n const existingLayout = await findAppFile(rootDir, localeDir, 'layout');\n if (existingLayout) {\n await transformExistingFile(\n rootDir,\n existingLayout,\n wrapLayoutWithProvider\n );\n } else {\n await createIfMissing(\n rootDir,\n join(localeDir, `layout.${scriptExtension}`),\n useTypeScript ? LOCALE_LAYOUT_TEMPLATE_TS : LOCALE_LAYOUT_TEMPLATE_JS,\n 'locale layout'\n );\n }\n\n // 5. Locale page — transform an existing one, else scaffold from template.\n const existingPage = await findAppFile(rootDir, localeDir, 'page');\n if (existingPage) {\n await transformExistingFile(rootDir, existingPage, wrapPageWithProvider);\n } else {\n await createIfMissing(\n rootDir,\n join(localeDir, `page.${scriptExtension}`),\n useTypeScript ? LOCALE_PAGE_TEMPLATE_TS : LOCALE_PAGE_TEMPLATE_JS,\n 'locale page'\n );\n }\n },\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let fast_glob = require("fast-glob");
|
|
6
|
+
fast_glob = require_runtime.__toESM(fast_glob);
|
|
7
|
+
let node_fs = require("node:fs");
|
|
8
|
+
let recast = require("recast");
|
|
9
|
+
recast = require_runtime.__toESM(recast);
|
|
10
|
+
|
|
11
|
+
//#region src/init/frameworkSetup/nextAppRouter/restructure.ts
|
|
12
|
+
const { namedTypes: n } = recast.types;
|
|
13
|
+
/** Source file extensions whose relative imports must be rewritten after a move. */
|
|
14
|
+
const SCRIPT_GLOB = "**/*.{ts,tsx,js,jsx,mjs,cjs}";
|
|
15
|
+
/** Strips a known script extension from a file name, e.g. `page.tsx` -> `page`. */
|
|
16
|
+
const stripScriptExtension = (fileName) => fileName.replace(/\.(tsx|ts|jsx|js|mjs|cjs)$/, "");
|
|
17
|
+
/**
|
|
18
|
+
* Top-level App Router entries that must stay at the app root and never be
|
|
19
|
+
* moved under `[locale]`:
|
|
20
|
+
* - `api/` route handlers (not locale-prefixed),
|
|
21
|
+
* - global stylesheets,
|
|
22
|
+
* - metadata/asset file conventions (favicon, icon, sitemap, robots, manifest…),
|
|
23
|
+
* - `global-error` and `not-found` boundaries (kept as root fallbacks).
|
|
24
|
+
*
|
|
25
|
+
* Everything else (`page`, `loading`, `error`, `template`, `default`, the root
|
|
26
|
+
* `layout`, and nested route folders) is moved so it becomes locale-aware.
|
|
27
|
+
*/
|
|
28
|
+
const shouldKeepAppEntryAtRoot = (entryName) => {
|
|
29
|
+
if (entryName === "api") return true;
|
|
30
|
+
if (entryName.toLowerCase().endsWith(".css")) return true;
|
|
31
|
+
if (entryName === "favicon.ico") return true;
|
|
32
|
+
const base = stripScriptExtension(entryName);
|
|
33
|
+
if (new Set([
|
|
34
|
+
"not-found",
|
|
35
|
+
"global-error",
|
|
36
|
+
"sitemap",
|
|
37
|
+
"robots",
|
|
38
|
+
"manifest"
|
|
39
|
+
]).has(base)) return true;
|
|
40
|
+
if ([
|
|
41
|
+
"favicon",
|
|
42
|
+
"icon",
|
|
43
|
+
"apple-icon",
|
|
44
|
+
"opengraph-image",
|
|
45
|
+
"twitter-image"
|
|
46
|
+
].some((prefix) => base.startsWith(prefix))) return true;
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Maps an import target's pre-move absolute path to its post-move absolute path.
|
|
51
|
+
* Targets that live inside a moved top-level entry are relocated under
|
|
52
|
+
* `[locale]`; targets that stayed at the app root or live outside the app
|
|
53
|
+
* directory are returned unchanged.
|
|
54
|
+
*/
|
|
55
|
+
const mapTargetPath = (oldTargetAbs, { appDirAbs, localeDirAbs, movedTopLevelNames }) => {
|
|
56
|
+
const relFromApp = (0, node_path.relative)(appDirAbs, oldTargetAbs);
|
|
57
|
+
if (relFromApp.startsWith("..") || (0, node_path.isAbsolute)(relFromApp)) return oldTargetAbs;
|
|
58
|
+
const firstSegment = relFromApp.split(node_path.sep)[0] ?? "";
|
|
59
|
+
if (!movedTopLevelNames.some((name) => name === firstSegment || stripScriptExtension(name) === firstSegment)) return oldTargetAbs;
|
|
60
|
+
return (0, node_path.join)(localeDirAbs, relFromApp);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Rewrites relative import/export/`import()`/`require()` specifiers in a file
|
|
64
|
+
* that has moved from `oldAbs` to `newAbs`, so they keep resolving to the same
|
|
65
|
+
* modules after the move. Non-relative specifiers (bare packages, `@/` aliases)
|
|
66
|
+
* are left untouched. Returns the original code unchanged when nothing matched.
|
|
67
|
+
*/
|
|
68
|
+
const rewriteRelativeImports = (code, oldAbs, newAbs, context) => {
|
|
69
|
+
const ast = recast.parse(code, { parser: require("recast/parsers/babel-ts") });
|
|
70
|
+
let changed = false;
|
|
71
|
+
const rewriteSource = (sourceNode) => {
|
|
72
|
+
if (!sourceNode || !n.StringLiteral.check(sourceNode)) return;
|
|
73
|
+
const specifier = sourceNode.value;
|
|
74
|
+
if (typeof specifier !== "string" || !specifier.startsWith(".")) return;
|
|
75
|
+
const newTargetAbs = mapTargetPath((0, node_path.resolve)((0, node_path.dirname)(oldAbs), specifier), context);
|
|
76
|
+
let newSpecifier = (0, node_path.relative)((0, node_path.dirname)(newAbs), newTargetAbs).split(node_path.sep).join("/");
|
|
77
|
+
if (!newSpecifier.startsWith(".")) newSpecifier = `./${newSpecifier}`;
|
|
78
|
+
if (newSpecifier !== specifier) {
|
|
79
|
+
sourceNode.value = newSpecifier;
|
|
80
|
+
changed = true;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
recast.visit(ast, {
|
|
84
|
+
visitImportDeclaration(path) {
|
|
85
|
+
rewriteSource(path.node.source);
|
|
86
|
+
return false;
|
|
87
|
+
},
|
|
88
|
+
visitExportAllDeclaration(path) {
|
|
89
|
+
rewriteSource(path.node.source);
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
visitExportNamedDeclaration(path) {
|
|
93
|
+
if (path.node.source) rewriteSource(path.node.source);
|
|
94
|
+
return false;
|
|
95
|
+
},
|
|
96
|
+
visitCallExpression(path) {
|
|
97
|
+
const { callee, arguments: args } = path.node;
|
|
98
|
+
const isDynamicImport = callee.type === "Import";
|
|
99
|
+
const isRequire = n.Identifier.check(callee) && callee.name === "require";
|
|
100
|
+
if ((isDynamicImport || isRequire) && args.length > 0) rewriteSource(args[0]);
|
|
101
|
+
this.traverse(path);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (!changed) return code;
|
|
105
|
+
return recast.print(ast).code;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Moves the routable App Router entries of `appDir` under a new `[locale]`
|
|
109
|
+
* segment and rewrites relative imports in the moved files. Idempotent: it is a
|
|
110
|
+
* no-op when `[locale]` already exists. Root-only files (see
|
|
111
|
+
* {@link shouldKeepAppEntryAtRoot}) are left in place.
|
|
112
|
+
*/
|
|
113
|
+
const restructureAppIntoLocale = async (rootDir, appDir) => {
|
|
114
|
+
const appDirAbs = (0, node_path.join)(rootDir, appDir);
|
|
115
|
+
const localeDirAbs = (0, node_path.join)(appDirAbs, "[locale]");
|
|
116
|
+
if ((0, node_fs.existsSync)(localeDirAbs)) return { status: "already-structured" };
|
|
117
|
+
const movedTopLevelNames = (await (0, node_fs_promises.readdir)(appDirAbs, { withFileTypes: true })).map((entry) => entry.name).filter((name) => !shouldKeepAppEntryAtRoot(name));
|
|
118
|
+
if (movedTopLevelNames.length === 0) return { status: "nothing-to-move" };
|
|
119
|
+
await (0, node_fs_promises.mkdir)(localeDirAbs, { recursive: true });
|
|
120
|
+
for (const name of movedTopLevelNames) await (0, node_fs_promises.rename)((0, node_path.join)(appDirAbs, name), (0, node_path.join)(localeDirAbs, name));
|
|
121
|
+
const movedFiles = await (0, fast_glob.default)(SCRIPT_GLOB, {
|
|
122
|
+
cwd: localeDirAbs,
|
|
123
|
+
absolute: true,
|
|
124
|
+
onlyFiles: true
|
|
125
|
+
});
|
|
126
|
+
const rewriteContext = {
|
|
127
|
+
appDirAbs,
|
|
128
|
+
localeDirAbs,
|
|
129
|
+
movedTopLevelNames
|
|
130
|
+
};
|
|
131
|
+
for (const newAbs of movedFiles) {
|
|
132
|
+
const oldAbs = (0, node_path.join)(appDirAbs, (0, node_path.relative)(localeDirAbs, newAbs));
|
|
133
|
+
const code = await (0, node_fs_promises.readFile)(newAbs, "utf8");
|
|
134
|
+
const rewritten = rewriteRelativeImports(code, oldAbs, newAbs, rewriteContext);
|
|
135
|
+
if (rewritten !== code) await (0, node_fs_promises.writeFile)(newAbs, rewritten, "utf8");
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
status: "moved",
|
|
139
|
+
movedEntries: movedTopLevelNames
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
exports.restructureAppIntoLocale = restructureAppIntoLocale;
|
|
145
|
+
exports.rewriteRelativeImports = rewriteRelativeImports;
|
|
146
|
+
exports.shouldKeepAppEntryAtRoot = shouldKeepAppEntryAtRoot;
|
|
147
|
+
//# sourceMappingURL=restructure.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restructure.cjs","names":["sep"],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/restructure.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\nimport fg from 'fast-glob';\nimport * as recast from 'recast';\n\nconst { namedTypes: n } = recast.types;\n\n/** Source file extensions whose relative imports must be rewritten after a move. */\nconst SCRIPT_GLOB = '**/*.{ts,tsx,js,jsx,mjs,cjs}';\n\n/** Strips a known script extension from a file name, e.g. `page.tsx` -> `page`. */\nconst stripScriptExtension = (fileName: string): string =>\n fileName.replace(/\\.(tsx|ts|jsx|js|mjs|cjs)$/, '');\n\n/**\n * Top-level App Router entries that must stay at the app root and never be\n * moved under `[locale]`:\n * - `api/` route handlers (not locale-prefixed),\n * - global stylesheets,\n * - metadata/asset file conventions (favicon, icon, sitemap, robots, manifest…),\n * - `global-error` and `not-found` boundaries (kept as root fallbacks).\n *\n * Everything else (`page`, `loading`, `error`, `template`, `default`, the root\n * `layout`, and nested route folders) is moved so it becomes locale-aware.\n */\nexport const shouldKeepAppEntryAtRoot = (entryName: string): boolean => {\n if (entryName === 'api') return true;\n if (entryName.toLowerCase().endsWith('.css')) return true;\n if (entryName === 'favicon.ico') return true;\n\n const base = stripScriptExtension(entryName);\n const keepExactBases = new Set([\n 'not-found',\n 'global-error',\n 'sitemap',\n 'robots',\n 'manifest',\n ]);\n if (keepExactBases.has(base)) return true;\n\n // Image metadata conventions: favicon, icon, apple-icon, opengraph-image,\n // twitter-image — optionally suffixed (e.g. `icon1`, `opengraph-image-alt`).\n const imageConventionPrefixes = [\n 'favicon',\n 'icon',\n 'apple-icon',\n 'opengraph-image',\n 'twitter-image',\n ];\n if (imageConventionPrefixes.some((prefix) => base.startsWith(prefix))) {\n return true;\n }\n\n return false;\n};\n\ntype RewriteContext = {\n appDirAbs: string;\n localeDirAbs: string;\n movedTopLevelNames: string[];\n};\n\n/**\n * Maps an import target's pre-move absolute path to its post-move absolute path.\n * Targets that live inside a moved top-level entry are relocated under\n * `[locale]`; targets that stayed at the app root or live outside the app\n * directory are returned unchanged.\n */\nconst mapTargetPath = (\n oldTargetAbs: string,\n { appDirAbs, localeDirAbs, movedTopLevelNames }: RewriteContext\n): string => {\n const relFromApp = relative(appDirAbs, oldTargetAbs);\n\n // Outside the app directory (e.g. `../components/...`) — never moved.\n if (relFromApp.startsWith('..') || isAbsolute(relFromApp)) {\n return oldTargetAbs;\n }\n\n const firstSegment = relFromApp.split(sep)[0] ?? '';\n const isMoved = movedTopLevelNames.some(\n (name) =>\n name === firstSegment || stripScriptExtension(name) === firstSegment\n );\n\n if (!isMoved) return oldTargetAbs;\n\n return join(localeDirAbs, relFromApp);\n};\n\n/**\n * Rewrites relative import/export/`import()`/`require()` specifiers in a file\n * that has moved from `oldAbs` to `newAbs`, so they keep resolving to the same\n * modules after the move. Non-relative specifiers (bare packages, `@/` aliases)\n * are left untouched. Returns the original code unchanged when nothing matched.\n */\nexport const rewriteRelativeImports = (\n code: string,\n oldAbs: string,\n newAbs: string,\n context: RewriteContext\n): string => {\n // babel-ts handles TypeScript *and* JSX (App Router files are `.tsx`).\n const ast = recast.parse(code, {\n parser: require('recast/parsers/babel-ts'),\n });\n\n let changed = false;\n\n const rewriteSource = (sourceNode: any): void => {\n if (!sourceNode || !n.StringLiteral.check(sourceNode)) return;\n const specifier = sourceNode.value;\n if (typeof specifier !== 'string' || !specifier.startsWith('.')) return;\n\n const oldTargetAbs = resolve(dirname(oldAbs), specifier);\n const newTargetAbs = mapTargetPath(oldTargetAbs, context);\n\n let newSpecifier = relative(dirname(newAbs), newTargetAbs)\n .split(sep)\n .join('/');\n if (!newSpecifier.startsWith('.')) {\n newSpecifier = `./${newSpecifier}`;\n }\n\n if (newSpecifier !== specifier) {\n sourceNode.value = newSpecifier;\n changed = true;\n }\n };\n\n recast.visit(ast, {\n visitImportDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportAllDeclaration(path) {\n rewriteSource(path.node.source);\n return false;\n },\n visitExportNamedDeclaration(path) {\n if (path.node.source) rewriteSource(path.node.source);\n return false;\n },\n visitCallExpression(path) {\n const { callee, arguments: args } = path.node;\n const isDynamicImport = callee.type === 'Import';\n const isRequire = n.Identifier.check(callee) && callee.name === 'require';\n if ((isDynamicImport || isRequire) && args.length > 0) {\n rewriteSource(args[0]);\n }\n this.traverse(path);\n },\n });\n\n if (!changed) return code;\n return recast.print(ast).code;\n};\n\n/** Outcome of an attempted `[locale]` restructure. */\nexport type RestructureResult =\n | { status: 'already-structured' }\n | { status: 'nothing-to-move' }\n | { status: 'moved'; movedEntries: string[] };\n\n/**\n * Moves the routable App Router entries of `appDir` under a new `[locale]`\n * segment and rewrites relative imports in the moved files. Idempotent: it is a\n * no-op when `[locale]` already exists. Root-only files (see\n * {@link shouldKeepAppEntryAtRoot}) are left in place.\n */\nexport const restructureAppIntoLocale = async (\n rootDir: string,\n appDir: string\n): Promise<RestructureResult> => {\n const appDirAbs = join(rootDir, appDir);\n const localeDirAbs = join(appDirAbs, '[locale]');\n\n if (existsSync(localeDirAbs)) {\n return { status: 'already-structured' };\n }\n\n const entries = await readdir(appDirAbs, { withFileTypes: true });\n const movedTopLevelNames = entries\n .map((entry) => entry.name)\n .filter((name) => !shouldKeepAppEntryAtRoot(name));\n\n if (movedTopLevelNames.length === 0) {\n return { status: 'nothing-to-move' };\n }\n\n await mkdir(localeDirAbs, { recursive: true });\n\n for (const name of movedTopLevelNames) {\n await rename(join(appDirAbs, name), join(localeDirAbs, name));\n }\n\n const movedFiles = await fg(SCRIPT_GLOB, {\n cwd: localeDirAbs,\n absolute: true,\n onlyFiles: true,\n });\n\n const rewriteContext: RewriteContext = {\n appDirAbs,\n localeDirAbs,\n movedTopLevelNames,\n };\n\n for (const newAbs of movedFiles) {\n const relFromLocale = relative(localeDirAbs, newAbs);\n const oldAbs = join(appDirAbs, relFromLocale);\n const code = await readFile(newAbs, 'utf8');\n const rewritten = rewriteRelativeImports(\n code,\n oldAbs,\n newAbs,\n rewriteContext\n );\n if (rewritten !== code) {\n await writeFile(newAbs, rewritten, 'utf8');\n }\n }\n\n return { status: 'moved', movedEntries: movedTopLevelNames };\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/init/frameworkSetup/nextAppRouter/templates.ts
|
|
4
|
+
/**
|
|
5
|
+
* File templates for a fresh Next.js App Router integration. These are only
|
|
6
|
+
* written when the target file does not exist (or, for the locale layout/page,
|
|
7
|
+
* when the app is effectively empty) — they never overwrite user code.
|
|
8
|
+
*/
|
|
9
|
+
/** Next.js >= 16 locale-detection proxy (`src/proxy.ts`). */
|
|
10
|
+
const PROXY_TEMPLATE = `export { intlayerProxy as proxy } from "next-intlayer/proxy";
|
|
11
|
+
|
|
12
|
+
export const config = {
|
|
13
|
+
matcher:
|
|
14
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\..*|_next).*)",
|
|
15
|
+
};
|
|
16
|
+
`;
|
|
17
|
+
/** Next.js < 16 locale-detection middleware (`src/middleware.ts`). */
|
|
18
|
+
const MIDDLEWARE_TEMPLATE = `export { intlayerMiddleware as middleware } from "next-intlayer/middleware";
|
|
19
|
+
|
|
20
|
+
export const config = {
|
|
21
|
+
matcher:
|
|
22
|
+
"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\..*|_next).*)",
|
|
23
|
+
};
|
|
24
|
+
`;
|
|
25
|
+
/** Minimal pass-through root layout (`app/layout.tsx`), lets `[locale]/layout` own `<html>`. */
|
|
26
|
+
const ROOT_LAYOUT_TEMPLATE_TS = `import type { PropsWithChildren, FC } from "react";
|
|
27
|
+
|
|
28
|
+
const RootLayout: FC<PropsWithChildren> = ({ children }) => <>{children}</>;
|
|
29
|
+
|
|
30
|
+
export default RootLayout;
|
|
31
|
+
`;
|
|
32
|
+
const ROOT_LAYOUT_TEMPLATE_JS = `const RootLayout = ({ children }) => <>{children}</>;
|
|
33
|
+
|
|
34
|
+
export default RootLayout;
|
|
35
|
+
`;
|
|
36
|
+
/** Locale layout (`app/[locale]/layout.tsx`) providing `<html>` + client provider. */
|
|
37
|
+
const LOCALE_LAYOUT_TEMPLATE_TS = `import { type NextLayoutIntlayer, IntlayerClientProvider } from "next-intlayer";
|
|
38
|
+
import { getHTMLTextDir } from "intlayer";
|
|
39
|
+
|
|
40
|
+
export { generateStaticParams } from "next-intlayer";
|
|
41
|
+
|
|
42
|
+
const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {
|
|
43
|
+
const { locale } = await params;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
47
|
+
<body>
|
|
48
|
+
<IntlayerClientProvider locale={locale}>
|
|
49
|
+
{children}
|
|
50
|
+
</IntlayerClientProvider>
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default LocaleLayout;
|
|
57
|
+
`;
|
|
58
|
+
const LOCALE_LAYOUT_TEMPLATE_JS = `import { IntlayerClientProvider } from "next-intlayer";
|
|
59
|
+
import { getHTMLTextDir } from "intlayer";
|
|
60
|
+
|
|
61
|
+
export { generateStaticParams } from "next-intlayer";
|
|
62
|
+
|
|
63
|
+
const LocaleLayout = async ({ children, params }) => {
|
|
64
|
+
const { locale } = await params;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
68
|
+
<body>
|
|
69
|
+
<IntlayerClientProvider locale={locale}>
|
|
70
|
+
{children}
|
|
71
|
+
</IntlayerClientProvider>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default LocaleLayout;
|
|
78
|
+
`;
|
|
79
|
+
/**
|
|
80
|
+
* Locale home page (`app/[locale]/page.tsx`). Self-contained starter that does
|
|
81
|
+
* not depend on an example content declaration — add Intlayer content (a
|
|
82
|
+
* `*.content.ts` file consumed via `useIntlayer`) as the next step.
|
|
83
|
+
*/
|
|
84
|
+
const LOCALE_PAGE_TEMPLATE_TS = `import { type NextPageIntlayer } from "next-intlayer";
|
|
85
|
+
|
|
86
|
+
const Page: NextPageIntlayer = async ({ params }) => {
|
|
87
|
+
const { locale } = await params;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<main>
|
|
91
|
+
<h1>{locale}</h1>
|
|
92
|
+
<p>Get started by editing this page.</p>
|
|
93
|
+
</main>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default Page;
|
|
98
|
+
`;
|
|
99
|
+
const LOCALE_PAGE_TEMPLATE_JS = `const Page = async ({ params }) => {
|
|
100
|
+
const { locale } = await params;
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<main>
|
|
104
|
+
<h1>{locale}</h1>
|
|
105
|
+
<p>Get started by editing this page.</p>
|
|
106
|
+
</main>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default Page;
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
exports.LOCALE_LAYOUT_TEMPLATE_JS = LOCALE_LAYOUT_TEMPLATE_JS;
|
|
115
|
+
exports.LOCALE_LAYOUT_TEMPLATE_TS = LOCALE_LAYOUT_TEMPLATE_TS;
|
|
116
|
+
exports.LOCALE_PAGE_TEMPLATE_JS = LOCALE_PAGE_TEMPLATE_JS;
|
|
117
|
+
exports.LOCALE_PAGE_TEMPLATE_TS = LOCALE_PAGE_TEMPLATE_TS;
|
|
118
|
+
exports.MIDDLEWARE_TEMPLATE = MIDDLEWARE_TEMPLATE;
|
|
119
|
+
exports.PROXY_TEMPLATE = PROXY_TEMPLATE;
|
|
120
|
+
exports.ROOT_LAYOUT_TEMPLATE_JS = ROOT_LAYOUT_TEMPLATE_JS;
|
|
121
|
+
exports.ROOT_LAYOUT_TEMPLATE_TS = ROOT_LAYOUT_TEMPLATE_TS;
|
|
122
|
+
//# sourceMappingURL=templates.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.cjs","names":[],"sources":["../../../../../src/init/frameworkSetup/nextAppRouter/templates.ts"],"sourcesContent":["/**\n * File templates for a fresh Next.js App Router integration. These are only\n * written when the target file does not exist (or, for the locale layout/page,\n * when the app is effectively empty) — they never overwrite user code.\n */\n\n/** Next.js >= 16 locale-detection proxy (`src/proxy.ts`). */\nexport const PROXY_TEMPLATE = `export { intlayerProxy as proxy } from \"next-intlayer/proxy\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Next.js < 16 locale-detection middleware (`src/middleware.ts`). */\nexport const MIDDLEWARE_TEMPLATE = `export { intlayerMiddleware as middleware } from \"next-intlayer/middleware\";\n\nexport const config = {\n matcher:\n \"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\\\\\\\..*|_next).*)\",\n};\n`;\n\n/** Minimal pass-through root layout (`app/layout.tsx`), lets `[locale]/layout` own `<html>`. */\nexport const ROOT_LAYOUT_TEMPLATE_TS = `import type { PropsWithChildren, FC } from \"react\";\n\nconst RootLayout: FC<PropsWithChildren> = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\nexport const ROOT_LAYOUT_TEMPLATE_JS = `const RootLayout = ({ children }) => <>{children}</>;\n\nexport default RootLayout;\n`;\n\n/** Locale layout (`app/[locale]/layout.tsx`) providing `<html>` + client provider. */\nexport const LOCALE_LAYOUT_TEMPLATE_TS = `import { type NextLayoutIntlayer, IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\nexport const LOCALE_LAYOUT_TEMPLATE_JS = `import { IntlayerClientProvider } from \"next-intlayer\";\nimport { getHTMLTextDir } from \"intlayer\";\n\nexport { generateStaticParams } from \"next-intlayer\";\n\nconst LocaleLayout = async ({ children, params }) => {\n const { locale } = await params;\n\n return (\n <html lang={locale} dir={getHTMLTextDir(locale)}>\n <body>\n <IntlayerClientProvider locale={locale}>\n {children}\n </IntlayerClientProvider>\n </body>\n </html>\n );\n};\n\nexport default LocaleLayout;\n`;\n\n/**\n * Locale home page (`app/[locale]/page.tsx`). Self-contained starter that does\n * not depend on an example content declaration — add Intlayer content (a\n * `*.content.ts` file consumed via `useIntlayer`) as the next step.\n */\nexport const LOCALE_PAGE_TEMPLATE_TS = `import { type NextPageIntlayer } from \"next-intlayer\";\n\nconst Page: NextPageIntlayer = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n\nexport const LOCALE_PAGE_TEMPLATE_JS = `const Page = async ({ params }) => {\n const { locale } = await params;\n\n return (\n <main>\n <h1>{locale}</h1>\n <p>Get started by editing this page.</p>\n </main>\n );\n};\n\nexport default Page;\n`;\n"],"mappings":";;;;;;;;;AAOA,MAAa,iBAAiB;;;;;;;;AAS9B,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,0BAA0B;;;;;;AAOvC,MAAa,0BAA0B;;;;;AAMvC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;AAsBzC,MAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BzC,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAa,0BAA0B"}
|