@cedarjs/vite 4.2.1-next.0 → 4.2.1-next.258
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/bins/cedar-unified-dev.mjs +7 -0
- package/dist/apiDevMiddleware.d.ts.map +1 -1
- package/dist/apiDevMiddleware.js +18 -5
- package/dist/buildApp.d.ts +2 -1
- package/dist/buildApp.d.ts.map +1 -1
- package/dist/buildApp.js +125 -6
- package/dist/buildFeServer.d.ts.map +1 -1
- package/dist/buildFeServer.js +1 -1
- package/dist/buildRouteHooks.d.ts.map +1 -1
- package/dist/buildRouteHooks.js +7 -3
- package/dist/cedar-unified-dev.d.ts +13 -2
- package/dist/cedar-unified-dev.d.ts.map +1 -1
- package/dist/cedar-unified-dev.js +171 -16
- package/dist/cjs/apiDevMiddleware.js +18 -5
- package/dist/cjs/buildApp.js +129 -10
- package/dist/cjs/buildFeServer.js +1 -1
- package/dist/cjs/buildRouteHooks.js +17 -3
- package/dist/cjs/cedar-unified-dev.js +184 -16
- package/dist/cjs/devFeServer.js +2 -1
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/lib/getMergedConfig.js +12 -4
- package/dist/cjs/lib/workspacePackageAliases.js +2 -8
- package/dist/cjs/plugins/vite-plugin-cedar-entry-injection.js +20 -5
- package/dist/cjs/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +61 -0
- package/dist/cjs/plugins/vite-plugin-cedar-universal-deploy.js +194 -14
- package/dist/cjs/runFeServer.js +2 -1
- package/dist/cjs/utils.js +2 -1
- package/dist/devFeServer.d.ts +1 -0
- package/dist/devFeServer.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/lib/getMergedConfig.d.ts.map +1 -1
- package/dist/lib/getMergedConfig.js +12 -4
- package/dist/lib/workspacePackageAliases.d.ts.map +1 -1
- package/dist/lib/workspacePackageAliases.js +2 -8
- package/dist/plugins/vite-plugin-cedar-entry-injection.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-entry-injection.js +20 -5
- package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts +15 -0
- package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.d.ts.map +1 -0
- package/dist/plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js +37 -0
- package/dist/plugins/vite-plugin-cedar-universal-deploy.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-cedar-universal-deploy.js +194 -14
- package/dist/runFeServer.d.ts +1 -0
- package/dist/runFeServer.d.ts.map +1 -1
- package/dist/runFeServer.js +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/package.json +30 -60
- package/dist/buildUDApiServer.d.ts +0 -24
- package/dist/buildUDApiServer.d.ts.map +0 -1
- package/dist/buildUDApiServer.js +0 -41
- package/dist/cjs/buildUDApiServer.js +0 -75
- package/dist/cjs/ud-handlers/catch-all.js +0 -65
- package/dist/cjs/ud-handlers/function.js +0 -47
- package/dist/cjs/ud-handlers/graphql.js +0 -59
- package/dist/ud-handlers/catch-all.d.ts +0 -15
- package/dist/ud-handlers/catch-all.d.ts.map +0 -1
- package/dist/ud-handlers/catch-all.js +0 -41
- package/dist/ud-handlers/function.d.ts +0 -5
- package/dist/ud-handlers/function.d.ts.map +0 -1
- package/dist/ud-handlers/function.js +0 -23
- package/dist/ud-handlers/graphql.d.ts +0 -7
- package/dist/ud-handlers/graphql.d.ts.map +0 -1
- package/dist/ud-handlers/graphql.js +0 -35
package/dist/cjs/buildApp.js
CHANGED
|
@@ -33,7 +33,9 @@ __export(buildApp_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(buildApp_exports);
|
|
34
34
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
|
-
var
|
|
36
|
+
var import_store = require("@universal-deploy/store");
|
|
37
|
+
var import_vite = require("@universal-deploy/vite");
|
|
38
|
+
var import_vite2 = require("vite");
|
|
37
39
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
38
40
|
var import_files = require("@cedarjs/internal/dist/files.js");
|
|
39
41
|
var import_project_config = require("@cedarjs/project-config");
|
|
@@ -52,7 +54,8 @@ function resolveWithExtensions(id) {
|
|
|
52
54
|
}
|
|
53
55
|
async function buildCedarApp({
|
|
54
56
|
verbose = false,
|
|
55
|
-
workspace = ["api", "web"]
|
|
57
|
+
workspace = ["api", "web"],
|
|
58
|
+
ud = false
|
|
56
59
|
} = {}) {
|
|
57
60
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
58
61
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
@@ -85,13 +88,13 @@ async function buildCedarApp({
|
|
|
85
88
|
format,
|
|
86
89
|
preserveModules: true,
|
|
87
90
|
preserveModulesRoot: cedarPaths.api.src,
|
|
88
|
-
entryFileNames: "[name].js"
|
|
91
|
+
entryFileNames: "[name].js",
|
|
92
|
+
exports: "named"
|
|
89
93
|
},
|
|
90
94
|
external: (id) => {
|
|
91
95
|
if (id.startsWith("node:")) {
|
|
92
96
|
return true;
|
|
93
|
-
}
|
|
94
|
-
if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
|
|
97
|
+
} else if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
|
|
95
98
|
return true;
|
|
96
99
|
}
|
|
97
100
|
return false;
|
|
@@ -99,6 +102,31 @@ async function buildCedarApp({
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
};
|
|
105
|
+
if (ud) {
|
|
106
|
+
environments["ssr"] = {
|
|
107
|
+
build: {
|
|
108
|
+
ssr: true,
|
|
109
|
+
outDir: import_node_path.default.join(cedarPaths.api.dist, "ud"),
|
|
110
|
+
emptyOutDir: true,
|
|
111
|
+
rollupOptions: {
|
|
112
|
+
input: import_store.catchAllEntry,
|
|
113
|
+
output: {
|
|
114
|
+
entryFileNames: "index.js"
|
|
115
|
+
},
|
|
116
|
+
external: (id) => {
|
|
117
|
+
if (id.startsWith("virtual:")) {
|
|
118
|
+
return false;
|
|
119
|
+
} else if (id.startsWith("node:")) {
|
|
120
|
+
return true;
|
|
121
|
+
} else if (!id.startsWith(".") && !import_node_path.default.isAbsolute(id)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
102
130
|
}
|
|
103
131
|
const babelPlugins = workspace.includes("api") ? (0, import_babel_config.getApiSideBabelPlugins)({
|
|
104
132
|
openTelemetry: (cedarConfig.experimental?.opentelemetry?.enabled ?? false) && (cedarConfig.experimental?.opentelemetry?.wrapApi ?? false),
|
|
@@ -106,10 +134,45 @@ async function buildCedarApp({
|
|
|
106
134
|
}) : null;
|
|
107
135
|
const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
|
|
108
136
|
Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
|
|
109
|
-
([name, sourceFile]) => [name, (0,
|
|
137
|
+
([name, sourceFile]) => [name, (0, import_vite2.normalizePath)(sourceFile)]
|
|
110
138
|
)
|
|
111
139
|
) : {};
|
|
112
140
|
const plugins = [
|
|
141
|
+
// Suppress noisy warnings from third-party dependencies across all
|
|
142
|
+
// environments by injecting onwarn into every environment's rollupOptions.
|
|
143
|
+
{
|
|
144
|
+
name: "cedar-suppress-third-party-warnings",
|
|
145
|
+
configResolved(config) {
|
|
146
|
+
function onwarn(warning, warn) {
|
|
147
|
+
if (warning.code === "EVAL" && warning.id?.includes("@prisma/internals")) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (warning.code === "INVALID_ANNOTATION" && warning.id?.includes("graphql-scalars")) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
warn(warning);
|
|
154
|
+
}
|
|
155
|
+
for (const env of Object.values(config.environments ?? {})) {
|
|
156
|
+
env.build.rollupOptions ??= {};
|
|
157
|
+
const existingOnwarn = env.build.rollupOptions.onwarn;
|
|
158
|
+
env.build.rollupOptions.onwarn = existingOnwarn ? (warning, warn) => {
|
|
159
|
+
onwarn(warning, (w) => existingOnwarn(w, warn));
|
|
160
|
+
} : onwarn;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// Resolve bare-specifier dynamic imports from node_modules as external
|
|
165
|
+
// before Rollup attempts resolution, avoiding UNRESOLVED_IMPORT warnings
|
|
166
|
+
// for optional peer dependencies (e.g. @simplewebauthn/server).
|
|
167
|
+
{
|
|
168
|
+
name: "cedar-optional-peer-deps",
|
|
169
|
+
resolveDynamicImport(specifier, importer) {
|
|
170
|
+
if (typeof specifier === "string" && !specifier.startsWith(".") && !specifier.startsWith("/") && importer?.includes("node_modules") && this.environment.config.consumer === "server") {
|
|
171
|
+
return { id: specifier, external: true };
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
113
176
|
{
|
|
114
177
|
name: "cedar-build-app-cleanup",
|
|
115
178
|
configResolved(config) {
|
|
@@ -120,8 +183,58 @@ async function buildCedarApp({
|
|
|
120
183
|
delete config.environments.ssr;
|
|
121
184
|
}
|
|
122
185
|
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "cedar-build-app",
|
|
189
|
+
buildApp: {
|
|
190
|
+
order: "pre",
|
|
191
|
+
async handler(builder2) {
|
|
192
|
+
if (workspace.includes("web") && builder2.environments.client && !builder2.environments.client.isBuilt) {
|
|
193
|
+
await builder2.build(builder2.environments.client);
|
|
194
|
+
}
|
|
195
|
+
if (workspace.includes("api") && builder2.environments.api && !builder2.environments.api.isBuilt) {
|
|
196
|
+
await builder2.build(builder2.environments.api);
|
|
197
|
+
}
|
|
198
|
+
if (workspace.includes("api") && builder2.environments["ssr"] && !builder2.environments["ssr"].isBuilt) {
|
|
199
|
+
await builder2.build(builder2.environments["ssr"]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
123
203
|
}
|
|
124
204
|
];
|
|
205
|
+
if (ud) {
|
|
206
|
+
plugins.push((0, import_vite.catchAll)());
|
|
207
|
+
plugins.push({
|
|
208
|
+
name: "cedar-ud-verify-routes",
|
|
209
|
+
configResolved() {
|
|
210
|
+
const entries = (0, import_store.getAllEntries)();
|
|
211
|
+
if (entries.length === 0) {
|
|
212
|
+
console.warn(
|
|
213
|
+
"\n",
|
|
214
|
+
" Warning: No Universal Deploy API routes were registered.\n",
|
|
215
|
+
" The built server entry will be an empty router (404 for all\n",
|
|
216
|
+
" requests). Check that you have API functions under\n",
|
|
217
|
+
" `api/src/functions/` and that your vite config includes\n",
|
|
218
|
+
" `cedarUniversalDeployPlugin()`.\n"
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
plugins.push({
|
|
224
|
+
name: "cedar-ud-write-package-json",
|
|
225
|
+
applyToEnvironment(env) {
|
|
226
|
+
return env.name === "ssr";
|
|
227
|
+
},
|
|
228
|
+
closeBundle() {
|
|
229
|
+
const dir = import_node_path.default.join(cedarPaths.api.dist, "ud");
|
|
230
|
+
import_node_fs.default.mkdirSync(dir, { recursive: true });
|
|
231
|
+
import_node_fs.default.writeFileSync(
|
|
232
|
+
import_node_path.default.join(dir, "package.json"),
|
|
233
|
+
JSON.stringify({ type: "module" }, null, 2)
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
125
238
|
if (workspace.includes("api")) {
|
|
126
239
|
plugins.push({
|
|
127
240
|
name: "cedar-api-src-redirect",
|
|
@@ -141,17 +254,23 @@ async function buildCedarApp({
|
|
|
141
254
|
if (babelPlugins) {
|
|
142
255
|
plugins.push({
|
|
143
256
|
name: "cedar-vite-api-babel-transform",
|
|
144
|
-
|
|
257
|
+
enforce: "pre",
|
|
258
|
+
async transform(code, id) {
|
|
145
259
|
if (!/\.(js|ts|tsx|jsx)$/.test(id)) {
|
|
146
260
|
return null;
|
|
147
261
|
}
|
|
148
262
|
if (id.includes("node_modules")) {
|
|
149
263
|
return null;
|
|
150
264
|
}
|
|
151
|
-
if (!(0,
|
|
265
|
+
if (!(0, import_vite2.normalizePath)(id).startsWith((0, import_vite2.normalizePath)(cedarPaths.api.base))) {
|
|
152
266
|
return null;
|
|
153
267
|
}
|
|
154
|
-
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
268
|
+
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
269
|
+
code,
|
|
270
|
+
id,
|
|
271
|
+
babelPlugins,
|
|
272
|
+
true
|
|
273
|
+
);
|
|
155
274
|
if (transformedCode?.code) {
|
|
156
275
|
return {
|
|
157
276
|
code: transformedCode.code,
|
|
@@ -163,7 +282,7 @@ async function buildCedarApp({
|
|
|
163
282
|
});
|
|
164
283
|
}
|
|
165
284
|
}
|
|
166
|
-
const builder = await (0,
|
|
285
|
+
const builder = await (0, import_vite2.createBuilder)({
|
|
167
286
|
configFile: cedarPaths.web.viteConfig,
|
|
168
287
|
envFile: false,
|
|
169
288
|
logLevel: verbose ? "info" : "warn",
|
|
@@ -37,7 +37,7 @@ const buildFeServer = async ({ verbose, webDir } = {}) => {
|
|
|
37
37
|
const streamingSsrEnabled = rwConfig.experimental?.streamingSsr?.enabled;
|
|
38
38
|
if (!viteConfigPath) {
|
|
39
39
|
throw new Error(
|
|
40
|
-
"Vite config not found.
|
|
40
|
+
"Vite config not found. Please set up Vite before building."
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
if (!rwPaths.web.entryServer || !rwPaths.web.entryClient) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,12 +17,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var buildRouteHooks_exports = {};
|
|
20
30
|
__export(buildRouteHooks_exports, {
|
|
21
31
|
buildRouteHooks: () => buildRouteHooks
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(buildRouteHooks_exports);
|
|
34
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
24
35
|
var import_esbuild = require("esbuild");
|
|
25
36
|
var import_babel_config = require("@cedarjs/babel-config");
|
|
26
37
|
var import_files = require("@cedarjs/internal/dist/files.js");
|
|
@@ -31,9 +42,12 @@ async function buildRouteHooks(verbose, rwPaths) {
|
|
|
31
42
|
name: "rw-esbuild-babel-transform",
|
|
32
43
|
setup(build) {
|
|
33
44
|
build.onLoad({ filter: /\.(js|ts|tsx|jsx)$/ }, async (args) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
const fileContents = await import_node_fs.default.promises.readFile(args.path, "utf-8");
|
|
46
|
+
const transformedCode = await (0, import_babel_config.transformWithBabel)(
|
|
47
|
+
fileContents,
|
|
48
|
+
args.path,
|
|
49
|
+
[...(0, import_babel_config.getRouteHookBabelPlugins)()]
|
|
50
|
+
);
|
|
37
51
|
if (transformedCode?.code) {
|
|
38
52
|
return {
|
|
39
53
|
contents: transformedCode.code,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
"use strict";
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -6,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
9
12
|
var __copyProps = (to, from, except, desc) => {
|
|
10
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -22,6 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
26
|
mod
|
|
24
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var cedar_unified_dev_exports = {};
|
|
30
|
+
__export(cedar_unified_dev_exports, {
|
|
31
|
+
openDebugger: () => openDebugger,
|
|
32
|
+
parseCliArgs: () => parseCliArgs,
|
|
33
|
+
startUnifiedDevServer: () => startUnifiedDevServer
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(cedar_unified_dev_exports);
|
|
25
36
|
var import_server = require("@whatwg-node/server");
|
|
26
37
|
var import_vite = require("vite");
|
|
27
38
|
var import_yargs_parser = __toESM(require("yargs-parser"), 1);
|
|
@@ -34,25 +45,180 @@ function isViteInternalRequest(url) {
|
|
|
34
45
|
function isApiRequest(url, apiUrl, apiGqlUrl) {
|
|
35
46
|
return url === apiUrl || url.startsWith(apiUrl + "/") || url.startsWith(apiUrl + "?") || url === apiGqlUrl || url.startsWith(apiGqlUrl + "/") || url.startsWith(apiGqlUrl + "?");
|
|
36
47
|
}
|
|
37
|
-
|
|
38
|
-
process.env.__CEDAR_UNIFIED_DEV = "true";
|
|
39
|
-
const rwPaths = (0, import_project_config.getPaths)();
|
|
40
|
-
const cedarConfig = (0, import_project_config.getConfig)();
|
|
41
|
-
const configFile = rwPaths.web.viteConfig;
|
|
42
|
-
if (!configFile) {
|
|
43
|
-
throw new Error("Could not locate your web/vite.config.{js,ts} file");
|
|
44
|
-
}
|
|
48
|
+
function parseCliArgs(argv = process.argv) {
|
|
45
49
|
const {
|
|
46
50
|
force: forceOptimize,
|
|
47
51
|
debug,
|
|
48
52
|
port: portArg,
|
|
49
53
|
apiPort: _apiPortArg,
|
|
54
|
+
"debug-port": debugPort,
|
|
55
|
+
"debug-brk": debugBrk,
|
|
50
56
|
_: _positional,
|
|
51
57
|
...serverArgs
|
|
52
|
-
} = (0, import_yargs_parser.default)(
|
|
53
|
-
boolean: [
|
|
54
|
-
|
|
58
|
+
} = (0, import_yargs_parser.default)(argv.slice(2), {
|
|
59
|
+
boolean: [
|
|
60
|
+
"https",
|
|
61
|
+
"open",
|
|
62
|
+
"strictPort",
|
|
63
|
+
"force",
|
|
64
|
+
"cors",
|
|
65
|
+
"debug",
|
|
66
|
+
"debug-brk"
|
|
67
|
+
],
|
|
68
|
+
number: ["port", "apiPort", "debug-port"]
|
|
55
69
|
});
|
|
70
|
+
return { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs };
|
|
71
|
+
}
|
|
72
|
+
async function clearPendingPause() {
|
|
73
|
+
const inspector = await import("node:inspector");
|
|
74
|
+
const s = new inspector.Session();
|
|
75
|
+
try {
|
|
76
|
+
s.connect();
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
s.post("Debugger.enable", (err) => err ? reject(err) : resolve());
|
|
79
|
+
});
|
|
80
|
+
await new Promise((resolve) => {
|
|
81
|
+
let done = false;
|
|
82
|
+
s.once("Debugger.paused", () => {
|
|
83
|
+
s.post("Debugger.resume", () => {
|
|
84
|
+
done = true;
|
|
85
|
+
resolve();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
s.post("Runtime.evaluate", { expression: "1" }, () => {
|
|
89
|
+
if (!done) {
|
|
90
|
+
resolve();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
} catch {
|
|
95
|
+
} finally {
|
|
96
|
+
s.disconnect();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function openDebugger(port, waitForDebugger = false) {
|
|
100
|
+
const inspector = await import("node:inspector");
|
|
101
|
+
inspector.open(port, "127.0.0.1");
|
|
102
|
+
if (waitForDebugger) {
|
|
103
|
+
inspector.waitForDebugger();
|
|
104
|
+
const session = new inspector.Session();
|
|
105
|
+
session.connect();
|
|
106
|
+
await session.post("Debugger.enable");
|
|
107
|
+
let resumedResolve;
|
|
108
|
+
const resumedPromise = new Promise((resolve) => {
|
|
109
|
+
resumedResolve = resolve;
|
|
110
|
+
});
|
|
111
|
+
const onSessionDead = () => {
|
|
112
|
+
if (paused) {
|
|
113
|
+
tryResume();
|
|
114
|
+
} else {
|
|
115
|
+
clearPendingPause().then(
|
|
116
|
+
() => resumedResolve?.(),
|
|
117
|
+
() => resumedResolve?.()
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
session.once("error", onSessionDead);
|
|
122
|
+
session.once("Inspector.detached", onSessionDead);
|
|
123
|
+
let paused = false;
|
|
124
|
+
session.once("Debugger.paused", () => {
|
|
125
|
+
paused = true;
|
|
126
|
+
tryResume();
|
|
127
|
+
});
|
|
128
|
+
session.once("Debugger.resumed", () => {
|
|
129
|
+
resumedResolve?.();
|
|
130
|
+
});
|
|
131
|
+
const FIVE_MINUTES_MS = 5 * 60 * 1e3;
|
|
132
|
+
const timeout = setTimeout(() => {
|
|
133
|
+
if (paused) {
|
|
134
|
+
tryResume();
|
|
135
|
+
} else {
|
|
136
|
+
resumedResolve?.();
|
|
137
|
+
}
|
|
138
|
+
}, FIVE_MINUTES_MS);
|
|
139
|
+
let hasTriedResume = false;
|
|
140
|
+
const tryResume = () => {
|
|
141
|
+
if (hasTriedResume) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!paused) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
hasTriedResume = true;
|
|
148
|
+
(async () => {
|
|
149
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
150
|
+
const s = attempt === 0 ? session : new inspector.Session();
|
|
151
|
+
if (attempt > 0) {
|
|
152
|
+
try {
|
|
153
|
+
s.connect();
|
|
154
|
+
await new Promise((resolve, reject) => {
|
|
155
|
+
s.post(
|
|
156
|
+
"Debugger.enable",
|
|
157
|
+
(err) => err ? reject(err) : resolve()
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
} catch {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const ok = await new Promise((resolve) => {
|
|
165
|
+
s.post("Debugger.resume", (err) => resolve(!err));
|
|
166
|
+
});
|
|
167
|
+
if (attempt > 0) {
|
|
168
|
+
s.disconnect();
|
|
169
|
+
}
|
|
170
|
+
if (ok) {
|
|
171
|
+
resumedResolve?.();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
console.warn(
|
|
176
|
+
"[cedar-unified-dev] Failed to clear debugger pause after external debugger disconnect. API functions may pause on next execution."
|
|
177
|
+
);
|
|
178
|
+
resumedResolve?.();
|
|
179
|
+
})();
|
|
180
|
+
};
|
|
181
|
+
void new Promise((resolve, reject) => {
|
|
182
|
+
session.post("Debugger.pause", (err) => {
|
|
183
|
+
if (err) {
|
|
184
|
+
reject(err);
|
|
185
|
+
} else {
|
|
186
|
+
resolve();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}).catch(() => {
|
|
190
|
+
resumedResolve?.();
|
|
191
|
+
});
|
|
192
|
+
void new Promise((resolve, reject) => {
|
|
193
|
+
session.post("Runtime.evaluate", { expression: "1" }, (err) => {
|
|
194
|
+
if (err) {
|
|
195
|
+
reject(err);
|
|
196
|
+
} else {
|
|
197
|
+
resolve();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}).catch(() => {
|
|
201
|
+
clearPendingPause().then(
|
|
202
|
+
() => resumedResolve?.(),
|
|
203
|
+
() => resumedResolve?.()
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
await resumedPromise;
|
|
207
|
+
clearTimeout(timeout);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function startUnifiedDevServer() {
|
|
211
|
+
process.env.__CEDAR_UNIFIED_DEV = "true";
|
|
212
|
+
const rwPaths = (0, import_project_config.getPaths)();
|
|
213
|
+
const cedarConfig = (0, import_project_config.getConfig)();
|
|
214
|
+
const configFile = rwPaths.web.viteConfig;
|
|
215
|
+
if (!configFile) {
|
|
216
|
+
throw new Error("Could not locate your web/vite.config.{js,ts} file");
|
|
217
|
+
}
|
|
218
|
+
const { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs } = parseCliArgs();
|
|
219
|
+
if (debugPort !== void 0) {
|
|
220
|
+
await openDebugger(debugPort, debugBrk);
|
|
221
|
+
}
|
|
56
222
|
const webPort = portArg ?? cedarConfig.web.port ?? 8910;
|
|
57
223
|
const { close: closeApi, handler: apiHandler } = await (0, import_apiDevMiddleware.startApiDevMiddleware)();
|
|
58
224
|
const apiAdapter = (0, import_server.createServerAdapter)(apiHandler);
|
|
@@ -135,8 +301,10 @@ const startUnifiedDevServer = async () => {
|
|
|
135
301
|
};
|
|
136
302
|
process.on("SIGINT", shutdown);
|
|
137
303
|
process.on("SIGTERM", shutdown);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
304
|
+
}
|
|
305
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
306
|
+
0 && (module.exports = {
|
|
307
|
+
openDebugger,
|
|
308
|
+
parseCliArgs,
|
|
309
|
+
startUnifiedDevServer
|
|
142
310
|
});
|
package/dist/cjs/devFeServer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -59,7 +60,7 @@ async function createServer() {
|
|
|
59
60
|
}
|
|
60
61
|
if (!rwPaths.web.viteConfig) {
|
|
61
62
|
throw new Error(
|
|
62
|
-
"Vite config not found.
|
|
63
|
+
"Vite config not found. Please set up Vite before running the dev server."
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
const vite = await (0, import_vite.createServer)({
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
cedarImportDirPlugin: () => import_vite_plugin_cedar_import_dir.cedarImportDirPlugin,
|
|
38
38
|
cedarMergedConfig: () => import_vite_plugin_merged_config2.cedarMergedConfig,
|
|
39
39
|
cedarNodePolyfills: () => import_vite_plugin_cedar_node_polyfills2.cedarNodePolyfills,
|
|
40
|
+
cedarRemoveDevFatalErrorPage: () => import_vite_plugin_cedar_remove_dev_fatal_error_page2.cedarRemoveDevFatalErrorPage,
|
|
40
41
|
cedarRemoveFromBundle: () => import_vite_plugin_cedar_remove_from_bundle2.cedarRemoveFromBundle,
|
|
41
42
|
cedarSwapApolloProvider: () => import_vite_plugin_swap_apollo_provider2.cedarSwapApolloProvider,
|
|
42
43
|
cedarTransformJsAsJsx: () => import_vite_plugin_jsx_loader2.cedarTransformJsAsJsx,
|
|
@@ -55,6 +56,7 @@ var import_vite_plugin_cedar_cell = require("./plugins/vite-plugin-cedar-cell.js
|
|
|
55
56
|
var import_vite_plugin_cedar_entry_injection = require("./plugins/vite-plugin-cedar-entry-injection.js");
|
|
56
57
|
var import_vite_plugin_cedar_html_env = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
57
58
|
var import_vite_plugin_cedar_node_polyfills = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
59
|
+
var import_vite_plugin_cedar_remove_dev_fatal_error_page = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
58
60
|
var import_vite_plugin_cedar_remove_from_bundle = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
59
61
|
var import_vite_plugin_cedar_wait_for_api_server = require("./plugins/vite-plugin-cedar-wait-for-api-server.js");
|
|
60
62
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
@@ -68,6 +70,7 @@ var import_vite_plugin_cedar_entry_injection2 = require("./plugins/vite-plugin-c
|
|
|
68
70
|
var import_vite_plugin_cedar_html_env2 = require("./plugins/vite-plugin-cedar-html-env.js");
|
|
69
71
|
var import_vite_plugin_cedar_import_dir = require("./plugins/vite-plugin-cedar-import-dir.js");
|
|
70
72
|
var import_vite_plugin_cedar_node_polyfills2 = require("./plugins/vite-plugin-cedar-node-polyfills.js");
|
|
73
|
+
var import_vite_plugin_cedar_remove_dev_fatal_error_page2 = require("./plugins/vite-plugin-cedar-remove-dev-fatal-error-page.js");
|
|
71
74
|
var import_vite_plugin_cedar_remove_from_bundle2 = require("./plugins/vite-plugin-cedar-remove-from-bundle.js");
|
|
72
75
|
var import_vite_plugin_cedarjs_resolve_cedar_style_imports2 = require("./plugins/vite-plugin-cedarjs-resolve-cedar-style-imports.js");
|
|
73
76
|
var import_vite_plugin_cedarjs_job_path_injector = require("./plugins/vite-plugin-cedarjs-job-path-injector.js");
|
|
@@ -106,6 +109,7 @@ function cedar({ mode } = {}) {
|
|
|
106
109
|
(0, import_vite_plugin_cedar_cell.cedarCellTransform)(),
|
|
107
110
|
(0, import_vite_plugin_jsx_loader.cedarTransformJsAsJsx)(),
|
|
108
111
|
(0, import_vite_plugin_cedar_remove_from_bundle.cedarRemoveFromBundle)(),
|
|
112
|
+
(0, import_vite_plugin_cedar_remove_dev_fatal_error_page.cedarRemoveDevFatalErrorPage)(),
|
|
109
113
|
(0, import_plugin_react.default)({ babel: babelConfig })
|
|
110
114
|
];
|
|
111
115
|
}
|
|
@@ -121,6 +125,7 @@ var index_default = cedar;
|
|
|
121
125
|
cedarImportDirPlugin,
|
|
122
126
|
cedarMergedConfig,
|
|
123
127
|
cedarNodePolyfills,
|
|
128
|
+
cedarRemoveDevFatalErrorPage,
|
|
124
129
|
cedarRemoveFromBundle,
|
|
125
130
|
cedarSwapApolloProvider,
|
|
126
131
|
cedarTransformJsAsJsx,
|
|
@@ -50,9 +50,14 @@ function getMergedConfig(cedarConfig, cedarPaths) {
|
|
|
50
50
|
apiPort = cedarConfig.api.port;
|
|
51
51
|
}
|
|
52
52
|
const defaultCedarViteConfig = {
|
|
53
|
-
root: cedarPaths.web.
|
|
53
|
+
root: cedarPaths.web.base,
|
|
54
54
|
resolve: {
|
|
55
|
-
alias:
|
|
55
|
+
alias: {
|
|
56
|
+
...workspaceAliases,
|
|
57
|
+
// In test mode, register the virtual module alias so that
|
|
58
|
+
// MockProviders can resolve the user's Routes file
|
|
59
|
+
...env.mode === "test" ? { "~__CEDAR__USER_ROUTES_FOR_MOCK": cedarPaths.web.routes } : {}
|
|
60
|
+
}
|
|
56
61
|
},
|
|
57
62
|
// @MARK: when we have these aliases, the warnings from the FE server go
|
|
58
63
|
// away BUT, if you have imports like this:
|
|
@@ -104,7 +109,7 @@ function getMergedConfig(cedarConfig, cedarPaths) {
|
|
|
104
109
|
// Note that sourcemap can be boolean or 'inline'
|
|
105
110
|
sourcemap: !env.isSsrBuild && cedarConfig.web.sourceMap,
|
|
106
111
|
rollupOptions: {
|
|
107
|
-
input: getRollupInput(!!env.isSsrBuild)
|
|
112
|
+
input: getRollupInput(userConfig, !!env.isSsrBuild)
|
|
108
113
|
}
|
|
109
114
|
},
|
|
110
115
|
// @MARK: do not set buildSsrCjsExternalHeuristics here
|
|
@@ -137,9 +142,12 @@ function getMergedConfig(cedarConfig, cedarPaths) {
|
|
|
137
142
|
return (0, import_vite.mergeConfig)(defaultCedarViteConfig, userConfig);
|
|
138
143
|
};
|
|
139
144
|
}
|
|
140
|
-
function getRollupInput(ssr) {
|
|
145
|
+
function getRollupInput(userConfig, ssr) {
|
|
141
146
|
const cedarConfig = (0, import_project_config.getConfig)();
|
|
142
147
|
const cedarPaths = (0, import_project_config.getPaths)();
|
|
148
|
+
if (userConfig.build?.rollupOptions?.input) {
|
|
149
|
+
return userConfig.build.rollupOptions.input;
|
|
150
|
+
}
|
|
143
151
|
if (!cedarPaths.web.entryClient) {
|
|
144
152
|
throw new Error("entryClient not defined");
|
|
145
153
|
}
|
|
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(workspacePackageAliases_exports);
|
|
|
34
34
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
35
35
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
36
36
|
var import_vite = require("vite");
|
|
37
|
+
var import_workspaces = require("@cedarjs/project-config/workspaces");
|
|
37
38
|
function findSourceEntry(pkgDir, pkgJson) {
|
|
38
39
|
let distEntry = null;
|
|
39
40
|
if (typeof pkgJson.main === "string") {
|
|
@@ -71,14 +72,7 @@ function getWorkspacePackageAliases(cedarPaths, cedarConfig) {
|
|
|
71
72
|
return {};
|
|
72
73
|
}
|
|
73
74
|
try {
|
|
74
|
-
const
|
|
75
|
-
const rootPkg = JSON.parse(import_node_fs.default.readFileSync(rootPkgPath, "utf-8"));
|
|
76
|
-
if (!Array.isArray(rootPkg.workspaces) || rootPkg.workspaces.length <= 2) {
|
|
77
|
-
return {};
|
|
78
|
-
}
|
|
79
|
-
const nonApiWebWorkspaces = rootPkg.workspaces.filter(
|
|
80
|
-
(w) => w !== "api" && w !== "web"
|
|
81
|
-
);
|
|
75
|
+
const nonApiWebWorkspaces = (0, import_workspaces.getNonApiWebWorkspaces)(cedarPaths.base);
|
|
82
76
|
if (nonApiWebWorkspaces.length === 0) {
|
|
83
77
|
return {};
|
|
84
78
|
}
|
|
@@ -36,21 +36,36 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
36
36
|
var import_vite = require("vite");
|
|
37
37
|
var import_project_config = require("@cedarjs/project-config");
|
|
38
38
|
function cedarEntryInjectionPlugin() {
|
|
39
|
-
const
|
|
40
|
-
const clientEntryPath =
|
|
39
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
40
|
+
const clientEntryPath = cedarPaths.web.entryClient;
|
|
41
41
|
if (!clientEntryPath) {
|
|
42
42
|
throw new Error(
|
|
43
43
|
"Vite client entry point not found. Please check that your project has an entry.client.{jsx,tsx} file in the web/src directory."
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
|
-
const relativeEntryPath =
|
|
46
|
+
const relativeEntryPath = (0, import_vite.normalizePath)(
|
|
47
|
+
import_node_path.default.relative(cedarPaths.web.base, clientEntryPath)
|
|
48
|
+
);
|
|
47
49
|
return {
|
|
48
50
|
name: "cedar-entry-injection",
|
|
51
|
+
// Vite's dependency optimizer and dev server resolve the script tag
|
|
52
|
+
// src="/src/entry.client.{tsx,jsx}" as an absolute filesystem path
|
|
53
|
+
// (/src/entry.client.tsx) instead of relative to the Vite root.
|
|
54
|
+
// This hook maps it to the real file path so Vite can find it.
|
|
55
|
+
resolveId(id) {
|
|
56
|
+
if (id === "/" + relativeEntryPath) {
|
|
57
|
+
return clientEntryPath;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
49
61
|
// ---------- Bundle injection ----------
|
|
50
62
|
// Used by Vite during dev, to inject the entrypoint.
|
|
51
63
|
transformIndexHtml: {
|
|
52
64
|
order: "pre",
|
|
53
|
-
handler: (html) => {
|
|
65
|
+
handler: (html, ctx) => {
|
|
66
|
+
if (!ctx.filename || (0, import_vite.normalizePath)(ctx.filename) !== (0, import_vite.normalizePath)(cedarPaths.web.html)) {
|
|
67
|
+
return html;
|
|
68
|
+
}
|
|
54
69
|
if (import_node_fs.default.existsSync(clientEntryPath)) {
|
|
55
70
|
return html.replace(
|
|
56
71
|
"</head>",
|
|
@@ -67,7 +82,7 @@ function cedarEntryInjectionPlugin() {
|
|
|
67
82
|
// Used by rollup during build to inject the entrypoint
|
|
68
83
|
// but note index.html does not come through as an id during dev
|
|
69
84
|
transform: (code, id) => {
|
|
70
|
-
if (import_node_fs.default.existsSync(clientEntryPath) && (0, import_vite.normalizePath)(id) === (0, import_vite.normalizePath)(
|
|
85
|
+
if (import_node_fs.default.existsSync(clientEntryPath) && (0, import_vite.normalizePath)(id) === (0, import_vite.normalizePath)(cedarPaths.web.html)) {
|
|
71
86
|
return {
|
|
72
87
|
code: code.replace(
|
|
73
88
|
"</head>",
|