@tsed/cli 7.5.0-rc.1 → 7.5.0-rc.3

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.
@@ -0,0 +1,42 @@
1
+ import { register } from "node:module";
2
+ import { join } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ const EXT = process.env.CLI_MODE === "ts" ? "ts" : "js";
5
+ register(pathToFileURL(join(import.meta.dirname, `../loaders/alias.hook.${EXT}`)), {
6
+ parentURL: import.meta.dirname,
7
+ data: {
8
+ "@tsed/core": import.meta.resolve("@tsed/core"),
9
+ "@tsed/di": import.meta.resolve("@tsed/di"),
10
+ "@tsed/schema": import.meta.resolve("@tsed/schema"),
11
+ "@tsed/cli-core": import.meta.resolve("@tsed/cli-core"),
12
+ "@tsed/cli": import.meta.resolve("@tsed/cli")
13
+ },
14
+ transferList: []
15
+ });
16
+ const { tools, commands, resources, CliCore, PKG, TEMPLATE_DIR, ArchitectureConvention, ProjectConvention } = await import("../index.js");
17
+ CliCore.bootstrap({
18
+ name: "tsed",
19
+ pkg: PKG,
20
+ templateDir: TEMPLATE_DIR,
21
+ plugins: true,
22
+ updateNotifier: true,
23
+ checkPrecondition: true,
24
+ commands,
25
+ tools,
26
+ resources,
27
+ defaultProjectPreferences() {
28
+ return {
29
+ convention: ProjectConvention.DEFAULT,
30
+ architecture: ArchitectureConvention.DEFAULT
31
+ };
32
+ },
33
+ project: {
34
+ reinstallAfterRun: true
35
+ },
36
+ logger: {
37
+ level: "info"
38
+ }
39
+ }).catch((error) => {
40
+ console.error(error);
41
+ process.exit(-1);
42
+ });
@@ -0,0 +1,23 @@
1
+ import { spawn } from "node:child_process";
2
+ import process from "node:process";
3
+ import { fileURLToPath } from "node:url";
4
+ function runNode(cmd, args) {
5
+ return new Promise((resolve, reject) => {
6
+ const child = spawn(cmd, args, {
7
+ env: process.env,
8
+ stdio: "inherit"
9
+ });
10
+ child.on("error", reject);
11
+ child.on("exit", (code) => {
12
+ if (code === 0) {
13
+ resolve();
14
+ return;
15
+ }
16
+ reject(new Error(`vite build exited with code ${code}`));
17
+ });
18
+ });
19
+ }
20
+ export async function build(rawArgs = process.argv.slice(2)) {
21
+ const viteBin = fileURLToPath(import.meta.resolve("vite/bin/vite.js"));
22
+ await runNode(process.execPath, [viteBin, "build", ...rawArgs]);
23
+ }
@@ -0,0 +1,131 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import process from "node:process";
4
+ import { fileURLToPath } from "node:url";
5
+ import { normalizePath } from "@tsed/cli-core";
6
+ import { logger } from "@tsed/di";
7
+ const RUN_MODE = "TSED_VITE_RUN_MODE";
8
+ function parseWatchValue(args) {
9
+ if (args.includes("--no-watch")) {
10
+ return false;
11
+ }
12
+ const watchIndex = args.findIndex((arg) => arg === "--watch" || arg.startsWith("--watch="));
13
+ if (watchIndex === -1) {
14
+ return true;
15
+ }
16
+ const watchArg = args[watchIndex];
17
+ if (watchArg === "--watch") {
18
+ const nextValue = args[watchIndex + 1];
19
+ if (!nextValue || nextValue.startsWith("-")) {
20
+ return true;
21
+ }
22
+ return nextValue !== "false";
23
+ }
24
+ if (watchArg === "--watch=false") {
25
+ return false;
26
+ }
27
+ if (watchArg === "--watch=true") {
28
+ return true;
29
+ }
30
+ return true;
31
+ }
32
+ function assertViteProject() {
33
+ const configFile = normalizePath("vite.config.ts");
34
+ if (!existsSync(configFile)) {
35
+ throw new Error("tsed dev is only available for ViteRuntime projects. Missing vite.config.ts in the current directory.");
36
+ }
37
+ }
38
+ async function createViteDevServer() {
39
+ // @ts-ignore
40
+ const { createServer } = await import("vite");
41
+ return createServer({
42
+ configFile: normalizePath("vite.config.ts"),
43
+ server: {
44
+ middlewareMode: true,
45
+ hmr: false,
46
+ ws: false
47
+ }
48
+ });
49
+ }
50
+ async function runViteApp() {
51
+ const vite = await createViteDevServer();
52
+ const shutdown = async () => {
53
+ await vite.close();
54
+ process.exit(0);
55
+ };
56
+ process.on("SIGINT", shutdown);
57
+ process.on("SIGTERM", shutdown);
58
+ await vite.ssrLoadModule("/src/index.ts");
59
+ await new Promise(() => { });
60
+ }
61
+ async function runViteController(rawArgs) {
62
+ const runnerFile = fileURLToPath(import.meta.url);
63
+ const watch = parseWatchValue(rawArgs);
64
+ const vite = await createViteDevServer();
65
+ let childProcess;
66
+ let restarting = false;
67
+ let queued = false;
68
+ const startChild = () => {
69
+ const cliEntry = process.argv[1];
70
+ childProcess = spawn(process.execPath, cliEntry ? [cliEntry, "dev", ...rawArgs] : [runnerFile, ...rawArgs], {
71
+ env: {
72
+ ...process.env,
73
+ [RUN_MODE]: "app"
74
+ },
75
+ stdio: "inherit"
76
+ });
77
+ };
78
+ const stopChild = async () => {
79
+ if (!childProcess || childProcess.killed) {
80
+ return;
81
+ }
82
+ await new Promise((resolve) => {
83
+ childProcess.once("exit", resolve);
84
+ childProcess.kill("SIGTERM");
85
+ });
86
+ };
87
+ const restartChild = async (reason, file = "") => {
88
+ if (restarting) {
89
+ queued = true;
90
+ return;
91
+ }
92
+ restarting = true;
93
+ const suffix = file ? `: ${file}` : "";
94
+ logger().info(`[tsed-dev] restart (${reason})${suffix}`);
95
+ await stopChild();
96
+ startChild();
97
+ restarting = false;
98
+ if (queued) {
99
+ queued = false;
100
+ await restartChild("queued");
101
+ }
102
+ };
103
+ if (watch) {
104
+ vite.watcher.on("all", async (event, file) => {
105
+ if (!file || file.includes("node_modules") || file.includes(".git") || file.includes("/dist/")) {
106
+ return;
107
+ }
108
+ if (["add", "change", "unlink"].includes(event)) {
109
+ await restartChild(event, file);
110
+ }
111
+ });
112
+ }
113
+ vite.watcher.once("ready", () => {
114
+ startChild();
115
+ });
116
+ const shutdown = async () => {
117
+ await stopChild();
118
+ await vite.close();
119
+ process.exit(0);
120
+ };
121
+ process.on("SIGINT", shutdown);
122
+ process.on("SIGTERM", shutdown);
123
+ await new Promise(() => { });
124
+ }
125
+ export async function dev(rawArgs = process.argv.slice(2)) {
126
+ if (process.env[RUN_MODE] === "app") {
127
+ await runViteApp();
128
+ return;
129
+ }
130
+ await runViteController(rawArgs);
131
+ }
@@ -1,44 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import "./ts-mode.js";
3
- import { register } from "node:module";
4
- import { join } from "node:path";
5
- import { pathToFileURL } from "node:url";
6
2
  const EXT = process.env.CLI_MODE === "ts" ? "ts" : "js";
