jskelet 0.2.3 → 0.2.5
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 +132 -132
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -21
- package/bin/jskelet.mjs +103 -103
- package/docs/01-baslangic.md +285 -285
- package/docs/02-mimari.md +287 -287
- package/docs/03-routing.md +480 -480
- package/docs/04-render-ve-sablonlar.md +490 -490
- package/docs/05-islands.md +482 -482
- package/docs/06-cache.md +1209 -1202
- package/docs/08-build.md +366 -366
- package/docs/09-dev-araclari.md +335 -335
- package/docs/10-dagitim.md +329 -329
- package/docs/12-panel-ve-oturum.md +384 -384
- package/docs/README.md +105 -105
- package/docs/en/01-getting-started.md +292 -292
- package/docs/en/02-architecture.md +305 -305
- package/docs/en/03-routing.md +497 -497
- package/docs/en/04-rendering.md +504 -504
- package/docs/en/05-islands.md +492 -492
- package/docs/en/06-caching.md +1239 -1232
- package/docs/en/07-configuration.md +986 -986
- package/docs/en/08-build.md +383 -383
- package/docs/en/09-dev-tools.md +342 -342
- package/docs/en/10-deployment.md +332 -332
- package/docs/en/11-migration.md +359 -359
- package/docs/en/12-dashboards-and-sessions.md +392 -392
- package/docs/en/README.md +112 -112
- package/package.json +102 -102
- package/src/build/ensure-build.mjs +15 -15
- package/src/build/paths.mjs +143 -143
- package/src/build/resolve-peer.mjs +36 -36
- package/src/build/tasks/client.mjs +268 -268
- package/src/build/tasks/css.mjs +124 -124
- package/src/build/tasks/fonts.mjs +146 -146
- package/src/build/tasks/icons.mjs +224 -224
- package/src/build/tasks/images.mjs +244 -244
- package/src/build/tasks/precompress.mjs +78 -78
- package/src/client/cache-panel/i18n.js +670 -0
- package/src/client/cache-panel/login.html +74 -71
- package/src/client/cache-panel/panel.css +756 -740
- package/src/client/cache-panel/panel.html +308 -307
- package/src/client/cache-panel/panel.js +915 -808
- package/src/client/devtools/report.html +185 -185
- package/src/client/devtools/report.js +725 -725
- package/src/client/dom.js +95 -95
- package/src/client/form.js +192 -192
- package/src/client/index.js +35 -35
- package/src/client/registry.js +297 -297
- package/src/client/safe-image.js +91 -91
- package/src/client/store.js +36 -36
- package/src/client/swap.js +188 -188
- package/src/config/pattern.js +107 -107
- package/src/http/control-flow.js +71 -71
- package/src/http/cookies.js +257 -257
- package/src/http/request-cache.js +46 -46
- package/src/http/request-context.js +162 -162
- package/src/index.js +83 -83
- package/src/init.mjs +221 -221
- package/src/runtime/alias-hooks.mjs +119 -119
- package/src/runtime/register.mjs +4 -4
- package/src/server/assets.js +147 -147
- package/src/server/cache-deps.js +42 -42
- package/src/server/cache-panel.js +759 -738
- package/src/server/cloudflare.js +607 -595
- package/src/server/create-app.js +291 -291
- package/src/server/data-cache.js +462 -462
- package/src/server/dev/report.js +369 -369
- package/src/server/dev/socket.js +170 -170
- package/src/server/dev/version-check.mjs +139 -139
- package/src/server/html-cache.js +817 -817
- package/src/server/metadata.js +102 -102
- package/src/server/middleware/compression.js +205 -205
- package/src/server/middleware/csrf.js +134 -134
- package/src/server/middleware/dev-gate.js +62 -62
- package/src/server/middleware/headers.js +37 -37
- package/src/server/middleware/redirects.js +32 -32
- package/src/server/middleware/static-precompressed.js +100 -100
- package/src/server/middleware/upstream-proxy.js +141 -141
- package/src/server/prewarm.js +601 -601
- package/src/server/redis.js +569 -569
- package/src/server/router.js +128 -128
- package/src/server/status-page.js +164 -164
- package/src/server/upstream-limiter.js +376 -376
- package/src/server/upstream-tracking.js +166 -166
- package/src/start.mjs +7 -7
- package/src/templates/layout.ejs +44 -44
- package/src/version.mjs +31 -31
- package/src/views/components/loader.js +85 -85
- package/src/views/helpers/html.js +102 -102
- package/src/views/helpers/tags.js +245 -245
package/src/init.mjs
CHANGED
|
@@ -1,221 +1,221 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `jskelet init` — bulunduğun dizine çalışan bir minimum iskelet kurar.
|
|
3
|
-
*
|
|
4
|
-
* Var olan dosyaların üzerine yazmaz: komutu ikinci kez çalıştırmak yalnızca
|
|
5
|
-
* eksikleri tamamlar. Amaç, "kurulum yaptım ama hiçbir şey çalışmıyor"
|
|
6
|
-
* aşamasını tamamen atlamak — `jskelet dev` hemen ardından çalışır.
|
|
7
|
-
*/
|
|
8
|
-
import fs from "node:fs";
|
|
9
|
-
import path from "node:path";
|
|
10
|
-
import * as log from "./log.mjs";
|
|
11
|
-
|
|
12
|
-
/** @type {Record<string, string>} */
|
|
13
|
-
const FILES = {
|
|
14
|
-
"jskelet.config.mjs": `/**
|
|
15
|
-
* JSkelet configuration. Every field is optional; the app still runs on
|
|
16
|
-
* defaults if you delete this file.
|
|
17
|
-
*
|
|
18
|
-
* Details: node_modules/jskelet/docs/en/07-configuration.md
|
|
19
|
-
*/
|
|
20
|
-
export default {
|
|
21
|
-
brand: { lang: "en" },
|
|
22
|
-
|
|
23
|
-
/** Third-party origins; emitted as preconnect in \`<head>\`. */
|
|
24
|
-
preconnect: [],
|
|
25
|
-
|
|
26
|
-
async cache() {
|
|
27
|
-
return {
|
|
28
|
-
/** How long a page's HTML stays in the cache (seconds). */
|
|
29
|
-
html: { "/": 60 },
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
hooks: {
|
|
34
|
-
/** Metadata defaults for every page. */
|
|
35
|
-
metadata() {
|
|
36
|
-
return {
|
|
37
|
-
titleTemplate: "%s | JSkelet",
|
|
38
|
-
description: "A site built with JSkelet.",
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
/** Locals added to the layout on every render. */
|
|
43
|
-
layoutContext() {
|
|
44
|
-
return { bodyClass: "min-h-full" };
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
/** 404 page. */
|
|
48
|
-
notFound() {
|
|
49
|
-
return {
|
|
50
|
-
view: "pages/not-found",
|
|
51
|
-
metadata: { title: "Page not found", robots: { index: false } },
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
`,
|
|
57
|
-
|
|
58
|
-
"routes/10-pages.mjs": `/**
|
|
59
|
-
* Route module. The default export receives \`(app, api)\`; \`api.route()\` wraps
|
|
60
|
-
* the controller with the HTML cache, the notFound/redirect flow and
|
|
61
|
-
* compression.
|
|
62
|
-
*
|
|
63
|
-
* The numeric prefix in the file name sets load order: catch-all routes
|
|
64
|
-
* (like "/:slug") belong to a higher number.
|
|
65
|
-
*/
|
|
66
|
-
export default function register(app, { route }) {
|
|
67
|
-
app.get(
|
|
68
|
-
"/",
|
|
69
|
-
route(
|
|
70
|
-
async () => ({
|
|
71
|
-
view: "pages/home",
|
|
72
|
-
metadata: { title: "Home" },
|
|
73
|
-
data: { message: "JSkelet is running." },
|
|
74
|
-
}),
|
|
75
|
-
{ revalidate: 60 },
|
|
76
|
-
),
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
`,
|
|
80
|
-
|
|
81
|
-
"views/pages/home.ejs": `<section class="wrapper">
|
|
82
|
-
<h1><%= metadata.title %></h1>
|
|
83
|
-
<p><%= message %></p>
|
|
84
|
-
<div data-island="counter" data-island-props='{"start":0}'></div>
|
|
85
|
-
</section>
|
|
86
|
-
`,
|
|
87
|
-
|
|
88
|
-
"views/pages/not-found.ejs": `<section class="wrapper">
|
|
89
|
-
<h1>404</h1>
|
|
90
|
-
<p>The page you are looking for was not found.</p>
|
|
91
|
-
<p><a href="/">Back to home</a></p>
|
|
92
|
-
</section>
|
|
93
|
-
`,
|
|
94
|
-
|
|
95
|
-
"views/components/button.js": `import { attrs, esc } from "jskelet/html";
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Every named export under \`views/components/**\` is usable directly in
|
|
99
|
-
* templates: \`<%- button({ text: "Save" }) %>\`. No import needed.
|
|
100
|
-
*
|
|
101
|
-
* @param {{ text: string, href?: string, class?: string }} props
|
|
102
|
-
* @returns {string}
|
|
103
|
-
*/
|
|
104
|
-
export function button({ text, href, class: className }) {
|
|
105
|
-
const tag = href ? "a" : "button";
|
|
106
|
-
return \`<\${tag}\${attrs({ href, class: className })}>\${esc(text)}</\${tag}>\`;
|
|
107
|
-
}
|
|
108
|
-
`,
|
|
109
|
-
|
|
110
|
-
"client/entries/main.js": `import { registerAll, start } from "jskelet/client";
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Island registry. Values are dynamic imports: a module is downloaded only if
|
|
114
|
-
* that island is actually on the page and becomes visible.
|
|
115
|
-
*/
|
|
116
|
-
registerAll({
|
|
117
|
-
counter: () => import("../islands/counter.js"),
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
start();
|
|
121
|
-
`,
|
|
122
|
-
|
|
123
|
-
"client/islands/counter.js": `/**
|
|
124
|
-
* Island contract: a named export called \`mount(element, props)\`.
|
|
125
|
-
* The returned function, if any, is reserved for cleanup.
|
|
126
|
-
*
|
|
127
|
-
* @param {HTMLElement} element
|
|
128
|
-
* @param {{ start?: number }} props
|
|
129
|
-
*/
|
|
130
|
-
export function mount(element, props) {
|
|
131
|
-
let value = props.start ?? 0;
|
|
132
|
-
|
|
133
|
-
const button = document.createElement("button");
|
|
134
|
-
button.type = "button";
|
|
135
|
-
|
|
136
|
-
const paint = () => {
|
|
137
|
-
button.textContent = \`Clicks: \${value}\`;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
button.addEventListener("click", () => {
|
|
141
|
-
value += 1;
|
|
142
|
-
paint();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
paint();
|
|
146
|
-
element.append(button);
|
|
147
|
-
}
|
|
148
|
-
`,
|
|
149
|
-
|
|
150
|
-
"styles/globals.css": `@import "tailwindcss" source(none);
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Tailwind's class scanning depends on these directives. Automatic detection
|
|
154
|
-
* only scans the directory holding this file; variants used in templates
|
|
155
|
-
* (like data-[active=false]:…) would otherwise be dropped silently.
|
|
156
|
-
*/
|
|
157
|
-
@source "../views";
|
|
158
|
-
@source "../client";
|
|
159
|
-
@source "../routes";
|
|
160
|
-
|
|
161
|
-
body {
|
|
162
|
-
margin: 0;
|
|
163
|
-
font-family: system-ui, sans-serif;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.wrapper {
|
|
167
|
-
max-width: 64rem;
|
|
168
|
-
margin-inline: auto;
|
|
169
|
-
padding: 2rem 1rem;
|
|
170
|
-
}
|
|
171
|
-
`,
|
|
172
|
-
|
|
173
|
-
"jsconfig.json": `{
|
|
174
|
-
"compilerOptions": {
|
|
175
|
-
"checkJs": true,
|
|
176
|
-
"module": "esnext",
|
|
177
|
-
"moduleResolution": "bundler",
|
|
178
|
-
"target": "es2022",
|
|
179
|
-
"baseUrl": ".",
|
|
180
|
-
"paths": { "@/*": ["./*"] }
|
|
181
|
-
},
|
|
182
|
-
"exclude": ["node_modules", "public/assets"]
|
|
183
|
-
}
|
|
184
|
-
`,
|
|
185
|
-
|
|
186
|
-
".gitignore": `node_modules/
|
|
187
|
-
.jskelet/
|
|
188
|
-
public/assets/
|
|
189
|
-
.env
|
|
190
|
-
`,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @param {string} root
|
|
195
|
-
* @returns {Promise<void>}
|
|
196
|
-
*/
|
|
197
|
-
export async function init(root) {
|
|
198
|
-
log.section("init");
|
|
199
|
-
|
|
200
|
-
const created = [];
|
|
201
|
-
const skipped = [];
|
|
202
|
-
|
|
203
|
-
for (const [relative, contents] of Object.entries(FILES)) {
|
|
204
|
-
const target = path.join(root, relative);
|
|
205
|
-
|
|
206
|
-
if (fs.existsSync(target)) {
|
|
207
|
-
skipped.push(relative);
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
212
|
-
fs.writeFileSync(target, contents);
|
|
213
|
-
created.push(relative);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
for (const file of created) log.line(`+ ${file}`);
|
|
217
|
-
if (skipped.length) log.warn(`${skipped.length} files already existed, skipped`);
|
|
218
|
-
|
|
219
|
-
log.line("");
|
|
220
|
-
log.line("next step: npx jskelet dev");
|
|
221
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* `jskelet init` — bulunduğun dizine çalışan bir minimum iskelet kurar.
|
|
3
|
+
*
|
|
4
|
+
* Var olan dosyaların üzerine yazmaz: komutu ikinci kez çalıştırmak yalnızca
|
|
5
|
+
* eksikleri tamamlar. Amaç, "kurulum yaptım ama hiçbir şey çalışmıyor"
|
|
6
|
+
* aşamasını tamamen atlamak — `jskelet dev` hemen ardından çalışır.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import * as log from "./log.mjs";
|
|
11
|
+
|
|
12
|
+
/** @type {Record<string, string>} */
|
|
13
|
+
const FILES = {
|
|
14
|
+
"jskelet.config.mjs": `/**
|
|
15
|
+
* JSkelet configuration. Every field is optional; the app still runs on
|
|
16
|
+
* defaults if you delete this file.
|
|
17
|
+
*
|
|
18
|
+
* Details: node_modules/jskelet/docs/en/07-configuration.md
|
|
19
|
+
*/
|
|
20
|
+
export default {
|
|
21
|
+
brand: { lang: "en" },
|
|
22
|
+
|
|
23
|
+
/** Third-party origins; emitted as preconnect in \`<head>\`. */
|
|
24
|
+
preconnect: [],
|
|
25
|
+
|
|
26
|
+
async cache() {
|
|
27
|
+
return {
|
|
28
|
+
/** How long a page's HTML stays in the cache (seconds). */
|
|
29
|
+
html: { "/": 60 },
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
hooks: {
|
|
34
|
+
/** Metadata defaults for every page. */
|
|
35
|
+
metadata() {
|
|
36
|
+
return {
|
|
37
|
+
titleTemplate: "%s | JSkelet",
|
|
38
|
+
description: "A site built with JSkelet.",
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/** Locals added to the layout on every render. */
|
|
43
|
+
layoutContext() {
|
|
44
|
+
return { bodyClass: "min-h-full" };
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/** 404 page. */
|
|
48
|
+
notFound() {
|
|
49
|
+
return {
|
|
50
|
+
view: "pages/not-found",
|
|
51
|
+
metadata: { title: "Page not found", robots: { index: false } },
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
`,
|
|
57
|
+
|
|
58
|
+
"routes/10-pages.mjs": `/**
|
|
59
|
+
* Route module. The default export receives \`(app, api)\`; \`api.route()\` wraps
|
|
60
|
+
* the controller with the HTML cache, the notFound/redirect flow and
|
|
61
|
+
* compression.
|
|
62
|
+
*
|
|
63
|
+
* The numeric prefix in the file name sets load order: catch-all routes
|
|
64
|
+
* (like "/:slug") belong to a higher number.
|
|
65
|
+
*/
|
|
66
|
+
export default function register(app, { route }) {
|
|
67
|
+
app.get(
|
|
68
|
+
"/",
|
|
69
|
+
route(
|
|
70
|
+
async () => ({
|
|
71
|
+
view: "pages/home",
|
|
72
|
+
metadata: { title: "Home" },
|
|
73
|
+
data: { message: "JSkelet is running." },
|
|
74
|
+
}),
|
|
75
|
+
{ revalidate: 60 },
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
`,
|
|
80
|
+
|
|
81
|
+
"views/pages/home.ejs": `<section class="wrapper">
|
|
82
|
+
<h1><%= metadata.title %></h1>
|
|
83
|
+
<p><%= message %></p>
|
|
84
|
+
<div data-island="counter" data-island-props='{"start":0}'></div>
|
|
85
|
+
</section>
|
|
86
|
+
`,
|
|
87
|
+
|
|
88
|
+
"views/pages/not-found.ejs": `<section class="wrapper">
|
|
89
|
+
<h1>404</h1>
|
|
90
|
+
<p>The page you are looking for was not found.</p>
|
|
91
|
+
<p><a href="/">Back to home</a></p>
|
|
92
|
+
</section>
|
|
93
|
+
`,
|
|
94
|
+
|
|
95
|
+
"views/components/button.js": `import { attrs, esc } from "jskelet/html";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Every named export under \`views/components/**\` is usable directly in
|
|
99
|
+
* templates: \`<%- button({ text: "Save" }) %>\`. No import needed.
|
|
100
|
+
*
|
|
101
|
+
* @param {{ text: string, href?: string, class?: string }} props
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
export function button({ text, href, class: className }) {
|
|
105
|
+
const tag = href ? "a" : "button";
|
|
106
|
+
return \`<\${tag}\${attrs({ href, class: className })}>\${esc(text)}</\${tag}>\`;
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
|
|
110
|
+
"client/entries/main.js": `import { registerAll, start } from "jskelet/client";
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Island registry. Values are dynamic imports: a module is downloaded only if
|
|
114
|
+
* that island is actually on the page and becomes visible.
|
|
115
|
+
*/
|
|
116
|
+
registerAll({
|
|
117
|
+
counter: () => import("../islands/counter.js"),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
start();
|
|
121
|
+
`,
|
|
122
|
+
|
|
123
|
+
"client/islands/counter.js": `/**
|
|
124
|
+
* Island contract: a named export called \`mount(element, props)\`.
|
|
125
|
+
* The returned function, if any, is reserved for cleanup.
|
|
126
|
+
*
|
|
127
|
+
* @param {HTMLElement} element
|
|
128
|
+
* @param {{ start?: number }} props
|
|
129
|
+
*/
|
|
130
|
+
export function mount(element, props) {
|
|
131
|
+
let value = props.start ?? 0;
|
|
132
|
+
|
|
133
|
+
const button = document.createElement("button");
|
|
134
|
+
button.type = "button";
|
|
135
|
+
|
|
136
|
+
const paint = () => {
|
|
137
|
+
button.textContent = \`Clicks: \${value}\`;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
button.addEventListener("click", () => {
|
|
141
|
+
value += 1;
|
|
142
|
+
paint();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
paint();
|
|
146
|
+
element.append(button);
|
|
147
|
+
}
|
|
148
|
+
`,
|
|
149
|
+
|
|
150
|
+
"styles/globals.css": `@import "tailwindcss" source(none);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Tailwind's class scanning depends on these directives. Automatic detection
|
|
154
|
+
* only scans the directory holding this file; variants used in templates
|
|
155
|
+
* (like data-[active=false]:…) would otherwise be dropped silently.
|
|
156
|
+
*/
|
|
157
|
+
@source "../views";
|
|
158
|
+
@source "../client";
|
|
159
|
+
@source "../routes";
|
|
160
|
+
|
|
161
|
+
body {
|
|
162
|
+
margin: 0;
|
|
163
|
+
font-family: system-ui, sans-serif;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.wrapper {
|
|
167
|
+
max-width: 64rem;
|
|
168
|
+
margin-inline: auto;
|
|
169
|
+
padding: 2rem 1rem;
|
|
170
|
+
}
|
|
171
|
+
`,
|
|
172
|
+
|
|
173
|
+
"jsconfig.json": `{
|
|
174
|
+
"compilerOptions": {
|
|
175
|
+
"checkJs": true,
|
|
176
|
+
"module": "esnext",
|
|
177
|
+
"moduleResolution": "bundler",
|
|
178
|
+
"target": "es2022",
|
|
179
|
+
"baseUrl": ".",
|
|
180
|
+
"paths": { "@/*": ["./*"] }
|
|
181
|
+
},
|
|
182
|
+
"exclude": ["node_modules", "public/assets"]
|
|
183
|
+
}
|
|
184
|
+
`,
|
|
185
|
+
|
|
186
|
+
".gitignore": `node_modules/
|
|
187
|
+
.jskelet/
|
|
188
|
+
public/assets/
|
|
189
|
+
.env
|
|
190
|
+
`,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {string} root
|
|
195
|
+
* @returns {Promise<void>}
|
|
196
|
+
*/
|
|
197
|
+
export async function init(root) {
|
|
198
|
+
log.section("init");
|
|
199
|
+
|
|
200
|
+
const created = [];
|
|
201
|
+
const skipped = [];
|
|
202
|
+
|
|
203
|
+
for (const [relative, contents] of Object.entries(FILES)) {
|
|
204
|
+
const target = path.join(root, relative);
|
|
205
|
+
|
|
206
|
+
if (fs.existsSync(target)) {
|
|
207
|
+
skipped.push(relative);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
212
|
+
fs.writeFileSync(target, contents);
|
|
213
|
+
created.push(relative);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
for (const file of created) log.line(`+ ${file}`);
|
|
217
|
+
if (skipped.length) log.warn(`${skipped.length} files already existed, skipped`);
|
|
218
|
+
|
|
219
|
+
log.line("");
|
|
220
|
+
log.line("next step: npx jskelet dev");
|
|
221
|
+
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node ESM resolve hook'ları. İki iş yapar:
|
|
3
|
-
*
|
|
4
|
-
* 1. `jsconfig.json` / `tsconfig.json` içindeki `compilerOptions.paths`
|
|
5
|
-
* alias'larını çözer (`@/lib/x` → `<root>/lib/x`). Editör ve çalışma zamanı
|
|
6
|
-
* aynı dosyadan beslendiği için ikisi birbirinden ayrışmaz.
|
|
7
|
-
* 2. Uzantısız göreli import'lara uzantı ekler (`./cache` → `./cache.js`).
|
|
8
|
-
* Node ESM bunu yapmaz; bundler'dan taşınan kodda en sık karşılaşılan
|
|
9
|
-
* kırılma noktası bu.
|
|
10
|
-
*
|
|
11
|
-
* `node --import jskelet/register` ile kurulur.
|
|
12
|
-
*/
|
|
13
|
-
import fs from "node:fs";
|
|
14
|
-
import path from "node:path";
|
|
15
|
-
import process from "node:process";
|
|
16
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
-
|
|
18
|
-
const ROOT = process.cwd();
|
|
19
|
-
|
|
20
|
-
/** Uzantısız hedefler için denenecek sıra. */
|
|
21
|
-
const EXTENSIONS = [".js", ".mjs", ".json", "/index.js", "/index.mjs"];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @returns {{ prefix: string, target: string }[]}
|
|
25
|
-
*/
|
|
26
|
-
function readAliases() {
|
|
27
|
-
for (const name of ["jsconfig.json", "tsconfig.json"]) {
|
|
28
|
-
const file = path.join(ROOT, name);
|
|
29
|
-
if (!fs.existsSync(file)) continue;
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
// Yorum içerebilen tsconfig'ler için kaba ama yeterli bir temizlik;
|
|
33
|
-
// tam bir JSON5 ayrıştırıcısı bağımlılık eklemeye değmiyor.
|
|
34
|
-
const raw = fs
|
|
35
|
-
.readFileSync(file, "utf8")
|
|
36
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
37
|
-
.replace(/^\s*\/\/.*$/gm, "");
|
|
38
|
-
|
|
39
|
-
const config = JSON.parse(raw);
|
|
40
|
-
const baseUrl = path.resolve(ROOT, config.compilerOptions?.baseUrl ?? ".");
|
|
41
|
-
const paths = config.compilerOptions?.paths ?? {};
|
|
42
|
-
|
|
43
|
-
/** @type {{ prefix: string, target: string }[]} */
|
|
44
|
-
const aliases = [];
|
|
45
|
-
|
|
46
|
-
for (const [pattern, targets] of Object.entries(paths)) {
|
|
47
|
-
const target = Array.isArray(targets) ? targets[0] : targets;
|
|
48
|
-
if (!pattern.endsWith("/*") || typeof target !== "string") continue;
|
|
49
|
-
|
|
50
|
-
aliases.push({
|
|
51
|
-
prefix: pattern.slice(0, -1),
|
|
52
|
-
target: path.resolve(baseUrl, target.slice(0, -1)),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Uzun önek önce: `@flags/` `@/`den önce denenmeli, yoksa `@/` yakalar.
|
|
57
|
-
return aliases.sort((a, b) => b.prefix.length - a.prefix.length);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.warn(`[alias] could not read ${name}, aliases disabled`, error);
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const ALIASES = readAliases();
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @param {string} filePath
|
|
71
|
-
* @returns {boolean}
|
|
72
|
-
*/
|
|
73
|
-
function isFile(filePath) {
|
|
74
|
-
try {
|
|
75
|
-
return fs.statSync(filePath).isFile();
|
|
76
|
-
} catch {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @param {string} filePath
|
|
83
|
-
* @returns {string | null}
|
|
84
|
-
*/
|
|
85
|
-
function resolveFile(filePath) {
|
|
86
|
-
if (path.extname(filePath) && isFile(filePath)) return filePath;
|
|
87
|
-
|
|
88
|
-
for (const suffix of EXTENSIONS) {
|
|
89
|
-
const candidate = `${filePath}${suffix}`;
|
|
90
|
-
if (isFile(candidate)) return candidate;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return isFile(filePath) ? filePath : null;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function resolve(specifier, context, nextResolve) {
|
|
97
|
-
for (const { prefix, target } of ALIASES) {
|
|
98
|
-
if (!specifier.startsWith(prefix)) continue;
|
|
99
|
-
|
|
100
|
-
const base = path.join(target, specifier.slice(prefix.length));
|
|
101
|
-
const resolved = resolveFile(base);
|
|
102
|
-
|
|
103
|
-
return nextResolve(pathToFileURL(resolved ?? base).href, context);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
(specifier.startsWith("./") || specifier.startsWith("../")) &&
|
|
108
|
-
!path.extname(specifier) &&
|
|
109
|
-
context.parentURL?.startsWith("file:")
|
|
110
|
-
) {
|
|
111
|
-
const parentDir = path.dirname(fileURLToPath(context.parentURL));
|
|
112
|
-
const base = path.resolve(parentDir, specifier);
|
|
113
|
-
const resolved = resolveFile(base);
|
|
114
|
-
|
|
115
|
-
if (resolved) return nextResolve(pathToFileURL(resolved).href, context);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return nextResolve(specifier, context);
|
|
119
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Node ESM resolve hook'ları. İki iş yapar:
|
|
3
|
+
*
|
|
4
|
+
* 1. `jsconfig.json` / `tsconfig.json` içindeki `compilerOptions.paths`
|
|
5
|
+
* alias'larını çözer (`@/lib/x` → `<root>/lib/x`). Editör ve çalışma zamanı
|
|
6
|
+
* aynı dosyadan beslendiği için ikisi birbirinden ayrışmaz.
|
|
7
|
+
* 2. Uzantısız göreli import'lara uzantı ekler (`./cache` → `./cache.js`).
|
|
8
|
+
* Node ESM bunu yapmaz; bundler'dan taşınan kodda en sık karşılaşılan
|
|
9
|
+
* kırılma noktası bu.
|
|
10
|
+
*
|
|
11
|
+
* `node --import jskelet/register` ile kurulur.
|
|
12
|
+
*/
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import process from "node:process";
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
|
|
18
|
+
const ROOT = process.cwd();
|
|
19
|
+
|
|
20
|
+
/** Uzantısız hedefler için denenecek sıra. */
|
|
21
|
+
const EXTENSIONS = [".js", ".mjs", ".json", "/index.js", "/index.mjs"];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns {{ prefix: string, target: string }[]}
|
|
25
|
+
*/
|
|
26
|
+
function readAliases() {
|
|
27
|
+
for (const name of ["jsconfig.json", "tsconfig.json"]) {
|
|
28
|
+
const file = path.join(ROOT, name);
|
|
29
|
+
if (!fs.existsSync(file)) continue;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Yorum içerebilen tsconfig'ler için kaba ama yeterli bir temizlik;
|
|
33
|
+
// tam bir JSON5 ayrıştırıcısı bağımlılık eklemeye değmiyor.
|
|
34
|
+
const raw = fs
|
|
35
|
+
.readFileSync(file, "utf8")
|
|
36
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
37
|
+
.replace(/^\s*\/\/.*$/gm, "");
|
|
38
|
+
|
|
39
|
+
const config = JSON.parse(raw);
|
|
40
|
+
const baseUrl = path.resolve(ROOT, config.compilerOptions?.baseUrl ?? ".");
|
|
41
|
+
const paths = config.compilerOptions?.paths ?? {};
|
|
42
|
+
|
|
43
|
+
/** @type {{ prefix: string, target: string }[]} */
|
|
44
|
+
const aliases = [];
|
|
45
|
+
|
|
46
|
+
for (const [pattern, targets] of Object.entries(paths)) {
|
|
47
|
+
const target = Array.isArray(targets) ? targets[0] : targets;
|
|
48
|
+
if (!pattern.endsWith("/*") || typeof target !== "string") continue;
|
|
49
|
+
|
|
50
|
+
aliases.push({
|
|
51
|
+
prefix: pattern.slice(0, -1),
|
|
52
|
+
target: path.resolve(baseUrl, target.slice(0, -1)),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Uzun önek önce: `@flags/` `@/`den önce denenmeli, yoksa `@/` yakalar.
|
|
57
|
+
return aliases.sort((a, b) => b.prefix.length - a.prefix.length);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn(`[alias] could not read ${name}, aliases disabled`, error);
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const ALIASES = readAliases();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} filePath
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
function isFile(filePath) {
|
|
74
|
+
try {
|
|
75
|
+
return fs.statSync(filePath).isFile();
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} filePath
|
|
83
|
+
* @returns {string | null}
|
|
84
|
+
*/
|
|
85
|
+
function resolveFile(filePath) {
|
|
86
|
+
if (path.extname(filePath) && isFile(filePath)) return filePath;
|
|
87
|
+
|
|
88
|
+
for (const suffix of EXTENSIONS) {
|
|
89
|
+
const candidate = `${filePath}${suffix}`;
|
|
90
|
+
if (isFile(candidate)) return candidate;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return isFile(filePath) ? filePath : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
97
|
+
for (const { prefix, target } of ALIASES) {
|
|
98
|
+
if (!specifier.startsWith(prefix)) continue;
|
|
99
|
+
|
|
100
|
+
const base = path.join(target, specifier.slice(prefix.length));
|
|
101
|
+
const resolved = resolveFile(base);
|
|
102
|
+
|
|
103
|
+
return nextResolve(pathToFileURL(resolved ?? base).href, context);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
(specifier.startsWith("./") || specifier.startsWith("../")) &&
|
|
108
|
+
!path.extname(specifier) &&
|
|
109
|
+
context.parentURL?.startsWith("file:")
|
|
110
|
+
) {
|
|
111
|
+
const parentDir = path.dirname(fileURLToPath(context.parentURL));
|
|
112
|
+
const base = path.resolve(parentDir, specifier);
|
|
113
|
+
const resolved = resolveFile(base);
|
|
114
|
+
|
|
115
|
+
if (resolved) return nextResolve(pathToFileURL(resolved).href, context);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return nextResolve(specifier, context);
|
|
119
|
+
}
|