jskelet 0.5.4 → 0.6.0
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/AGENTS.md +18 -13
- package/CHANGELOG.md +387 -385
- package/README.md +9 -7
- package/bin/jskelet.mjs +24 -10
- package/docs/01-baslangic.md +4 -3
- package/docs/02-mimari.md +4 -3
- package/docs/03-routing.md +11 -6
- package/docs/04-render-ve-sablonlar.md +35 -43
- package/docs/05-islands.md +12 -8
- package/docs/07-yapilandirma.md +53 -25
- package/docs/08-build.md +40 -18
- package/docs/09-dev-araclari.md +5 -1
- package/docs/10-dagitim.md +6 -1
- package/docs/11-tasima.md +51 -17
- package/docs/12-panel-ve-oturum.md +10 -4
- package/docs/README.md +7 -5
- package/docs/en/01-getting-started.md +4 -3
- package/docs/en/02-architecture.md +5 -5
- package/docs/en/03-routing.md +12 -7
- package/docs/en/04-rendering.md +47 -59
- package/docs/en/05-islands.md +13 -8
- package/docs/en/07-configuration.md +55 -27
- package/docs/en/08-build.md +43 -21
- package/docs/en/09-dev-tools.md +6 -1
- package/docs/en/10-deployment.md +6 -1
- package/docs/en/11-migration.md +51 -16
- package/docs/en/12-dashboards-and-sessions.md +9 -4
- package/docs/en/README.md +7 -5
- package/package.json +49 -14
- package/src/build/tasks/client.mjs +91 -10
- package/src/build/tasks/icons.mjs +152 -18
- package/src/client/index.js +2 -2
- package/src/compile/codegen.js +4 -0
- package/src/compile/compile-all.js +12 -21
- package/src/compile/expr.js +5 -0
- package/src/compile/parse.js +64 -8
- package/src/compile/resolve.js +3 -0
- package/src/config/defaults.js +12 -2
- package/src/config/index.js +31 -3
- package/src/dev-server.mjs +26 -3
- package/src/http/cookies-entry.js +1 -0
- package/src/http/cookies.js +18 -0
- package/src/logo.png +0 -0
- package/src/migrate/apply.mjs +262 -0
- package/src/migrate/babel.mjs +79 -0
- package/src/migrate/classify.mjs +155 -0
- package/src/migrate/config.mjs +126 -0
- package/src/migrate/fs-walk.mjs +191 -0
- package/src/migrate/parse.mjs +26 -0
- package/src/migrate/scan.mjs +177 -0
- package/src/migrate/transform/expr-source.mjs +168 -0
- package/src/migrate/transform/island.mjs +67 -0
- package/src/migrate/transform/jsx-to-component.mjs +302 -0
- package/src/migrate/transform/jsx-to-jsk.mjs +330 -0
- package/src/migrate/transform/page-split.mjs +435 -0
- package/src/migrate/write.mjs +81 -0
- package/src/migrate.mjs +171 -0
- package/src/server/auth/handoff.js +94 -11
- package/src/server/create-app.js +28 -10
- package/src/server/ejs-adapter.js +59 -0
- package/src/server/image-optimizer.js +94 -26
- package/src/server/port-guard.js +255 -0
- package/src/server/render.js +27 -9
- package/src/server/status-page.js +105 -4
- package/src/start.mjs +18 -3
- package/src/templates/layout.ejs +8 -28
- package/src/templates/layout.jsk +30 -0
- package/src/templates/layout.render.js +41 -0
- package/src/views/helpers/tags.js +86 -3
- package/types/build/resolve-peer.d.mts +13 -0
- package/types/client/dom.d.ts +55 -0
- package/types/client/form.d.ts +19 -0
- package/types/client/index.d.ts +20 -0
- package/types/client/registry.d.ts +53 -0
- package/types/client/safe-image.d.ts +19 -0
- package/types/client/shared-cookie.d.ts +82 -0
- package/types/client/store.d.ts +18 -0
- package/types/client/swap.d.ts +46 -0
- package/types/compile/codegen.d.ts +32 -0
- package/types/compile/compile-all.d.ts +42 -0
- package/types/compile/errors.d.ts +30 -0
- package/types/compile/expr.d.ts +67 -0
- package/types/compile/index.d.ts +10 -0
- package/types/compile/parse.d.ts +82 -0
- package/types/compile/resolve.d.ts +46 -0
- package/types/compile/scan-exports.d.ts +9 -0
- package/types/config/defaults.d.ts +449 -0
- package/types/config/index.d.ts +299 -0
- package/types/config/pattern.d.ts +38 -0
- package/types/http/control-flow.d.ts +45 -0
- package/types/http/cookies-entry.d.ts +5 -0
- package/types/http/cookies.d.ts +113 -0
- package/types/http/request-cache.d.ts +13 -0
- package/types/http/request-context.d.ts +67 -0
- package/types/http/shared-cookie.d.ts +73 -0
- package/types/index.d.ts +30 -0
- package/types/log.d.mts +153 -0
- package/types/server/admin/actions.d.ts +16 -0
- package/types/server/admin/auth.d.ts +52 -0
- package/types/server/admin/event-log.d.ts +38 -0
- package/types/server/admin/gate.d.ts +43 -0
- package/types/server/admin/inventory.d.ts +40 -0
- package/types/server/admin/mount.d.ts +6 -0
- package/types/server/admin/router.d.ts +6 -0
- package/types/server/admin/snapshot.d.ts +6 -0
- package/types/server/assets.d.ts +47 -0
- package/types/server/auth/handoff.d.ts +12 -0
- package/types/server/cache-deps.d.ts +16 -0
- package/types/server/cache-vary.d.ts +30 -0
- package/types/server/cloudflare.d.ts +163 -0
- package/types/server/create-app.d.ts +25 -0
- package/types/server/data-cache.d.ts +116 -0
- package/types/server/dev/devtools.d.ts +44 -0
- package/types/server/dev/report.d.ts +229 -0
- package/types/server/dev/socket.d.ts +17 -0
- package/types/server/dev/version-check.d.mts +15 -0
- package/types/server/ejs-adapter.d.ts +11 -0
- package/types/server/head-hints.d.ts +40 -0
- package/types/server/html-cache.d.ts +173 -0
- package/types/server/image-optimizer.d.ts +68 -0
- package/types/server/logs/access-middleware.d.ts +7 -0
- package/types/server/logs/file-sink.d.ts +17 -0
- package/types/server/logs/pipeline.d.ts +37 -0
- package/types/server/logs/s3-put.d.ts +85 -0
- package/types/server/logs/s3-sink.d.ts +26 -0
- package/types/server/metadata.d.ts +38 -0
- package/types/server/middleware/compression.d.ts +17 -0
- package/types/server/middleware/csrf.d.ts +4 -0
- package/types/server/middleware/dev-gate.d.ts +2 -0
- package/types/server/middleware/headers.d.ts +2 -0
- package/types/server/middleware/redirects.d.ts +2 -0
- package/types/server/middleware/static-precompressed.d.ts +5 -0
- package/types/server/middleware/trailing-slash.d.ts +11 -0
- package/types/server/middleware/upstream-proxy.d.ts +21 -0
- package/types/server/og-image.d.ts +149 -0
- package/types/server/port-guard.d.ts +50 -0
- package/types/server/prewarm.d.ts +128 -0
- package/types/server/redis.d.ts +163 -0
- package/types/server/render.d.ts +101 -0
- package/types/server/router.d.ts +5 -0
- package/types/server/status-page.d.ts +24 -0
- package/types/server/upstream-limiter.d.ts +123 -0
- package/types/server/upstream-tracking.d.ts +42 -0
- package/types/shared/cookie-domain.d.ts +29 -0
- package/types/templates/layout.render.d.ts +7 -0
- package/types/version.d.mts +10 -0
- package/types/views/components/loader.d.ts +5 -0
- package/types/views/helpers/html.d.ts +39 -0
- package/types/views/helpers/tags.d.ts +127 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bir kaynak dosyasını page / layout / client / server-component olarak sınıflandırır.
|
|
3
|
+
*/
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { t } from "./babel.mjs";
|
|
6
|
+
import { parseSource } from "./parse.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {'page' | 'layout' | 'client' | 'server-component' | 'unknown'} FileKind
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* kind: FileKind,
|
|
12
|
+
* isClient: boolean,
|
|
13
|
+
* hasHooks: boolean,
|
|
14
|
+
* hasServerAction: boolean,
|
|
15
|
+
* hasSuspense: boolean,
|
|
16
|
+
* revalidate: number | null,
|
|
17
|
+
* hasGenerateMetadata: boolean,
|
|
18
|
+
* hasGenerateStaticParams: boolean,
|
|
19
|
+
* reasons: string[],
|
|
20
|
+
* }} Classification
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} code
|
|
25
|
+
* @param {string} filename
|
|
26
|
+
* @returns {Classification}
|
|
27
|
+
*/
|
|
28
|
+
export function classifySource(code, filename) {
|
|
29
|
+
const base = path.basename(filename);
|
|
30
|
+
/** @type {Classification} */
|
|
31
|
+
const out = {
|
|
32
|
+
kind: "unknown",
|
|
33
|
+
isClient: false,
|
|
34
|
+
hasHooks: false,
|
|
35
|
+
hasServerAction: false,
|
|
36
|
+
hasSuspense: false,
|
|
37
|
+
revalidate: null,
|
|
38
|
+
hasGenerateMetadata: false,
|
|
39
|
+
hasGenerateStaticParams: false,
|
|
40
|
+
reasons: [],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (/^["']use client["'];?/.test(code.trim()) || /\n["']use client["'];?/.test(code)) {
|
|
44
|
+
out.isClient = true;
|
|
45
|
+
}
|
|
46
|
+
if (code.includes('"use server"') || code.includes("'use server'")) {
|
|
47
|
+
out.hasServerAction = true;
|
|
48
|
+
out.reasons.push("contains \"use server\"");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let ast;
|
|
52
|
+
try {
|
|
53
|
+
ast = parseSource(code, filename);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
out.reasons.push(
|
|
56
|
+
`parse error: ${error instanceof Error ? error.message : String(error)}`,
|
|
57
|
+
);
|
|
58
|
+
if (out.isClient) out.kind = "client";
|
|
59
|
+
else if (/^page\./.test(base)) out.kind = "page";
|
|
60
|
+
else if (/^layout\./.test(base)) out.kind = "layout";
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const node of ast.program.directives ?? []) {
|
|
65
|
+
if (node.value?.value === "use client") out.isClient = true;
|
|
66
|
+
if (node.value?.value === "use server") {
|
|
67
|
+
out.hasServerAction = true;
|
|
68
|
+
out.reasons.push("directive \"use server\"");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const node of ast.program.body) {
|
|
73
|
+
if (t.isImportDeclaration(node)) {
|
|
74
|
+
const src = node.source.value;
|
|
75
|
+
if (src === "react" || src === "react/jsx-runtime") {
|
|
76
|
+
for (const spec of node.specifiers) {
|
|
77
|
+
const name =
|
|
78
|
+
(t.isImportSpecifier(spec) && t.isIdentifier(spec.imported)
|
|
79
|
+
? spec.imported.name
|
|
80
|
+
: null) ||
|
|
81
|
+
(t.isImportDefaultSpecifier(spec) ? "default" : null);
|
|
82
|
+
if (name === "Suspense") out.hasSuspense = true;
|
|
83
|
+
if (
|
|
84
|
+
name &&
|
|
85
|
+
/^(use[A-Z]|useState|useEffect|useMemo|useCallback|useRef|useContext|useReducer|useLayoutEffect|useId|useTransition|useDeferredValue|useSyncExternalStore)/.test(
|
|
86
|
+
name,
|
|
87
|
+
)
|
|
88
|
+
) {
|
|
89
|
+
out.hasHooks = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
t.isExportNamedDeclaration(node) &&
|
|
97
|
+
node.declaration &&
|
|
98
|
+
t.isVariableDeclaration(node.declaration)
|
|
99
|
+
) {
|
|
100
|
+
for (const decl of node.declaration.declarations) {
|
|
101
|
+
if (t.isIdentifier(decl.id) && decl.id.name === "revalidate") {
|
|
102
|
+
if (t.isNumericLiteral(decl.init)) out.revalidate = decl.init.value;
|
|
103
|
+
else if (t.isLiteral(decl.init) && typeof decl.init.value === "number") {
|
|
104
|
+
out.revalidate = /** @type {number} */ (decl.init.value);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (t.isExportNamedDeclaration(node)) {
|
|
111
|
+
const id = namedExportName(node);
|
|
112
|
+
if (id === "generateMetadata") out.hasGenerateMetadata = true;
|
|
113
|
+
if (id === "generateStaticParams") out.hasGenerateStaticParams = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Hook çağrıları (import alias olmadan da)
|
|
118
|
+
if (/\buse(State|Effect|Memo|Callback|Ref|Context|Reducer)\s*\(/.test(code)) {
|
|
119
|
+
out.hasHooks = true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (out.isClient || out.hasHooks) {
|
|
123
|
+
out.kind = "client";
|
|
124
|
+
} else if (/^page\./.test(base)) {
|
|
125
|
+
out.kind = "page";
|
|
126
|
+
} else if (/^layout\./.test(base)) {
|
|
127
|
+
out.kind = "layout";
|
|
128
|
+
} else {
|
|
129
|
+
out.kind = "server-component";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {import('@babel/types').ExportNamedDeclaration} node
|
|
137
|
+
* @returns {string | null}
|
|
138
|
+
*/
|
|
139
|
+
function namedExportName(node) {
|
|
140
|
+
if (node.declaration) {
|
|
141
|
+
if (t.isFunctionDeclaration(node.declaration) && node.declaration.id) {
|
|
142
|
+
return node.declaration.id.name;
|
|
143
|
+
}
|
|
144
|
+
if (t.isVariableDeclaration(node.declaration)) {
|
|
145
|
+
const id = node.declaration.declarations[0]?.id;
|
|
146
|
+
if (t.isIdentifier(id)) return id.name;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const spec of node.specifiers) {
|
|
150
|
+
if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported)) {
|
|
151
|
+
return spec.exported.name;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* next.config → jskelet.config.mjs taslağı.
|
|
3
|
+
*/
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { findNextConfig, findClientEnvKeys } from "./fs-walk.mjs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} root
|
|
11
|
+
* @returns {Promise<{ status: 'ok' | 'partial' | 'skipped', notes: string[], code: string | null }>}
|
|
12
|
+
*/
|
|
13
|
+
export async function draftConfig(root) {
|
|
14
|
+
/** @type {string[]} */
|
|
15
|
+
const notes = [];
|
|
16
|
+
const configPath = findNextConfig(root);
|
|
17
|
+
const clientEnv = findClientEnvKeys(root);
|
|
18
|
+
|
|
19
|
+
/** @type {Record<string, unknown>} */
|
|
20
|
+
let next = {};
|
|
21
|
+
|
|
22
|
+
if (!configPath) {
|
|
23
|
+
notes.push("no next.config.* — emitting minimal jskelet.config.mjs");
|
|
24
|
+
} else if (configPath.endsWith(".ts")) {
|
|
25
|
+
notes.push("next.config.ts cannot be imported — copy headers/redirects/rewrites manually");
|
|
26
|
+
} else {
|
|
27
|
+
try {
|
|
28
|
+
const mod = await import(pathToFileURL(configPath).href);
|
|
29
|
+
next = mod.default ?? mod;
|
|
30
|
+
if (typeof next === "function") {
|
|
31
|
+
next = await next({ default: {} });
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
notes.push(
|
|
35
|
+
`could not load next.config: ${error instanceof Error ? error.message : String(error)}`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const trailingSlash = Boolean(next.trailingSlash);
|
|
41
|
+
const deviceSizes =
|
|
42
|
+
next.images && typeof next.images === "object" && Array.isArray(next.images.deviceSizes)
|
|
43
|
+
? next.images.deviceSizes
|
|
44
|
+
: null;
|
|
45
|
+
|
|
46
|
+
if (next.experimental) {
|
|
47
|
+
notes.push("experimental.* has no JSkelet equivalent — ignored");
|
|
48
|
+
}
|
|
49
|
+
if (fs.existsSync(path.join(root, "middleware.ts")) || fs.existsSync(path.join(root, "middleware.js"))) {
|
|
50
|
+
notes.push("middleware.ts/js → port to Express middleware manually");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const headersSrc = fnSource(next.headers, "headers", notes);
|
|
54
|
+
const redirectsSrc = fnSource(next.redirects, "redirects", notes);
|
|
55
|
+
const rewritesSrc = fnSource(next.rewrites, "rewrites", notes);
|
|
56
|
+
|
|
57
|
+
const clientEnvList =
|
|
58
|
+
clientEnv.length > 0
|
|
59
|
+
? clientEnv.map((k) => JSON.stringify(k)).join(", ")
|
|
60
|
+
: "";
|
|
61
|
+
|
|
62
|
+
const imagesBlock = deviceSizes
|
|
63
|
+
? `\n images: {\n widths: ${JSON.stringify(deviceSizes)},\n },\n`
|
|
64
|
+
: "";
|
|
65
|
+
|
|
66
|
+
const code =
|
|
67
|
+
`/**\n` +
|
|
68
|
+
` * Drafted by \`jskelet migrate config\` from ${configPath ? path.basename(configPath) : "defaults"}.\n` +
|
|
69
|
+
` * Review before use — complex path-to-regexp patterns are not supported.\n` +
|
|
70
|
+
` */\n` +
|
|
71
|
+
`export default {\n` +
|
|
72
|
+
` brand: { lang: "en" },\n` +
|
|
73
|
+
(trailingSlash ? ` trailingSlash: true,\n` : "") +
|
|
74
|
+
(clientEnvList ? ` clientEnv: [${clientEnvList}],\n` : "") +
|
|
75
|
+
imagesBlock +
|
|
76
|
+
(headersSrc ? `\n async headers() {\n${headersSrc}\n },\n` : "") +
|
|
77
|
+
(redirectsSrc ? `\n async redirects() {\n${redirectsSrc}\n },\n` : "") +
|
|
78
|
+
(rewritesSrc ? `\n async rewrites() {\n${rewritesSrc}\n },\n` : "") +
|
|
79
|
+
`\n hooks: {\n` +
|
|
80
|
+
` metadata() {\n` +
|
|
81
|
+
` return {\n` +
|
|
82
|
+
` titleTemplate: "%s | Site",\n` +
|
|
83
|
+
` description: "",\n` +
|
|
84
|
+
` };\n` +
|
|
85
|
+
` },\n` +
|
|
86
|
+
` layoutContext() {\n` +
|
|
87
|
+
` return { bodyClass: "min-h-full" };\n` +
|
|
88
|
+
` },\n` +
|
|
89
|
+
` notFound() {\n` +
|
|
90
|
+
` return {\n` +
|
|
91
|
+
` view: "pages/not-found",\n` +
|
|
92
|
+
` metadata: { title: "Page not found", robots: { index: false } },\n` +
|
|
93
|
+
` };\n` +
|
|
94
|
+
` },\n` +
|
|
95
|
+
` },\n` +
|
|
96
|
+
`};\n`;
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
status: notes.length ? "partial" : "ok",
|
|
100
|
+
notes,
|
|
101
|
+
code,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {unknown} value
|
|
107
|
+
* @param {string} name
|
|
108
|
+
* @param {string[]} notes
|
|
109
|
+
* @returns {string | null}
|
|
110
|
+
*/
|
|
111
|
+
function fnSource(value, name, notes) {
|
|
112
|
+
if (typeof value !== "function") return null;
|
|
113
|
+
try {
|
|
114
|
+
const src = Function.prototype.toString.call(value);
|
|
115
|
+
// "async headers() { ... }" or "headers() { ... }" or arrow
|
|
116
|
+
const bodyMatch = src.match(/^[^{]*\{([\s\S]*)\}$/);
|
|
117
|
+
if (!bodyMatch) {
|
|
118
|
+
notes.push(`${name}() could not be inlined — copy manually`);
|
|
119
|
+
return ` // TODO[jskelet-migrate]: paste ${name}() from next.config\n return [];`;
|
|
120
|
+
}
|
|
121
|
+
return bodyMatch[1].replace(/^\n/, "").replace(/\n$/, "");
|
|
122
|
+
} catch {
|
|
123
|
+
notes.push(`${name}() could not be serialized`);
|
|
124
|
+
return ` // TODO[jskelet-migrate]: paste ${name}() from next.config\n return [];`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next App Router ağacında dosya keşfi ve path → URL eşlemesi.
|
|
3
|
+
*/
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
const PAGE_RE = /^page\.(jsx?|tsx?|mjs|cjs)$/;
|
|
8
|
+
const LAYOUT_RE = /^layout\.(jsx?|tsx?|mjs|cjs)$/;
|
|
9
|
+
const SOURCE_RE = /\.(jsx?|tsx?|mjs|cjs)$/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} root
|
|
13
|
+
* @returns {string | null}
|
|
14
|
+
*/
|
|
15
|
+
export function findAppDir(root) {
|
|
16
|
+
for (const candidate of ["app", "src/app"]) {
|
|
17
|
+
const abs = path.join(root, candidate);
|
|
18
|
+
if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) return abs;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} root
|
|
25
|
+
* @returns {string | null}
|
|
26
|
+
*/
|
|
27
|
+
export function findNextConfig(root) {
|
|
28
|
+
for (const name of [
|
|
29
|
+
"next.config.mjs",
|
|
30
|
+
"next.config.js",
|
|
31
|
+
"next.config.cjs",
|
|
32
|
+
"next.config.ts",
|
|
33
|
+
]) {
|
|
34
|
+
const abs = path.join(root, name);
|
|
35
|
+
if (fs.existsSync(abs)) return abs;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} dir
|
|
42
|
+
* @param {(rel: string, abs: string) => void} visit
|
|
43
|
+
* @param {string} [base]
|
|
44
|
+
*/
|
|
45
|
+
export function walkFiles(dir, visit, base = dir) {
|
|
46
|
+
if (!fs.existsSync(dir)) return;
|
|
47
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
48
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
49
|
+
const abs = path.join(dir, entry.name);
|
|
50
|
+
if (entry.isDirectory()) {
|
|
51
|
+
walkFiles(abs, visit, base);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
visit(path.relative(base, abs).replace(/\\/g, "/"), abs);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* App Router segment yolunu Express path'ine çevirir.
|
|
60
|
+
* `news/[slug]` → `/news/:slug`, `docs/[...slug]` → `/docs/:slug*`
|
|
61
|
+
*
|
|
62
|
+
* @param {string} relativeDir app/ altındaki dizin (posix, trailing slash yok)
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
export function segmentToExpressPath(relativeDir) {
|
|
66
|
+
if (!relativeDir || relativeDir === ".") return "/";
|
|
67
|
+
const parts = relativeDir.split("/").filter(Boolean);
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const part of parts) {
|
|
70
|
+
if (part.startsWith("(") && part.endsWith(")")) continue; // route groups
|
|
71
|
+
if (part.startsWith("@")) continue; // parallel routes
|
|
72
|
+
const catchAll = part.match(/^\[\.\.\.(.+)\]$/);
|
|
73
|
+
if (catchAll) {
|
|
74
|
+
out.push(`:${catchAll[1]}*`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const optional = part.match(/^\[\[\.\.\.(.+)\]\]$/);
|
|
78
|
+
if (optional) {
|
|
79
|
+
out.push(`:${optional[1]}*`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const dyn = part.match(/^\[(.+)\]$/);
|
|
83
|
+
if (dyn) {
|
|
84
|
+
out.push(`:${dyn[1]}`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
out.push(part);
|
|
88
|
+
}
|
|
89
|
+
return "/" + out.join("/");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Feature adı: ilk anlamlı segment veya `home`.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} relativeDir
|
|
96
|
+
* @returns {string}
|
|
97
|
+
*/
|
|
98
|
+
export function featureNameFromDir(relativeDir) {
|
|
99
|
+
const parts = relativeDir
|
|
100
|
+
.split("/")
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.filter((p) => !(p.startsWith("(") && p.endsWith(")")))
|
|
103
|
+
.filter((p) => !p.startsWith("@"))
|
|
104
|
+
.filter((p) => !p.startsWith("["));
|
|
105
|
+
if (parts.length === 0) return "home";
|
|
106
|
+
return parts[0].replace(/[^a-zA-Z0-9_-]/g, "-") || "home";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sayfa dosya gövde adı.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} relativeDir
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
export function pageNameFromDir(relativeDir) {
|
|
116
|
+
const parts = relativeDir
|
|
117
|
+
.split("/")
|
|
118
|
+
.filter(Boolean)
|
|
119
|
+
.filter((p) => !(p.startsWith("(") && p.endsWith(")")))
|
|
120
|
+
.filter((p) => !p.startsWith("@"));
|
|
121
|
+
if (parts.length === 0) return "home";
|
|
122
|
+
const last = parts[parts.length - 1];
|
|
123
|
+
if (last.startsWith("[")) {
|
|
124
|
+
return parts.length > 1 ? parts[parts.length - 2] : "detail";
|
|
125
|
+
}
|
|
126
|
+
return last.replace(/[^a-zA-Z0-9_-]/g, "-") || "page";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} appDir
|
|
131
|
+
* @returns {{ pages: Array<{ abs: string, rel: string, dir: string, url: string, feature: string, page: string }>, layouts: Array<{ abs: string, rel: string, dir: string, depth: number }>, sources: Array<{ abs: string, rel: string }> }}
|
|
132
|
+
*/
|
|
133
|
+
export function inventoryApp(appDir) {
|
|
134
|
+
/** @type {Array<{ abs: string, rel: string, dir: string, url: string, feature: string, page: string }>} */
|
|
135
|
+
const pages = [];
|
|
136
|
+
/** @type {Array<{ abs: string, rel: string, dir: string, depth: number }>} */
|
|
137
|
+
const layouts = [];
|
|
138
|
+
/** @type {Array<{ abs: string, rel: string }>} */
|
|
139
|
+
const sources = [];
|
|
140
|
+
|
|
141
|
+
walkFiles(appDir, (rel, abs) => {
|
|
142
|
+
const base = path.basename(rel);
|
|
143
|
+
const dir = path.posix.dirname(rel);
|
|
144
|
+
const dirKey = dir === "." ? "" : dir;
|
|
145
|
+
|
|
146
|
+
if (PAGE_RE.test(base)) {
|
|
147
|
+
pages.push({
|
|
148
|
+
abs,
|
|
149
|
+
rel,
|
|
150
|
+
dir: dirKey,
|
|
151
|
+
url: segmentToExpressPath(dirKey),
|
|
152
|
+
feature: featureNameFromDir(dirKey),
|
|
153
|
+
page: pageNameFromDir(dirKey),
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (LAYOUT_RE.test(base)) {
|
|
158
|
+
const depth = dirKey ? dirKey.split("/").length : 0;
|
|
159
|
+
layouts.push({ abs, rel, dir: dirKey, depth });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (SOURCE_RE.test(base)) {
|
|
163
|
+
sources.push({ abs, rel });
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
layouts.sort((a, b) => a.depth - b.depth);
|
|
168
|
+
pages.sort((a, b) => a.url.localeCompare(b.url));
|
|
169
|
+
return { pages, layouts, sources };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} root
|
|
174
|
+
* @returns {string[]}
|
|
175
|
+
*/
|
|
176
|
+
export function findClientEnvKeys(root) {
|
|
177
|
+
/** @type {Set<string>} */
|
|
178
|
+
const keys = new Set();
|
|
179
|
+
for (const name of [".env", ".env.local", ".env.production", ".env.development"]) {
|
|
180
|
+
const abs = path.join(root, name);
|
|
181
|
+
if (!fs.existsSync(abs)) continue;
|
|
182
|
+
const text = fs.readFileSync(abs, "utf8");
|
|
183
|
+
for (const line of text.split(/\r?\n/)) {
|
|
184
|
+
const m = line.match(/^\s*NEXT_PUBLIC_([A-Za-z0-9_]+)\s*=/);
|
|
185
|
+
if (m) keys.add(m[1]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return [...keys].sort();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { PAGE_RE, LAYOUT_RE, SOURCE_RE };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js / React kaynak dosyalarını Babel ile parse eder (JSX + TS).
|
|
3
|
+
*
|
|
4
|
+
* `@babel/parser` opsiyonel peerdır; yoksa `getBabel()` kurulum mesajı fırlatır.
|
|
5
|
+
*/
|
|
6
|
+
import { getBabel } from "./babel.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} code
|
|
10
|
+
* @param {string} [filename]
|
|
11
|
+
* @returns {import('@babel/types').File}
|
|
12
|
+
*/
|
|
13
|
+
export function parseSource(code, filename = "file.tsx") {
|
|
14
|
+
const { parse } = getBabel();
|
|
15
|
+
return parse(code, {
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
sourceFilename: filename,
|
|
18
|
+
plugins: [
|
|
19
|
+
"jsx",
|
|
20
|
+
"typescript",
|
|
21
|
+
"importAttributes",
|
|
22
|
+
"topLevelAwait",
|
|
23
|
+
],
|
|
24
|
+
errorRecovery: false,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next App Router envanteri + engel listesi.
|
|
3
|
+
*/
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
findAppDir,
|
|
8
|
+
findNextConfig,
|
|
9
|
+
inventoryApp,
|
|
10
|
+
findClientEnvKeys,
|
|
11
|
+
walkFiles,
|
|
12
|
+
} from "./fs-walk.mjs";
|
|
13
|
+
import { ensureBabel } from "./babel.mjs";
|
|
14
|
+
import { classifySource } from "./classify.mjs";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} root
|
|
18
|
+
* @returns {object}
|
|
19
|
+
*/
|
|
20
|
+
export function scanProject(root) {
|
|
21
|
+
// Babel yoksa yüzlerce "parse error" yerine tek net kurulum mesajı.
|
|
22
|
+
ensureBabel(root);
|
|
23
|
+
|
|
24
|
+
const appDir = findAppDir(root);
|
|
25
|
+
const nextConfig = findNextConfig(root);
|
|
26
|
+
const clientEnv = findClientEnvKeys(root);
|
|
27
|
+
|
|
28
|
+
if (!appDir) {
|
|
29
|
+
return {
|
|
30
|
+
root,
|
|
31
|
+
appDir: null,
|
|
32
|
+
nextConfig,
|
|
33
|
+
clientEnv,
|
|
34
|
+
pages: [],
|
|
35
|
+
layouts: [],
|
|
36
|
+
clients: [],
|
|
37
|
+
components: [],
|
|
38
|
+
blockers: [
|
|
39
|
+
{
|
|
40
|
+
kind: "no-app-dir",
|
|
41
|
+
message: "No app/ or src/app/ directory found (App Router required).",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
pagesRouter: fs.existsSync(path.join(root, "pages")),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const inv = inventoryApp(appDir);
|
|
49
|
+
/** @type {object[]} */
|
|
50
|
+
const pages = [];
|
|
51
|
+
/** @type {object[]} */
|
|
52
|
+
const clients = [];
|
|
53
|
+
/** @type {object[]} */
|
|
54
|
+
const components = [];
|
|
55
|
+
/** @type {object[]} */
|
|
56
|
+
const blockers = [];
|
|
57
|
+
|
|
58
|
+
if (fs.existsSync(path.join(root, "pages"))) {
|
|
59
|
+
blockers.push({
|
|
60
|
+
kind: "pages-router",
|
|
61
|
+
message: "pages/ directory present — Pages Router is out of scope for this codemod.",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const nestedLayouts = inv.layouts.filter((l) => l.depth > 0);
|
|
66
|
+
if (nestedLayouts.length) {
|
|
67
|
+
blockers.push({
|
|
68
|
+
kind: "nested-layouts",
|
|
69
|
+
message: `${nestedLayouts.length} nested layout(s); JSkelet has a single layout — flatten manually.`,
|
|
70
|
+
files: nestedLayouts.map((l) => l.rel),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (const page of inv.pages) {
|
|
75
|
+
const code = fs.readFileSync(page.abs, "utf8");
|
|
76
|
+
const classification = classifySource(code, page.rel);
|
|
77
|
+
pages.push({ ...page, classification });
|
|
78
|
+
if (classification.hasServerAction) {
|
|
79
|
+
blockers.push({
|
|
80
|
+
kind: "server-action",
|
|
81
|
+
file: page.rel,
|
|
82
|
+
message: "Server Actions have no equivalent — use app.post handlers.",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (classification.hasSuspense) {
|
|
86
|
+
blockers.push({
|
|
87
|
+
kind: "suspense",
|
|
88
|
+
file: page.rel,
|
|
89
|
+
message: "Suspense / streaming is not supported — use fragment endpoints.",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (const layout of inv.layouts) {
|
|
95
|
+
const code = fs.readFileSync(layout.abs, "utf8");
|
|
96
|
+
layout.classification = classifySource(code, layout.rel);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const src of inv.sources) {
|
|
100
|
+
const code = fs.readFileSync(src.abs, "utf8");
|
|
101
|
+
const classification = classifySource(code, src.rel);
|
|
102
|
+
if (classification.kind === "client" || classification.isClient) {
|
|
103
|
+
clients.push({ ...src, classification });
|
|
104
|
+
} else if (classification.kind === "server-component") {
|
|
105
|
+
components.push({ ...src, classification });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
for (const dir of ["components", "src/components", "lib/components"]) {
|
|
110
|
+
const abs = path.join(root, dir);
|
|
111
|
+
if (!fs.existsSync(abs)) continue;
|
|
112
|
+
walkFiles(abs, (_rel, fileAbs) => {
|
|
113
|
+
if (!/\.(jsx?|tsx?)$/.test(fileAbs)) return;
|
|
114
|
+
const fromRoot = path.relative(root, fileAbs).replace(/\\/g, "/");
|
|
115
|
+
const code = fs.readFileSync(fileAbs, "utf8");
|
|
116
|
+
const classification = classifySource(code, fromRoot);
|
|
117
|
+
if (classification.kind === "client" || classification.isClient) {
|
|
118
|
+
clients.push({ abs: fileAbs, rel: fromRoot, classification });
|
|
119
|
+
} else if (classification.kind === "server-component") {
|
|
120
|
+
components.push({ abs: fileAbs, rel: fromRoot, classification });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
root,
|
|
127
|
+
appDir: path.relative(root, appDir).replace(/\\/g, "/"),
|
|
128
|
+
nextConfig: nextConfig ? path.relative(root, nextConfig).replace(/\\/g, "/") : null,
|
|
129
|
+
clientEnv,
|
|
130
|
+
pages,
|
|
131
|
+
layouts: inv.layouts,
|
|
132
|
+
clients,
|
|
133
|
+
components,
|
|
134
|
+
blockers,
|
|
135
|
+
pagesRouter: fs.existsSync(path.join(root, "pages")),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* İnsan-okur özet.
|
|
141
|
+
* @param {ReturnType<typeof scanProject>} report
|
|
142
|
+
* @returns {string}
|
|
143
|
+
*/
|
|
144
|
+
export function formatScanReport(report) {
|
|
145
|
+
const lines = [];
|
|
146
|
+
lines.push(`Next.js → JSkelet scan`);
|
|
147
|
+
lines.push(` app: ${report.appDir ?? "(missing)"}`);
|
|
148
|
+
lines.push(` config: ${report.nextConfig ?? "(none)"}`);
|
|
149
|
+
lines.push(` pages: ${report.pages.length}`);
|
|
150
|
+
lines.push(` layouts: ${report.layouts.length}`);
|
|
151
|
+
lines.push(` client modules: ${report.clients.length}`);
|
|
152
|
+
lines.push(` server components: ${report.components.length}`);
|
|
153
|
+
if (report.clientEnv.length) {
|
|
154
|
+
lines.push(` NEXT_PUBLIC_* → clientEnv candidates: ${report.clientEnv.join(", ")}`);
|
|
155
|
+
}
|
|
156
|
+
if (report.pages.length) {
|
|
157
|
+
lines.push("");
|
|
158
|
+
lines.push("Pages:");
|
|
159
|
+
for (const p of report.pages) {
|
|
160
|
+
const flags = [];
|
|
161
|
+
if (p.classification?.revalidate != null) flags.push(`revalidate=${p.classification.revalidate}`);
|
|
162
|
+
if (p.classification?.hasGenerateMetadata) flags.push("metadata");
|
|
163
|
+
if (p.classification?.hasGenerateStaticParams) flags.push("staticParams");
|
|
164
|
+
lines.push(` ${p.url} ← ${p.rel}${flags.length ? ` (${flags.join(", ")})` : ""}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (report.blockers.length) {
|
|
168
|
+
lines.push("");
|
|
169
|
+
lines.push("Blockers:");
|
|
170
|
+
for (const b of report.blockers) {
|
|
171
|
+
lines.push(` ⚠ ${b.message}${b.file ? ` [${b.file}]` : ""}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
lines.push("");
|
|
175
|
+
lines.push("Next: jskelet migrate apply [--write] | jskelet migrate config [--write]");
|
|
176
|
+
return lines.join("\n");
|
|
177
|
+
}
|