@tsed/cli 7.5.0-rc.4 → 7.5.0-rc.6
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/esm/commands/init/InitCmd.js +6 -4
- package/lib/esm/commands/init/config/FeaturesPrompt.js +4 -0
- package/lib/esm/commands/init/config/InitSchema.js +6 -2
- package/lib/esm/commands/mcp/schema/ProjectPreferencesSchema.js +2 -2
- package/lib/esm/runtimes/RuntimesModule.js +3 -2
- package/lib/esm/runtimes/index.js +1 -0
- package/lib/esm/runtimes/supports/BunViteRuntime.js +30 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/mcp/schema/ProjectPreferencesSchema.d.ts +1 -1
- package/lib/types/interfaces/RenderDataContext.d.ts +1 -0
- package/lib/types/interfaces/RuntimeTypes.d.ts +1 -1
- package/lib/types/runtimes/index.d.ts +1 -0
- package/lib/types/runtimes/supports/BunViteRuntime.d.ts +11 -0
- package/package.json +6 -6
package/lib/esm/bin/tsed-dev.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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
|
-
import { normalizePath } from "@tsed/cli-core";
|
|
6
|
-
import { logger } from "@tsed/di";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
6
|
const RUN_MODE = "TSED_VITE_RUN_MODE";
|
|
7
|
+
const runnerFile = fileURLToPath(import.meta.url);
|
|
8
|
+
const configFile = path.resolve(process.cwd(), "vite.config.ts");
|
|
8
9
|
function parseWatchValue(args) {
|
|
9
10
|
if (args.includes("--no-watch")) {
|
|
10
11
|
return false;
|
|
@@ -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
|
+
}
|
|
@@ -13,6 +13,7 @@ import { taskOutput } from "../../fn/taskOutput.js";
|
|
|
13
13
|
import { PlatformsModule } from "../../platforms/PlatformsModule.js";
|
|
14
14
|
import { RuntimesModule } from "../../runtimes/RuntimesModule.js";
|
|
15
15
|
import { BunRuntime } from "../../runtimes/supports/BunRuntime.js";
|
|
16
|
+
import { BunViteRuntime } from "../../runtimes/supports/BunViteRuntime.js";
|
|
16
17
|
import { NodeRuntime } from "../../runtimes/supports/NodeRuntime.js";
|
|
17
18
|
import { ViteRuntime } from "../../runtimes/supports/ViteRuntime.js";
|
|
18
19
|
import { CliProjectService } from "../../services/CliProjectService.js";
|
|
@@ -75,7 +76,7 @@ export class InitCmd {
|
|
|
75
76
|
this.resolveRootDir(ctx);
|
|
76
77
|
ctx = mapToContext(ctx);
|
|
77
78
|
if (this.isLaunchedWithBunx()) {
|
|
78
|
-
ctx.runtime
|
|
79
|
+
ctx.runtime ??= "bun";
|
|
79
80
|
ctx.packageManager = "bun";
|
|
80
81
|
}
|
|
81
82
|
this.runtimes.init(ctx);
|
|
@@ -95,7 +96,7 @@ export class InitCmd {
|
|
|
95
96
|
return Boolean(globalThis.Bun);
|
|
96
97
|
}
|
|
97
98
|
filterOnlyBun(values) {
|
|
98
|
-
const filtered = values.filter((value) =>
|
|
99
|
+
const filtered = values.filter((value) => ["bun", "bun-vite"].includes(value));
|
|
99
100
|
return filtered.length ? filtered : values;
|
|
100
101
|
}
|
|
101
102
|
async writeRcFiles(ctx) {
|
|
@@ -143,8 +144,9 @@ export class InitCmd {
|
|
|
143
144
|
ctx = {
|
|
144
145
|
...ctx,
|
|
145
146
|
node: runtime instanceof NodeRuntime,
|
|
146
|
-
bun: runtime instanceof BunRuntime,
|
|
147
|
-
|
|
147
|
+
bun: runtime instanceof BunRuntime || runtime instanceof BunViteRuntime,
|
|
148
|
+
bunVite: runtime instanceof BunViteRuntime,
|
|
149
|
+
vite: runtime instanceof ViteRuntime || runtime instanceof BunViteRuntime,
|
|
148
150
|
compiled: runtime.isCompiled()
|
|
149
151
|
};
|
|
150
152
|
return [
|
|
@@ -278,6 +278,10 @@ export const InitSchema = () => {
|
|
|
278
278
|
label: "Node.js + Vite",
|
|
279
279
|
value: "vite"
|
|
280
280
|
},
|
|
281
|
+
{
|
|
282
|
+
label: "Bun.js + Vite",
|
|
283
|
+
value: "bun-vite"
|
|
284
|
+
},
|
|
281
285
|
{
|
|
282
286
|
label: "Node.js + SWC",
|
|
283
287
|
value: "node"
|
|
@@ -291,7 +295,7 @@ export const InitSchema = () => {
|
|
|
291
295
|
value: "webpack"
|
|
292
296
|
},
|
|
293
297
|
{
|
|
294
|
-
label: "Bun",
|
|
298
|
+
label: "Bun.js",
|
|
295
299
|
value: "bun"
|
|
296
300
|
}
|
|
297
301
|
].filter((o) => availableRuntimes.includes(o.value)))
|
|
@@ -301,7 +305,7 @@ export const InitSchema = () => {
|
|
|
301
305
|
packageManager: s
|
|
302
306
|
.enums(availablePackageManagers)
|
|
303
307
|
.prompt("Choose the package manager:")
|
|
304
|
-
.when((answers) =>
|
|
308
|
+
.when((answers) => !["bun", "bun-vite"].includes(answers.runtime))
|
|
305
309
|
.default(PackageManager.NPM)
|
|
306
310
|
.choices([
|
|
307
311
|
{
|
|
@@ -8,8 +8,8 @@ export const ProjectPreferenceSchema = s
|
|
|
8
8
|
packageManager: s.string().enum(PackageManager).description("Used project manager to install dependencies"),
|
|
9
9
|
runtime: s
|
|
10
10
|
.string()
|
|
11
|
-
.enum("vite", "node", "babel", "swc", "webpack", "bun")
|
|
12
|
-
.description("The javascript runtime used to start application (node, node + webpack, node + swc, node + babel, bun
|
|
11
|
+
.enum("vite", "bun-vite", "node", "babel", "swc", "webpack", "bun")
|
|
12
|
+
.description("The javascript runtime used to start application (node + vite, bun + vite, node + webpack, node + swc, node + babel, bun)"),
|
|
13
13
|
platform: s.string().enum(PlatformType).description("Node.js framework used to run server (Express, Koa, Fastify)")
|
|
14
14
|
})
|
|
15
15
|
.optional()
|
|
@@ -3,6 +3,7 @@ import { inject, injectable, injectMany } from "@tsed/di";
|
|
|
3
3
|
import { BabelRuntime } from "./supports/BabelRuntime.js";
|
|
4
4
|
import { BaseRuntime } from "./supports/BaseRuntime.js";
|
|
5
5
|
import { BunRuntime } from "./supports/BunRuntime.js";
|
|
6
|
+
import { BunViteRuntime } from "./supports/BunViteRuntime.js";
|
|
6
7
|
import { NodeRuntime } from "./supports/NodeRuntime.js";
|
|
7
8
|
import { ViteRuntime } from "./supports/ViteRuntime.js";
|
|
8
9
|
import { WebpackRuntime } from "./supports/WebpackRuntime.js";
|
|
@@ -13,7 +14,7 @@ export class RuntimesModule {
|
|
|
13
14
|
}
|
|
14
15
|
init(ctx) {
|
|
15
16
|
ctx.runtime = ctx.runtime || this.get().name;
|
|
16
|
-
if (ctx.runtime
|
|
17
|
+
if (ctx.runtime.startsWith("bun")) {
|
|
17
18
|
ctx.packageManager = "bun";
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -42,4 +43,4 @@ export class RuntimesModule {
|
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
injectable(RuntimesModule).imports([ViteRuntime, NodeRuntime, BabelRuntime, WebpackRuntime, BunRuntime]);
|
|
46
|
+
injectable(RuntimesModule).imports([ViteRuntime, BunViteRuntime, NodeRuntime, BabelRuntime, WebpackRuntime, BunRuntime]);
|
|
@@ -2,6 +2,7 @@ export * from "./RuntimesModule.js";
|
|
|
2
2
|
export * from "./supports/BabelRuntime.js";
|
|
3
3
|
export * from "./supports/BaseRuntime.js";
|
|
4
4
|
export * from "./supports/BunRuntime.js";
|
|
5
|
+
export * from "./supports/BunViteRuntime.js";
|
|
5
6
|
export * from "./supports/NodeRuntime.js";
|
|
6
7
|
export * from "./supports/ViteRuntime.js";
|
|
7
8
|
export * from "./supports/WebpackRuntime.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { injectable } from "@tsed/di";
|
|
2
|
+
import { BaseRuntime } from "./BaseRuntime.js";
|
|
3
|
+
export class BunViteRuntime extends BaseRuntime {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.name = "bun-vite";
|
|
7
|
+
this.cmd = "bun";
|
|
8
|
+
this.order = 1;
|
|
9
|
+
}
|
|
10
|
+
files() {
|
|
11
|
+
return ["vite.config.ts"];
|
|
12
|
+
}
|
|
13
|
+
compile() {
|
|
14
|
+
return "tsed build";
|
|
15
|
+
}
|
|
16
|
+
startDev() {
|
|
17
|
+
return "tsed dev";
|
|
18
|
+
}
|
|
19
|
+
startProd(args) {
|
|
20
|
+
return `bun ${args}`;
|
|
21
|
+
}
|
|
22
|
+
devDependencies() {
|
|
23
|
+
return {
|
|
24
|
+
"@tsed/cli": "{{cliVersion}}",
|
|
25
|
+
typescript: "latest",
|
|
26
|
+
vite: "latest"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
injectable(BunViteRuntime).type("runtime");
|