@taujs/server 0.4.4 → 0.4.6

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 CHANGED
@@ -17,7 +17,7 @@ type NetResolved = {
17
17
 
18
18
  type CreateServerOptions = {
19
19
  config: TaujsConfig;
20
- serviceRegistry: ServiceRegistry;
20
+ serviceRegistry?: ServiceRegistry;
21
21
  clientRoot?: string;
22
22
  alias?: Record<string, string>;
23
23
  fastify?: FastifyInstance;
package/dist/index.js CHANGED
@@ -97,101 +97,10 @@ var require_picocolors = __commonJS({
97
97
  }
98
98
  });
99
99
 
100
- // node_modules/fastify-plugin/lib/getPluginName.js
101
- var require_getPluginName = __commonJS({
102
- "node_modules/fastify-plugin/lib/getPluginName.js"(exports, module) {
103
- "use strict";
104
- var fpStackTracePattern = /at\s{1}(?:.*\.)?plugin\s{1}.*\n\s*(.*)/;
105
- var fileNamePattern = /(\w*(\.\w*)*)\..*/;
106
- module.exports = function getPluginName(fn) {
107
- if (fn.name.length > 0) return fn.name;
108
- const stackTraceLimit = Error.stackTraceLimit;
109
- Error.stackTraceLimit = 10;
110
- try {
111
- throw new Error("anonymous function");
112
- } catch (e) {
113
- Error.stackTraceLimit = stackTraceLimit;
114
- return extractPluginName(e.stack);
115
- }
116
- };
117
- function extractPluginName(stack) {
118
- const m = stack.match(fpStackTracePattern);
119
- return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
120
- }
121
- module.exports.extractPluginName = extractPluginName;
122
- }
123
- });
124
-
125
- // node_modules/fastify-plugin/lib/toCamelCase.js
126
- var require_toCamelCase = __commonJS({
127
- "node_modules/fastify-plugin/lib/toCamelCase.js"(exports, module) {
128
- "use strict";
129
- module.exports = function toCamelCase(name) {
130
- if (name[0] === "@") {
131
- name = name.slice(1).replace("/", "-");
132
- }
133
- return name.replace(/-(.)/g, function(match2, g1) {
134
- return g1.toUpperCase();
135
- });
136
- };
137
- }
138
- });
139
-
140
- // node_modules/fastify-plugin/plugin.js
141
- var require_plugin = __commonJS({
142
- "node_modules/fastify-plugin/plugin.js"(exports, module) {
143
- "use strict";
144
- var getPluginName = require_getPluginName();
145
- var toCamelCase = require_toCamelCase();
146
- var count = 0;
147
- function plugin(fn, options = {}) {
148
- let autoName = false;
149
- if (fn.default !== void 0) {
150
- fn = fn.default;
151
- }
152
- if (typeof fn !== "function") {
153
- throw new TypeError(
154
- `fastify-plugin expects a function, instead got a '${typeof fn}'`
155
- );
156
- }
157
- if (typeof options === "string") {
158
- options = {
159
- fastify: options
160
- };
161
- }
162
- if (typeof options !== "object" || Array.isArray(options) || options === null) {
163
- throw new TypeError("The options object should be an object");
164
- }
165
- if (options.fastify !== void 0 && typeof options.fastify !== "string") {
166
- throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof options.fastify}'`);
167
- }
168
- if (!options.name) {
169
- autoName = true;
170
- options.name = getPluginName(fn) + "-auto-" + count++;
171
- }
172
- fn[Symbol.for("skip-override")] = options.encapsulate !== true;
173
- fn[Symbol.for("fastify.display-name")] = options.name;
174
- fn[Symbol.for("plugin-meta")] = options;
175
- if (!fn.default) {
176
- fn.default = fn;
177
- }
178
- const camelCase = toCamelCase(options.name);
179
- if (!autoName && !fn[camelCase]) {
180
- fn[camelCase] = fn;
181
- }
182
- return fn;
183
- }
184
- module.exports = plugin;
185
- module.exports.default = plugin;
186
- module.exports.fastifyPlugin = plugin;
187
- }
188
- });
189
-
190
100
  // src/CreateServer.ts
191
101
  var import_picocolors4 = __toESM(require_picocolors(), 1);
192
102
  import path7 from "path";
193
103
  import { performance as performance3 } from "perf_hooks";
194
- import fastifyStatic from "@fastify/static";
195
104
  import Fastify from "fastify";
196
105
 
197
106
  // src/Setup.ts
@@ -851,8 +760,8 @@ var verifyContracts = (app, routes, contracts, security) => {
851
760
  };
