@tsed/cli 7.5.0-rc.4 → 7.5.0-rc.5
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/lib/esm/bin/tsed-dev.js +23 -15
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -6
package/lib/esm/bin/tsed-dev.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
3
4
|
import process from "node:process";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
const runnerFile = fileURLToPath(import.meta.url);
|
|
7
|
+
const configFile = path.resolve(path.dirname(runnerFile), "../../vite.config.ts");
|
|
7
8
|
const RUN_MODE = "TSED_VITE_RUN_MODE";
|
|
8
9
|
function parseWatchValue(args) {
|
|
9
10
|
if (args.includes("--no-watch")) {
|
|
@@ -30,7 +31,6 @@ function parseWatchValue(args) {
|
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
32
33
|
function assertViteProject() {
|
|
33
|
-
const configFile = normalizePath("vite.config.ts");
|
|
34
34
|
if (!existsSync(configFile)) {
|
|
35
35
|
throw new Error("tsed dev is only available for ViteRuntime projects. Missing vite.config.ts in the current directory.");
|
|
36
36
|
}
|
|
@@ -39,13 +39,9 @@ async function createViteDevServer() {
|
|
|
39
39
|
// @ts-ignore
|
|
40
40
|
const { createServer } = await import("vite");
|
|
41
41
|
return createServer({
|
|
42
|
-
configFile
|
|
43
|
-
optimizeDeps: {
|
|
44
|
-
noDiscovery: true,
|
|
45
|
-
include: []
|
|
46
|
-
},
|
|
42
|
+
configFile,
|
|
47
43
|
server: {
|
|
48
|
-
middlewareMode:
|
|
44
|
+
middlewareMode: "ssr",
|
|
49
45
|
hmr: false,
|
|
50
46
|
ws: false
|
|
51
47
|
}
|
|
@@ -63,7 +59,6 @@ async function runViteApp() {
|
|
|
63
59
|
await new Promise(() => { });
|
|
64
60
|
}
|
|
65
61
|
async function runViteController(rawArgs) {
|
|
66
|
-
const runnerFile = fileURLToPath(import.meta.url);
|
|
67
62
|
const watch = parseWatchValue(rawArgs);
|
|
68
63
|
const vite = await createViteDevServer();
|
|
69
64
|
let childProcess;
|
|
@@ -75,8 +70,7 @@ async function runViteController(rawArgs) {
|
|
|
75
70
|
return;
|
|
76
71
|
}
|
|
77
72
|
childStarted = true;
|
|
78
|
-
|
|
79
|
-
childProcess = spawn(process.execPath, cliEntry ? [cliEntry, "dev", ...rawArgs] : [runnerFile, ...rawArgs], {
|
|
73
|
+
childProcess = spawn(process.execPath, [runnerFile, ...rawArgs], {
|
|
80
74
|
env: {
|
|
81
75
|
...process.env,
|
|
82
76
|
[RUN_MODE]: "app"
|
|
@@ -107,7 +101,7 @@ async function runViteController(rawArgs) {
|
|
|
107
101
|
}
|
|
108
102
|
restarting = true;
|
|
109
103
|
const suffix = file ? `: ${file}` : "";
|
|
110
|
-
logger
|
|
104
|
+
vite.config.logger.info(`[tsed-dev] restart (${reason})${suffix}`);
|
|
111
105
|
await stopChild();
|
|
112
106
|
startChild();
|
|
113
107
|
restarting = false;
|
|
@@ -126,7 +120,15 @@ async function runViteController(rawArgs) {
|
|
|
126
120
|
}
|
|
127
121
|
});
|
|
128
122
|
}
|
|
129
|
-
|
|
123
|
+
vite.watcher.once("ready", () => {
|
|
124
|
+
startChild();
|
|
125
|
+
});
|
|
126
|
+
// Fallback: some environments can miss/lag watcher "ready" when Vite re-optimizes deps.
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
if (!childStarted) {
|
|
129
|
+
startChild();
|
|
130
|
+
}
|
|
131
|
+
}, 2500);
|
|
130
132
|
const shutdown = async () => {
|
|
131
133
|
await stopChild();
|
|
132
134
|
await vite.close();
|
|
@@ -143,3 +145,9 @@ export async function dev(rawArgs = process.argv.slice(2)) {
|
|
|
143
145
|
}
|
|
144
146
|
await runViteController(rawArgs);
|
|
145
147
|
}
|
|
148
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
149
|
+
dev().catch((error) => {
|
|
150
|
+
console.error(error);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
});
|
|
153
|
+
}
|