@rpcbase/vite 0.113.0 → 0.115.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.
Files changed (39) hide show
  1. package/dist/dotEnvExpand.d.ts +2 -0
  2. package/dist/dotEnvExpand.d.ts.map +1 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +566 -0
  6. package/dist/plugins/posthog-sourcemaps/index.d.ts +8 -0
  7. package/dist/plugins/posthog-sourcemaps/index.d.ts.map +1 -0
  8. package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.input.d.ts +9 -0
  9. package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.input.d.ts.map +1 -0
  10. package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.output.d.ts +8 -0
  11. package/dist/plugins/prune-models-for-client/fixtures/alias-and-types.output.d.ts.map +1 -0
  12. package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.input.d.ts +101 -0
  13. package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.input.d.ts.map +1 -0
  14. package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.output.d.ts +5 -0
  15. package/dist/plugins/prune-models-for-client/fixtures/chained-bindings.output.d.ts.map +1 -0
  16. package/dist/plugins/prune-models-for-client/fixtures/contact-model.input.d.ts +242 -0
  17. package/dist/plugins/prune-models-for-client/fixtures/contact-model.input.d.ts.map +1 -0
  18. package/dist/plugins/prune-models-for-client/fixtures/contact-model.output.d.ts +32 -0
  19. package/dist/plugins/prune-models-for-client/fixtures/contact-model.output.d.ts.map +1 -0
  20. package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.input.d.ts +7 -0
  21. package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.input.d.ts.map +1 -0
  22. package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.output.d.ts +5 -0
  23. package/dist/plugins/prune-models-for-client/fixtures/destructuring-bindings.output.d.ts.map +1 -0
  24. package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.input.d.ts +5 -0
  25. package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.input.d.ts.map +1 -0
  26. package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.output.d.ts +3 -0
  27. package/dist/plugins/prune-models-for-client/fixtures/export-specifiers.output.d.ts.map +1 -0
  28. package/dist/plugins/prune-models-for-client/index.d.ts +3 -0
  29. package/dist/plugins/prune-models-for-client/index.d.ts.map +1 -0
  30. package/dist/plugins/prune-models-for-client/transformSource.d.ts +6 -0
  31. package/dist/plugins/prune-models-for-client/transformSource.d.ts.map +1 -0
  32. package/dist/resolveIntegratedPackagePath.d.ts +2 -0
  33. package/dist/resolveIntegratedPackagePath.d.ts.map +1 -0
  34. package/package.json +49 -16
  35. package/index.d.ts +0 -31
  36. package/index.js +0 -334
  37. package/src/dotEnvExpand.js +0 -14
  38. package/src/posthogSourcemapsPlugin.js +0 -76
  39. package/src/resolveIntegratedPackagePath.js +0 -96
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dotEnvExpand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotEnvExpand.d.ts","sourceRoot":"","sources":["../src/dotEnvExpand.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { createServer as viteCreateServer, UserConfigExport, UserConfigFn } from 'vite';
2
+ declare const resolveAliases: Record<string, string>;
3
+ export { resolveAliases };
4
+ export declare const extendConfig: (userConfig: UserConfigExport) => UserConfigFn;
5
+ export declare const extendSpecConfig: (userConfig: UserConfigExport) => UserConfigFn;
6
+ export declare const createServer: typeof viteCreateServer;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAA;AAKvB,OAAO,EACL,YAAY,IAAI,gBAAgB,EAGjC,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAyB,gBAAgB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAoEjF,QAAA,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAM1C,CAAA;AA4BD,OAAO,EAAE,cAAc,EAAE,CAAA;AAgIzB,eAAO,MAAM,YAAY,GAAI,YAAY,gBAAgB,KAAG,YAW3D,CAAA;AA4CD,eAAO,MAAM,gBAAgB,GAAI,YAAY,gBAAgB,KAAG,YAW/D,CAAA;AAED,eAAO,MAAM,YAAY,yBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,566 @@
1
+ import fs, { existsSync, readFileSync } from "node:fs";
2
+ import path from "path";
3
+ import dotenv from "dotenv";
4
+ import { expand } from "dotenv-expand";
5
+ import { createServer as createServer$1, mergeConfig, loadEnv } from "vite";
6
+ import { viteSingleFile } from "vite-plugin-singlefile";
7
+ import react from "@vitejs/plugin-react";
8
+ import { createHtmlPlugin } from "vite-plugin-html";
9
+ import { globSync } from "glob";
10
+ import { createRequire } from "node:module";
11
+ import { spawn } from "node:child_process";
12
+ import path$1 from "node:path";
13
+ import { fileURLToPath } from "node:url";
14
+ import { Project } from "ts-morph";
15
+ import * as ts from "typescript";
16
+ const envFilePath = path.resolve(process.cwd(), ".env");
17
+ if (fs.existsSync(envFilePath)) {
18
+ const parsedFile = dotenv.parse(fs.readFileSync(envFilePath));
19
+ const expanded = expand({ parsed: parsedFile }).parsed || {};
20
+ Object.assign(process.env, expanded);
21
+ }
22
+ const require$1 = createRequire(import.meta.url);
23
+ const splitPackageSpecifier = (specifier) => {
24
+ if (!specifier) return { pkgName: specifier, subpath: "" };
25
+ if (specifier.startsWith("@")) {
26
+ const segments = specifier.split("/");
27
+ if (segments.length < 2) return { pkgName: specifier, subpath: "" };
28
+ return {
29
+ pkgName: `${segments[0]}/${segments[1]}`,
30
+ subpath: segments.slice(2).join("/")
31
+ };
32
+ }
33
+ const [pkgName, ...rest] = specifier.split("/");
34
+ return { pkgName, subpath: rest.join("/") };
35
+ };
36
+ const withTrailingSep = (p) => p.endsWith(path.sep) ? p : p + path.sep;
37
+ const resolvePackageRoot = (pkg) => {
38
+ const { pkgName } = splitPackageSpecifier(pkg);
39
+ if (!pkgName) return pkg;
40
+ try {
41
+ const pkgJson = require$1.resolve(`${pkgName}/package.json`);
42
+ return path.dirname(pkgJson);
43
+ } catch (err) {
44
+ const entry = require$1.resolve(pkgName);
45
+ let dir = path.dirname(entry);
46
+ while (true) {
47
+ const pkgJsonPath = path.join(dir, "package.json");
48
+ if (existsSync(pkgJsonPath)) {
49
+ try {
50
+ const json = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
51
+ if (json && json.name === pkgName) return dir;
52
+ } catch {
53
+ }
54
+ }
55
+ const parent = path.dirname(dir);
56
+ if (parent === dir) break;
57
+ dir = parent;
58
+ }
59
+ const nmMarker = `${path.sep}node_modules${path.sep}`;
60
+ const idx = entry.lastIndexOf(nmMarker);
61
+ if (idx !== -1) {
62
+ const nmRoot = entry.slice(0, idx + nmMarker.length);
63
+ return path.join(nmRoot, pkgName);
64
+ }
65
+ throw err;
66
+ }
67
+ };
68
+ const resolveIntegratedPackagePath = (specifier) => {
69
+ const { pkgName, subpath } = splitPackageSpecifier(specifier);
70
+ if (!pkgName) return specifier;
71
+ const root = resolvePackageRoot(pkgName);
72
+ if (!subpath) {
73
+ return withTrailingSep(root);
74
+ }
75
+ const subDir = path.join(root, subpath);
76
+ const pkgJsonPath = path.join(subDir, "package.json");
77
+ if (existsSync(pkgJsonPath)) {
78
+ try {
79
+ const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
80
+ const entry = pkgJson.module || pkgJson.main;
81
+ if (entry) {
82
+ return path.join(subDir, entry);
83
+ }
84
+ } catch {
85
+ }
86
+ }
87
+ try {
88
+ return require$1.resolve(specifier);
89
+ } catch {
90
+ return withTrailingSep(subDir);
91
+ }
92
+ };
93
+ const __dirname$1 = path$1.dirname(fileURLToPath(import.meta.url));
94
+ function run(bin, args) {
95
+ return new Promise((resolve, reject) => {
96
+ const p = spawn(bin, args, { stdio: "inherit" });
97
+ p.on("close", (code) => code === 0 ? resolve() : reject(new Error(`posthog-cli exited ${code}`)));
98
+ });
99
+ }
100
+ function resolvePosthogCliBin() {
101
+ const binName = "posthog-cli";
102
+ const fromCwd = path$1.join(process.cwd(), "node_modules", ".bin", binName);
103
+ if (fs.existsSync(fromCwd)) return fromCwd;
104
+ let dir = __dirname$1;
105
+ while (true) {
106
+ const candidate = path$1.join(dir, "node_modules", ".bin", binName);
107
+ if (fs.existsSync(candidate)) return candidate;
108
+ const parent = path$1.dirname(dir);
109
+ if (parent === dir) break;
110
+ dir = parent;
111
+ }
112
+ return binName;
113
+ }
114
+ function posthogSourcemapsPlugin(opts = {}) {
115
+ const {
116
+ directory = "build/dist",
117
+ version,
118
+ host = process.env.RB_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com",
119
+ deleteAfterUpload = true
120
+ } = opts;
121
+ const bin = resolvePosthogCliBin();
122
+ const globalArgs = ["--host", host];
123
+ return {
124
+ name: "posthog-sourcemaps",
125
+ apply: "build",
126
+ closeBundle: async () => {
127
+ const orange = "\x1B[38;5;208m";
128
+ const reset = "\x1B[0m";
129
+ const envId = process.env.POSTHOG_CLI_ENV_ID;
130
+ const token = process.env.POSTHOG_CLI_TOKEN;
131
+ if (!envId || !token) {
132
+ console.warn(`${orange}posthog-sourcemaps: plugin is enabled but no env vars for auth configured (POSTHOG_CLI_ENV_ID/POSTHOG_CLI_TOKEN). Skipping without failing.${reset}`);
133
+ return;
134
+ }
135
+ const injectArgs = ["sourcemap", "inject", "--directory", directory];
136
+ if (version) injectArgs.push("--version", version);
137
+ const uploadArgs = ["sourcemap", "upload", "--directory", directory];
138
+ if (deleteAfterUpload) uploadArgs.push("--delete-after");
139
+ await run(bin, [...globalArgs, ...injectArgs]);
140
+ await run(bin, [...globalArgs, ...uploadArgs]);
141
+ }
142
+ };
143
+ }
144
+ function isForbiddenModuleSource(source) {
145
+ if (source === "mongoose") return true;
146
+ if (source.startsWith("node:")) return true;
147
+ if (source.endsWith("/extendMongooseSchema") || source.endsWith("./extendMongooseSchema") || source.endsWith("extendMongooseSchema")) {
148
+ return true;
149
+ }
150
+ return false;
151
+ }
152
+ function getImportValueLocals(importDeclaration) {
153
+ if (importDeclaration.isTypeOnly()) return [];
154
+ const locals = [];
155
+ const defaultImport = importDeclaration.getDefaultImport();
156
+ if (defaultImport) locals.push(defaultImport.getText());
157
+ const namespaceImport = importDeclaration.getNamespaceImport();
158
+ if (namespaceImport) locals.push(namespaceImport.getText());
159
+ for (const specifier of importDeclaration.getNamedImports()) {
160
+ if (specifier.isTypeOnly()) continue;
161
+ const alias = specifier.getAliasNode()?.getText();
162
+ locals.push(alias ?? specifier.getName());
163
+ }
164
+ return locals;
165
+ }
166
+ function rewriteRpcbaseDbImport(importDeclaration, forbiddenIdentifiers) {
167
+ const valueLocals = getImportValueLocals(importDeclaration);
168
+ const zLocals = /* @__PURE__ */ new Set();
169
+ for (const specifier of importDeclaration.getNamedImports()) {
170
+ if (importDeclaration.isTypeOnly() || specifier.isTypeOnly()) continue;
171
+ if (specifier.getName() !== "z") continue;
172
+ const local = specifier.getAliasNode()?.getText() ?? "z";
173
+ zLocals.add(local);
174
+ }
175
+ for (const local of valueLocals) {
176
+ if (!zLocals.has(local)) forbiddenIdentifiers.add(local);
177
+ }
178
+ if (zLocals.size === 0) {
179
+ importDeclaration.remove();
180
+ return;
181
+ }
182
+ const specifierText = Array.from(zLocals).map((local) => local === "z" ? "z" : `z as ${local}`).join(", ");
183
+ importDeclaration.replaceWithText(`import { ${specifierText} } from "@rpcbase/db"`);
184
+ }
185
+ function collectBindingNames(name, out) {
186
+ if (ts.isIdentifier(name)) {
187
+ out.push(name.text);
188
+ return;
189
+ }
190
+ for (const element of name.elements) {
191
+ if (ts.isOmittedExpression(element)) continue;
192
+ collectBindingNames(element.name, out);
193
+ }
194
+ }
195
+ function getTopLevelBindings(statement) {
196
+ if (ts.isVariableStatement(statement)) {
197
+ const names = [];
198
+ for (const decl of statement.declarationList.declarations) {
199
+ collectBindingNames(decl.name, names);
200
+ }
201
+ return names;
202
+ }
203
+ if (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) {
204
+ return statement.name ? [statement.name.text] : [];
205
+ }
206
+ return [];
207
+ }
208
+ function isRuntimeReferenceIdentifier(identifier) {
209
+ const parent = identifier.parent;
210
+ if (!parent) return true;
211
+ if (ts.isVariableDeclaration(parent) && parent.name === identifier) return false;
212
+ if (ts.isParameter(parent) && parent.name === identifier) return false;
213
+ if ((ts.isFunctionDeclaration(parent) || ts.isFunctionExpression(parent)) && parent.name === identifier) return false;
214
+ if ((ts.isClassDeclaration(parent) || ts.isClassExpression(parent)) && parent.name === identifier) return false;
215
+ if (ts.isEnumDeclaration(parent) && parent.name === identifier) return false;
216
+ if (ts.isTypeAliasDeclaration(parent) && parent.name === identifier) return false;
217
+ if (ts.isInterfaceDeclaration(parent) && parent.name === identifier) return false;
218
+ if (ts.isModuleDeclaration(parent) && parent.name === identifier) return false;
219
+ if (ts.isTypeParameterDeclaration(parent) && parent.name === identifier) return false;
220
+ if (ts.isImportClause(parent) && parent.name === identifier) return false;
221
+ if (ts.isNamespaceImport(parent) && parent.name === identifier) return false;
222
+ if (ts.isImportSpecifier(parent) && parent.name === identifier) return false;
223
+ if (ts.isImportEqualsDeclaration(parent) && parent.name === identifier) return false;
224
+ if (ts.isBindingElement(parent)) {
225
+ if (parent.name === identifier) return false;
226
+ if (parent.propertyName === identifier) return false;
227
+ }
228
+ if (ts.isPropertyAccessExpression(parent) && parent.name === identifier) return false;
229
+ if (ts.isQualifiedName(parent)) return false;
230
+ if (ts.isPropertyAssignment(parent) && parent.name === identifier) return false;
231
+ if (ts.isPropertyDeclaration(parent) && parent.name === identifier) return false;
232
+ if (ts.isPropertySignature(parent) && parent.name === identifier) return false;
233
+ if (ts.isMethodDeclaration(parent) && parent.name === identifier) return false;
234
+ if (ts.isMethodSignature(parent) && parent.name === identifier) return false;
235
+ if (ts.isGetAccessorDeclaration(parent) && parent.name === identifier) return false;
236
+ if (ts.isSetAccessorDeclaration(parent) && parent.name === identifier) return false;
237
+ if (ts.isShorthandPropertyAssignment(parent) && parent.name === identifier) return true;
238
+ if (ts.isExportSpecifier(parent)) {
239
+ const local = parent.propertyName ?? parent.name;
240
+ return identifier === local;
241
+ }
242
+ if (ts.isLabeledStatement(parent) && parent.label === identifier) return false;
243
+ if ((ts.isBreakStatement(parent) || ts.isContinueStatement(parent)) && parent.label === identifier) return false;
244
+ return true;
245
+ }
246
+ function referencesForbiddenRuntime(statement, forbidden) {
247
+ if (forbidden.size === 0) return false;
248
+ if (ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement)) return false;
249
+ let found = false;
250
+ const visit = (node) => {
251
+ if (found) return;
252
+ if (ts.isTypeNode(node)) return;
253
+ if (ts.isHeritageClause(node) && node.token === ts.SyntaxKind.ImplementsKeyword) return;
254
+ if (ts.isIdentifier(node)) {
255
+ if (forbidden.has(node.text) && isRuntimeReferenceIdentifier(node)) {
256
+ found = true;
257
+ return;
258
+ }
259
+ }
260
+ ts.forEachChild(node, visit);
261
+ };
262
+ visit(statement);
263
+ return found;
264
+ }
265
+ function createTransformSource() {
266
+ const project = new Project({ compilerOptions: { noUnusedLocals: true } });
267
+ return ({ code, filePath }) => {
268
+ const sourceFile = project.createSourceFile(filePath, code, { overwrite: true });
269
+ const forbiddenIdentifiers = /* @__PURE__ */ new Set();
270
+ for (const importDeclaration of sourceFile.getImportDeclarations()) {
271
+ const source = importDeclaration.getModuleSpecifierValue();
272
+ if (source === "@rpcbase/db") {
273
+ rewriteRpcbaseDbImport(importDeclaration, forbiddenIdentifiers);
274
+ continue;
275
+ }
276
+ if (!isForbiddenModuleSource(source)) continue;
277
+ getImportValueLocals(importDeclaration).forEach((local) => forbiddenIdentifiers.add(local));
278
+ importDeclaration.remove();
279
+ }
280
+ let changed = true;
281
+ while (changed) {
282
+ changed = false;
283
+ for (const statement of sourceFile.getStatements()) {
284
+ const compilerStatement = statement.compilerNode;
285
+ if (ts.isImportDeclaration(compilerStatement)) continue;
286
+ if (!referencesForbiddenRuntime(compilerStatement, forbiddenIdentifiers)) continue;
287
+ getTopLevelBindings(compilerStatement).forEach((name) => forbiddenIdentifiers.add(name));
288
+ statement.remove();
289
+ changed = true;
290
+ }
291
+ }
292
+ sourceFile.fixUnusedIdentifiers();
293
+ sourceFile.organizeImports();
294
+ const nextCode = sourceFile.getFullText();
295
+ return nextCode === code ? null : nextCode;
296
+ };
297
+ }
298
+ function inferIsSsrTransform(transformOptions) {
299
+ if (typeof transformOptions === "boolean") return transformOptions;
300
+ if (!transformOptions || typeof transformOptions !== "object") return false;
301
+ return transformOptions.ssr === true;
302
+ }
303
+ function pruneModelsForClientPlugin() {
304
+ const modelsDir = `${path$1.resolve(process.cwd(), "src/models")}${path$1.sep}`;
305
+ const prune = createTransformSource();
306
+ return {
307
+ name: "lz-models-prune-for-browser",
308
+ enforce: "pre",
309
+ transform(code, id, transformOptions) {
310
+ if (inferIsSsrTransform(transformOptions)) return;
311
+ const filePath = id.split("?", 1)[0] ?? id;
312
+ if (!filePath.startsWith(modelsDir)) return;
313
+ const nextCode = prune({ code, filePath });
314
+ if (!nextCode) return;
315
+ return { code: nextCode };
316
+ }
317
+ };
318
+ }
319
+ const ensureEnvPolyfillInjectPath = () => {
320
+ const injectDir = path.resolve(process.cwd(), "node_modules/.rpcbase");
321
+ const injectPath = path.join(injectDir, "rb-env-polyfill-inject.js");
322
+ const injectContents = 'import "@rpcbase/env/polyfill"\n';
323
+ fs.mkdirSync(injectDir, { recursive: true });
324
+ try {
325
+ const existing = fs.readFileSync(injectPath, "utf8");
326
+ if (existing === injectContents) {
327
+ return injectPath;
328
+ }
329
+ } catch {
330
+ }
331
+ fs.writeFileSync(injectPath, injectContents, "utf8");
332
+ return injectPath;
333
+ };
334
+ const esbuildInjectPath = ensureEnvPolyfillInjectPath();
335
+ const esbuildInject = [esbuildInjectPath];
336
+ const esbuildInjectPlugins = [
337
+ {
338
+ name: "rb-env-polyfill-inject",
339
+ setup(build) {
340
+ build.onResolve({ filter: /.*/ }, (args) => {
341
+ if (args.path === esbuildInjectPath) {
342
+ return { path: esbuildInjectPath, namespace: "file" };
343
+ }
344
+ return void 0;
345
+ });
346
+ }
347
+ }
348
+ ];
349
+ const isProduction = process.env.NODE_ENV === "production";
350
+ const ALLOWED_DEV_ENV = ["NODE_ENV", "APP_NAME"];
351
+ const ALLOWED_ENV_PREFIXES = [
352
+ "RB_PUBLIC_",
353
+ ...isProduction ? [] : ALLOWED_DEV_ENV
354
+ ];
355
+ const htmlMinifyOptions = {
356
+ collapseWhitespace: true,
357
+ keepClosingSlash: true,
358
+ removeComments: false,
359
+ removeRedundantAttributes: true,
360
+ removeScriptTypeAttributes: true,
361
+ removeStyleLinkTypeAttributes: true,
362
+ useShortDoctype: true,
363
+ minifyCSS: true
364
+ };
365
+ const resolveAliases = {
366
+ "@/api": path.resolve(process.cwd(), "./src/api/"),
367
+ "@/models": path.resolve(process.cwd(), "./src/models/"),
368
+ "@/shared": path.resolve(process.cwd(), "./src/shared/"),
369
+ "@/types": path.resolve(process.cwd(), "./src/types/"),
370
+ "@": path.resolve(process.cwd(), "./src/client/")
371
+ };
372
+ const integratedPackages = [
373
+ "@hookform/resolvers",
374
+ "axios",
375
+ "events",
376
+ "libphonenumber-js",
377
+ "posthog-js",
378
+ "posthog-js/react",
379
+ "posthog-node",
380
+ "react-router",
381
+ "react-hook-form"
382
+ ];
383
+ integratedPackages.forEach((pkg) => {
384
+ const resolved = resolveIntegratedPackagePath(pkg);
385
+ resolveAliases[pkg] = resolved;
386
+ });
387
+ resolveAliases["node:events"] = resolveIntegratedPackagePath("events");
388
+ const posthogReactEsm = resolveIntegratedPackagePath("posthog-js/react/dist/esm/index.js");
389
+ resolveAliases["posthog-js/react"] = posthogReactEsm;
390
+ resolveAliases["posthog-js/react/dist/esm/index.js"] = posthogReactEsm;
391
+ const rbPackagesNeedingEnvPolyfill = [
392
+ "@rpcbase/auth",
393
+ "@rpcbase/env",
394
+ // "@rpcbase/env/polyfill",
395
+ "@rpcbase/server",
396
+ "@rpcbase/client",
397
+ "@rpcbase/form",
398
+ "@rpcbase/router"
399
+ ];
400
+ const createRuntimeEnv = (args) => {
401
+ const { env, configEnv } = args;
402
+ const { command, mode, isSsrBuild } = configEnv;
403
+ const isDevCommand = command === "serve";
404
+ const mergedEnv = {
405
+ ...env
406
+ };
407
+ return {
408
+ ...mergedEnv,
409
+ BASE_URL: mergedEnv.BASE_URL ?? "/",
410
+ MODE: mode,
411
+ DEV: isDevCommand,
412
+ PROD: !isDevCommand,
413
+ SSR: Boolean(isSsrBuild)
414
+ };
415
+ };
416
+ const getBaseConfig = (configEnv) => {
417
+ const { mode } = configEnv;
418
+ const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES);
419
+ const runtimeEnv = createRuntimeEnv({ env, configEnv });
420
+ return {
421
+ clearScreen: false,
422
+ plugins: [
423
+ pruneModelsForClientPlugin(),
424
+ react(),
425
+ createHtmlPlugin({
426
+ // IMPORTANT: minify removes comments by default, which are used by the app ssr
427
+ minify: htmlMinifyOptions
428
+ }),
429
+ viteSingleFile({
430
+ useRecommendedBuildConfig: false,
431
+ deleteInlinedFiles: true,
432
+ inlinePattern: ["**/*.css"],
433
+ removeViteModuleLoader: false
434
+ }),
435
+ isProduction && posthogSourcemapsPlugin({})
436
+ ].filter(Boolean),
437
+ define: {
438
+ __vite_env__: runtimeEnv
439
+ },
440
+ envPrefix: ALLOWED_ENV_PREFIXES,
441
+ publicDir: path.join(process.cwd(), "./src/client/public"),
442
+ build: {
443
+ sourcemap: isProduction ? "hidden" : false,
444
+ cssCodeSplit: false,
445
+ outDir: "./build/dist/",
446
+ rollupOptions: {
447
+ input: {
448
+ app: "./src/client/index.html"
449
+ }
450
+ },
451
+ commonjsOptions: { transformMixedEsModules: true }
452
+ },
453
+ server: {
454
+ allowedHosts: true,
455
+ headers: {
456
+ "Cache-Control": "no-store"
457
+ },
458
+ watch: {
459
+ ignored: ["**/build/playwright/**"]
460
+ }
461
+ },
462
+ resolve: {
463
+ alias: {
464
+ ...resolveAliases
465
+ },
466
+ dedupe: ["react", "react-dom", "react-router", "react-hook-form"],
467
+ preserveSymlinks: true
468
+ },
469
+ ssr: {
470
+ external: [
471
+ // "react", "react-dom",
472
+ "cookie",
473
+ "mongoose",
474
+ "mongodb"
475
+ ],
476
+ noExternal: [
477
+ ...rbPackagesNeedingEnvPolyfill
478
+ // "react-use",
479
+ ]
480
+ },
481
+ optimizeDeps: {
482
+ include: [
483
+ // Force RPC Base packages through esbuild so rb-env-polyfill injects before their dist code touches globalThis.__rb_env__
484
+ ...rbPackagesNeedingEnvPolyfill,
485
+ "hoist-non-react-statics"
486
+ // "react", "react-dom", "react-dom/server"
487
+ // "cookie"
488
+ ],
489
+ exclude: [
490
+ "@radix-ui/*",
491
+ "@rpcbase/ui"
492
+ // TMP only in sample app?
493
+ // "react", "react-dom/server",
494
+ // "react-hook-form",
495
+ // "react-dom"
496
+ ],
497
+ esbuildOptions: {
498
+ inject: esbuildInject,
499
+ plugins: esbuildInjectPlugins
500
+ }
501
+ }
502
+ // future: {
503
+ // removeSsrLoadModule: true
504
+ // },
505
+ };
506
+ };
507
+ const extendConfig = (userConfig) => {
508
+ return async (configEnv) => {
509
+ const config = typeof userConfig === "function" ? await userConfig(configEnv) : userConfig;
510
+ const baseConfig = getBaseConfig(configEnv);
511
+ return mergeConfig(baseConfig, config);
512
+ };
513
+ };
514
+ const getSpecBaseConfig = (configEnv) => {
515
+ const { mode } = configEnv;
516
+ const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES);
517
+ const runtimeEnv = createRuntimeEnv({ env, configEnv });
518
+ const input = globSync("spec/**/*.spec.ts").reduce(
519
+ (inputs, file) => {
520
+ const relativePath = path.relative("spec", file);
521
+ const outputName = relativePath.replace(/\.ts$/, "");
522
+ inputs[outputName] = file;
523
+ return inputs;
524
+ },
525
+ {}
526
+ );
527
+ return {
528
+ clearScreen: false,
529
+ define: {
530
+ __vite_env__: runtimeEnv
531
+ },
532
+ envPrefix: ALLOWED_ENV_PREFIXES,
533
+ build: {
534
+ outDir: "./build/spec/",
535
+ ssr: true,
536
+ rollupOptions: {
537
+ input
538
+ },
539
+ commonjsOptions: { transformMixedEsModules: true }
540
+ },
541
+ resolve: {
542
+ alias: {
543
+ ...resolveAliases
544
+ },
545
+ preserveSymlinks: true
546
+ },
547
+ ssr: {
548
+ external: ["mongoose"],
549
+ noExternal: ["@rpcbase/*"]
550
+ }
551
+ };
552
+ };
553
+ const extendSpecConfig = (userConfig) => {
554
+ return async (configEnv) => {
555
+ const config = typeof userConfig === "function" ? await userConfig(configEnv) : userConfig;
556
+ const baseConfig = getSpecBaseConfig(configEnv);
557
+ return mergeConfig(baseConfig, config);
558
+ };
559
+ };
560
+ const createServer = createServer$1;
561
+ export {
562
+ createServer,
563
+ extendConfig,
564
+ extendSpecConfig,
565
+ resolveAliases
566
+ };
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function posthogSourcemapsPlugin(opts?: {
3
+ directory?: string;
4
+ version?: string;
5
+ host?: string;
6
+ deleteAfterUpload?: boolean;
7
+ }): Plugin;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/posthog-sourcemaps/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AA+BlC,wBAAgB,uBAAuB,CAAC,IAAI,GAAE;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,MAAM,CAyCd"}
@@ -0,0 +1,9 @@
1
+ import { z as zz } from '../../../../../db/src';
2
+ export declare const ZThing: zz.ZodObject<{
3
+ value: zz.ZodNumber;
4
+ }, zz.core.$strip>;
5
+ type Thing = DbSchema;
6
+ export declare const x: Thing;
7
+ export declare const leaked: import('../../../../../db/src').ModelsClient<import('../../../../../db/src/registerModels').ModelModules, Record<string, never>>;
8
+ export {};
9
+ //# sourceMappingURL=alias-and-types.input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-and-types.input.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prune-models-for-client/fixtures/alias-and-types.input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,IAAI,EAAE,EAAoC,MAAM,aAAa,CAAA;AAGvE,eAAO,MAAM,MAAM;;kBAAoC,CAAA;AAEvD,KAAK,KAAK,GAAG,QAAQ,CAAA;AACrB,eAAO,MAAM,CAAC,EAAmB,KAAK,CAAA;AAGtC,eAAO,MAAM,MAAM,wHAAS,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { z as zz } from '../../../../../db/src';
2
+ export declare const ZThing: zz.ZodObject<{
3
+ value: zz.ZodNumber;
4
+ }, zz.core.$strip>;
5
+ type Thing = DbSchema;
6
+ export declare const x: Thing;
7
+ export {};
8
+ //# sourceMappingURL=alias-and-types.output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alias-and-types.output.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prune-models-for-client/fixtures/alias-and-types.output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,aAAa,CAAA;AAGrC,eAAO,MAAM,MAAM;;kBAAoC,CAAA;AAEvD,KAAK,KAAK,GAAG,QAAQ,CAAA;AACrB,eAAO,MAAM,CAAC,EAAmB,KAAK,CAAA"}