852
761
 
853
762
  // src/SSRServer.ts
854
- var import_fastify_plugin3 = __toESM(require_plugin(), 1);
855
763
  import path6 from "path";
764
+ import fp3 from "fastify-plugin";
856
765
 
857
766
  // src/logging/utils/index.ts
858
767
  var httpStatusFrom = (err, fallback = 500) => err instanceof AppError ? err.httpStatus : fallback;
@@ -1083,7 +992,7 @@ var createAuthHook = (routeMatchers, logger) => {
1083
992
  };
1084
993
 
1085
994
  // src/security/CSP.ts
1086
- var import_fastify_plugin = __toESM(require_plugin(), 1);
995
+ import fp from "fastify-plugin";
1087
996
  import crypto from "crypto";
1088
997
 
1089
998
  // src/utils/System.ts
@@ -1129,7 +1038,7 @@ var findMatchingRoute = (routeMatchers, path9) => {
1129
1038
  const match2 = matchRoute(path9, routeMatchers);
1130
1039
  return match2 ? { route: match2.route, params: match2.params } : null;
1131
1040
  };
1132
- var cspPlugin = (0, import_fastify_plugin.default)(
1041
+ var cspPlugin = fp(
1133
1042
  async (fastify, opts) => {
1134
1043
  const { generateCSP = defaultGenerateCSP, routes = [], routeMatchers, debug } = opts;
1135
1044
  const globalDirectives = opts.directives || DEV_CSP_DIRECTIVES;
@@ -1180,7 +1089,7 @@ var cspPlugin = (0, import_fastify_plugin.default)(
1180
1089
  );
1181
1090
 
1182
1091
  // src/security/CSPReporting.ts
1183
- var import_fastify_plugin2 = __toESM(require_plugin(), 1);
1092
+ import fp2 from "fastify-plugin";
1184
1093
  function sanitiseContext(ctx) {
1185
1094
  return {
1186
1095
  userAgent: ctx.userAgent,
@@ -1263,7 +1172,7 @@ var processCSPReport = (body, context, logger) => {
1263
1172
  );
1264
1173
  }
1265
1174
  };
1266
- var cspReportPlugin = (0, import_fastify_plugin2.default)(
1175
+ var cspReportPlugin = fp2(
1267
1176
  async (fastify, opts) => {
1268
1177
  const { onViolation } = opts;
1269
1178
  if (!opts.path || typeof opts.path !== "string") throw AppError.badRequest("CSP report path is required and must be a string");
@@ -2018,9 +1927,9 @@ async function registerStaticAssets(app, baseClientRoot, reg, defaults, projectR
2018
1927
  }
2019
1928
 
2020
1929
  // src/SSRServer.ts
2021
- var SSRServer = (0, import_fastify_plugin3.default)(
1930
+ var SSRServer = fp3(
2022
1931
  async (app, opts) => {
2023
- const { alias, configs, routes, serviceRegistry, clientRoot: baseClientRoot, security } = opts;
1932
+ const { alias, configs, routes, serviceRegistry = {}, clientRoot: baseClientRoot, security } = opts;
2024
1933
  const logger = createLogger({
2025
1934
  debug: opts.debug,
2026
1935
  context: { component: "ssr-server" },
@@ -2183,7 +2092,7 @@ var createServer = async (opts) => {
2183
2092
  configs,
2184
2093
  routes,
2185
2094
  serviceRegistry: opts.serviceRegistry,
2186
- staticAssets: opts.staticAssets !== void 0 ? opts.staticAssets : { plugin: fastifyStatic },
2095
+ staticAssets: opts.staticAssets ?? false,
2187
2096
  debug: opts.debug,
2188
2097
  alias: opts.alias,
2189
2098
  security,
@@ -2339,6 +2248,37 @@ function mergeViteConfig(framework, userOverride, context) {
2339
2248
  }
2340
2249
  return merged;
2341
2250
  }
2251
+ function resolveAppFilter(argv, env) {
2252
+ const read = (keys) => {
2253
+ const end = argv.indexOf("--");
2254
+ const limit = end === -1 ? argv.length : end;
2255
+ for (let i = 0; i < limit; i++) {
2256
+ const arg = argv[i];
2257
+ if (!arg) continue;
2258
+ for (const key of keys) {
2259
+ if (arg === key) {
2260
+ const next = argv[i + 1];
2261
+ if (!next || next.startsWith("-")) return "";
2262
+ return next.trim();
2263
+ }
2264
+ const pref = `${key}=`;
2265
+ if (arg.startsWith(pref)) {
2266
+ const v = arg.slice(pref.length).trim();
2267
+ return v;
2268
+ }
2269
+ }
2270
+ }
2271
+ return void 0;
2272
+ };
2273
+ const envFilter = env.TAUJS_APP || env.TAUJS_APPS;
2274
+ const cliFilter = read(["--app", "--apps", "-a"]);
2275
+ const raw = (cliFilter ?? envFilter)?.trim() || void 0;
2276
+ if (!raw) return { selectedIds: null, raw: void 0 };
2277
+ const selectedIds = new Set(
2278
+ raw.split(",").map((s) => s.trim()).filter(Boolean)
2279
+ );
2280
+ return { selectedIds, raw };
2281
+ }
2342
2282
  async function taujsBuild({
2343
2283
  config,
2344
2284
  projectRoot,
@@ -2359,8 +2299,16 @@ async function taujsBuild({
2359
2299
  };
2360
2300
  const extractedConfigs = extractBuildConfigs(config);
2361
2301
  const processedConfigs = processConfigs(extractedConfigs, clientBaseDir, TEMPLATE);
2302
+ const { selectedIds, raw: appFilterRaw } = resolveAppFilter(process.argv.slice(2), process.env);
2303
+ const configsToBuild = selectedIds ? processedConfigs.filter(({ appId, entryPoint }) => selectedIds.has(appId) || selectedIds.has(entryPoint)) : processedConfigs;
2304
+ if (selectedIds && configsToBuild.length === 0) {
2305
+ console.error(
2306
+ `[taujs:build] No apps match filter "${appFilterRaw}". Known apps: ${processedConfigs.map((c) => `${c.appId}${c.entryPoint ? ` (entry: ${c.entryPoint})` : ""}`).join(", ")}`
2307
+ );
2308
+ process.exit(1);
2309
+ }
2362
2310
  if (!isSSRBuild) await deleteDist();
2363
- for (const appConfig of processedConfigs) {
2311
+ for (const appConfig of configsToBuild) {
2364
2312
  const { appId, entryPoint, clientRoot, entryClient, entryServer, htmlTemplate, plugins = [] } = appConfig;
2365
2313
  const outDir = path8.resolve(projectRoot, isSSRBuild ? `dist/ssr/${entryPoint}` : `dist/client/${entryPoint}`);
2366
2314
  const root = entryPoint ? path8.resolve(clientBaseDir, entryPoint) : clientBaseDir;
@@ -2399,8 +2347,6 @@ async function taujsBuild({
2399
2347
  },
2400
2348
  plugins,
2401
2349
  publicDir: isSSRBuild ? false : "public",
2402
- // single shared public
2403
- // publicDir: isSSRBuild ? false : path.join(root, 'public'), // per-app. no public dir for SSR builds
2404
2350
  resolve: { alias: resolvedAlias },
2405
2351
  root
2406
2352
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taujs/server",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
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,36 +44,29 @@
44
44
  "dist"
45
45
  ],
46
46
  "dependencies": {
47
+ "fastify": "^5.6.1",
48
+ "fastify-plugin": "^5.1.0",
47
49
  "path-to-regexp": "^8.1.0",
48
- "vite-plugin-node-polyfills": "^0.24.0"
50
+ "vite": "^7.1.11"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@arethetypeswrong/cli": "^0.15.4",
52
54
  "@babel/preset-typescript": "^7.24.7",
53
55
  "@changesets/cli": "^2.27.7",
54
- "@fastify/static": "^8.3.0",
55
56
  "@types/node": "^20.14.9",
56
57
  "@vitest/coverage-v8": "^3.2.4",
57
58
  "@vitest/ui": "^3.2.4",
58
- "fastify": "^5.6.1",
59
59
  "jsdom": "^25.0.0",
60
60
  "prettier": "^3.3.3",
61
61
  "tsup": "^8.2.4",
62
62
  "typescript": "^5.5.4",
63
- "vite": "^7.1.11",
64
63
  "vitest": "^3.2.4"
65
64
  },
66
65
  "peerDependencies": {
67
- "@fastify/static": "^8.3.0",
68
66
  "fastify": "^5.6.1",
69
67
  "typescript": "^5.5.4",
70
68
  "vite": "^7.1.11"
71
69
  },
72
- "peerDependenciesMeta": {
73
- "@fastify/static": {
74
- "optional": true
75
- }
76
- },
77
70
  "scripts": {
78
71
  "build": "tsup",
79
72
  "build-local": "tsup && ./move.sh",