@foxford/den 4.0.0 → 4.2.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/README.mdx +43 -4
- package/adapter.cjs +2 -3
- package/adapter.js +1 -2
- package/bin/den.cjs +31 -51
- package/bin/den.js +31 -51
- package/builder/index.cjs +2 -3
- package/builder/index.d.cts +3 -2
- package/builder/index.d.ts +3 -2
- package/builder/index.js +1 -2
- package/{chunk-E56BKBQZ.js → chunk-AS6ZNCUY.js} +7 -7
- package/{chunk-H5DKRHHQ.cjs → chunk-BFRLBMH2.cjs} +8 -8
- package/chunk-ETO2T2TA.cjs +503 -0
- package/{chunk-E23E2VUC.js → chunk-HWDDAFGV.js} +1 -1
- package/{chunk-XQ7EHXHG.js → chunk-JW24N6O4.js} +47 -55
- package/{chunk-2P5TAWRW.cjs → chunk-MH2WIOTQ.cjs} +65 -60
- package/{chunk-XOJ2VWX4.cjs → chunk-MWDNN7Q4.cjs} +1 -1
- package/{chunk-QTWJTYZW.cjs → chunk-NOI7FSBX.cjs} +47 -55
- package/{chunk-DUU4MQ4B.js → chunk-VCIMVMHG.js} +64 -59
- package/{chunk-WBHHHICS.js → chunk-WKCIOQOY.js} +1 -1
- package/{chunk-C7BM4DGX.cjs → chunk-Y7DGFJFA.cjs} +1 -1
- package/chunk-YWWRJMWN.js +503 -0
- package/define.cjs +3 -4
- package/define.js +2 -3
- package/index.cjs +54 -71
- package/index.js +53 -70
- package/island/index.cjs +5 -8
- package/island/index.js +4 -7
- package/ops/index.cjs +2 -3
- package/ops/index.js +1 -2
- package/package.json +17 -18
- package/serve/index.cjs +294 -108
- package/serve/index.d.cts +11 -1
- package/serve/index.d.ts +11 -1
- package/serve/index.js +293 -107
- package/chunk-6FNC3XMI.js +0 -45
- package/chunk-FMRORLLE.js +0 -558
- package/chunk-OC4LQ2CK.cjs +0 -558
- package/chunk-T5QVCXVB.cjs +0 -45
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkKQAB6C6Qcjs = require('./chunk-KQAB6C6Q.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkA6ZPAM6Zcjs = require('./chunk-A6ZPAM6Z.cjs');
|
|
7
|
+
|
|
8
|
+
// src/builder/config.ts
|
|
9
|
+
function defineAppConfig(config) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/builder/build.ts
|
|
14
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
15
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
16
|
+
|
|
17
|
+
// src/builder/assets.ts
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var MANIFEST_PATH = ".vite/manifest.json";
|
|
21
|
+
function readManifest(outDir) {
|
|
22
|
+
const manifestPath = _path2.default.join(outDir, MANIFEST_PATH);
|
|
23
|
+
if (!_fs2.default.existsSync(manifestPath)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return JSON.parse(_fs2.default.readFileSync(manifestPath, "utf-8"));
|
|
27
|
+
}
|
|
28
|
+
function collectAssets(outDir, base) {
|
|
29
|
+
const manifest = readManifest(outDir);
|
|
30
|
+
if (manifest === null) {
|
|
31
|
+
return { css: [], js: [] };
|
|
32
|
+
}
|
|
33
|
+
const css = [];
|
|
34
|
+
const js = [];
|
|
35
|
+
const seen = /* @__PURE__ */ new Set();
|
|
36
|
+
const prefix = base === "" ? "" : base.endsWith("/") ? base : "".concat(base, "/");
|
|
37
|
+
function walk(key) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (seen.has(key)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
seen.add(key);
|
|
43
|
+
const chunk = manifest == null ? void 0 : manifest[key];
|
|
44
|
+
if (!chunk) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const imported of (_a = chunk.imports) != null ? _a : []) {
|
|
48
|
+
walk(imported);
|
|
49
|
+
}
|
|
50
|
+
for (const href of (_b = chunk.css) != null ? _b : []) {
|
|
51
|
+
css.push("".concat(prefix).concat(href));
|
|
52
|
+
}
|
|
53
|
+
js.push("".concat(prefix).concat(chunk.file));
|
|
54
|
+
}
|
|
55
|
+
for (const [key, chunk] of Object.entries(manifest)) {
|
|
56
|
+
if (chunk.isEntry === true) {
|
|
57
|
+
walk(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { css, js };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/serve/port.ts
|
|
64
|
+
var DEFAULT_PORT = 8080;
|
|
65
|
+
function resolvePort(declared) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
return Number((_b = (_a = process.env["PORT"]) != null ? _a : declared) != null ? _b : DEFAULT_PORT);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/builder/entries.ts
|
|
71
|
+
var VIRTUAL_CLIENT = "virtual:den/client";
|
|
72
|
+
var VIRTUAL_SERVER_APP = "virtual:den/server-app";
|
|
73
|
+
var VIRTUAL_SERVER_PROCESS = "virtual:den/server-process";
|
|
74
|
+
function toResolvedId(id) {
|
|
75
|
+
return "\0".concat(id);
|
|
76
|
+
}
|
|
77
|
+
function generateClientEntry(entry, clientEntry, runtime = []) {
|
|
78
|
+
return "".concat(runtimeImports(runtime), "import app from ").concat(JSON.stringify(entry), "\nimport { hydrateApp } from ").concat(JSON.stringify(clientEntry), "\n\n").concat(runtimeInstall(runtime), "hydrateApp(app)\n");
|
|
79
|
+
}
|
|
80
|
+
function runtimeImports(runtime) {
|
|
81
|
+
if (runtime.length === 0) {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
return "import { getAppContainer, installRuntime } from '@foxford/den/island'\n".concat(runtime.map((specifier, index) => "import runtime".concat(String(index), " from ").concat(JSON.stringify(specifier))).join("\n"), "\n");
|
|
85
|
+
}
|
|
86
|
+
function runtimeInstall(runtime) {
|
|
87
|
+
if (runtime.length === 0) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
return "installRuntime(getAppContainer(), [".concat(runtime.map((_, index) => "runtime".concat(String(index))).join(", "), "])\n");
|
|
91
|
+
}
|
|
92
|
+
function generateServerApp(entry, configPath, assets, runtime = []) {
|
|
93
|
+
const imports = runtime.map((specifier, index) => "import runtime".concat(String(index), " from ").concat(JSON.stringify(specifier), "\n")).join("");
|
|
94
|
+
const install = runtime.length === 0 ? "" : " ".concat(runtimeInstall(runtime));
|
|
95
|
+
return "import { getAppContainer, installRuntime, viewAdapterOf } from '@foxford/den/island'\n\nimport app from ".concat(JSON.stringify(entry), "\nimport config from ").concat(JSON.stringify(configPath), "\n").concat(imports, "\nconst server = config.server ?? {}\n\nasync function setup() {\n if (app.viewLayer) {\n viewAdapterOf(app.viewLayer).installResolver()\n }\n").concat(install, " server.container?.(getAppContainer())\n await server.setup?.()\n}\n\nconst descriptor = { ...app, assets: ").concat(JSON.stringify(assets), ", setup }\n\nif (server.render) {\n descriptor.serverRender = server.render\n}\n\nexport default descriptor\n");
|
|
96
|
+
}
|
|
97
|
+
function generateServerProcess(configPath, base, mode) {
|
|
98
|
+
const assets = mode === "development" ? " assets: { base: ".concat(JSON.stringify(base), ", dir: fileURLToPath(new URL('./client', import.meta.url)) },\n") : "";
|
|
99
|
+
return "import { fileURLToPath } from 'node:url'\n\nimport { loadAppEnv, serveAppProcess } from '@foxford/den/serve'\n\nimport app from ".concat(JSON.stringify(VIRTUAL_SERVER_APP), "\nimport config from ").concat(JSON.stringify(configPath), "\n\n// \u0423\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044F \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u044F \u2014 \u0434\u043E \u043F\u0435\u0440\u0432\u043E\u0433\u043E \u0447\u0442\u0435\u043D\u0438\u044F: \u043F\u043E\u0440\u0442 \u0438 \u0430\u0434\u0440\u0435\u0441\u0430 \u0447\u0438\u0442\u0430\u044E\u0442\u0441\u044F \u043D\u0438\u0436\u0435\nloadAppEnv(fileURLToPath(new URL('..', import.meta.url)))\n\nawait serveAppProcess(app, {\n").concat(assets, " configure: config.server?.configure,\n host: process.env.HOST,\n ops: { host: process.env.OPS_HOST, port: Number(process.env.SERVICE_PORT ?? ").concat(mode === "development" ? "config.server?.opsPort ?? 9090" : "9090", ") },\n port: Number(process.env.PORT ?? ").concat(mode === "development" ? "config.server?.port ?? " : "").concat(String(DEFAULT_PORT), "),\n workers: Number(process.env.WORKERS ?? 1),\n})\n");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/builder/plugin.ts
|
|
103
|
+
function denAppModules(options) {
|
|
104
|
+
const { assets, base, config, configPath, entry, mode } = options;
|
|
105
|
+
const sources = {
|
|
106
|
+
// Клиентский вход спрашивают только у клиентского выхода, а его без пресета не собирают.
|
|
107
|
+
// Отказ здесь означает, что выход всё-таки запустили, — это ошибка команд, а не приложения
|
|
108
|
+
[VIRTUAL_CLIENT]: () => {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!config.preset) {
|
|
111
|
+
throw new Error("den: \u043A\u043B\u0438\u0435\u043D\u0442\u0441\u043A\u0438\u0439 \u0432\u0445\u043E\u0434 \u0437\u0430\u043F\u0440\u043E\u0448\u0435\u043D, \u043D\u043E \u043F\u0440\u0435\u0441\u0435\u0442 \u043D\u0435 \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D \u2014 \u043E\u0436\u0438\u0432\u043B\u044F\u0442\u044C \u043D\u0435\u0447\u0435\u043C");
|
|
112
|
+
}
|
|
113
|
+
return generateClientEntry(entry, config.preset.clientEntry, (_a = config.runtime) != null ? _a : []);
|
|
114
|
+
},
|
|
115
|
+
[VIRTUAL_SERVER_APP]: () => {
|
|
116
|
+
var _a;
|
|
117
|
+
return generateServerApp(entry, configPath, assets, (_a = config.runtime) != null ? _a : []);
|
|
118
|
+
},
|
|
119
|
+
[VIRTUAL_SERVER_PROCESS]: () => generateServerProcess(configPath, base, mode)
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
load: (id) => {
|
|
123
|
+
for (const [virtual, source] of Object.entries(sources)) {
|
|
124
|
+
if (id === toResolvedId(virtual)) {
|
|
125
|
+
return source();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
},
|
|
130
|
+
name: "den:app-modules",
|
|
131
|
+
resolveId: (id) => id in sources ? toResolvedId(id) : null
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/builder/build.ts
|
|
136
|
+
var CONFIG_FILE = "den.config.ts";
|
|
137
|
+
var OUT_ROOT = "build";
|
|
138
|
+
var OUT_CLIENT = "build/client";
|
|
139
|
+
var OUT_SERVER = "build/server";
|
|
140
|
+
var ENGINE = /^@foxford\/den(\/|$)/;
|
|
141
|
+
async function loadAppConfig(root) {
|
|
142
|
+
const configPath = _path2.default.join(root, CONFIG_FILE);
|
|
143
|
+
if (!_fs2.default.existsSync(configPath)) {
|
|
144
|
+
throw new Error("den: ".concat(CONFIG_FILE, " \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \xAB").concat(root, "\xBB"));
|
|
145
|
+
}
|
|
146
|
+
const { createServer } = await Promise.resolve().then(() => _interopRequireWildcard(require("vite")));
|
|
147
|
+
const server = await createServer({
|
|
148
|
+
appType: "custom",
|
|
149
|
+
configFile: false,
|
|
150
|
+
logLevel: "silent",
|
|
151
|
+
root,
|
|
152
|
+
// Этот сервер только загружает конфиг; пересборкой в dev управляет watchSources.
|
|
153
|
+
server: { middlewareMode: true, watch: null }
|
|
154
|
+
});
|
|
155
|
+
try {
|
|
156
|
+
const loaded = await server.ssrLoadModule(configPath);
|
|
157
|
+
const config = loaded.default;
|
|
158
|
+
if (!config) {
|
|
159
|
+
throw new Error("den: ".concat(CONFIG_FILE, " \u043D\u0435 \u043E\u0442\u0434\u0430\u0451\u0442 \u043A\u043E\u043D\u0444\u0438\u0433 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u2014 \u0441\u043E\u0431\u0438\u0440\u0430\u0442\u044C \u043D\u0435\u0447\u0435\u043C"));
|
|
160
|
+
}
|
|
161
|
+
return { config, configPath };
|
|
162
|
+
} finally {
|
|
163
|
+
await server.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function dependenciesOf(root) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
const manifestPath = _path2.default.join(root, "package.json");
|
|
169
|
+
if (!_fs2.default.existsSync(manifestPath)) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
const manifest = JSON.parse(_fs2.default.readFileSync(manifestPath, "utf-8"));
|
|
173
|
+
return [...Object.keys((_a = manifest.dependencies) != null ? _a : {}), ...Object.keys((_b = manifest.devDependencies) != null ? _b : {})];
|
|
174
|
+
}
|
|
175
|
+
async function viteConfigFor(options) {
|
|
176
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
177
|
+
const { foxfordBrowserBuild } = await Promise.resolve().then(() => _interopRequireWildcard(require("@foxford/browserslist-config/vite")));
|
|
178
|
+
const { assets, base, config, configPath, entryFileNames, input, mode, outDir, root, target } = options;
|
|
179
|
+
const entry = (_a = config.entry) != null ? _a : "src/index.ts";
|
|
180
|
+
const external = (_c = (_b = config.server) == null ? void 0 : _b.external) != null ? _c : [];
|
|
181
|
+
const composed = {
|
|
182
|
+
// Сборщику относительный префикс, если своего нет: ленивые чанки тогда грузятся от адреса
|
|
183
|
+
// уже загруженного чанка, и подмена CDN уводит за собой и их
|
|
184
|
+
base: base === "" ? "./" : base,
|
|
185
|
+
build: {
|
|
186
|
+
// Клиентский выход чистит свой каталог сам, серверные — нет: они пишут рядом с уже
|
|
187
|
+
// собранным клиентским, и очистка снесла бы его вместе с манифестом
|
|
188
|
+
emptyOutDir: target === "client",
|
|
189
|
+
manifest: target === "client",
|
|
190
|
+
outDir: _path2.default.join(root, outDir),
|
|
191
|
+
// Вход задаётся `input`, а не `build.ssr`: строку в `build.ssr` сборщик понимает как путь
|
|
192
|
+
// к файлу, а входы у нас виртуальные — их резолвит плагин
|
|
193
|
+
rollupOptions: {
|
|
194
|
+
input,
|
|
195
|
+
...target === "server" ? { external: [ENGINE, ...external] } : {},
|
|
196
|
+
...entryFileNames === void 0 ? {} : { output: { entryFileNames } }
|
|
197
|
+
},
|
|
198
|
+
ssr: target === "server"
|
|
199
|
+
},
|
|
200
|
+
configFile: false,
|
|
201
|
+
// Режим объявляем явно: плагины сборщика выбирают по нему рантайм фреймворка, а через
|
|
202
|
+
// программный вызов он иначе не доедет.
|
|
203
|
+
mode,
|
|
204
|
+
plugins: [
|
|
205
|
+
...(_e = (_d = config.preset) == null ? void 0 : _d.plugins) != null ? _e : [],
|
|
206
|
+
denAppModules({ assets, base, config, configPath, entry: _path2.default.join(root, entry), mode })
|
|
207
|
+
],
|
|
208
|
+
root,
|
|
209
|
+
ssr: {
|
|
210
|
+
external,
|
|
211
|
+
noExternal: (_g = (_f = config.server) == null ? void 0 : _f.noExternal) != null ? _g : []
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const customized = config.vite ? config.vite(composed, target) : composed;
|
|
215
|
+
return {
|
|
216
|
+
...customized,
|
|
217
|
+
plugins: [customized["plugins"], foxfordBrowserBuild({ env: mode })]
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async function buildApp(options) {
|
|
221
|
+
var _a, _b, _c;
|
|
222
|
+
const { mode = "production" } = options;
|
|
223
|
+
process.env["NODE_ENV"] = mode;
|
|
224
|
+
const root = _path2.default.resolve(options.root);
|
|
225
|
+
_chunkKQAB6C6Qcjs.loadAppEnv.call(void 0, root);
|
|
226
|
+
const { config, configPath } = await loadAppConfig(root);
|
|
227
|
+
const port = resolvePort((_a = config.server) == null ? void 0 : _a.port);
|
|
228
|
+
const base = (_b = options.base) != null ? _b : "";
|
|
229
|
+
const { preset } = config;
|
|
230
|
+
const refusal = (_c = preset == null ? void 0 : preset.validate) == null ? void 0 : _c.call(preset, dependenciesOf(root));
|
|
231
|
+
if (refusal !== void 0 && refusal !== null) {
|
|
232
|
+
throw new Error("den: ".concat(refusal));
|
|
233
|
+
}
|
|
234
|
+
const { build } = await Promise.resolve().then(() => _interopRequireWildcard(require("vite")));
|
|
235
|
+
const shared = { base, config, configPath, mode, root };
|
|
236
|
+
const empty = { css: [], js: [] };
|
|
237
|
+
let assets = empty;
|
|
238
|
+
if (preset) {
|
|
239
|
+
_chunkA6ZPAM6Zcjs.logger.info("\u0441\u0431\u043E\u0440\u043A\u0430 \u043A\u043B\u0438\u0435\u043D\u0442\u0441\u043A\u043E\u0433\u043E \u0432\u044B\u0445\u043E\u0434\u0430 (".concat(preset.view, ")"));
|
|
240
|
+
await build(
|
|
241
|
+
await viteConfigFor({ ...shared, assets: empty, input: VIRTUAL_CLIENT, outDir: OUT_CLIENT, target: "client" })
|
|
242
|
+
);
|
|
243
|
+
assets = collectAssets(_path2.default.join(root, OUT_CLIENT), base);
|
|
244
|
+
_chunkA6ZPAM6Zcjs.logger.info("\u0430\u0440\u0442\u0435\u0444\u0430\u043A\u0442\u044B: ".concat(String(assets.js.length), " js, ").concat(String(assets.css.length), " css"));
|
|
245
|
+
} else {
|
|
246
|
+
_chunkA6ZPAM6Zcjs.logger.info("\u043A\u043B\u0438\u0435\u043D\u0442\u0441\u043A\u043E\u0433\u043E \u0432\u044B\u0445\u043E\u0434\u0430 \u043D\u0435\u0442: \u043F\u0440\u0435\u0441\u0435\u0442 \u043D\u0435 \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D, \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u0441\u0432\u043E\u0435\u0433\u043E \u0444\u0440\u0430\u0433\u043C\u0435\u043D\u0442\u0430 \u043D\u0435 \u0440\u0438\u0441\u0443\u0435\u0442");
|
|
247
|
+
}
|
|
248
|
+
_chunkA6ZPAM6Zcjs.logger.info("\u0441\u0431\u043E\u0440\u043A\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043D\u043E\u0433\u043E \u0434\u0435\u0441\u043A\u0440\u0438\u043F\u0442\u043E\u0440\u0430");
|
|
249
|
+
await build(
|
|
250
|
+
await viteConfigFor({
|
|
251
|
+
...shared,
|
|
252
|
+
assets,
|
|
253
|
+
entryFileNames: "index.mjs",
|
|
254
|
+
input: VIRTUAL_SERVER_APP,
|
|
255
|
+
outDir: OUT_SERVER,
|
|
256
|
+
target: "server"
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
_chunkA6ZPAM6Zcjs.logger.info("\u0441\u0431\u043E\u0440\u043A\u0430 \u0442\u043E\u0447\u043A\u0438 \u0432\u0445\u043E\u0434\u0430 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u0430");
|
|
260
|
+
await build(
|
|
261
|
+
await viteConfigFor({
|
|
262
|
+
...shared,
|
|
263
|
+
assets,
|
|
264
|
+
entryFileNames: "server.mjs",
|
|
265
|
+
input: VIRTUAL_SERVER_PROCESS,
|
|
266
|
+
outDir: OUT_ROOT,
|
|
267
|
+
target: "server"
|
|
268
|
+
})
|
|
269
|
+
);
|
|
270
|
+
return { base, port };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/builder/dev.ts
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
var _url = require('url');
|
|
277
|
+
|
|
278
|
+
// src/builder/banner.ts
|
|
279
|
+
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
280
|
+
var TOOL = "den";
|
|
281
|
+
var PAD = 11;
|
|
282
|
+
var ENDPOINTS = ["/_render?url=<\u043F\u0443\u0442\u044C>", "/_routes"];
|
|
283
|
+
var OUTPUTS = ["build/client", "build/server", "build/server.mjs"];
|
|
284
|
+
var SHORTCUTS = [
|
|
285
|
+
{ key: "r", title: "\u043F\u0435\u0440\u0435\u0441\u043E\u0431\u0440\u0430\u0442\u044C" },
|
|
286
|
+
{ key: "h", title: "\u0441\u043F\u0440\u0430\u0432\u043A\u0430" },
|
|
287
|
+
{ key: "q", title: "\u0432\u044B\u0439\u0442\u0438" }
|
|
288
|
+
];
|
|
289
|
+
function networkAddress() {
|
|
290
|
+
for (const addresses of Object.values(_os2.default.networkInterfaces())) {
|
|
291
|
+
for (const address of addresses != null ? addresses : []) {
|
|
292
|
+
if (address.family === "IPv4" && !address.internal) {
|
|
293
|
+
return address.address;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return void 0;
|
|
298
|
+
}
|
|
299
|
+
function assetsSummary(assets) {
|
|
300
|
+
if (!assets) {
|
|
301
|
+
return "\u043D\u0435 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u044B";
|
|
302
|
+
}
|
|
303
|
+
return "".concat(String(assets.js.length), " js, ").concat(String(assets.css.length), " css");
|
|
304
|
+
}
|
|
305
|
+
function bannerLines(facts2) {
|
|
306
|
+
var _a;
|
|
307
|
+
const port = String((_a = facts2.port) != null ? _a : "");
|
|
308
|
+
const network = networkAddress();
|
|
309
|
+
const label = (title) => " \u2192 ".concat(title.padEnd(PAD));
|
|
310
|
+
return [
|
|
311
|
+
"",
|
|
312
|
+
" ".concat(TOOL, " ").concat(facts2.mode, " \u0441\u043E\u0431\u0440\u0430\u043D\u043E \u0437\u0430 ").concat(String(facts2.elapsedMs), "\u043C\u0441"),
|
|
313
|
+
"",
|
|
314
|
+
...facts2.name === void 0 ? [] : ["".concat(label("\u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435")).concat(facts2.name)],
|
|
315
|
+
...facts2.routes === void 0 ? [] : ["".concat(label("\u0430\u0434\u0440\u0435\u0441\u0430")).concat(facts2.routes.join(" "))],
|
|
316
|
+
"".concat(label("\u043B\u043E\u043A\u0430\u043B\u044C\u043D\u043E"), "http://localhost:").concat(port),
|
|
317
|
+
...network === void 0 ? [] : ["".concat(label("\u0432 \u0441\u0435\u0442\u0438"), "http://").concat(network, ":").concat(port)],
|
|
318
|
+
"".concat(label("\u0440\u0443\u0447\u043A\u0438")).concat(ENDPOINTS.join(" ")),
|
|
319
|
+
// Префикс печатается, только когда он есть: при относительной сборке артефакты идут с
|
|
320
|
+
// адреса самого приложения, а он уже назван строкой выше
|
|
321
|
+
...facts2.base === void 0 || facts2.base === "" ? [] : ["".concat(label("\u043F\u0440\u0435\u0444\u0438\u043A\u0441")).concat(facts2.base)],
|
|
322
|
+
"".concat(label("\u0447\u0430\u043D\u043A\u0438")).concat(assetsSummary(facts2.assets)),
|
|
323
|
+
"".concat(label("\u0432\u044B\u0445\u043E\u0434\u044B")).concat(OUTPUTS.join(", ")),
|
|
324
|
+
"".concat(label("\u043F\u0440\u0430\u0432\u043A\u0438")).concat(facts2.watched.join(", ")),
|
|
325
|
+
"".concat(label("\u043A\u043B\u0430\u0432\u0438\u0448\u0438")).concat(SHORTCUTS.map(({ key, title }) => "".concat(key, " \u2014 ").concat(title)).join(", ")),
|
|
326
|
+
""
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
function helpLines() {
|
|
330
|
+
return ["", " \u043A\u043B\u0430\u0432\u0438\u0448\u0430 + enter:", ...SHORTCUTS.map(({ key, title }) => " ".concat(key, " ").concat(title)), ""];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/builder/process.ts
|
|
334
|
+
var _child_process = require('child_process');
|
|
335
|
+
var SHUTDOWN_TIMEOUT_MS = 5e3;
|
|
336
|
+
function signalGroup(pid, signal) {
|
|
337
|
+
try {
|
|
338
|
+
process.kill(-pid, signal);
|
|
339
|
+
} catch (e) {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function appProcess(entry) {
|
|
343
|
+
let child = null;
|
|
344
|
+
async function stop() {
|
|
345
|
+
const running = child;
|
|
346
|
+
child = null;
|
|
347
|
+
if (!running || running.exitCode !== null || running.pid === void 0) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const { pid } = running;
|
|
351
|
+
await new Promise((resolve) => {
|
|
352
|
+
const forced = setTimeout(() => signalGroup(pid, "SIGKILL"), SHUTDOWN_TIMEOUT_MS);
|
|
353
|
+
running.once("exit", () => {
|
|
354
|
+
clearTimeout(forced);
|
|
355
|
+
resolve();
|
|
356
|
+
});
|
|
357
|
+
signalGroup(pid, "SIGTERM");
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function start(env) {
|
|
361
|
+
const started = _child_process.spawn.call(void 0, process.execPath, [...process.execArgv, entry], {
|
|
362
|
+
detached: true,
|
|
363
|
+
env: { ...process.env, ...env },
|
|
364
|
+
stdio: "inherit"
|
|
365
|
+
});
|
|
366
|
+
child = started;
|
|
367
|
+
started.on("exit", (code, signal) => {
|
|
368
|
+
if (child !== started) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
child = null;
|
|
372
|
+
_chunkA6ZPAM6Zcjs.logger.error("\u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F \u0441\u0430\u043C (\u043A\u043E\u0434 ".concat(String(code), ", \u0441\u0438\u0433\u043D\u0430\u043B ").concat(String(signal), ")"));
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
376
|
+
process.once(signal, () => {
|
|
377
|
+
void stop().then(() => process.exit(0));
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
process.on("exit", () => {
|
|
381
|
+
if ((child == null ? void 0 : child.pid) !== void 0) {
|
|
382
|
+
signalGroup(child.pid, "SIGTERM");
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
return { start, stop };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/builder/dev.ts
|
|
389
|
+
var SERVER_ENTRY = "build/server.mjs";
|
|
390
|
+
var WATCHED = ["src", "den.config.ts"];
|
|
391
|
+
var DEBUG_SCOPES = ["@foxford/den:*"];
|
|
392
|
+
function debugPattern(name) {
|
|
393
|
+
return (name === void 0 ? DEBUG_SCOPES : ["".concat(name, ":*"), ...DEBUG_SCOPES]).join(",");
|
|
394
|
+
}
|
|
395
|
+
var DEBOUNCE_MS = 150;
|
|
396
|
+
function watchSources(root, onChange) {
|
|
397
|
+
let pending = null;
|
|
398
|
+
for (const target of WATCHED) {
|
|
399
|
+
const watched = _path2.default.join(root, target);
|
|
400
|
+
if (!_fs2.default.existsSync(watched)) {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
_fs2.default.watch(watched, { recursive: true }, () => {
|
|
404
|
+
if (pending) {
|
|
405
|
+
clearTimeout(pending);
|
|
406
|
+
}
|
|
407
|
+
pending = setTimeout(onChange, DEBOUNCE_MS);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
async function facts(root) {
|
|
412
|
+
try {
|
|
413
|
+
const loaded = await Promise.resolve().then(() => _interopRequireWildcard(require(_url.pathToFileURL.call(void 0, _path2.default.join(root, "build/server/index.mjs")).href)));
|
|
414
|
+
const app = loaded.default;
|
|
415
|
+
return { assets: app == null ? void 0 : app.assets, name: app == null ? void 0 : app.name, routes: app == null ? void 0 : app.routes };
|
|
416
|
+
} catch (e) {
|
|
417
|
+
return {};
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function describer(root) {
|
|
421
|
+
let described = null;
|
|
422
|
+
return async () => {
|
|
423
|
+
described != null ? described : described = await facts(root);
|
|
424
|
+
return described;
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
async function devApp(options) {
|
|
428
|
+
_chunkA6ZPAM6Zcjs.logger.setDebug(true);
|
|
429
|
+
const root = _path2.default.resolve(options.root);
|
|
430
|
+
let building = false;
|
|
431
|
+
let dirty = false;
|
|
432
|
+
const describe = describer(root);
|
|
433
|
+
const app = appProcess(_path2.default.join(root, SERVER_ENTRY));
|
|
434
|
+
function show(lines) {
|
|
435
|
+
process.stdout.write("".concat(lines.join("\n"), "\n"));
|
|
436
|
+
}
|
|
437
|
+
function listenForKeys() {
|
|
438
|
+
if (!process.stdin.isTTY) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
process.stdin.setEncoding("utf8");
|
|
442
|
+
process.stdin.on("data", (chunk) => {
|
|
443
|
+
const key = chunk.trim().toLowerCase();
|
|
444
|
+
if (key === "r") {
|
|
445
|
+
void rebuild();
|
|
446
|
+
}
|
|
447
|
+
if (key === "h") {
|
|
448
|
+
show(helpLines());
|
|
449
|
+
}
|
|
450
|
+
if (key === "q") {
|
|
451
|
+
void app.stop().then(() => process.exit(0));
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
async function rebuild() {
|
|
456
|
+
var _a;
|
|
457
|
+
if (building) {
|
|
458
|
+
dirty = true;
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
building = true;
|
|
462
|
+
let built = null;
|
|
463
|
+
try {
|
|
464
|
+
do {
|
|
465
|
+
dirty = false;
|
|
466
|
+
await app.stop();
|
|
467
|
+
try {
|
|
468
|
+
const result = await buildApp({ ...options, mode: "development" });
|
|
469
|
+
app.start({ DEBUG: (_a = process.env["DEBUG"]) != null ? _a : debugPattern((await describe()).name) });
|
|
470
|
+
built = result;
|
|
471
|
+
} catch (error) {
|
|
472
|
+
_chunkA6ZPAM6Zcjs.logger.error("\u0441\u0431\u043E\u0440\u043A\u0430 \u043D\u0435 \u043F\u0440\u043E\u0448\u043B\u0430 \u2014 \u0441\u0435\u0440\u0432\u0438\u0441 \u041D\u0415 \u041F\u041E\u0414\u041D\u042F\u0422, \u0436\u0434\u0443 \u043F\u0440\u0430\u0432\u043A\u0438:", error);
|
|
473
|
+
}
|
|
474
|
+
} while (dirty);
|
|
475
|
+
} finally {
|
|
476
|
+
building = false;
|
|
477
|
+
}
|
|
478
|
+
return built;
|
|
479
|
+
}
|
|
480
|
+
const startedAt = Date.now();
|
|
481
|
+
const address = await rebuild();
|
|
482
|
+
const elapsed = Date.now() - startedAt;
|
|
483
|
+
watchSources(root, () => void rebuild());
|
|
484
|
+
if (address !== null) {
|
|
485
|
+
show(
|
|
486
|
+
bannerLines({
|
|
487
|
+
base: address.base,
|
|
488
|
+
elapsedMs: elapsed,
|
|
489
|
+
mode: "development",
|
|
490
|
+
port: address.port,
|
|
491
|
+
watched: WATCHED,
|
|
492
|
+
...await describe()
|
|
493
|
+
})
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
listenForKeys();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
exports.defineAppConfig = defineAppConfig; exports.buildApp = buildApp; exports.devApp = devApp;
|
|
@@ -14,7 +14,7 @@ function viewAdapterOf(layer) {
|
|
|
14
14
|
function adapterOfConfig(config) {
|
|
15
15
|
if (!isViewAdapter(config.adapter)) {
|
|
16
16
|
throw new Error(
|
|
17
|
-
|
|
17
|
+
"den/island: view-\u0441\u043B\u043E\u0439 \xAB".concat(config.name, "\xBB \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D \u0431\u0435\u0437 \u0430\u0434\u0430\u043F\u0442\u0435\u0440\u0430 \u2014 ") + "\u043E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F ViewAdapter (type + createIsland + renderIsland + installResolver), \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 reactAdapter()"
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
return config.adapter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveViewAdapter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HWDDAFGV.js";
|
|
4
4
|
import {
|
|
5
5
|
RequestContextToken
|
|
6
6
|
} from "./chunk-3RX2OSUL.js";
|
|
@@ -9,10 +9,6 @@ import {
|
|
|
9
9
|
logger,
|
|
10
10
|
unitLogger
|
|
11
11
|
} from "./chunk-TPBI6TOU.js";
|
|
12
|
-
import {
|
|
13
|
-
__async,
|
|
14
|
-
__spreadValues
|
|
15
|
-
} from "./chunk-6FNC3XMI.js";
|
|
16
12
|
|
|
17
13
|
// src/island/document.ts
|
|
18
14
|
function isDocumentSource(value) {
|
|
@@ -39,7 +35,7 @@ function installRuntime(container, extensions) {
|
|
|
39
35
|
unit.register(container);
|
|
40
36
|
}
|
|
41
37
|
installed.push(extension);
|
|
42
|
-
((_a = logger.getLogger("island:runtime")) != null ? _a : logger).debug(
|
|
38
|
+
((_a = logger.getLogger("island:runtime")) != null ? _a : logger).debug("\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043D\u0438\u0435 \u0440\u0430\u043D\u0442\u0430\u0439\u043C\u0430 \xAB".concat(extension.name, "\xBB \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E"));
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
function bindInstalled(container) {
|
|
@@ -120,7 +116,7 @@ function registerIslandParts(container, descriptor, islandLog) {
|
|
|
120
116
|
const viewModels = (_b = descriptor.viewModels) != null ? _b : [];
|
|
121
117
|
const slots = Object.entries((_c = descriptor.slots) != null ? _c : {});
|
|
122
118
|
islandLog.info(
|
|
123
|
-
|
|
119
|
+
"\u043E\u0441\u0442\u0440\u043E\u0432: \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D (units=".concat(descriptor.units.length, ", vms=").concat(viewModels.length, ", slots=").concat(slots.length, ")")
|
|
124
120
|
);
|
|
125
121
|
for (const unit of descriptor.units) {
|
|
126
122
|
unit.register(container);
|
|
@@ -160,18 +156,16 @@ function hydrateIslandState(container, descriptor, denState) {
|
|
|
160
156
|
}
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
|
-
function activateIslandViewModels(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
);
|
|
174
|
-
});
|
|
159
|
+
async function activateIslandViewModels(container, descriptor, route = EMPTY_ROUTE) {
|
|
160
|
+
var _a;
|
|
161
|
+
await Promise.all(
|
|
162
|
+
((_a = descriptor.viewModels) != null ? _a : []).map(async (vm) => {
|
|
163
|
+
var _a2;
|
|
164
|
+
const instance = container.resolve(vm.token);
|
|
165
|
+
unitLogger(container, vm.token.description).debug("\u0430\u043A\u0442\u0438\u0432\u0430\u0446\u0438\u044F VM (".concat(route.pathname || "\u2014", ")"));
|
|
166
|
+
await ((_a2 = instance.activate) == null ? void 0 : _a2.call(instance, route));
|
|
167
|
+
})
|
|
168
|
+
);
|
|
175
169
|
}
|
|
176
170
|
function collectIslandState(container, descriptor) {
|
|
177
171
|
var _a, _b;
|
|
@@ -194,10 +188,10 @@ function collectDocumentContribution(container, descriptor) {
|
|
|
194
188
|
}
|
|
195
189
|
const part = instance.describeDocument();
|
|
196
190
|
if (part.head) {
|
|
197
|
-
contribution.head =
|
|
191
|
+
contribution.head = { ...contribution.head, ...part.head };
|
|
198
192
|
}
|
|
199
193
|
if (part.data) {
|
|
200
|
-
contribution.data =
|
|
194
|
+
contribution.data = { ...contribution.data, ...part.data };
|
|
201
195
|
}
|
|
202
196
|
if (part.assets && contribution.assets === void 0) {
|
|
203
197
|
contribution.assets = part.assets;
|
|
@@ -238,41 +232,39 @@ function setupOnce(descriptor) {
|
|
|
238
232
|
}
|
|
239
233
|
return started;
|
|
240
234
|
}
|
|
241
|
-
function renderApp(descriptor, request) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
235
|
+
async function renderApp(descriptor, request) {
|
|
236
|
+
var _a, _b, _c;
|
|
237
|
+
await setupOnce(descriptor);
|
|
238
|
+
const route = {
|
|
239
|
+
params: (_a = request.params) != null ? _a : {},
|
|
240
|
+
pathname: request.pathname,
|
|
241
|
+
search: (_b = request.search) != null ? _b : ""
|
|
242
|
+
};
|
|
243
|
+
const inputs = islandInputsOf(descriptor, request.inputs);
|
|
244
|
+
const container = createIslandContainer(descriptor, { context: request.context, inputs, parent: request.parent });
|
|
245
|
+
if (container === null) {
|
|
246
|
+
throw new Error("den/island: \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \xAB".concat(descriptor.name, "\xBB \u043D\u0435 \u0441\u043E\u0431\u0440\u0430\u043B\u043E\u0441\u044C \u2014 \u0440\u0435\u043D\u0434\u0435\u0440 \u043D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u0435\u043D"));
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
await activateIslandViewModels(container, descriptor, route);
|
|
250
|
+
const contribution = collectDocumentContribution(container, descriptor);
|
|
251
|
+
const { data, head, redirect, status = STATUS_OK } = contribution;
|
|
252
|
+
if (status !== STATUS_OK) {
|
|
253
|
+
return { data, head, html: "", redirect, state: {}, status };
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (status !== STATUS_OK) {
|
|
260
|
-
return { data, head, html: "", redirect, state: {}, status };
|
|
261
|
-
}
|
|
262
|
-
const assets = (_c = contribution.assets) != null ? _c : descriptor.assets;
|
|
263
|
-
const state = __spreadValues(__spreadValues({}, inputs), collectIslandState(container, descriptor));
|
|
264
|
-
if (descriptor.view === void 0 || descriptor.viewLayer === void 0) {
|
|
265
|
-
return { assets, data, head, html: "", state, status };
|
|
266
|
-
}
|
|
267
|
-
const rendered = resolveViewAdapter(container).renderIsland(descriptor, {
|
|
268
|
-
container,
|
|
269
|
-
slots: request.slots
|
|
270
|
-
});
|
|
271
|
-
return { assets, data, head, headHtml: rendered.head, html: rendered.html, state, status };
|
|
272
|
-
} finally {
|
|
273
|
-
yield container.dispose();
|
|
255
|
+
const assets = (_c = contribution.assets) != null ? _c : descriptor.assets;
|
|
256
|
+
const state = { ...inputs, ...collectIslandState(container, descriptor) };
|
|
257
|
+
if (descriptor.view === void 0 || descriptor.viewLayer === void 0) {
|
|
258
|
+
return { assets, data, head, html: "", state, status };
|
|
274
259
|
}
|
|
275
|
-
|
|
260
|
+
const rendered = resolveViewAdapter(container).renderIsland(descriptor, {
|
|
261
|
+
container,
|
|
262
|
+
slots: request.slots
|
|
263
|
+
});
|
|
264
|
+
return { assets, data, head, headHtml: rendered.head, html: rendered.html, state, status };
|
|
265
|
+
} finally {
|
|
266
|
+
await container.dispose();
|
|
267
|
+
}
|
|
276
268
|
}
|
|
277
269
|
|
|
278
270
|
// src/island/routes.ts
|
|
@@ -305,7 +297,7 @@ function decodeParams(groups) {
|
|
|
305
297
|
var REGEXP_SPECIALS = /[.*+?^${}()|[\]\\]/g;
|
|
306
298
|
var PARAM_SEGMENT = /\/:([A-Za-z_$][\w$]*)/g;
|
|
307
299
|
function pathPattern(pattern) {
|
|
308
|
-
return
|
|
300
|
+
return "^".concat(pattern.replace(REGEXP_SPECIALS, "\\$&").replace(PARAM_SEGMENT, "/(?<$1>[^/]+)"), "$");
|
|
309
301
|
}
|
|
310
302
|
|
|
311
303
|
export {
|