@cedarjs/project-config 7.0.1-next.467 → 7.1.0-rc.32

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 (40) hide show
  1. package/dist/cjs/config.d.ts +154 -0
  2. package/dist/cjs/config.d.ts.map +1 -0
  3. package/dist/cjs/configPath.d.ts +5 -0
  4. package/dist/cjs/configPath.d.ts.map +1 -0
  5. package/dist/cjs/envVarDefinitions.d.ts +14 -0
  6. package/dist/cjs/envVarDefinitions.d.ts.map +1 -0
  7. package/dist/cjs/envVars.d.ts +32 -0
  8. package/dist/cjs/envVars.d.ts.map +1 -0
  9. package/dist/cjs/findUp.d.ts +5 -0
  10. package/dist/cjs/findUp.d.ts.map +1 -0
  11. package/dist/cjs/generatedDataDir.d.ts +10 -0
  12. package/dist/cjs/generatedDataDir.d.ts.map +1 -0
  13. package/dist/cjs/index.d.ts +9 -0
  14. package/dist/cjs/index.d.ts.map +1 -0
  15. package/dist/cjs/index.js +782 -0
  16. package/dist/cjs/package.json +1 -0
  17. package/dist/cjs/packageManager.d.ts +20 -0
  18. package/dist/cjs/packageManager.d.ts.map +1 -0
  19. package/dist/cjs/packageManager.js +349 -0
  20. package/dist/cjs/paths.d.ts +152 -0
  21. package/dist/cjs/paths.d.ts.map +1 -0
  22. package/dist/cjs/prisma.d.ts +99 -0
  23. package/dist/cjs/prisma.d.ts.map +1 -0
  24. package/dist/cjs/prismaClientOutputDirsWorker.d.ts +2 -0
  25. package/dist/cjs/prismaClientOutputDirsWorker.d.ts.map +1 -0
  26. package/dist/cjs/prismaClientOutputDirsWorkerUrl.d.ts +2 -0
  27. package/dist/cjs/prismaClientOutputDirsWorkerUrl.d.ts.map +1 -0
  28. package/dist/cjs/workspaces.d.ts +2 -0
  29. package/dist/cjs/workspaces.d.ts.map +1 -0
  30. package/dist/cjs/workspaces.js +376 -0
  31. package/dist/config.d.ts +3 -47
  32. package/dist/config.d.ts.map +1 -1
  33. package/dist/index.js +30 -30
  34. package/dist/package.json +1 -0
  35. package/dist/packageManager.js +1 -2
  36. package/dist/paths.d.ts +3 -0
  37. package/dist/paths.d.ts.map +1 -1
  38. package/dist/prismaClientOutputDirsWorker.js +1 -2
  39. package/dist/workspaces.js +1 -2
  40. package/package.json +31 -13
