@rpcbase/vite 0.112.0 → 0.114.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/dist/dotEnvExpand.d.ts +2 -0
- package/dist/dotEnvExpand.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +566 -0
- package/dist/plugins/posthog-sourcemaps/index.d.ts +8 -0
- package/dist/plugins/posthog-sourcemaps/index.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/index.d.ts +3 -0
- package/dist/plugins/prune-models-for-client/index.d.ts.map +1 -0
- package/dist/plugins/prune-models-for-client/transformSource.d.ts +6 -0
- package/dist/plugins/prune-models-for-client/transformSource.d.ts.map +1 -0
- package/dist/resolveIntegratedPackagePath.d.ts +2 -0
- package/dist/resolveIntegratedPackagePath.d.ts.map +1 -0
- package/package.json +53 -20
- package/index.d.ts +0 -31
- package/index.js +0 -334
- package/src/dotEnvExpand.js +0 -14
- package/src/posthogSourcemapsPlugin.js +0 -76
- package/src/resolveIntegratedPackagePath.js +0 -96
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dotEnvExpand.d.ts","sourceRoot":"","sources":["../src/dotEnvExpand.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -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 "zod"`);
|
|
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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/prune-models-for-client/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAalC,wBAAgB,0BAA0B,IAAI,MAAM,CAkBnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformSource.d.ts","sourceRoot":"","sources":["../../../src/plugins/prune-models-for-client/transformSource.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,6BAA6B,GAAG,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,GAAG,IAAI,CAAA;AAsKvG,wBAAgB,qBAAqB,IAAI,6BAA6B,CA0CrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveIntegratedPackagePath.d.ts","sourceRoot":"","sources":["../src/resolveIntegratedPackagePath.ts"],"names":[],"mappings":"AAmEA,eAAO,MAAM,4BAA4B,GAAI,WAAW,MAAM,WA4B7D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.114.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"index.d.ts",
|
|
8
|
-
"src"
|
|
6
|
+
"dist"
|
|
9
7
|
],
|
|
10
|
-
"main": "./index.js",
|
|
11
|
-
"types": "./index.d.ts",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
12
17
|
"scripts": {
|
|
13
|
-
"
|
|
18
|
+
"build": "wireit",
|
|
19
|
+
"test": "wireit",
|
|
14
20
|
"release": "wireit"
|
|
15
21
|
},
|
|
16
22
|
"wireit": {
|
|
23
|
+
"build": {
|
|
24
|
+
"command": "../../node_modules/.bin/vite build",
|
|
25
|
+
"files": [
|
|
26
|
+
"src/**/*",
|
|
27
|
+
"../../tsconfig.json",
|
|
28
|
+
"../../scripts/tsconfig.pkg.json",
|
|
29
|
+
"./tsconfig.json",
|
|
30
|
+
"./vite.config.js",
|
|
31
|
+
"../../scripts/vite.config-pkg.js"
|
|
32
|
+
],
|
|
33
|
+
"output": [
|
|
34
|
+
"dist/"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"build-watch": {
|
|
38
|
+
"command": "../../node_modules/.bin/vite build --watch",
|
|
39
|
+
"service": true
|
|
40
|
+
},
|
|
41
|
+
"test": {
|
|
42
|
+
"command": "../../node_modules/.bin/vitest run --config ../../pkg/test/src/vitest.config.mjs",
|
|
43
|
+
"files": [
|
|
44
|
+
"src/**/*",
|
|
45
|
+
"tsconfig.json",
|
|
46
|
+
"../../scripts/tsconfig.pkg.json"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": []
|
|
49
|
+
},
|
|
17
50
|
"release": {
|
|
18
51
|
"command": "../../scripts/publish.js",
|
|
19
|
-
"dependencies": [
|
|
52
|
+
"dependencies": [
|
|
53
|
+
"build"
|
|
54
|
+
],
|
|
20
55
|
"files": [
|
|
21
56
|
"../../scripts/publish.js",
|
|
22
57
|
"package.json",
|
|
23
|
-
"
|
|
24
|
-
"index.d.ts",
|
|
25
|
-
"src/"
|
|
58
|
+
"dist/**/*"
|
|
26
59
|
],
|
|
27
60
|
"output": [
|
|
28
61
|
"publish-output.txt"
|
|
@@ -36,26 +69,26 @@
|
|
|
36
69
|
},
|
|
37
70
|
"dependencies": {
|
|
38
71
|
"@hookform/resolvers": "5.2.2",
|
|
39
|
-
"@posthog/cli": "0.5.
|
|
72
|
+
"@posthog/cli": "0.5.22",
|
|
40
73
|
"@tailwindcss/vite": "4.1.18",
|
|
41
74
|
"@vitejs/plugin-react": "5.1.2",
|
|
42
75
|
"clsx": "2.1.1",
|
|
43
76
|
"glob": "13.0.0",
|
|
44
77
|
"libphonenumber-js": "1.12.33",
|
|
45
78
|
"lucide-react": "0.562.0",
|
|
46
|
-
"mongoose": "9.
|
|
47
|
-
"
|
|
48
|
-
"posthog-
|
|
49
|
-
"posthog-node": "5.18.0",
|
|
79
|
+
"mongoose": "9.1.2",
|
|
80
|
+
"posthog-js": "1.316.0",
|
|
81
|
+
"posthog-node": "5.20.0",
|
|
50
82
|
"react": "19.2.3",
|
|
51
83
|
"react-dom": "19.2.3",
|
|
52
|
-
"react-hook-form": "7.
|
|
53
|
-
"react-router": "7.
|
|
84
|
+
"react-hook-form": "7.70.0",
|
|
85
|
+
"react-router": "7.12.0",
|
|
54
86
|
"tailwindcss": "4.1.18",
|
|
87
|
+
"ts-morph": "27.0.2",
|
|
55
88
|
"validator": "13.15.26",
|
|
56
|
-
"vite": "7.3.
|
|
89
|
+
"vite": "7.3.1",
|
|
57
90
|
"vite-plugin-html": "3.2.2",
|
|
58
91
|
"vite-plugin-singlefile": "2.3.0",
|
|
59
|
-
"zod": "4.
|
|
92
|
+
"zod": "4.3.5"
|
|
60
93
|
}
|
|
61
94
|
}
|
package/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { UserConfigExport, UserConfigFn, createServer as viteCreateServer } from "vite"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Resolved aliases injected into the Vite config for RPC Base projects.
|
|
5
|
-
*/
|
|
6
|
-
export const resolveAliases: Record<string, string>
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Merge the shared RPC Base Vite config with a consumer-provided config.
|
|
10
|
-
*/
|
|
11
|
-
export function extendConfig(userConfig: UserConfigExport): UserConfigFn
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Merge the shared RPC Base spec/SSR Vite config with a consumer-provided config.
|
|
15
|
-
*/
|
|
16
|
-
export function extendSpecConfig(userConfig: UserConfigExport): UserConfigFn
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Re-export of Vite's `createServer` helper.
|
|
20
|
-
*/
|
|
21
|
-
export const createServer: typeof viteCreateServer
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Disable HTTP caching on an Express-style app (turns off etags and installs a no-cache middleware).
|
|
25
|
-
*/
|
|
26
|
-
export function disableAppCache(app: {
|
|
27
|
-
set(name: string, value: any): any
|
|
28
|
-
use: (...handlers: any[]) => any
|
|
29
|
-
}): void
|
|
30
|
-
|
|
31
|
-
export {}
|
package/index.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import "./src/dotEnvExpand.js"
|
|
2
|
-
|
|
3
|
-
import path from "path"
|
|
4
|
-
import fs from "node:fs"
|
|
5
|
-
|
|
6
|
-
import nocache from "nocache"
|
|
7
|
-
import {
|
|
8
|
-
createServer as viteCreateServer,
|
|
9
|
-
defineConfig,
|
|
10
|
-
mergeConfig,
|
|
11
|
-
loadEnv,
|
|
12
|
-
} from "vite"
|
|
13
|
-
import { viteSingleFile } from "vite-plugin-singlefile"
|
|
14
|
-
import react from "@vitejs/plugin-react"
|
|
15
|
-
import { createHtmlPlugin } from "vite-plugin-html"
|
|
16
|
-
import { glob } from "glob"
|
|
17
|
-
|
|
18
|
-
import { resolveIntegratedPackagePath } from "./src/resolveIntegratedPackagePath.js"
|
|
19
|
-
import { posthogSourcemapsPlugin } from "./src/posthogSourcemapsPlugin.js"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const ensureEnvPolyfillInjectPath = () => {
|
|
23
|
-
const injectDir = path.resolve(process.cwd(), "node_modules/.rpcbase")
|
|
24
|
-
const injectPath = path.join(injectDir, "rb-env-polyfill-inject.js")
|
|
25
|
-
const injectContents = "import \"@rpcbase/env/polyfill\"\n"
|
|
26
|
-
|
|
27
|
-
fs.mkdirSync(injectDir, { recursive: true })
|
|
28
|
-
try {
|
|
29
|
-
const existing = fs.readFileSync(injectPath, "utf8")
|
|
30
|
-
if (existing === injectContents) {
|
|
31
|
-
return injectPath
|
|
32
|
-
}
|
|
33
|
-
} catch {
|
|
34
|
-
// file does not exist yet
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fs.writeFileSync(injectPath, injectContents, "utf8")
|
|
38
|
-
return injectPath
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const esbuildInjectPath = ensureEnvPolyfillInjectPath()
|
|
42
|
-
const esbuildInject = [esbuildInjectPath]
|
|
43
|
-
const esbuildInjectPlugins = [
|
|
44
|
-
{
|
|
45
|
-
name: "rb-env-polyfill-inject",
|
|
46
|
-
setup(build) {
|
|
47
|
-
build.onResolve({ filter: /.*/ }, (args) => {
|
|
48
|
-
if (args.path === esbuildInjectPath) {
|
|
49
|
-
return { path: esbuildInjectPath, namespace: "file" }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return undefined
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// const isCI = process.env.CI === "true"
|
|
60
|
-
|
|
61
|
-
const isProduction = process.env.NODE_ENV === "production"
|
|
62
|
-
|
|
63
|
-
const ALLOWED_DEV_ENV = ["NODE_ENV", "APP_NAME"]
|
|
64
|
-
// workaround vite.ssrLoadModule not setting ssrBuild properly
|
|
65
|
-
const ALLOWED_ENV_PREFIXES = [
|
|
66
|
-
"RB_PUBLIC_",
|
|
67
|
-
...(isProduction ? [] : ALLOWED_DEV_ENV),
|
|
68
|
-
]
|
|
69
|
-
|
|
70
|
-
// https://github.com/vbenjs/vite-plugin-html?tab=readme-ov-file#minifyoptions
|
|
71
|
-
const htmlMinifyOptions = {
|
|
72
|
-
collapseWhitespace: true,
|
|
73
|
-
keepClosingSlash: true,
|
|
74
|
-
removeComments: false,
|
|
75
|
-
removeRedundantAttributes: true,
|
|
76
|
-
removeScriptTypeAttributes: true,
|
|
77
|
-
removeStyleLinkTypeAttributes: true,
|
|
78
|
-
useShortDoctype: true,
|
|
79
|
-
minifyCSS: true,
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const resolveAliases = {
|
|
83
|
-
"@/api": path.resolve(process.cwd(), "./src/api/"),
|
|
84
|
-
"@/models": path.resolve(process.cwd(), "./src/models/"),
|
|
85
|
-
"@/shared": path.resolve(process.cwd(), "./src/shared/"),
|
|
86
|
-
"@/types": path.resolve(process.cwd(), "./src/types/"),
|
|
87
|
-
"@": path.resolve(process.cwd(), "./src/client/"),
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const integratedPackages = [
|
|
91
|
-
"@hookform/resolvers",
|
|
92
|
-
"axios",
|
|
93
|
-
"events",
|
|
94
|
-
"libphonenumber-js",
|
|
95
|
-
"posthog-js",
|
|
96
|
-
"posthog-js/react",
|
|
97
|
-
"posthog-node",
|
|
98
|
-
"react-router",
|
|
99
|
-
"react-hook-form"
|
|
100
|
-
]
|
|
101
|
-
|
|
102
|
-
// Add each integrated package to resolveAliases
|
|
103
|
-
integratedPackages.forEach(pkg => {
|
|
104
|
-
const resolved = resolveIntegratedPackagePath(pkg)
|
|
105
|
-
resolveAliases[pkg] = resolved
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
resolveAliases["node:events"] = resolveIntegratedPackagePath("events")
|
|
109
|
-
|
|
110
|
-
// Force PostHog React imports to resolve to the ESM bundle to avoid Node ESM
|
|
111
|
-
// directory import errors while keeping SSR compatibility.
|
|
112
|
-
const posthogReactEsm = resolveIntegratedPackagePath("posthog-js/react/dist/esm/index.js")
|
|
113
|
-
resolveAliases["posthog-js/react"] = posthogReactEsm
|
|
114
|
-
resolveAliases["posthog-js/react/dist/esm/index.js"] = posthogReactEsm
|
|
115
|
-
|
|
116
|
-
export {resolveAliases}
|
|
117
|
-
|
|
118
|
-
const rbPackagesNeedingEnvPolyfill = [
|
|
119
|
-
"@rpcbase/auth",
|
|
120
|
-
"@rpcbase/env",
|
|
121
|
-
// "@rpcbase/env/polyfill",
|
|
122
|
-
"@rpcbase/server",
|
|
123
|
-
"@rpcbase/client",
|
|
124
|
-
"@rpcbase/form",
|
|
125
|
-
"@rpcbase/router",
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
const createRuntimeEnv = ({ env, command, mode, isSsrBuild }) => {
|
|
129
|
-
const isDevCommand = command === "serve"
|
|
130
|
-
|
|
131
|
-
const mergedEnv = {
|
|
132
|
-
...env,
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
...mergedEnv,
|
|
137
|
-
BASE_URL: mergedEnv.BASE_URL ?? "/",
|
|
138
|
-
MODE: mode,
|
|
139
|
-
DEV: isDevCommand,
|
|
140
|
-
PROD: !isDevCommand,
|
|
141
|
-
SSR: Boolean(isSsrBuild),
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// https://vite.dev/config/
|
|
146
|
-
const getBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
|
|
147
|
-
const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
|
|
148
|
-
const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
clearScreen: false,
|
|
152
|
-
plugins: [
|
|
153
|
-
react(),
|
|
154
|
-
createHtmlPlugin({
|
|
155
|
-
// IMPORTANT: minify removes comments by default, which are used by the app ssr
|
|
156
|
-
minify: htmlMinifyOptions,
|
|
157
|
-
}),
|
|
158
|
-
viteSingleFile({
|
|
159
|
-
useRecommendedBuildConfig: false,
|
|
160
|
-
deleteInlinedFiles: true,
|
|
161
|
-
inlinePattern: ["**/*.css"],
|
|
162
|
-
removeViteModuleLoader: false
|
|
163
|
-
}),
|
|
164
|
-
|
|
165
|
-
isProduction && posthogSourcemapsPlugin({}),
|
|
166
|
-
].filter(Boolean),
|
|
167
|
-
define: {
|
|
168
|
-
__vite_env__: runtimeEnv,
|
|
169
|
-
},
|
|
170
|
-
envPrefix: ALLOWED_ENV_PREFIXES,
|
|
171
|
-
publicDir: path.join(process.cwd(), "./src/client/public"),
|
|
172
|
-
build: {
|
|
173
|
-
sourcemap: isProduction ? "hidden" : false,
|
|
174
|
-
cssCodeSplit: false,
|
|
175
|
-
outDir: "./build/dist/",
|
|
176
|
-
rollupOptions: {
|
|
177
|
-
input: {
|
|
178
|
-
app: "./src/client/index.html",
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
commonjsOptions: { transformMixedEsModules: true },
|
|
182
|
-
},
|
|
183
|
-
server: {
|
|
184
|
-
allowedHosts: true,
|
|
185
|
-
headers: {
|
|
186
|
-
"Cache-Control": "no-store",
|
|
187
|
-
},
|
|
188
|
-
watch: {
|
|
189
|
-
ignored: [
|
|
190
|
-
"**/build/playwright/**",
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
resolve: {
|
|
195
|
-
alias: {
|
|
196
|
-
...resolveAliases,
|
|
197
|
-
},
|
|
198
|
-
dedupe: [
|
|
199
|
-
"react", "react-dom",
|
|
200
|
-
"react-router", "react-hook-form"
|
|
201
|
-
],
|
|
202
|
-
preserveSymlinks: true,
|
|
203
|
-
},
|
|
204
|
-
ssr: {
|
|
205
|
-
external: [
|
|
206
|
-
// "react", "react-dom",
|
|
207
|
-
"cookie",
|
|
208
|
-
"mongoose",
|
|
209
|
-
"mongodb",
|
|
210
|
-
],
|
|
211
|
-
noExternal: [
|
|
212
|
-
...rbPackagesNeedingEnvPolyfill,
|
|
213
|
-
// "react-use",
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
optimizeDeps: {
|
|
217
|
-
include: [
|
|
218
|
-
// Force RPC Base packages through esbuild so rb-env-polyfill injects before their dist code touches globalThis.__rb_env__
|
|
219
|
-
...rbPackagesNeedingEnvPolyfill,
|
|
220
|
-
"hoist-non-react-statics",
|
|
221
|
-
// "react", "react-dom", "react-dom/server"
|
|
222
|
-
// "cookie"
|
|
223
|
-
],
|
|
224
|
-
exclude: [
|
|
225
|
-
"@radix-ui/*",
|
|
226
|
-
"@rpcbase/ui",
|
|
227
|
-
// TMP only in sample app?
|
|
228
|
-
// "react", "react-dom/server",
|
|
229
|
-
// "react-hook-form",
|
|
230
|
-
// "react-dom"
|
|
231
|
-
],
|
|
232
|
-
esbuildOptions: {
|
|
233
|
-
inject: esbuildInject,
|
|
234
|
-
plugins: esbuildInjectPlugins,
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
// future: {
|
|
238
|
-
// removeSsrLoadModule: true
|
|
239
|
-
// },
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export const extendConfig = (userConfig) => {
|
|
244
|
-
return defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
|
245
|
-
let config
|
|
246
|
-
if (typeof userConfig === "function") {
|
|
247
|
-
config = userConfig({ command, mode, isSsrBuild, isPreview })
|
|
248
|
-
} else {
|
|
249
|
-
config = userConfig
|
|
250
|
-
}
|
|
251
|
-
const baseConfig = getBaseConfig({ command, mode, isSsrBuild, isPreview })
|
|
252
|
-
|
|
253
|
-
return mergeConfig(baseConfig, config)
|
|
254
|
-
})
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const getSpecBaseConfig = ({ command, mode, isSsrBuild, isPreview }) => {
|
|
258
|
-
const env = loadEnv(mode, process.cwd(), ALLOWED_ENV_PREFIXES)
|
|
259
|
-
const runtimeEnv = createRuntimeEnv({ env, command, mode, isSsrBuild })
|
|
260
|
-
|
|
261
|
-
const input = glob
|
|
262
|
-
.sync("spec/**/*.spec.ts")
|
|
263
|
-
.reduce((inputs, file) => {
|
|
264
|
-
const relativePath = path.relative("spec", file)
|
|
265
|
-
const outputName = relativePath.replace(/\.ts$/, "")
|
|
266
|
-
inputs[outputName] = file
|
|
267
|
-
return inputs
|
|
268
|
-
}, {})
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
clearScreen: false,
|
|
272
|
-
define: {
|
|
273
|
-
__vite_env__: runtimeEnv,
|
|
274
|
-
},
|
|
275
|
-
envPrefix: ALLOWED_ENV_PREFIXES,
|
|
276
|
-
build: {
|
|
277
|
-
outDir: "./build/spec/",
|
|
278
|
-
ssr: true,
|
|
279
|
-
rollupOptions: {
|
|
280
|
-
input,
|
|
281
|
-
},
|
|
282
|
-
commonjsOptions: { transformMixedEsModules: true },
|
|
283
|
-
},
|
|
284
|
-
resolve: {
|
|
285
|
-
alias: {
|
|
286
|
-
...resolveAliases,
|
|
287
|
-
},
|
|
288
|
-
preserveSymlinks: true,
|
|
289
|
-
},
|
|
290
|
-
ssr: {
|
|
291
|
-
external: ["mongoose"],
|
|
292
|
-
noExternal: ["@rpcbase/*"],
|
|
293
|
-
},
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export const extendSpecConfig = (userConfig) => {
|
|
298
|
-
return defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
|
|
299
|
-
let config
|
|
300
|
-
if (typeof userConfig === "function") {
|
|
301
|
-
config = userConfig({ command, mode, isSsrBuild, isPreview })
|
|
302
|
-
} else {
|
|
303
|
-
config = userConfig
|
|
304
|
-
}
|
|
305
|
-
const baseConfig = getSpecBaseConfig({ command, mode, isSsrBuild, isPreview })
|
|
306
|
-
|
|
307
|
-
return mergeConfig(baseConfig, config)
|
|
308
|
-
})
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
export const createServer = viteCreateServer
|
|
313
|
-
// export const createServer = async (config /* : Record<string, any>*/) => {
|
|
314
|
-
// const env = {
|
|
315
|
-
// command: "serve",
|
|
316
|
-
// mode: process.env.NODE_ENV ?? "development",
|
|
317
|
-
// isSsrBuild: false,
|
|
318
|
-
// isPreview: false,
|
|
319
|
-
// }
|
|
320
|
-
|
|
321
|
-
// const extendedConfig = extendConfig(config)(env)
|
|
322
|
-
// delete extendedConfig.plugins
|
|
323
|
-
|
|
324
|
-
// const viteServer = await viteCreateServer(extendedConfig)
|
|
325
|
-
|
|
326
|
-
// return viteServer
|
|
327
|
-
// }
|
|
328
|
-
|
|
329
|
-
// TODO: I think is is unused, verify and remove if so
|
|
330
|
-
export const disableAppCache = (app) => {
|
|
331
|
-
app.set("etag", false)
|
|
332
|
-
|
|
333
|
-
app.use(nocache())
|
|
334
|
-
}
|
package/src/dotEnvExpand.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import fs from "fs"
|
|
2
|
-
import path from "path"
|
|
3
|
-
|
|
4
|
-
import dotenv from "dotenv"
|
|
5
|
-
import {expand} from "dotenv-expand"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const envFilePath = path.resolve(process.cwd(), ".env")
|
|
9
|
-
|
|
10
|
-
if (fs.existsSync(envFilePath)) {
|
|
11
|
-
const parsedFile = dotenv.parse(fs.readFileSync(envFilePath))
|
|
12
|
-
const expanded = expand({ parsed: parsedFile }).parsed || {}
|
|
13
|
-
Object.assign(process.env, expanded)
|
|
14
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import fs from "node:fs"
|
|
4
|
-
import { fileURLToPath } from "node:url"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
-
|
|
9
|
-
function run(bin, args) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const p = spawn(bin, args, { stdio: "inherit" })
|
|
12
|
-
p.on("close", code => code === 0 ? resolve() : reject(new Error(`posthog-cli exited ${code}`)))
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function resolvePosthogCliBin() {
|
|
17
|
-
const binName = "posthog-cli"
|
|
18
|
-
|
|
19
|
-
const fromCwd = path.join(process.cwd(), "node_modules", ".bin", binName)
|
|
20
|
-
if (fs.existsSync(fromCwd)) return fromCwd
|
|
21
|
-
|
|
22
|
-
let dir = __dirname
|
|
23
|
-
while (true) {
|
|
24
|
-
const candidate = path.join(dir, "node_modules", ".bin", binName)
|
|
25
|
-
if (fs.existsSync(candidate)) return candidate
|
|
26
|
-
|
|
27
|
-
const parent = path.dirname(dir)
|
|
28
|
-
if (parent === dir) break
|
|
29
|
-
dir = parent
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return binName
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function posthogSourcemapsPlugin(opts = {}) {
|
|
36
|
-
const {
|
|
37
|
-
directory = "build/dist",
|
|
38
|
-
version,
|
|
39
|
-
host = process.env.RB_PUBLIC_POSTHOG_HOST || "https://eu.posthog.com",
|
|
40
|
-
deleteAfterUpload = true
|
|
41
|
-
} = opts
|
|
42
|
-
|
|
43
|
-
const bin = resolvePosthogCliBin()
|
|
44
|
-
const globalArgs = ["--host", host]
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
name: "posthog-sourcemaps",
|
|
48
|
-
apply: "build",
|
|
49
|
-
closeBundle: async () => {
|
|
50
|
-
const orange = "\x1b[38;5;208m"
|
|
51
|
-
const reset = "\x1b[0m"
|
|
52
|
-
|
|
53
|
-
const envId = process.env.POSTHOG_CLI_ENV_ID
|
|
54
|
-
const token = process.env.POSTHOG_CLI_TOKEN
|
|
55
|
-
if (!envId || !token) {
|
|
56
|
-
|
|
57
|
-
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}`)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// if (!process.env.CI) {
|
|
62
|
-
// console.warn(`${orange}posthog-sourcemaps: plugin has correct configuration, but refusing to run when process.env.CI is not set. Skipping without failing.${reset}`)
|
|
63
|
-
// return
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
const injectArgs = ["sourcemap", "inject", "--directory", directory]
|
|
67
|
-
if (version) injectArgs.push("--version", version)
|
|
68
|
-
|
|
69
|
-
const uploadArgs = ["sourcemap", "upload", "--directory", directory]
|
|
70
|
-
if (deleteAfterUpload) uploadArgs.push("--delete-after")
|
|
71
|
-
|
|
72
|
-
await run(bin, [...globalArgs, ...injectArgs])
|
|
73
|
-
await run(bin, [...globalArgs, ...uploadArgs])
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import path from "path"
|
|
2
|
-
import { createRequire } from "module"
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url)
|
|
7
|
-
|
|
8
|
-
const splitPackageSpecifier = (specifier) => {
|
|
9
|
-
if (!specifier) return { pkgName: specifier, subpath: "" }
|
|
10
|
-
|
|
11
|
-
if (specifier.startsWith("@")) {
|
|
12
|
-
const segments = specifier.split("/")
|
|
13
|
-
if (segments.length < 2) return { pkgName: specifier, subpath: "" }
|
|
14
|
-
return {
|
|
15
|
-
pkgName: `${segments[0]}/${segments[1]}`,
|
|
16
|
-
subpath: segments.slice(2).join("/"),
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const [pkgName, ...rest] = specifier.split("/")
|
|
21
|
-
return { pkgName, subpath: rest.join("/") }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const withTrailingSep = p => (p.endsWith(path.sep) ? p : p + path.sep)
|
|
25
|
-
|
|
26
|
-
const resolvePackageRoot = (pkg) => {
|
|
27
|
-
const { pkgName } = splitPackageSpecifier(pkg)
|
|
28
|
-
if (!pkgName) return pkg
|
|
29
|
-
|
|
30
|
-
// 1) chemin rapide: si le package exporte son package.json
|
|
31
|
-
try {
|
|
32
|
-
const pkgJson = require.resolve(`${pkgName}/package.json`)
|
|
33
|
-
return path.dirname(pkgJson)
|
|
34
|
-
} catch (err) {
|
|
35
|
-
// 2) fallback: résoudre l'entrée du package puis remonter jusqu'à sa racine
|
|
36
|
-
const entry = require.resolve(pkgName) // ex: .../node_modules/<pkg>/dist/...
|
|
37
|
-
let dir = path.dirname(entry)
|
|
38
|
-
|
|
39
|
-
// remonter jusqu'à un package.json dont "name" === pkg
|
|
40
|
-
while (true) {
|
|
41
|
-
const pkgJsonPath = path.join(dir, "package.json")
|
|
42
|
-
if (existsSync(pkgJsonPath)) {
|
|
43
|
-
try {
|
|
44
|
-
const json = JSON.parse(readFileSync(pkgJsonPath, "utf8"))
|
|
45
|
-
if (json && json.name === pkgName) return dir
|
|
46
|
-
} catch {
|
|
47
|
-
// ignore parsing errors
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const parent = path.dirname(dir)
|
|
51
|
-
if (parent === dir) break
|
|
52
|
-
dir = parent
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 3) dernier recours: reconstruire depuis le segment node_modules (ok avec pnpm)
|
|
56
|
-
const nmMarker = `${path.sep}node_modules${path.sep}`
|
|
57
|
-
const idx = entry.lastIndexOf(nmMarker)
|
|
58
|
-
if (idx !== -1) {
|
|
59
|
-
const nmRoot = entry.slice(0, idx + nmMarker.length)
|
|
60
|
-
return path.join(nmRoot, pkgName)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// si vraiment rien trouvé, relancer l'erreur d'origine
|
|
64
|
-
throw err
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const resolveIntegratedPackagePath = (specifier) => {
|
|
69
|
-
const { pkgName, subpath } = splitPackageSpecifier(specifier)
|
|
70
|
-
if (!pkgName) return specifier
|
|
71
|
-
|
|
72
|
-
const root = resolvePackageRoot(pkgName)
|
|
73
|
-
if (!subpath) {
|
|
74
|
-
return withTrailingSep(root)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const subDir = path.join(root, subpath)
|
|
78
|
-
const pkgJsonPath = path.join(subDir, "package.json")
|
|
79
|
-
if (existsSync(pkgJsonPath)) {
|
|
80
|
-
try {
|
|
81
|
-
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8"))
|
|
82
|
-
const entry = pkgJson.module || pkgJson.main
|
|
83
|
-
if (entry) {
|
|
84
|
-
return path.join(subDir, entry)
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// ignore parsing errors
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
return require.resolve(specifier)
|
|
93
|
-
} catch {
|
|
94
|
-
return withTrailingSep(subDir)
|
|
95
|
-
}
|
|
96
|
-
}
|