7
- register(pathToFileURL(join(import.meta.dirname, `../loaders/alias.hook.${EXT}`)), {
8
- parentURL: import.meta.dirname,
9
- data: {
10
- "@tsed/core": import.meta.resolve("@tsed/core"),
11
- "@tsed/di": import.meta.resolve("@tsed/di"),
12
- "@tsed/schema": import.meta.resolve("@tsed/schema"),
13
- "@tsed/cli-core": import.meta.resolve("@tsed/cli-core"),
14
- "@tsed/cli": import.meta.resolve("@tsed/cli")
15
- },
16
- transferList: []
17
- });
18
- const { tools, commands, resources, CliCore, PKG, TEMPLATE_DIR, ArchitectureConvention, ProjectConvention } = await import("../index.js");
19
- CliCore.bootstrap({
20
- name: "tsed",
21
- pkg: PKG,
22
- templateDir: TEMPLATE_DIR,
23
- plugins: true,
24
- updateNotifier: true,
25
- checkPrecondition: true,
26
- commands,
27
- tools,
28
- resources,
29
- defaultProjectPreferences() {
30
- return {
31
- convention: ProjectConvention.DEFAULT,
32
- architecture: ArchitectureConvention.DEFAULT
33
- };
34
- },
35
- project: {
36
- reinstallAfterRun: true
37
- },
38
- logger: {
39
- level: "info"
40
- }
41
- }).catch((error) => {
42
- console.error(error);
43
- process.exit(-1);
44
- });
3
+ const [, , commandName, ...rawArgs] = process.argv;
4
+ switch (commandName) {
5
+ case "dev":
6
+ try {
7
+ const { dev } = await import("./tsed-dev.js");
8
+ await dev(rawArgs);
9
+ process.exit(0);
10
+ }
11
+ catch (error) {
12
+ console.error(error);
13
+ process.exit(1);
14
+ }
15
+ break;
16
+ case "build":
17
+ try {
18
+ const { build } = await import("./tsed-build.js");
19
+ await build(rawArgs);
20
+ process.exit(0);
21
+ }
22
+ catch (error) {
23
+ console.error(error);
24
+ process.exit(1);
25
+ }
26
+ break;
27
+ default:
28
+ await import("./ts-mode.js");
29
+ await import(`./boot.${EXT}`);
30
+ break;
31
+ }
32
+ export {};
@@ -1,6 +1,4 @@
1
1
  import { AddCmd } from "./add/AddCmd.js";
