@taujs/server 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +45 -42
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ type ViteBuildContext = {
|
|
|
95
95
|
type ViteConfigOverride = Partial<InlineConfig> | ((ctx: ViteBuildContext) => Partial<InlineConfig>);
|
|
96
96
|
declare function taujsBuild({ config, projectRoot, clientBaseDir, isSSRBuild, alias: userAlias, vite: userViteConfig, }: {
|
|
97
97
|
config: {
|
|
98
|
-
apps: AppConfig[];
|
|
98
|
+
apps: readonly AppConfig[];
|
|
99
99
|
};
|
|
100
100
|
projectRoot: string;
|
|
101
101
|
clientBaseDir: string;
|
package/dist/index.js
CHANGED
|
@@ -99,7 +99,7 @@ var require_picocolors = __commonJS({
|
|
|
99
99
|
|
|
100
100
|
// src/CreateServer.ts
|
|
101
101
|
var import_picocolors4 = __toESM(require_picocolors(), 1);
|
|
102
|
-
import
|
|
102
|
+
import path5 from "path";
|
|
103
103
|
import { performance as performance3 } from "perf_hooks";
|
|
104
104
|
import Fastify from "fastify";
|
|
105
105
|
|
|
@@ -168,8 +168,8 @@ var extractRoutes = (taujsConfig) => {
|
|
|
168
168
|
apps.push({ appId: app.appId, routeCount: appRoutes.length });
|
|
169
169
|
allRoutes.push(...appRoutes);
|
|
170
170
|
}
|
|
171
|
-
for (const [
|
|
172
|
-
if (appIds.length > 1) warnings.push(`Route path "${
|
|
171
|
+
for (const [path7, appIds] of pathTracker.entries()) {
|
|
172
|
+
if (appIds.length > 1) warnings.push(`Route path "${path7}" is declared in multiple apps: ${appIds.join(", ")}`);
|
|
173
173
|
}
|
|
174
174
|
const sortedRoutes = allRoutes.sort((a, b) => computeScore(b.path) - computeScore(a.path));
|
|
175
175
|
const durationMs = performance.now() - t0;
|
|
@@ -253,8 +253,8 @@ function printContractReport(logger, report) {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
var computeScore = (
|
|
257
|
-
return
|
|
256
|
+
var computeScore = (path7) => {
|
|
257
|
+
return path7.split("/").filter(Boolean).reduce((score, segment) => score + (segment.startsWith(":") ? 1 : 10), 0);
|
|
258
258
|
};
|
|
259
259
|
|
|
260
260
|
// src/logging/AppError.ts
|
|
@@ -760,7 +760,6 @@ var verifyContracts = (app, routes, contracts, security) => {
|
|
|
760
760
|
};
|
|
761
761
|
|
|
762
762
|
// src/SSRServer.ts
|
|
763
|
-
import path6 from "path";
|
|
764
763
|
import fp3 from "fastify-plugin";
|
|
765
764
|
|
|
766
765
|
// src/logging/utils/index.ts
|
|
@@ -858,15 +857,15 @@ var safeDecode = (value) => {
|
|
|
858
857
|
return value;
|
|
859
858
|
}
|
|
860
859
|
};
|
|
861
|
-
var cleanPath = (
|
|
862
|
-
if (!
|
|
863
|
-
const basePart =
|
|
860
|
+
var cleanPath = (path7) => {
|
|
861
|
+
if (!path7) return "/";
|
|
862
|
+
const basePart = path7.split("?")[0];
|
|
864
863
|
const base = basePart ? basePart.split("#")[0] : "/";
|
|
865
864
|
return base || "/";
|
|
866
865
|
};
|
|
867
|
-
var calculateSpecificity = (
|
|
866
|
+
var calculateSpecificity = (path7) => {
|
|
868
867
|
let score = 0;
|
|
869
|
-
const segments =
|
|
868
|
+
const segments = path7.split("/").filter(Boolean);
|
|
870
869
|
for (const segment of segments) {
|
|
871
870
|
if (segment.startsWith(":")) {
|
|
872
871
|
score += 1;
|
|
@@ -891,9 +890,9 @@ var createRouteMatchers = (routes) => {
|
|
|
891
890
|
});
|
|
892
891
|
};
|
|
893
892
|
var matchRoute = (url, routeMatchers) => {
|
|
894
|
-
const
|
|
893
|
+
const path7 = cleanPath(url);
|
|
895
894
|
for (const { route, matcher, keys } of routeMatchers) {
|
|
896
|
-
const match2 = matcher(
|
|
895
|
+
const match2 = matcher(path7);
|
|
897
896
|
if (match2) {
|
|
898
897
|
return {
|
|
899
898
|
route,
|
|
@@ -1033,9 +1032,9 @@ var mergeDirectives = (base, override) => {
|
|
|
1033
1032
|
}
|
|
1034
1033
|
return merged;
|
|
1035
1034
|
};
|
|
1036
|
-
var findMatchingRoute = (routeMatchers,
|
|
1035
|
+
var findMatchingRoute = (routeMatchers, path7) => {
|
|
1037
1036
|
if (!routeMatchers) return null;
|
|
1038
|
-
const match2 = matchRoute(
|
|
1037
|
+
const match2 = matchRoute(path7, routeMatchers);
|
|
1039
1038
|
return match2 ? { route: match2.route, params: match2.params } : null;
|
|
1040
1039
|
};
|
|
1041
1040
|
var cspPlugin = fp(
|
|
@@ -1365,7 +1364,6 @@ var loadAssets = async (processedConfigs, baseClientRoot, bootstrapModules, cssL
|
|
|
1365
1364
|
debug: opts.debug,
|
|
1366
1365
|
includeContext: true
|
|
1367
1366
|
});
|
|
1368
|
-
const projectRoot = opts.projectRoot ?? path2.resolve(process.cwd());
|
|
1369
1367
|
for (const config of processedConfigs) {
|
|
1370
1368
|
const { clientRoot, entryClient, entryServer, htmlTemplate, entryPoint } = config;
|
|
1371
1369
|
try {
|
|
@@ -1376,12 +1374,14 @@ var loadAssets = async (processedConfigs, baseClientRoot, bootstrapModules, cssL
|
|
|
1376
1374
|
const adjustedRelativePath = relativeBasePath ? `/${relativeBasePath}` : "";
|
|
1377
1375
|
if (!isDevelopment) {
|
|
1378
1376
|
try {
|
|
1379
|
-
const
|
|
1377
|
+
const distRoot = path2.dirname(baseClientRoot);
|
|
1378
|
+
const ssrRoot = path2.join(distRoot, "ssr");
|
|
1379
|
+
const clientDistPath = path2.join(baseClientRoot, entryPoint);
|
|
1380
1380
|
const manifestPath = path2.join(clientDistPath, ".vite/manifest.json");
|
|
1381
1381
|
const manifestContent = await readFile(manifestPath, "utf-8");
|
|
1382
1382
|
const manifest = JSON.parse(manifestContent);
|
|
1383
1383
|
manifests.set(clientRoot, manifest);
|
|
1384
|
-
const ssrDistPath = path2.
|
|
1384
|
+
const ssrDistPath = path2.join(ssrRoot, entryPoint);
|
|
1385
1385
|
const ssrManifestPath = path2.join(ssrDistPath, ".vite/ssr-manifest.json");
|
|
1386
1386
|
const ssrManifestContent = await readFile(ssrManifestPath, "utf-8");
|
|
1387
1387
|
const ssrManifest = JSON.parse(ssrManifestContent);
|
|
@@ -1902,7 +1902,6 @@ async function resolveRouteData(url, opts) {
|
|
|
1902
1902
|
}
|
|
1903
1903
|
|
|
1904
1904
|
// src/utils/StaticAssets.ts
|
|
1905
|
-
import path5 from "path";
|
|
1906
1905
|
function normaliseStaticAssets(reg) {
|
|
1907
1906
|
if (!reg) return [];
|
|
1908
1907
|
return Array.isArray(reg) ? reg : [reg];
|
|
@@ -1911,14 +1910,11 @@ function prefixWeight(prefix) {
|
|
|
1911
1910
|
if (typeof prefix !== "string" || prefix === "/" || prefix.length === 0) return 0;
|
|
1912
1911
|
return prefix.split("/").filter(Boolean).length;
|
|
1913
1912
|
}
|
|
1914
|
-
async function registerStaticAssets(app,
|
|
1915
|
-
const isDevelopment2 = process.env.NODE_ENV === "development";
|
|
1916
|
-
const effectiveProjectRoot = projectRoot ?? path5.resolve(process.cwd());
|
|
1917
|
-
const staticRoot = isDevelopment2 ? baseClientRoot : path5.resolve(effectiveProjectRoot, "client");
|
|
1913
|
+
async function registerStaticAssets(app, clientRoot, reg, defaults) {
|
|
1918
1914
|
const entries = normaliseStaticAssets(reg).map(({ plugin, options }) => ({
|
|
1919
1915
|
plugin,
|
|
1920
1916
|
options: {
|
|
1921
|
-
root:
|
|
1917
|
+
root: clientRoot,
|
|
1922
1918
|
prefix: "/",
|
|
1923
1919
|
index: false,
|
|
1924
1920
|
wildcard: false,
|
|
@@ -1935,7 +1931,7 @@ async function registerStaticAssets(app, baseClientRoot, reg, defaults, projectR
|
|
|
1935
1931
|
// src/SSRServer.ts
|
|
1936
1932
|
var SSRServer = fp3(
|
|
1937
1933
|
async (app, opts) => {
|
|
1938
|
-
const { alias, configs, routes, serviceRegistry = {}, clientRoot
|
|
1934
|
+
const { alias, configs, routes, serviceRegistry = {}, clientRoot, security } = opts;
|
|
1939
1935
|
const logger = createLogger({
|
|
1940
1936
|
debug: opts.debug,
|
|
1941
1937
|
context: { component: "ssr-server" },
|
|
@@ -1944,13 +1940,12 @@ var SSRServer = fp3(
|
|
|
1944
1940
|
singleLine: true
|
|
1945
1941
|
});
|
|
1946
1942
|
const maps = createMaps();
|
|
1947
|
-
const processedConfigs = processConfigs(configs,
|
|
1943
|
+
const processedConfigs = processConfigs(configs, clientRoot, TEMPLATE);
|
|
1948
1944
|
const routeMatchers = createRouteMatchers(routes);
|
|
1949
1945
|
let viteDevServer;
|
|
1950
|
-
const projectRoot = path6.resolve(baseClientRoot, "..");
|
|
1951
1946
|
await loadAssets(
|
|
1952
1947
|
processedConfigs,
|
|
1953
|
-
|
|
1948
|
+
clientRoot,
|
|
1954
1949
|
maps.bootstrapModules,
|
|
1955
1950
|
maps.cssLinks,
|
|
1956
1951
|
maps.manifests,
|
|
@@ -1960,11 +1955,14 @@ var SSRServer = fp3(
|
|
|
1960
1955
|
maps.templates,
|
|
1961
1956
|
{
|
|
1962
1957
|
debug: opts.debug,
|
|
1963
|
-
logger
|
|
1964
|
-
projectRoot
|
|
1958
|
+
logger
|
|
1965
1959
|
}
|
|
1966
1960
|
);
|
|
1967
|
-
if (
|
|
1961
|
+
if (!isDevelopment && !opts.staticAssets) {
|
|
1962
|
+
const fastifyStatic = await import("@fastify/static");
|
|
1963
|
+
await registerStaticAssets(app, clientRoot, { plugin: fastifyStatic.default });
|
|
1964
|
+
}
|
|
1965
|
+
if (opts.staticAssets) await registerStaticAssets(app, clientRoot, opts.staticAssets);
|
|
1968
1966
|
if (security?.csp?.reporting) {
|
|
1969
1967
|
app.register(cspReportPlugin, {
|
|
1970
1968
|
path: security.csp.reporting.endpoint,
|
|
@@ -1979,7 +1977,7 @@ var SSRServer = fp3(
|
|
|
1979
1977
|
routeMatchers,
|
|
1980
1978
|
debug: opts.debug
|
|
1981
1979
|
});
|
|
1982
|
-
if (isDevelopment) viteDevServer = await setupDevServer(app,
|
|
1980
|
+
if (isDevelopment) viteDevServer = await setupDevServer(app, clientRoot, alias, opts.debug, opts.devNet);
|
|
1983
1981
|
app.addHook("onRequest", createAuthHook(routeMatchers, logger));
|
|
1984
1982
|
app.get("/__taujs/data", async (req, reply) => {
|
|
1985
1983
|
const query = req.query;
|
|
@@ -2051,9 +2049,14 @@ var SSRServer = fp3(
|
|
|
2051
2049
|
);
|
|
2052
2050
|
|
|
2053
2051
|
// src/CreateServer.ts
|
|
2052
|
+
var resolveClientRoot = (userClientRoot) => {
|
|
2053
|
+
if (userClientRoot) return path5.isAbsolute(userClientRoot) ? userClientRoot : path5.resolve(process.cwd(), userClientRoot);
|
|
2054
|
+
const cwd = process.cwd();
|
|
2055
|
+
return process.env.NODE_ENV === "production" ? path5.resolve(cwd, "dist/client") : path5.resolve(cwd, "client");
|
|
2056
|
+
};
|
|
2054
2057
|
var createServer = async (opts) => {
|
|
2055
2058
|
const t0 = performance3.now();
|
|
2056
|
-
const clientRoot = opts.clientRoot
|
|
2059
|
+
const clientRoot = resolveClientRoot(opts.clientRoot);
|
|
2057
2060
|
const app = opts.fastify ?? Fastify({ logger: false });
|
|
2058
2061
|
const fastifyLogger = app.log && app.log.level && app.log.level !== "silent" ? app.log : void 0;
|
|
2059
2062
|
const logger = createLogger({
|
|
@@ -2123,7 +2126,7 @@ ${import_picocolors4.default.bgGreen(import_picocolors4.default.black(` ${CONTEN
|
|
|
2123
2126
|
|
|
2124
2127
|
// src/Build.ts
|
|
2125
2128
|
import { existsSync } from "fs";
|
|
2126
|
-
import
|
|
2129
|
+
import path6 from "path";
|
|
2127
2130
|
import { build } from "vite";
|
|
2128
2131
|
function resolveInputs(isSSRBuild, mainExists, paths) {
|
|
2129
2132
|
if (isSSRBuild) return { server: paths.server };
|
|
@@ -2295,7 +2298,7 @@ async function taujsBuild({
|
|
|
2295
2298
|
}) {
|
|
2296
2299
|
const deleteDist = async () => {
|
|
2297
2300
|
const { rm } = await import("fs/promises");
|
|
2298
|
-
const distPath =
|
|
2301
|
+
const distPath = path6.resolve(projectRoot, "dist");
|
|
2299
2302
|
try {
|
|
2300
2303
|
await rm(distPath, { recursive: true, force: true });
|
|
2301
2304
|
console.log("Deleted the dist directory\n");
|
|
@@ -2316,17 +2319,17 @@ async function taujsBuild({
|
|
|
2316
2319
|
if (!isSSRBuild) await deleteDist();
|
|
2317
2320
|
for (const appConfig of configsToBuild) {
|
|
2318
2321
|
const { appId, entryPoint, clientRoot, entryClient, entryServer, htmlTemplate, plugins = [] } = appConfig;
|
|
2319
|
-
const outDir =
|
|
2320
|
-
const root = entryPoint ?
|
|
2322
|
+
const outDir = path6.resolve(projectRoot, isSSRBuild ? `dist/ssr/${entryPoint}` : `dist/client/${entryPoint}`);
|
|
2323
|
+
const root = entryPoint ? path6.resolve(clientBaseDir, entryPoint) : clientBaseDir;
|
|
2321
2324
|
const defaultAlias = {
|
|
2322
2325
|
"@client": root,
|
|
2323
|
-
"@server":
|
|
2324
|
-
"@shared":
|
|
2326
|
+
"@server": path6.resolve(projectRoot, "src/server"),
|
|
2327
|
+
"@shared": path6.resolve(projectRoot, "src/shared")
|
|
2325
2328
|
};
|
|
2326
2329
|
const resolvedAlias = { ...defaultAlias, ...userAlias ?? {} };
|
|
2327
|
-
const server =
|
|
2328
|
-
const client =
|
|
2329
|
-
const main =
|
|
2330
|
+
const server = path6.resolve(clientRoot, `${entryServer}.tsx`);
|
|
2331
|
+
const client = path6.resolve(clientRoot, `${entryClient}.tsx`);
|
|
2332
|
+
const main = path6.resolve(clientRoot, htmlTemplate);
|
|
2330
2333
|
const inputs = resolveInputs(isSSRBuild, !isSSRBuild && existsSync(main), { server, client, main });
|
|
2331
2334
|
const nodeVersion = process.versions.node.split(".")[0];
|
|
2332
2335
|
const frameworkConfig = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taujs/server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "τjs [ taujs ]",
|
|
5
5
|
"author": "John Smith | Aoede <taujs@aoede.uk.net> (https://www.aoede.uk.net)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"@fastify/static": "^8.3.0",
|
|
47
48
|
"fastify": "^5.6.1",
|
|
48
49
|
"fastify-plugin": "^5.1.0",
|
|
49
50
|
"path-to-regexp": "^8.1.0",
|