@nodefony/frontend 10.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +544 -0
- package/README.md +338 -0
- package/dist/_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorate.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.148.0/helpers/esm/decorateMetadata.js +6 -0
- package/dist/index.js +63 -0
- package/dist/nodefony/command/frontend-build.js +68 -0
- package/dist/nodefony/command/frontend-dev.js +31 -0
- package/dist/nodefony/command/frontend-status.js +40 -0
- package/dist/nodefony/config/config.js +65 -0
- package/dist/nodefony/config/defineModuleConfig.js +34 -0
- package/dist/nodefony/interfaces/IFrontBuilder.js +1 -0
- package/dist/nodefony/interfaces/IFrontPreset.js +1 -0
- package/dist/nodefony/interfaces/IFrontendService.js +1 -0
- package/dist/nodefony/interfaces/IViteSupervisor.js +1 -0
- package/dist/nodefony/interfaces/index.js +1 -0
- package/dist/nodefony/service/FrontendService.js +708 -0
- package/dist/nodefony/service/ViteConfigGenerator.js +139 -0
- package/dist/nodefony/service/ViteProcessSupervisor.js +589 -0
- package/dist/nodefony/src/FrontendAdminApi.js +113 -0
- package/dist/nodefony/src/builders/ViteBuilder.js +75 -0
- package/dist/nodefony/src/errors/FrontendError.js +50 -0
- package/dist/nodefony/src/isolationGroups.js +116 -0
- package/dist/nodefony/src/presets/angular-vite.js +27 -0
- package/dist/nodefony/src/presets/react19-vite.js +26 -0
- package/dist/nodefony/src/presets/svelte5-vite.js +37 -0
- package/dist/nodefony/src/presets/vanilla-vite.js +17 -0
- package/dist/nodefony/src/presets/vue3-vite.js +23 -0
- package/dist/nodefony/src/remoteDev.js +157 -0
- package/dist/nodefony/src/template/TemplateHelper.js +255 -0
- package/dist/types/index.d.ts +51 -0
- package/dist/types/nodefony/command/frontend-build.d.ts +17 -0
- package/dist/types/nodefony/command/frontend-dev.d.ts +12 -0
- package/dist/types/nodefony/command/frontend-status.d.ts +14 -0
- package/dist/types/nodefony/config/config.d.ts +38 -0
- package/dist/types/nodefony/config/defineModuleConfig.d.ts +29 -0
- package/dist/types/nodefony/interfaces/IFrontBuilder.d.ts +69 -0
- package/dist/types/nodefony/interfaces/IFrontPreset.d.ts +26 -0
- package/dist/types/nodefony/interfaces/IFrontendService.d.ts +77 -0
- package/dist/types/nodefony/interfaces/IViteSupervisor.d.ts +56 -0
- package/dist/types/nodefony/interfaces/index.d.ts +4 -0
- package/dist/types/nodefony/service/FrontendService.d.ts +230 -0
- package/dist/types/nodefony/service/ViteConfigGenerator.d.ts +66 -0
- package/dist/types/nodefony/service/ViteProcessSupervisor.d.ts +214 -0
- package/dist/types/nodefony/src/FrontendAdminApi.d.ts +63 -0
- package/dist/types/nodefony/src/builders/ViteBuilder.d.ts +17 -0
- package/dist/types/nodefony/src/errors/FrontendError.d.ts +34 -0
- package/dist/types/nodefony/src/isolationGroups.d.ts +89 -0
- package/dist/types/nodefony/src/presets/angular-vite.d.ts +15 -0
- package/dist/types/nodefony/src/presets/react19-vite.d.ts +9 -0
- package/dist/types/nodefony/src/presets/svelte5-vite.d.ts +13 -0
- package/dist/types/nodefony/src/presets/vanilla-vite.d.ts +9 -0
- package/dist/types/nodefony/src/presets/vue3-vite.d.ts +11 -0
- package/dist/types/nodefony/src/remoteDev.d.ts +107 -0
- package/dist/types/nodefony/src/template/TemplateHelper.d.ts +99 -0
- package/docs/index.md +925 -0
- package/package.json +80 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { FrontendPresetUnknownError } from "../src/errors/FrontendError.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region nodefony/service/ViteConfigGenerator.ts
|
|
5
|
+
/**
|
|
6
|
+
* Normalise un chemin filesystem en séparateurs `/` avant sérialisation dans
|
|
7
|
+
* le fichier `.mjs` généré. Le fichier généré est du JS/ESM : un backslash
|
|
8
|
+
* (produit par `path.resolve` sur `win32`) y est un caractère d'échappement
|
|
9
|
+
* de string — Windows accepte nativement `/` comme séparateur, donc on
|
|
10
|
+
* normalise plutôt que de laisser fuir des `\` bruts dans la sortie.
|
|
11
|
+
*/
|
|
12
|
+
function toGeneratedPath(p) {
|
|
13
|
+
return p.replace(/\\/g, "/");
|
|
14
|
+
}
|
|
15
|
+
var ViteConfigGenerator = class {
|
|
16
|
+
/**
|
|
17
|
+
* Construit le content `.mjs` à écrire à côté de `index.html` du module.
|
|
18
|
+
*
|
|
19
|
+
* Si `opts.backendOrigin` est fourni en mode `development`, agrège les
|
|
20
|
+
* `apiProxyPaths` de toutes les entries et génère un `server.proxy` qui
|
|
21
|
+
* forward chaque préfixe vers le backend Nodefony. Sans ça, les fetch
|
|
22
|
+
* relatifs depuis l'app servie par Vite atterrissent sur Vite et reçoivent
|
|
23
|
+
* un SPA-fallback HTML (cause classique de `Unexpected token '<'`).
|
|
24
|
+
*/
|
|
25
|
+
toMjs(entries, mode, opts = {}) {
|
|
26
|
+
if (entries.length === 0) throw new Error("ViteConfigGenerator: empty entries");
|
|
27
|
+
const usedTypes = /* @__PURE__ */ new Set();
|
|
28
|
+
for (const e of entries) usedTypes.add(e.type);
|
|
29
|
+
const angularEntry = entries.find((e) => e.type === "angular");
|
|
30
|
+
const imports = [`import { defineConfig } from "vite";`, ...mode === "development" && !!opts.https ? [`import fs from "node:fs";`] : []];
|
|
31
|
+
const pluginsExprs = [];
|
|
32
|
+
const optimizeInclude = [];
|
|
33
|
+
for (const type of usedTypes) switch (type) {
|
|
34
|
+
case "react19":
|
|
35
|
+
imports.push(`import react from "@vitejs/plugin-react";`);
|
|
36
|
+
pluginsExprs.push(`react({ jsxRuntime: "automatic" })`);
|
|
37
|
+
optimizeInclude.push("react", "react-dom", "react-dom/client");
|
|
38
|
+
break;
|
|
39
|
+
case "vue3":
|
|
40
|
+
imports.push(`import vue from "@vitejs/plugin-vue";`);
|
|
41
|
+
pluginsExprs.push(`vue()`);
|
|
42
|
+
optimizeInclude.push("vue");
|
|
43
|
+
break;
|
|
44
|
+
case "angular": {
|
|
45
|
+
imports.push(`import angular from "@analogjs/vite-plugin-angular";`);
|
|
46
|
+
const tsconfigPath = toGeneratedPath(path.resolve(angularEntry.root, "tsconfig.app.json"));
|
|
47
|
+
pluginsExprs.push(`angular({ tsconfig: ${JSON.stringify(tsconfigPath)} })`);
|
|
48
|
+
optimizeInclude.push("@angular/core", "@angular/common", "@angular/platform-browser");
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case "svelte5":
|
|
52
|
+
imports.push(`import { svelte } from "@sveltejs/vite-plugin-svelte";`);
|
|
53
|
+
pluginsExprs.push(`svelte()`);
|
|
54
|
+
optimizeInclude.push("svelte");
|
|
55
|
+
break;
|
|
56
|
+
case "vanilla": break;
|
|
57
|
+
default: throw new FrontendPresetUnknownError(type);
|
|
58
|
+
}
|
|
59
|
+
const input = {};
|
|
60
|
+
for (const e of entries) input[e.entryName] = toGeneratedPath(path.resolve(e.root, e.entryFile));
|
|
61
|
+
const root = toGeneratedPath(entries[0].root);
|
|
62
|
+
const outDir = toGeneratedPath(entries[0].outDir);
|
|
63
|
+
const fsAllowSet = /* @__PURE__ */ new Set([toGeneratedPath(process.cwd())]);
|
|
64
|
+
for (const e of entries) fsAllowSet.add(toGeneratedPath(e.root));
|
|
65
|
+
try {
|
|
66
|
+
const dbg = toGeneratedPath(createRequire(import.meta.url).resolve("nodefony/debugbar"));
|
|
67
|
+
const clientRoot = dbg.includes("/dist/client/") ? dbg.slice(0, dbg.indexOf("/dist/client/") + 12) : path.dirname(dbg);
|
|
68
|
+
fsAllowSet.add(clientRoot);
|
|
69
|
+
} catch {}
|
|
70
|
+
const fsAllowLines = Array.from(fsAllowSet).map((p) => ` ${JSON.stringify(p)},`).join("\n");
|
|
71
|
+
const inputLines = Object.entries(input).map(([name, file]) => ` ${JSON.stringify(name)}: ${JSON.stringify(file)},`).join("\n");
|
|
72
|
+
const optimizeLines = optimizeInclude.map((d) => ` ${JSON.stringify(d)},`).join("\n");
|
|
73
|
+
const proxyPaths = /* @__PURE__ */ new Set();
|
|
74
|
+
if (mode === "development" && opts.backendOrigin) {
|
|
75
|
+
for (const e of entries) for (const p of e.apiProxyPaths) proxyPaths.add(p);
|
|
76
|
+
proxyPaths.add("^/nodefony/[^/]+/api");
|
|
77
|
+
}
|
|
78
|
+
const proxyLines = proxyPaths.size > 0 ? Array.from(proxyPaths).map((p) => ` ${JSON.stringify(p)}: { target: ${JSON.stringify(opts.backendOrigin)}, changeOrigin: false, secure: false, ws: true },`).join("\n") : "";
|
|
79
|
+
const useViteOrigin = mode === "development" && !!opts.viteOrigin;
|
|
80
|
+
const strictPort = useViteOrigin ? "true" : "false";
|
|
81
|
+
const httpsLines = mode === "development" && !!opts.https ? ` https: {
|
|
82
|
+
key: fs.readFileSync(${JSON.stringify(toGeneratedPath(opts.https.keyPath))}),
|
|
83
|
+
cert: fs.readFileSync(${JSON.stringify(toGeneratedPath(opts.https.certPath))}),
|
|
84
|
+
},\n` : "";
|
|
85
|
+
const fsBlock = ` fs: {
|
|
86
|
+
allow: [
|
|
87
|
+
${fsAllowLines}
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
`;
|
|
91
|
+
const allowedHostsLine = opts.allowedHosts === true ? ` allowedHosts: true,\n` : opts.allowedHosts && opts.allowedHosts.length > 0 ? ` allowedHosts: ${JSON.stringify(opts.allowedHosts)},\n` : "";
|
|
92
|
+
const hmrLine = opts.hmr ? ` hmr: { host: ${JSON.stringify(opts.hmr.host)}, clientPort: ${opts.hmr.clientPort}, protocol: ${JSON.stringify(opts.hmr.protocol)} },\n` : "";
|
|
93
|
+
const serverBlock = proxyPaths.size > 0 ? ` server: {
|
|
94
|
+
strictPort: ${strictPort},
|
|
95
|
+
cors: true,
|
|
96
|
+
${allowedHostsLine}${hmrLine}${httpsLines}${fsBlock} proxy: {
|
|
97
|
+
${proxyLines}
|
|
98
|
+
},
|
|
99
|
+
},` : ` server: {
|
|
100
|
+
strictPort: ${strictPort},
|
|
101
|
+
cors: true,
|
|
102
|
+
${allowedHostsLine}${hmrLine}${httpsLines}${fsBlock} },`;
|
|
103
|
+
const baseLine = useViteOrigin ? ` base: ${JSON.stringify(opts.viteOrigin + "/")},\n` : "";
|
|
104
|
+
const dedupe = [];
|
|
105
|
+
if (usedTypes.has("react19")) dedupe.push("react", "react-dom");
|
|
106
|
+
if (usedTypes.has("vue3")) dedupe.push("vue");
|
|
107
|
+
if (usedTypes.has("svelte5")) dedupe.push("svelte");
|
|
108
|
+
if (usedTypes.has("angular")) dedupe.push("@angular/core", "@angular/common", "@angular/platform-browser");
|
|
109
|
+
const dedupeLine = dedupe.length ? ` resolve: { dedupe: ${JSON.stringify(dedupe)} },\n` : "";
|
|
110
|
+
return `// AUTO-GENERATED by @nodefony/frontend — DO NOT EDIT.
|
|
111
|
+
// Regenerated at every dev server start.
|
|
112
|
+
${imports.join("\n")}
|
|
113
|
+
|
|
114
|
+
export default defineConfig({
|
|
115
|
+
mode: ${JSON.stringify(mode)},
|
|
116
|
+
${baseLine}${dedupeLine} root: ${JSON.stringify(root)},
|
|
117
|
+
plugins: [${pluginsExprs.join(", ")}],
|
|
118
|
+
optimizeDeps: {
|
|
119
|
+
include: [
|
|
120
|
+
${optimizeLines}
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
build: {
|
|
124
|
+
outDir: ${JSON.stringify(outDir)},
|
|
125
|
+
manifest: true,
|
|
126
|
+
emptyOutDir: true,
|
|
127
|
+
rollupOptions: {
|
|
128
|
+
input: {
|
|
129
|
+
${inputLines}
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
${serverBlock}
|
|
134
|
+
});
|
|
135
|
+
`;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
export { ViteConfigGenerator, ViteConfigGenerator as default };
|