2
- import { BuildCmd } from "./build/BuildCmd.js";
3
- import { DevCmd } from "./dev/DevCmd.js";
4
2
  import { GenerateCmd } from "./generate/GenerateCmd.js";
5
3
  import { InitCmd } from "./init/InitCmd.js";
6
4
  import { InitOptionsCommand } from "./init/InitOptionsCmd.js";
@@ -8,4 +6,4 @@ import { McpCommand } from "./mcp/McpCommand.js";
8
6
  import { RunCmd } from "./run/RunCmd.js";
9
7
  import { CreateTemplateCommand } from "./template/CreateTemplateCommand.js";
10
8
  import { UpdateCmd } from "./update/UpdateCmd.js";
11
- export default [AddCmd, InitCmd, InitOptionsCommand, GenerateCmd, UpdateCmd, RunCmd, DevCmd, BuildCmd, CreateTemplateCommand, McpCommand];
9
+ export default [AddCmd, InitCmd, InitOptionsCommand, GenerateCmd, UpdateCmd, RunCmd, CreateTemplateCommand, McpCommand];
@@ -42,4 +42,4 @@ export class RuntimesModule {
42
42
  };
43
43
  }
44
44
  }
45
- injectable(RuntimesModule).imports([ViteRuntime, NodeRuntime, BabelRuntime, WebpackRuntime, , BunRuntime]);
45
+ injectable(RuntimesModule).imports([ViteRuntime, NodeRuntime, BabelRuntime, WebpackRuntime, BunRuntime]);