@@ -0,0 +1,782 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
15
+ };
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // src/prismaClientOutputDirsWorkerUrl.ts
39
+ var prismaClientOutputDirsWorkerUrl_exports = {};
40
+ __export(prismaClientOutputDirsWorkerUrl_exports, {
41
+ prismaClientOutputDirsWorkerUrl: () => prismaClientOutputDirsWorkerUrl
42
+ });
43
+ var import_meta, prismaClientOutputDirsWorkerUrl;
44
+ var init_prismaClientOutputDirsWorkerUrl = __esm({
45
+ "src/prismaClientOutputDirsWorkerUrl.ts"() {
46
+ "use strict";
47
+ import_meta = {};
48
+ prismaClientOutputDirsWorkerUrl = new URL(
49
+ "./prismaClientOutputDirsWorker.js",
50
+ import_meta.url
51
+ );
52
+ }
53
+ });
54
+
55
+ // src/index.ts
56
+ var index_exports = {};
57
+ __export(index_exports, {
58
+ DEFAULT_CONFIG: () => DEFAULT_CONFIG,
59
+ TargetEnum: () => TargetEnum,
60
+ createPrismaClientFileMatcher: () => createPrismaClientFileMatcher,
61
+ ensurePosixPath: () => ensurePosixPath,
62
+ findUp: () => findUp,
63
+ getAppRouteHook: () => getAppRouteHook,
64
+ getBaseDir: () => getBaseDir,
65
+ getBaseDirFromFile: () => getBaseDirFromFile,
66
+ getBuiltDocumentFile: () => getBuiltDocumentFile,
67
+ getBuiltServerEntryFile: () => getBuiltServerEntryFile,
68
+ getConfig: () => getConfig,
69
+ getConfigPath: () => getConfigPath,
70
+ getDataMigrationsPath: () => getDataMigrationsPath,
71
+ getDbDir: () => getDbDir,
72
+ getEnvVarDefinitions: () => getEnvVarDefinitions,
73
+ getGeneratedDataDirPath: () => getGeneratedDataDirPath,
74
+ getMigrationsPath: () => getMigrationsPath,
75
+ getPaths: () => getPaths,
76
+ getPrismaClientOutputDirs: () => getPrismaClientOutputDirs,
77
+ getPrismaClientOutputDirsIsolated: () => getPrismaClientOutputDirsIsolated,
78
+ getPrismaDatasourceProvider: () => getPrismaDatasourceProvider,
79
+ getPrismaSchemas: () => getPrismaSchemas,
80
+ getRawConfig: () => getRawConfig,
81
+ getRouteHookForPage: () => getRouteHookForPage,
82
+ getSchemaPath: () => getSchemaPath,
83
+ importStatementPath: () => importStatementPath,
84
+ isTypeScriptProject: () => isTypeScriptProject,
85
+ loadPrismaConfig: () => loadPrismaConfig,
86
+ parsePort: () => parsePort,
87
+ processPagesDir: () => processPagesDir,
88
+ projectIsEsm: () => projectIsEsm,
89
+ projectRootIsEsm: () => projectRootIsEsm,
90
+ projectSideIsEsm: () => projectSideIsEsm,
91
+ readEnvVar: () => readEnvVar,
92
+ resolveFile: () => resolveFile,
93
+ resolveGeneratedPrismaClient: () => resolveGeneratedPrismaClient
94
+ });
95
+ module.exports = __toCommonJS(index_exports);
96
+
97
+ // src/config.ts
98
+ var import_node_fs2 = __toESM(require("node:fs"), 1);
99
+ var import_deepmerge = __toESM(require("deepmerge"), 1);
100
+ var toml = __toESM(require("smol-toml"), 1);
101
+ var import_string_env_interpolation = require("string-env-interpolation");
102
+
103
+ // src/findUp.ts
104
+ var import_node_fs = __toESM(require("node:fs"), 1);
105
+ var import_path = __toESM(require("path"), 1);
106
+ function findUp(file, startingDirectory = process.cwd()) {
107
+ const possibleFilepath = import_path.default.join(startingDirectory, file);
108
+ if (import_node_fs.default.existsSync(possibleFilepath)) {
109
+ return possibleFilepath;
110
+ }
111
+ const parentDirectory = import_path.default.dirname(startingDirectory);
112
+ if (parentDirectory === startingDirectory) {
113
+ return null;
114
+ }
115
+ return findUp(file, parentDirectory);
116
+ }
117
+
118
+ // src/configPath.ts
119
+ var CONFIG_FILE_NAMES = ["cedar.toml", "redwood.toml"];
120
+ var getConfigPathCache = /* @__PURE__ */ new Map();
121
+ var getConfigPath = (cwd = process.env.CEDAR_CWD ?? process.env.RWJS_CWD ?? process.cwd()) => {
122
+ const cachedPath = getConfigPathCache.get(cwd);
123
+ if (cachedPath) {
124
+ return cachedPath;
125
+ }
126
+ const configPath = findUp("cedar.toml", cwd) || findUp("redwood.toml", cwd);
127
+ if (!configPath) {
128
+ throw new Error(
129
+ `Could not find a "${CONFIG_FILE_NAMES.join('" or "')}" file, are you sure you're in a Cedar project?`
130
+ );
131
+ }
132
+ getConfigPathCache.set(cwd, configPath);
133
+ return configPath;
134
+ };
135
+
136
+ // src/config.ts
137
+ var TargetEnum = /* @__PURE__ */ ((TargetEnum2) => {
138
+ TargetEnum2["NODE"] = "node";
139
+ TargetEnum2["BROWSER"] = "browser";
140
+ TargetEnum2["REACT_NATIVE"] = "react-native";
141
+ TargetEnum2["ELECTRON"] = "electron";
142
+ return TargetEnum2;
143
+ })(TargetEnum || {});
144
+ var DEFAULT_CONFIG = {
145
+ web: {
146
+ title: "Cedar App",
147
+ port: 8910,
148
+ path: "./web",
149
+ target: "browser" /* BROWSER */,
150
+ includeEnvironmentVariables: [],
151
+ apiUrl: "/.api/functions",
152
+ fastRefresh: true,
153
+ a11y: true,
154
+ sourceMap: false
155
+ },
156
+ api: {
157
+ title: "Cedar App",
158
+ port: 8911,
159
+ path: "./api",
160
+ target: "node" /* NODE */,
161
+ prismaConfig: "./api/prisma.config.cjs",
162
+ prismaGenerateArgs: [],
163
+ serverConfig: "./api/server.config.js",
164
+ debugPort: void 0
165
+ },
166
+ graphql: {
167
+ fragments: false,
168
+ trustedDocuments: false,
169
+ includeScalars: { File: true }
170
+ },
171
+ browser: {
172
+ open: false
173
+ },
174
+ generate: {
175
+ tests: true,
176
+ stories: true,
177
+ nestScaffoldByModel: true
178
+ },
179
+ notifications: {
180
+ versionUpdates: []
181
+ },
182
+ studio: {
183
+ basePort: 4318,
184
+ graphiql: {
185
+ authImpersonation: {
186
+ authProvider: void 0,
187
+ userId: void 0,
188
+ email: void 0,
189
+ jwtSecret: "secret"
190
+ }
191
+ }
192
+ },
193
+ test: {
194
+ autoConsentToDbReset: false
195
+ },
196
+ experimental: {
197
+ opentelemetry: {
198
+ enabled: false,
199
+ wrapApi: true
200
+ },
201
+ cli: {
202
+ autoInstall: true,
203
+ plugins: [
204
+ {
205
+ package: "@cedarjs/cli-storybook-vite"
206
+ },
207
+ {
208
+ package: "@cedarjs/cli-data-migrate"
209
+ }
210
+ ]
211
+ },
212
+ useSDLCodeGenForGraphQLTypes: false,
213
+ streamingSsr: {
214
+ enabled: false
215
+ },
216
+ rsc: {
217
+ enabled: false
218
+ },
219
+ realtime: {
220
+ enabled: false
221
+ },
222
+ reactCompiler: {
223
+ enabled: false,
224
+ lintOnly: false
225
+ },
226
+ packagesWorkspace: {
227
+ enabled: false
228
+ },
229
+ gqlorm: {
230
+ enabled: false,
231
+ organizationModel: "Organization",
232
+ membershipModel: "Membership",
233
+ membershipUserField: "userId",
234
+ membershipOrganizationField: "organizationId"
235
+ }
236
+ }
237
+ };
238
+ function getConfig(configPath) {
239
+ const config = (0, import_deepmerge.default)(DEFAULT_CONFIG, getRawConfig(configPath));
240
+ return config;
241
+ }
242
+ function getRawConfig(configPath = getConfigPath()) {
243
+ try {
244
+ return toml.parse((0, import_string_env_interpolation.env)(import_node_fs2.default.readFileSync(configPath, "utf8")));
245
+ } catch (e) {
246
+ throw new Error(`Could not parse "${configPath}": ${e}`);
247
+ }
248
+ }
249
+
250
+ // src/envVars.ts
251
+ function readEnvVar(name, { deprecatedAlias }) {
252
+ return process.env[name] || process.env[deprecatedAlias] || void 0;
253
+ }
254
+ function parsePort(value, envVarName) {
255
+ const trimmed = value.trim();
256
+ if (!/^\d+$/.test(trimmed)) {
257
+ throw new Error(
258
+ `Invalid ${envVarName} env var value: "${value}". Must be an integer.`
259
+ );
260
+ }
261
+ const port = Number(trimmed);
262
+ if (port > 65535) {
263
+ throw new Error(
264
+ `Invalid ${envVarName} env var value: "${value}". Must be between 0 and 65535.`
265
+ );
266
+ }
267
+ return port;
268
+ }
269
+
270
+ // src/generatedDataDir.ts
271
+ var import_node_fs3 = __toESM(require("node:fs"), 1);
272
+ var import_node_path = __toESM(require("node:path"), 1);
273
+ function getGeneratedDataDirPath(cwd = process.env.CEDAR_CWD ?? process.env.RWJS_CWD ?? process.cwd()) {
274
+ const configPath = getConfigPath(cwd);
275
+ const projectRoot = import_node_path.default.dirname(configPath);
276
+ const rootDotCedarDir = import_node_path.default.join(projectRoot, ".cedar");
277
+ const rootDotRedwoodDir = import_node_path.default.join(projectRoot, ".redwood");
278
+ const generatedDirPath = import_node_fs3.default.existsSync(rootDotCedarDir) ? rootDotCedarDir : import_node_fs3.default.existsSync(rootDotRedwoodDir) ? rootDotRedwoodDir : rootDotCedarDir;
279
+ return generatedDirPath;
280
+ }
281
+
282
+ // src/paths.ts
283
+ var import_node_fs4 = __toESM(require("node:fs"), 1);
284
+ var import_path2 = __toESM(require("path"), 1);
285
+ var import_fast_glob = __toESM(require("fast-glob"), 1);
286
+ var getBaseDir = (configPath = getConfigPath()) => {
287
+ return import_path2.default.dirname(configPath);
288
+ };
289
+ var getBaseDirFromFile = (file) => {
290
+ return getBaseDir(getConfigPath(import_path2.default.dirname(file)));
291
+ };
292
+ var resolveFile = (filePath, extensions = [".js", ".tsx", ".ts", ".jsx", ".mjs", ".mts", ".cjs"]) => {
293
+ for (const extension of extensions) {
294
+ const p = `${filePath}${extension}`;
295
+ if (import_node_fs4.default.existsSync(p)) {
296
+ return p;
297
+ }
298
+ }
299
+ return null;
300
+ };
301
+ var getPathsCache = /* @__PURE__ */ new Map();
302
+ function getPaths(BASE_DIR = getBaseDir()) {
303
+ if (getPathsCache.has(BASE_DIR)) {
304
+ return getPathsCache.get(BASE_DIR);
305
+ }
306
+ const routes = resolveFile(import_path2.default.join(BASE_DIR, "web/src/Routes"));
307
+ const { prismaConfig: prismaConfigFromConfig } = getConfig(
308
+ getConfigPath(BASE_DIR)
309
+ ).api;
310
+ const prismaConfigBase = import_path2.default.join(
311
+ BASE_DIR,
312
+ prismaConfigFromConfig.replace(/\.[^.]+$/, "")
313
+ );
314
+ const prismaConfig = resolveFile(prismaConfigBase) || import_path2.default.join(BASE_DIR, prismaConfigFromConfig);
315
+ const viteConfig = resolveFile(
316
+ import_path2.default.join(BASE_DIR, "web/vite.config")
317
+ );
318
+ const generatedBase = getGeneratedDataDirPath(BASE_DIR);
319
+ const paths = {
320
+ base: BASE_DIR,
321
+ generated: {
322
+ base: generatedBase,
323
+ schema: import_path2.default.join(generatedBase, "schema.graphql"),
324
+ types: {
325
+ includes: import_path2.default.join(generatedBase, "types/includes"),
326
+ mirror: import_path2.default.join(generatedBase, "types/mirror")
327
+ },
328
+ prebuild: import_path2.default.join(generatedBase, "prebuild")
329
+ },
330
+ scripts: import_path2.default.join(BASE_DIR, "scripts"),
331
+ packages: import_path2.default.join(BASE_DIR, "packages"),
332
+ generatorTemplates: import_path2.default.join(BASE_DIR, "generatorTemplates"),
333
+ api: {
334
+ base: import_path2.default.join(BASE_DIR, "api"),
335
+ prismaConfig,
336
+ functions: import_path2.default.join(BASE_DIR, "api/src/functions"),
337
+ graphql: import_path2.default.join(BASE_DIR, "api/src/graphql"),
338
+ lib: import_path2.default.join(BASE_DIR, "api/src/lib"),
339
+ config: import_path2.default.join(BASE_DIR, "api/src/config"),
340
+ services: import_path2.default.join(BASE_DIR, "api/src/services"),
341
+ directives: import_path2.default.join(BASE_DIR, "api/src/directives"),
342
+ subscriptions: import_path2.default.join(BASE_DIR, "api/src/subscriptions"),
343
+ src: import_path2.default.join(BASE_DIR, "api/src"),
344
+ dist: import_path2.default.join(BASE_DIR, "api/dist"),
345
+ types: import_path2.default.join(BASE_DIR, "api/types"),
346
+ models: import_path2.default.join(BASE_DIR, "api/src/models"),
347
+ mail: import_path2.default.join(BASE_DIR, "api/src", "mail"),
348
+ jobs: import_path2.default.join(BASE_DIR, "api/src/jobs"),
349
+ distJobs: import_path2.default.join(BASE_DIR, "api/dist/jobs"),
350
+ jobsConfig: resolveFile(import_path2.default.join(BASE_DIR, "api/src/lib", "jobs")),
351
+ distJobsConfig: resolveFile(
352
+ import_path2.default.join(BASE_DIR, "api/dist", "lib", "jobs")
353
+ ),
354
+ logger: resolveFile(import_path2.default.join(BASE_DIR, "api/src/lib", "logger"))
355
+ },
356
+ web: {
357
+ routes,
358
+ base: import_path2.default.join(BASE_DIR, "web"),
359
+ pages: import_path2.default.join(BASE_DIR, "web/src/pages/"),
360
+ components: import_path2.default.join(BASE_DIR, "web/src/components"),
361
+ layouts: import_path2.default.join(BASE_DIR, "web/src/layouts/"),
362
+ src: import_path2.default.join(BASE_DIR, "web/src"),
363
+ storybook: import_path2.default.join(BASE_DIR, "web/.storybook"),
364
+ app: resolveFile(import_path2.default.join(BASE_DIR, "web/src/App")),
365
+ document: resolveFile(import_path2.default.join(BASE_DIR, "web/src/Document")),
366
+ html: import_path2.default.join(BASE_DIR, "web/index.html"),
367
+ config: import_path2.default.join(BASE_DIR, "web/config"),
368
+ viteConfig,
369
+ postcss: import_path2.default.join(BASE_DIR, "web/config/postcss.config.cjs"),
370
+ storybookConfig: import_path2.default.join(BASE_DIR, "web/.storybook/main.js"),
371
+ storybookPreviewConfig: resolveFile(
372
+ import_path2.default.join(BASE_DIR, "web/.storybook/preview")
373
+ ),
374
+ storybookManagerConfig: import_path2.default.join(BASE_DIR, "web/.storybook/manager.js"),
375
+ dist: import_path2.default.join(BASE_DIR, "web/dist"),
376
+ distBrowser: import_path2.default.join(BASE_DIR, "web/dist/browser"),
377
+ distRsc: import_path2.default.join(BASE_DIR, "web/dist/rsc"),
378
+ distSsr: import_path2.default.join(BASE_DIR, "web/dist/ssr"),
379
+ distSsrDocument: import_path2.default.join(BASE_DIR, "web/dist/ssr/Document"),
380
+ distSsrEntryServer: import_path2.default.join(BASE_DIR, "web/dist/ssr/entry.server"),
381
+ distRouteHooks: import_path2.default.join(BASE_DIR, "web/dist/ssr/routeHooks"),
382
+ distRscEntries: import_path2.default.join(BASE_DIR, "web/dist/rsc/entries.mjs"),
383
+ routeManifest: import_path2.default.join(BASE_DIR, "web/dist/ssr/route-manifest.json"),
384
+ types: import_path2.default.join(BASE_DIR, "web/types"),
385
+ entryClient: resolveFile(import_path2.default.join(BASE_DIR, "web/src/entry.client")),
386
+ // new vite/stream entry point for client
387
+ entryServer: resolveFile(import_path2.default.join(BASE_DIR, "web/src/entry.server")),
388
+ graphql: import_path2.default.join(BASE_DIR, "web/src/graphql")
389
+ }
390
+ };
391
+ import_node_fs4.default.mkdirSync(paths.generated.types.includes, { recursive: true });
392
+ import_node_fs4.default.mkdirSync(paths.generated.types.mirror, { recursive: true });
393
+ getPathsCache.set(BASE_DIR, paths);
394
+ return paths;
395
+ }
396
+ var getRouteHookForPage = (pagePath) => {
397
+ if (!pagePath) {
398
+ return null;
399
+ }
400
+ return import_fast_glob.default.sync("*.routeHooks.{js,ts,tsx,jsx}", {
401
+ absolute: true,
402
+ cwd: import_path2.default.dirname(pagePath)
403
+ // the page's folder
404
+ }).at(0) || null;
405
+ };
406
+ var getAppRouteHook = (forProd = false) => {
407
+ const rwPaths = getPaths();
408
+ if (forProd) {
409
+ const distAppRouteHook = import_path2.default.join(
410
+ rwPaths.web.distRouteHooks,
411
+ "App.routeHooks.js"
412
+ );
413
+ try {
414
+ import_node_fs4.default.statSync(distAppRouteHook).isFile();
415
+ return distAppRouteHook;
416
+ } catch {
417
+ return null;
418
+ }
419
+ }
420
+ return resolveFile(import_path2.default.join(rwPaths.web.src, "App.routeHooks"));
421
+ };
422
+ function getBuiltServerEntryFile() {
423
+ const entryServer = getPaths().web.distSsrEntryServer;
424
+ const resolvedEntryServer = resolveFile(entryServer);
425
+ if (!resolvedEntryServer) {
426
+ throw new Error("Server entry file not found (" + entryServer + ")");
427
+ }
428
+ return resolvedEntryServer;
429
+ }
430
+ function getBuiltDocumentFile() {
431
+ const document = getPaths().web.distSsrDocument;
432
+ const resolvedDocument = resolveFile(document);
433
+ if (!resolvedDocument) {
434
+ throw new Error("Document file not found (" + document + ")");
435
+ }
436
+ return resolvedDocument;
437
+ }
438
+ var processPagesDir = (webPagesDir = getPaths().web.pages) => {
439
+ const pagePaths = import_fast_glob.default.sync("**/*Page.{js,jsx,ts,tsx}", {
440
+ cwd: webPagesDir,
441
+ ignore: ["node_modules"]
442
+ });
443
+ return pagePaths.map((pagePath) => {
444
+ const p = import_path2.default.parse(pagePath);
445
+ const importName = p.dir.replace(/\//g, "");
446
+ const importPath = importStatementPath(
447
+ import_path2.default.join(webPagesDir, p.dir, p.name)
448
+ );
449
+ const importStatement = `const ${importName} = { name: '${importName}', loader: import('${importPath}') }`;
450
+ return {
451
+ importName,
452
+ constName: importName,
453
+ importPath,
454
+ path: import_path2.default.join(webPagesDir, pagePath),
455
+ importStatement
456
+ };
457
+ });
458
+ };
459
+ var ensurePosixPath = (path7) => {
460
+ let posixPath = path7;
461
+ if (process.platform === "win32") {
462
+ if (/^[A-Z]:\\/.test(path7)) {
463
+ const drive = path7[0].toLowerCase();
464
+ posixPath = `/${drive}/${path7.substring(3)}`;
465
+ }
466
+ posixPath = posixPath.replace(/\\/g, "/");
467
+ }
468
+ return posixPath;
469
+ };
470
+ var importStatementPath = (path7) => {
471
+ let importPath = path7;
472
+ if (process.platform === "win32") {
473
+ importPath = importPath.replaceAll("\\", "/");
474
+ }
475
+ return importPath;
476
+ };
477
+ function packageJsonIsEsm(packageJsonPath) {
478
+ const packageJsonContents = JSON.parse(
479
+ import_node_fs4.default.readFileSync(packageJsonPath, "utf-8")
480
+ );
481
+ return packageJsonContents.type === "module";
482
+ }
483
+ function projectRootIsEsm() {
484
+ return packageJsonIsEsm(import_path2.default.join(getPaths().base, "package.json"));
485
+ }
486
+ function projectSideIsEsm(side) {
487
+ const cedarProjectPaths = getPaths();
488
+ return packageJsonIsEsm(
489
+ import_path2.default.join(cedarProjectPaths[side].base, "package.json")
490
+ );
491
+ }
492
+ function projectIsEsm() {
493
+ if (!projectRootIsEsm()) {
494
+ return false;
495
+ }
496
+ for (const side of ["api", "web"]) {
497
+ if (!projectSideIsEsm(side)) {
498
+ return false;
499
+ }
500
+ }
501
+ return true;
502
+ }
503
+ var isTypeScriptProject = () => {
504
+ const paths = getPaths();
505
+ return import_node_fs4.default.existsSync(import_path2.default.join(paths.web.base, "tsconfig.json")) || import_node_fs4.default.existsSync(import_path2.default.join(paths.api.base, "tsconfig.json"));
506
+ };
507
+
508
+ // src/prisma.ts
509
+ var import_node_fs6 = __toESM(require("node:fs"), 1);
510
+ var import_node_path3 = __toESM(require("node:path"), 1);
511
+ var import_node_url = require("node:url");
512
+ var import_node_worker_threads = require("node:worker_threads");
513
+
514
+ // src/packageManager.ts
515
+ var import_node_fs5 = __toESM(require("node:fs"), 1);
516
+ var import_node_path2 = __toESM(require("node:path"), 1);
517
+ var packageManagerCache;
518
+ function getPackageManager() {
519
+ if (packageManagerCache) {
520
+ return packageManagerCache;
521
+ }
522
+ const base = getPaths().base;
523
+ packageManagerCache = "yarn";
524
+ const envPackageManager = process.env.npm_config_user_agent?.split(" ")[0]?.split("/")[0];
525
+ if (isPackageManager(envPackageManager)) {
526
+ packageManagerCache = envPackageManager;
527
+ } else if (import_node_fs5.default.existsSync(import_node_path2.default.join(base, "yarn.lock"))) {
528
+ packageManagerCache = "yarn";
529
+ } else if (import_node_fs5.default.existsSync(import_node_path2.default.join(base, "pnpm-lock.yaml"))) {
530
+ packageManagerCache = "pnpm";
531
+ } else if (import_node_fs5.default.existsSync(import_node_path2.default.join(base, "package-lock.json"))) {
532
+ packageManagerCache = "npm";
533
+ }
534
+ return packageManagerCache;
535
+ }
536
+ function isPackageManager(pm) {
537
+ return pm === "yarn" || pm === "npm" || pm === "pnpm";
538
+ }
539
+ function prettyPrintCedarCommand(args) {
540
+ const packageManager = getPackageManager();
541
+ const packageManagerBin = packageManager === "npm" ? "npx" : packageManager;
542
+ return `${packageManagerBin} cedar ${args.join(" ")}`;
543
+ }
544
+
545
+ // src/prisma.ts
546
+ var configCache = /* @__PURE__ */ new Map();
547
+ async function loadPrismaConfig(prismaConfigPath) {
548
+ if (!import_node_fs6.default.existsSync(prismaConfigPath)) {
549
+ throw new Error(`Prisma config file not found at: ${prismaConfigPath}`);
550
+ }
551
+ if (configCache.has(prismaConfigPath)) {
552
+ return configCache.get(prismaConfigPath);
553
+ }
554
+ const configUrl = (0, import_node_url.pathToFileURL)(prismaConfigPath).href;
555
+ let config;
556
+ try {
557
+ const mod = require(prismaConfigPath);
558
+ config = mod.default || mod;
559
+ if (!config) {
560
+ throw new Error("Prisma config must have a default export");
561
+ }
562
+ configCache.set(prismaConfigPath, config);
563
+ } catch (error) {
564
+ throw new Error(
565
+ `Failed to load Prisma config from ${prismaConfigPath}: ${error}`
566
+ );
567
+ }
568
+ return config;
569
+ }
570
+ async function getSchemaPath(prismaConfigPath) {
571
+ const config = await loadPrismaConfig(prismaConfigPath);
572
+ const configDir = import_node_path3.default.dirname(prismaConfigPath);
573
+ if (config.schema) {
574
+ return import_node_path3.default.isAbsolute(config.schema) ? config.schema : import_node_path3.default.resolve(configDir, config.schema);
575
+ }
576
+ return import_node_path3.default.join(configDir, "schema.prisma");
577
+ }
578
+ async function getPrismaSchemas() {
579
+ const mod = require("@prisma/internals");
580
+ const { createSchemaPathInput, getSchemaWithPath } = mod.default || mod;
581
+ const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
582
+ const schemaPathInput = createSchemaPathInput({
583
+ baseDir: import_node_fs6.default.lstatSync(schemaPath).isDirectory() ? schemaPath : import_node_path3.default.dirname(schemaPath),
584
+ schemaPathFromConfig: schemaPath
585
+ });
586
+ return getSchemaWithPath({ schemaPath: schemaPathInput });
587
+ }
588
+ async function getPrismaDatasourceProvider() {
589
+ const mod = await import("@prisma/internals");
590
+ const { getConfig: getConfig3 } = mod.default || mod;
591
+ const { schemas } = await getPrismaSchemas();
592
+ const config = await getConfig3({ datamodel: schemas });
593
+ return config.datasources[0].activeProvider;
594
+ }
595
+ async function getMigrationsPath(prismaConfigPath) {
596
+ const config = await loadPrismaConfig(prismaConfigPath);
597
+ const configDir = import_node_path3.default.dirname(prismaConfigPath);
598
+ if (config.migrations?.path) {
599
+ return import_node_path3.default.isAbsolute(config.migrations.path) ? config.migrations.path : import_node_path3.default.resolve(configDir, config.migrations.path);
600
+ }
601
+ const schemaPath = await getSchemaPath(prismaConfigPath);
602
+ const schemaDir = import_node_fs6.default.statSync(schemaPath).isDirectory() ? schemaPath : import_node_path3.default.dirname(schemaPath);
603
+ return import_node_path3.default.join(schemaDir, "migrations");
604
+ }
605
+ async function getDbDir(prismaConfigPath) {
606
+ const schemaPath = await getSchemaPath(prismaConfigPath);
607
+ if (import_node_fs6.default.existsSync(schemaPath) && import_node_fs6.default.statSync(schemaPath).isDirectory()) {
608
+ return schemaPath;
609
+ }
610
+ return import_node_path3.default.dirname(schemaPath);
611
+ }
612
+ async function getDataMigrationsPath(prismaConfigPath) {
613
+ const migrationsPath = await getMigrationsPath(prismaConfigPath);
614
+ const migrationsDir = import_node_path3.default.dirname(migrationsPath);
615
+ return import_node_path3.default.join(migrationsDir, "dataMigrations");
616
+ }
617
+ async function getPrismaClientOutputDirs() {
618
+ try {
619
+ const mod = await import("@prisma/internals");
620
+ const { getConfig: getConfig3 } = mod.default || mod;
621
+ const { schemas, schemaRootDir } = await getPrismaSchemas();
622
+ const config = await getConfig3({ datamodel: schemas });
623
+ return config.generators.filter(
624
+ (generator) => ["prisma-client", "prisma-client-js"].includes(
625
+ generator.provider.value ?? ""
626
+ )
627
+ ).map((generator) => generator.output?.value).filter((output) => Boolean(output)).map(
628
+ (output) => import_node_path3.default.isAbsolute(output) ? output : import_node_path3.default.resolve(schemaRootDir, output)
629
+ );
630
+ } catch {
631
+ return [];
632
+ }
633
+ }
634
+ async function getPrismaClientOutputDirsIsolated() {
635
+ const { prismaClientOutputDirsWorkerUrl: prismaClientOutputDirsWorkerUrl2 } = await Promise.resolve().then(() => (init_prismaClientOutputDirsWorkerUrl(), prismaClientOutputDirsWorkerUrl_exports));
636
+ return new Promise((resolve) => {
637
+ const worker = new import_node_worker_threads.Worker(prismaClientOutputDirsWorkerUrl2);
638
+ worker.once("message", (outputDirs) => {
639
+ resolve(
640
+ Array.isArray(outputDirs) ? outputDirs.filter((dir) => typeof dir === "string") : []
641
+ );
642
+ void worker.terminate();
643
+ });
644
+ worker.once("error", () => resolve([]));
645
+ worker.once("exit", () => resolve([]));
646
+ });
647
+ }
648
+ function createPrismaClientFileMatcher(resolveOutputDirs = getPrismaClientOutputDirsIsolated) {
649
+ let outputDirs;
650
+ const getOutputDirs = () => {
651
+ outputDirs ??= resolveOutputDirs();
652
+ return outputDirs;
653
+ };
654
+ return {
655
+ load: async () => {
656
+ await getOutputDirs();
657
+ },
658
+ matches: async (filePath) => {
659
+ return (await getOutputDirs()).some((dir) => {
660
+ const relativePath = import_node_path3.default.relative(dir, filePath);
661
+ return relativePath !== "" && !relativePath.startsWith("..") && !import_node_path3.default.isAbsolute(relativePath);
662
+ });
663
+ }
664
+ };
665
+ }
666
+ async function resolveGeneratedPrismaClient() {
667
+ let generatorOutputPath;
668
+ let ext = "ts";
669
+ try {
670
+ const prismaInternalsMod = require("@prisma/internals");
671
+ const { getConfig: getConfig3 } = prismaInternalsMod.default || prismaInternalsMod;
672
+ const { schemas, schemaRootDir } = await getPrismaSchemas();
673
+ const config = await getConfig3({ datamodel: schemas });
674
+ const generator = config.generators.find((entry) => entry.name === "client") ?? config.generators[0];
675
+ const output = generator?.output?.value;
676
+ const generatedFileExtension = generator?.config?.generatedFileExtension;
677
+ const resolvedExtension = Array.isArray(generatedFileExtension) ? generatedFileExtension[0] : generatedFileExtension;
678
+ if (typeof resolvedExtension === "string" && resolvedExtension.length > 0) {
679
+ ext = resolvedExtension;
680
+ }
681
+ if (output) {
682
+ generatorOutputPath = import_node_path3.default.isAbsolute(output) ? output : import_node_path3.default.resolve(schemaRootDir, output);
683
+ }
684
+ } catch {
685
+ }
686
+ const prismaClientEntry = typeof generatorOutputPath === "string" ? import_node_path3.default.join(generatorOutputPath, "client." + ext) : void 0;
687
+ if (!prismaClientEntry || !import_node_fs6.default.existsSync(prismaClientEntry)) {
688
+ const checked = prismaClientEntry ?? "(could not determine output path)";
689
+ const pmCommand = prettyPrintCedarCommand(["prisma", "generate"]);
690
+ return {
691
+ clientPath: prismaClientEntry,
692
+ error: `Could not find generated Prisma client entry. Checked: ${checked}. Run \`${pmCommand}\` and try again.`
693
+ };
694
+ }
695
+ return {
696
+ clientPath: prismaClientEntry,
697
+ error: void 0
698
+ };
699
+ }
700
+
701
+ // src/envVarDefinitions.ts
702
+ var import_node_path4 = __toESM(require("node:path"), 1);
703
+ var import_project_config = require("@cedarjs/project-config");
704
+ function getEnvVarDefinitions() {
705
+ const rwConfig = (0, import_project_config.getConfig)();
706
+ const rwPaths = (0, import_project_config.getPaths)();
707
+ return {
708
+ RWJS_ENV: {
709
+ RWJS_API_GRAPHQL_URL: rwConfig.web.apiGraphQLUrl ?? rwConfig.web.apiUrl + "/graphql",
710
+ RWJS_API_URL: rwConfig.web.apiUrl,
711
+ __REDWOOD__APP_TITLE: rwConfig.web.title || import_node_path4.default.basename(rwPaths.base),
712
+ RWJS_EXP_STREAMING_SSR: rwConfig.experimental.streamingSsr?.enabled,
713
+ RWJS_EXP_RSC: rwConfig.experimental?.rsc?.enabled
714
+ },
715
+ RWJS_DEBUG_ENV: {
716
+ RWJS_SRC_ROOT: rwPaths.web.src,
717
+ REDWOOD_ENV_EDITOR: JSON.stringify(process.env.REDWOOD_ENV_EDITOR)
718
+ },
719
+ // Vite can automatically expose environment variables, but we
720
+ // disable that in `buildFeServer.ts` by setting `envFile: false`
721
+ // because we want to use our own logic for loading .env,
722
+ // .env.defaults, etc
723
+ // The two object spreads below will expose all environment
724
+ // variables listed in cedar.toml and all environment variables
725
+ // that are prefixed with REDWOOD_ENV_
726
+ ...Object.fromEntries(
727
+ rwConfig.web.includeEnvironmentVariables.flatMap((envName) => [
728
+ [`import.meta.env.${envName}`, JSON.stringify(process.env[envName])],
729
+ [`process.env.${envName}`, JSON.stringify(process.env[envName])]
730
+ ])
731
+ ),
732
+ ...Object.entries(process.env).reduce(
733
+ (acc, [key, value]) => {
734
+ if (key.startsWith("REDWOOD_ENV_")) {
735
+ acc[`import.meta.env.${key}`] = JSON.stringify(value);
736
+ acc[`process.env.${key}`] = JSON.stringify(value);
737
+ }
738
+ return acc;
739
+ },
740
+ {}
741
+ )
742
+ };
743
+ }
744
+ // Annotate the CommonJS export names for ESM import in node:
745
+ 0 && (module.exports = {
746
+ DEFAULT_CONFIG,
747
+ TargetEnum,
748
+ createPrismaClientFileMatcher,
749
+ ensurePosixPath,
750
+ findUp,
751
+ getAppRouteHook,
752
+ getBaseDir,
753
+ getBaseDirFromFile,
754
+ getBuiltDocumentFile,
755
+ getBuiltServerEntryFile,
756
+ getConfig,
757
+ getConfigPath,
758
+ getDataMigrationsPath,
759
+ getDbDir,
760
+ getEnvVarDefinitions,
761
+ getGeneratedDataDirPath,
762
+ getMigrationsPath,
763
+ getPaths,
764
+ getPrismaClientOutputDirs,
765
+ getPrismaClientOutputDirsIsolated,
766
+ getPrismaDatasourceProvider,
767
+ getPrismaSchemas,
768
+ getRawConfig,
769
+ getRouteHookForPage,
770
+ getSchemaPath,
771
+ importStatementPath,
772
+ isTypeScriptProject,
773
+ loadPrismaConfig,
774
+ parsePort,
775
+ processPagesDir,
776
+ projectIsEsm,
777
+ projectRootIsEsm,
778
+ projectSideIsEsm,
779
+ readEnvVar,
780
+ resolveFile,
781
+ resolveGeneratedPrismaClient
782
+ });