silgi 0.43.17 → 0.43.19
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/dist/build.d.mts +2 -2
- package/dist/cli/build/dev.d.mts +4 -3
- package/dist/cli/build/dev.mjs +30 -44
- package/dist/cli/build/prepare.d.mts +1 -1
- package/dist/cli/commands/init.mjs +1 -1
- package/dist/cli/commands/run.mjs +14 -60
- package/dist/cli/commands/watch.mjs +114 -9
- package/dist/cli/config/index.d.mts +2 -2
- package/dist/cli/config/loader.d.mts +1 -1
- package/dist/cli/config/resolvers/compatibility.mjs +1 -1
- package/dist/cli/config/types.d.mts +1 -1
- package/dist/cli/core/app.mjs +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/module/install.mjs +1 -1
- package/dist/cli/module/scan.mjs +6 -6
- package/dist/cli/scan/prepareCommands.mjs +1 -1
- package/dist/cli/scan/scanExportFile.mjs +3 -3
- package/dist/cli/scan/writeTypesAndFiles.mjs +1 -1
- package/dist/cli/utils/compatibility.mjs +1 -1
- package/dist/cli/utils/processManager.mjs +158 -0
- package/dist/core/context.d.mts +1 -1
- package/dist/core/createSilgi.d.mts +1 -1
- package/dist/core/error.d.mts +1 -1
- package/dist/core/event.d.mts +1 -1
- package/dist/core/index.d.mts +19 -19
- package/dist/core/response.d.mts +2 -2
- package/dist/core/silgi.d.mts +1 -1
- package/dist/core/silgiApp.d.mts +1 -1
- package/dist/core/storage.d.mts +1 -1
- package/dist/core/unctx.d.mts +1 -1
- package/dist/core/utils/event-stream.d.mts +2 -2
- package/dist/core/utils/event.d.mts +1 -1
- package/dist/core/utils/internal/event-stream.d.mts +1 -1
- package/dist/core/utils/merge.d.mts +1 -1
- package/dist/core/utils/middleware.d.mts +1 -1
- package/dist/core/utils/resolver.d.mts +1 -1
- package/dist/core/utils/runtime.d.mts +1 -1
- package/dist/core/utils/schema.d.mts +1 -1
- package/dist/core/utils/service.d.mts +1 -1
- package/dist/core/utils/shared.d.mts +1 -1
- package/dist/core/utils/storage.d.mts +1 -1
- package/dist/index.d.mts +19 -19
- package/dist/kit/add/add-commands.d.mts +1 -1
- package/dist/kit/add/add-core-file.d.mts +1 -1
- package/dist/kit/add/add-imports.d.mts +1 -1
- package/dist/kit/add/add-npm.d.mts +1 -1
- package/dist/kit/define.d.mts +1 -1
- package/dist/kit/errors.d.mts +1 -1
- package/dist/kit/esm.d.mts +1 -1
- package/dist/kit/fs.d.mts +1 -1
- package/dist/kit/function-utils.d.mts +1 -1
- package/dist/kit/function-utils.mjs +1 -1
- package/dist/kit/gen.d.mts +1 -1
- package/dist/kit/hash.d.mts +1 -1
- package/dist/kit/index.d.mts +21 -21
- package/dist/kit/index.mjs +1 -1
- package/dist/kit/isFramework.d.mts +1 -1
- package/dist/kit/logger.d.mts +1 -1
- package/dist/kit/migration.d.mts +1 -1
- package/dist/kit/migration.mjs +1 -1
- package/dist/kit/module.d.mts +1 -1
- package/dist/kit/path.d.mts +1 -1
- package/dist/kit/preset.d.mts +1 -1
- package/dist/kit/resolve.d.mts +1 -1
- package/dist/kit/resolve.mjs +1 -1
- package/dist/kit/template.d.mts +1 -1
- package/dist/kit/useRequest.d.mts +1 -1
- package/dist/kit/utils.d.mts +1 -1
- package/dist/package.mjs +8 -9
- package/package.json +18 -19
package/dist/build.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { watchDev } from "./cli/build/dev.mjs";
|
|
2
|
-
import { prepareBuild } from "./cli/build/prepare.mjs";
|
|
1
|
+
import { watchDev$1 as watchDev } from "./cli/build/dev.mjs";
|
|
2
|
+
import { prepareBuild$1 as prepareBuild } from "./cli/build/prepare.mjs";
|
|
3
3
|
export { prepareBuild, watchDev };
|
package/dist/cli/build/dev.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { FSWatcher } from "chokidar";
|
|
2
2
|
|
|
3
3
|
//#region src/cli/build/dev.d.ts
|
|
4
|
-
|
|
4
|
+
interface WatchDevResult {
|
|
5
5
|
watcher: FSWatcher | undefined;
|
|
6
6
|
close: () => Promise<void>;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
|
+
declare function watchDev(): Promise<WatchDevResult>;
|
|
8
9
|
//#endregion
|
|
9
|
-
export { watchDev };
|
|
10
|
+
export { watchDev as watchDev$1 };
|
package/dist/cli/build/dev.mjs
CHANGED
|
@@ -8,46 +8,27 @@ import { basename } from "pathe";
|
|
|
8
8
|
import { debounce } from "perfect-debounce";
|
|
9
9
|
|
|
10
10
|
//#region src/cli/build/dev.ts
|
|
11
|
+
const WATCH_IGNORE_FILES = [
|
|
12
|
+
"scan",
|
|
13
|
+
"meta",
|
|
14
|
+
"core",
|
|
15
|
+
"configs"
|
|
16
|
+
];
|
|
17
|
+
const WATCH_IGNORE_EXTENSIONS = [
|
|
18
|
+
"ts",
|
|
19
|
+
"js",
|
|
20
|
+
"mjs",
|
|
21
|
+
"cjs",
|
|
22
|
+
"d.ts",
|
|
23
|
+
"d.mts",
|
|
24
|
+
"d.cts",
|
|
25
|
+
"d.js"
|
|
26
|
+
];
|
|
11
27
|
const IGNORED_WATCH_PATTERNS = [
|
|
12
28
|
"**/.silgi/**",
|
|
13
29
|
"**/.output/**",
|
|
14
30
|
"**/types/**",
|
|
15
|
-
|
|
16
|
-
"**/scan.js",
|
|
17
|
-
"**/scan.mjs",
|
|
18
|
-
"**/scan.cjs",
|
|
19
|
-
"**/scan.d.ts",
|
|
20
|
-
"**/scan.d.mts",
|
|
21
|
-
"**/scan.d.cts",
|
|
22
|
-
"**/scan.d.js",
|
|
23
|
-
"**/scan.d.ts",
|
|
24
|
-
"**/meta.ts",
|
|
25
|
-
"**/meta.js",
|
|
26
|
-
"**/meta.mjs",
|
|
27
|
-
"**/meta.cjs",
|
|
28
|
-
"**/meta.d.ts",
|
|
29
|
-
"**/meta.d.mts",
|
|
30
|
-
"**/meta.d.cts",
|
|
31
|
-
"**/meta.d.js",
|
|
32
|
-
"**/meta.d.ts",
|
|
33
|
-
"**/core.ts",
|
|
34
|
-
"**/core.js",
|
|
35
|
-
"**/core.mjs",
|
|
36
|
-
"**/core.cjs",
|
|
37
|
-
"**/core.d.ts",
|
|
38
|
-
"**/core.d.mts",
|
|
39
|
-
"**/core.d.cts",
|
|
40
|
-
"**/core.d.js",
|
|
41
|
-
"**/core.d.ts",
|
|
42
|
-
"**/configs.ts",
|
|
43
|
-
"**/configs.js",
|
|
44
|
-
"**/configs.mjs",
|
|
45
|
-
"**/configs.cjs",
|
|
46
|
-
"**/configs.d.ts",
|
|
47
|
-
"**/configs.d.mts",
|
|
48
|
-
"**/configs.d.cts",
|
|
49
|
-
"**/configs.d.js",
|
|
50
|
-
"**/configs.d.ts"
|
|
31
|
+
...WATCH_IGNORE_FILES.flatMap((file) => WATCH_IGNORE_EXTENSIONS.map((ext) => `**/${file}.${ext}`))
|
|
51
32
|
];
|
|
52
33
|
function isIgnoredByPattern(path) {
|
|
53
34
|
return IGNORED_WATCH_PATTERNS.some((pattern) => micromatch.isMatch(path, pattern));
|
|
@@ -55,14 +36,24 @@ function isIgnoredByPattern(path) {
|
|
|
55
36
|
async function watchDev() {
|
|
56
37
|
const silgi = useSilgiCLI();
|
|
57
38
|
let watcher;
|
|
39
|
+
const changedFiles = new Set();
|
|
58
40
|
async function load() {
|
|
41
|
+
const startTime = performance.now();
|
|
42
|
+
if (changedFiles.size > 0) {
|
|
43
|
+
const fileList = Array.from(changedFiles).map((f) => basename(f)).join(", ");
|
|
44
|
+
consola.info(`Rebuilding: ${fileList}`);
|
|
45
|
+
changedFiles.clear();
|
|
46
|
+
}
|
|
59
47
|
await prepareBuild({
|
|
60
48
|
commandType: "prepare",
|
|
61
49
|
activeEnvironment: silgi.options.activeEnvironment || ".env",
|
|
62
50
|
dev: true
|
|
63
51
|
});
|
|
52
|
+
const endTime = performance.now();
|
|
53
|
+
const elapsedTime = Math.round(endTime - startTime);
|
|
54
|
+
silgi.logger.success(`Build completed in ${elapsedTime}ms`);
|
|
64
55
|
}
|
|
65
|
-
const reload = debounce(load);
|
|
56
|
+
const reload = debounce(load, 300);
|
|
66
57
|
const watchReloadEvents = new Set([
|
|
67
58
|
"add",
|
|
68
59
|
"addDir",
|
|
@@ -72,22 +63,17 @@ async function watchDev() {
|
|
|
72
63
|
]);
|
|
73
64
|
if (silgi.options.devServer.watch.length > 0) {
|
|
74
65
|
silgi.options.devServer.watch = [...new Set(silgi.options.devServer.watch)].filter((p) => !isIgnoredByPattern(p));
|
|
75
|
-
consola.info(
|
|
66
|
+
consola.info(`[silgi] Watching ${silgi.options.devServer.watch.length} paths for changes`);
|
|
76
67
|
watcher = watch(silgi.options.devServer.watch, silgi.options.watchOptions);
|
|
77
68
|
watcher.on("all", async (event, path, stats) => {
|
|
78
69
|
if (!watchReloadEvents.has(event)) return;
|
|
79
|
-
|
|
80
|
-
silgi.errors = [];
|
|
70
|
+
changedFiles.add(path);
|
|
81
71
|
try {
|
|
82
72
|
await reloadScan(path, stats);
|
|
83
73
|
await reload();
|
|
84
74
|
} catch (error) {
|
|
85
75
|
consola.withTag("silgi").error(error);
|
|
86
76
|
}
|
|
87
|
-
silgi.errors = [];
|
|
88
|
-
const endTime = performance.now();
|
|
89
|
-
const elapsedTime = Math.round(endTime - startTime);
|
|
90
|
-
silgi.logger.success(`${basename(path)} - ${elapsedTime}ms`);
|
|
91
77
|
}).on("error", (error) => {
|
|
92
78
|
consola.withTag("silgi").error(error);
|
|
93
79
|
});
|
|
@@ -45,7 +45,7 @@ const command = defineCommand({
|
|
|
45
45
|
"",
|
|
46
46
|
"export default defineSilgiConfig({",
|
|
47
47
|
` preset: '${framework}',`,
|
|
48
|
-
` compatibilityDate: '${
|
|
48
|
+
` compatibilityDate: '${new Date().toISOString().split("T")[0]}',`,
|
|
49
49
|
"",
|
|
50
50
|
"})",
|
|
51
51
|
""
|
|
@@ -1,74 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { commonArgs } from "../utils/common.mjs";
|
|
3
|
-
import prepare_default from "./prepare.mjs";
|
|
1
|
+
import watch_default from "./watch.mjs";
|
|
4
2
|
import consola from "consola";
|
|
5
3
|
import { version } from "silgi/meta";
|
|
6
4
|
import { runCommand } from "citty";
|
|
7
|
-
import { execa } from "execa";
|
|
8
5
|
|
|
9
6
|
//#region src/cli/commands/run.ts
|
|
10
7
|
const command = {
|
|
11
8
|
meta: {
|
|
12
|
-
name: "
|
|
13
|
-
description: "
|
|
9
|
+
name: "run",
|
|
10
|
+
description: "Run a command with silgi watch (shortcut for \"silgi watch npm run <command>\")",
|
|
14
11
|
version
|
|
15
12
|
},
|
|
16
|
-
args: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
required: false
|
|
22
|
-
}
|
|
23
|
-
},
|
|
13
|
+
args: { command: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "your application start command",
|
|
16
|
+
required: false
|
|
17
|
+
} },
|
|
24
18
|
async run({ args, rawArgs }) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
] });
|
|
31
|
-
const startCommand = args.command || rawArgs[0];
|
|
32
|
-
let childProcess = null;
|
|
33
|
-
let watcher = null;
|
|
34
|
-
let exiting = false;
|
|
35
|
-
const cleanupAndExit = async (code = 0) => {
|
|
36
|
-
if (exiting) return;
|
|
37
|
-
exiting = true;
|
|
38
|
-
try {
|
|
39
|
-
if (watcher?.close) await watcher.close().catch(() => {});
|
|
40
|
-
if (childProcess) childProcess.kill("SIGTERM");
|
|
41
|
-
} catch {}
|
|
42
|
-
process.exit(code);
|
|
43
|
-
};
|
|
44
|
-
const handleSignal = (signal) => {
|
|
45
|
-
consola.info(`Received ${signal}, terminating...`);
|
|
46
|
-
cleanupAndExit(0);
|
|
47
|
-
};
|
|
48
|
-
process.on("SIGINT", handleSignal);
|
|
49
|
-
process.on("SIGTERM", handleSignal);
|
|
50
|
-
process.on("SIGHUP", handleSignal);
|
|
51
|
-
try {
|
|
52
|
-
watcher = await watchDev();
|
|
53
|
-
consola.info(`Starting: nr ${startCommand}`);
|
|
54
|
-
childProcess = execa("nr", [startCommand], {
|
|
55
|
-
stdio: "inherit",
|
|
56
|
-
cwd: process.cwd()
|
|
57
|
-
});
|
|
58
|
-
childProcess.on("exit", (code) => {
|
|
59
|
-
if (code !== 0) consola.error(`Process exited with code ${code}`);
|
|
60
|
-
else consola.success("Process exited successfully.");
|
|
61
|
-
cleanupAndExit(code ?? 0);
|
|
62
|
-
});
|
|
63
|
-
childProcess.on("error", (err) => {
|
|
64
|
-
consola.error("Child process error:", err);
|
|
65
|
-
cleanupAndExit(1);
|
|
66
|
-
});
|
|
67
|
-
await childProcess;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
consola.error("Error:", error);
|
|
70
|
-
cleanupAndExit(1);
|
|
19
|
+
const command$1 = args.command || rawArgs[0];
|
|
20
|
+
if (command$1 && !command$1.includes(" ")) {
|
|
21
|
+
const fullCommand = `npm run ${command$1}`;
|
|
22
|
+
consola.info(`Running: ${fullCommand}`);
|
|
23
|
+
return runCommand(watch_default, { rawArgs: [fullCommand] });
|
|
71
24
|
}
|
|
25
|
+
return runCommand(watch_default, { rawArgs });
|
|
72
26
|
}
|
|
73
27
|
};
|
|
74
28
|
var run_default = command;
|
|
@@ -1,11 +1,52 @@
|
|
|
1
1
|
import { watchDev } from "../build/dev.mjs";
|
|
2
2
|
import { commonArgs } from "../utils/common.mjs";
|
|
3
3
|
import prepare_default from "./prepare.mjs";
|
|
4
|
+
import { aggressiveCleanup, killPortProcesses, killProcessTree } from "../utils/processManager.mjs";
|
|
4
5
|
import consola from "consola";
|
|
5
6
|
import { version } from "silgi/meta";
|
|
6
7
|
import { defineCommand, runCommand } from "citty";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
7
9
|
|
|
8
10
|
//#region src/cli/commands/watch.ts
|
|
11
|
+
const runningProcesses = new Map();
|
|
12
|
+
const openPorts = new Set();
|
|
13
|
+
let watchHandle = null;
|
|
14
|
+
let isShuttingDown = false;
|
|
15
|
+
const isWindows = process.platform === "win32";
|
|
16
|
+
function detectPort(data) {
|
|
17
|
+
const patterns = [
|
|
18
|
+
/localhost:(\d+)/i,
|
|
19
|
+
/127\.0\.0\.1:(\d+)/,
|
|
20
|
+
/0\.0\.0\.0:(\d+)/,
|
|
21
|
+
/\[::1\]:(\d+)/,
|
|
22
|
+
/Local:\s*http:\/\/[^:]+:(\d+)/i,
|
|
23
|
+
/➜\s+Local:\s+http:\/\/[^:]+:(\d+)/i
|
|
24
|
+
];
|
|
25
|
+
for (const pattern of patterns) {
|
|
26
|
+
const match = data.match(pattern);
|
|
27
|
+
if (match && match[1]) return Number.parseInt(match[1], 10);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
async function shutdown() {
|
|
32
|
+
if (isShuttingDown) return;
|
|
33
|
+
isShuttingDown = true;
|
|
34
|
+
consola.info("\n🛑 Shutting down...");
|
|
35
|
+
for (const [pid, proc] of runningProcesses) if (!proc.killed) {
|
|
36
|
+
consola.info(`Terminating process ${pid}...`);
|
|
37
|
+
await killProcessTree(pid);
|
|
38
|
+
}
|
|
39
|
+
runningProcesses.clear();
|
|
40
|
+
for (const port of openPorts) await killPortProcesses(port);
|
|
41
|
+
openPorts.clear();
|
|
42
|
+
if (openPorts.size > 0 || runningProcesses.size > 0) {
|
|
43
|
+
consola.warn("Some processes may still be running, performing aggressive cleanup...");
|
|
44
|
+
await aggressiveCleanup();
|
|
45
|
+
}
|
|
46
|
+
if (watchHandle?.close) await watchHandle.close();
|
|
47
|
+
consola.success("✅ Shutdown complete\n");
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
9
50
|
const command = defineCommand({
|
|
10
51
|
meta: {
|
|
11
52
|
name: "dev",
|
|
@@ -21,27 +62,91 @@ const command = defineCommand({
|
|
|
21
62
|
stub: {
|
|
22
63
|
type: "boolean",
|
|
23
64
|
description: "Run in silgi development mode"
|
|
65
|
+
},
|
|
66
|
+
command: {
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "Optional command to run alongside watch (e.g., \"npm run dev\")",
|
|
69
|
+
required: false
|
|
24
70
|
}
|
|
25
71
|
},
|
|
26
|
-
async run() {
|
|
72
|
+
async run({ args, rawArgs }) {
|
|
27
73
|
await runCommand(prepare_default, { rawArgs: [
|
|
28
74
|
"--commandType",
|
|
29
75
|
"dev",
|
|
30
76
|
"--dev",
|
|
31
77
|
"true"
|
|
32
78
|
] });
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
79
|
+
watchHandle = await watchDev();
|
|
80
|
+
const userCommand = args.command || rawArgs[0];
|
|
81
|
+
if (userCommand) {
|
|
82
|
+
consola.withTag("silgi").info(`Starting: ${userCommand}`);
|
|
83
|
+
const [cmd, ...cmdArgs] = userCommand.split(" ");
|
|
84
|
+
if (!cmd) {
|
|
85
|
+
consola.error("Invalid command provided");
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
const childProcess = spawn(cmd, cmdArgs, {
|
|
89
|
+
stdio: [
|
|
90
|
+
"inherit",
|
|
91
|
+
"pipe",
|
|
92
|
+
"pipe"
|
|
93
|
+
],
|
|
94
|
+
cwd: process.cwd(),
|
|
95
|
+
shell: isWindows,
|
|
96
|
+
detached: !isWindows,
|
|
97
|
+
env: { ...process.env }
|
|
98
|
+
});
|
|
99
|
+
if (childProcess.pid) {
|
|
100
|
+
runningProcesses.set(childProcess.pid, childProcess);
|
|
101
|
+
consola.debug(`Started process ${childProcess.pid}`);
|
|
102
|
+
}
|
|
103
|
+
childProcess.stdout?.on("data", (data) => {
|
|
104
|
+
const output = data.toString();
|
|
105
|
+
process.stdout.write(output);
|
|
106
|
+
const port = detectPort(output);
|
|
107
|
+
if (port && !openPorts.has(port)) {
|
|
108
|
+
openPorts.add(port);
|
|
109
|
+
consola.info(`Detected server on port ${port}`);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
childProcess.stderr?.on("data", (data) => {
|
|
113
|
+
process.stderr.write(data);
|
|
114
|
+
});
|
|
115
|
+
childProcess.on("exit", (code, signal) => {
|
|
116
|
+
if (childProcess.pid) runningProcesses.delete(childProcess.pid);
|
|
117
|
+
if (!isShuttingDown) {
|
|
118
|
+
if (code !== null && code !== 0) consola.error(`Process exited with code ${code}`);
|
|
119
|
+
else if (signal) consola.error(`Process killed by signal ${signal}`);
|
|
120
|
+
process.exit(code ?? 1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
childProcess.on("error", (err) => {
|
|
124
|
+
consola.error("Child process error:", err);
|
|
125
|
+
if (!isShuttingDown) process.exit(1);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
40
128
|
consola.withTag("silgi").success("Prepare completed");
|
|
41
129
|
consola.withTag("silgi").info("Process is still running. Press Ctrl+C to exit.");
|
|
42
|
-
|
|
130
|
+
await new Promise(() => {});
|
|
43
131
|
}
|
|
44
132
|
});
|
|
133
|
+
process.on("SIGINT", shutdown);
|
|
134
|
+
process.on("SIGTERM", shutdown);
|
|
135
|
+
process.on("SIGHUP", shutdown);
|
|
136
|
+
process.on("SIGQUIT", shutdown);
|
|
137
|
+
process.on("exit", () => {
|
|
138
|
+
if (!isShuttingDown) for (const [pid] of runningProcesses) try {
|
|
139
|
+
process.kill(pid, "SIGKILL");
|
|
140
|
+
} catch {}
|
|
141
|
+
});
|
|
142
|
+
process.on("uncaughtException", (err) => {
|
|
143
|
+
consola.error("Uncaught exception:", err);
|
|
144
|
+
shutdown();
|
|
145
|
+
});
|
|
146
|
+
process.on("unhandledRejection", (err) => {
|
|
147
|
+
consola.error("Unhandled rejection:", err);
|
|
148
|
+
shutdown();
|
|
149
|
+
});
|
|
45
150
|
var watch_default = command;
|
|
46
151
|
|
|
47
152
|
//#endregion
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { loadOptions } from "./loader.mjs";
|
|
2
|
-
import { silgiGenerateType } from "./types.mjs";
|
|
1
|
+
import { loadOptions$1 as loadOptions } from "./loader.mjs";
|
|
2
|
+
import { silgiGenerateType$1 as silgiGenerateType } from "./types.mjs";
|
|
3
3
|
export { loadOptions, silgiGenerateType };
|
|
@@ -3,4 +3,4 @@ import { LoadConfigOptions, SilgiCLIConfig, SilgiCLIOptions } from "silgi/types"
|
|
|
3
3
|
//#region src/cli/config/loader.d.ts
|
|
4
4
|
declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
|
|
5
5
|
//#endregion
|
|
6
|
-
export { loadOptions };
|
|
6
|
+
export { loadOptions as loadOptions$1 };
|
|
@@ -12,7 +12,7 @@ async function resolveCompatibilityOptions(options) {
|
|
|
12
12
|
let _fallbackInfoShown = false;
|
|
13
13
|
let _promptedUserToUpdate = false;
|
|
14
14
|
async function _resolveDefault(options) {
|
|
15
|
-
const _todayDate = formatDate(
|
|
15
|
+
const _todayDate = formatDate(new Date());
|
|
16
16
|
const consola$2 = consola.withTag("silgi");
|
|
17
17
|
consola$2.warn(`No valid compatibility date is specified.`);
|
|
18
18
|
const onFallback = () => {
|
package/dist/cli/core/app.mjs
CHANGED
|
@@ -42,7 +42,7 @@ async function generateApp(app, options = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
const templateContext = { app };
|
|
44
44
|
const writes = [];
|
|
45
|
-
const dirs =
|
|
45
|
+
const dirs = new Set();
|
|
46
46
|
const changedTemplates = [];
|
|
47
47
|
async function processTemplate(template) {
|
|
48
48
|
let dir;
|
package/dist/cli/index.mjs
CHANGED
package/dist/cli/module/scan.mjs
CHANGED
|
@@ -103,12 +103,12 @@ async function scanModules(silgi) {
|
|
|
103
103
|
silgi.scanModules = modules;
|
|
104
104
|
}
|
|
105
105
|
function createDependencyGraph(modules) {
|
|
106
|
-
const graph =
|
|
107
|
-
const inDegree =
|
|
106
|
+
const graph = new Map();
|
|
107
|
+
const inDegree = new Map();
|
|
108
108
|
modules.forEach((module) => {
|
|
109
109
|
const key = module.meta?.configKey;
|
|
110
110
|
if (key) {
|
|
111
|
-
graph.set(key,
|
|
111
|
+
graph.set(key, new Set());
|
|
112
112
|
inDegree.set(key, 0);
|
|
113
113
|
}
|
|
114
114
|
});
|
|
@@ -118,7 +118,7 @@ function createDependencyGraph(modules) {
|
|
|
118
118
|
const requiredDeps = module.meta?.requiredDependencies || [];
|
|
119
119
|
const beforeDeps = module.meta?.beforeDependencies || [];
|
|
120
120
|
const afterDeps = module.meta?.afterDependencies || [];
|
|
121
|
-
const processedDeps =
|
|
121
|
+
const processedDeps = new Set();
|
|
122
122
|
requiredDeps.forEach((dep) => {
|
|
123
123
|
if (!graph.has(dep)) throw new Error(`Required dependency "${dep}" for module "${key}" is missing`);
|
|
124
124
|
graph.get(dep)?.add(key);
|
|
@@ -143,8 +143,8 @@ function createDependencyGraph(modules) {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
function findCyclicDependencies(graph) {
|
|
146
|
-
const visited =
|
|
147
|
-
const recursionStack =
|
|
146
|
+
const visited = new Set();
|
|
147
|
+
const recursionStack = new Set();
|
|
148
148
|
const cycles = [];
|
|
149
149
|
function dfs(node, path = []) {
|
|
150
150
|
visited.add(node);
|
|
@@ -19,7 +19,7 @@ async function prepareCommands(silgi = useSilgiCLI()) {
|
|
|
19
19
|
if (command.tags) command.tags.forEach((tag) => acc.add(tag));
|
|
20
20
|
});
|
|
21
21
|
return acc;
|
|
22
|
-
},
|
|
22
|
+
}, new Set());
|
|
23
23
|
const data = [
|
|
24
24
|
genAugmentation("silgi/types", { SilgiCommands: { ...Object.fromEntries(Array.from(allTags.values()).map((tag) => [tag, "string"])) } }),
|
|
25
25
|
"",
|
|
@@ -152,7 +152,7 @@ async function extractExportEntitiesFromFile(absoluteFilePath, functionExportNam
|
|
|
152
152
|
const exportEntities = [];
|
|
153
153
|
const fileContent = await readFile(absoluteFilePath, "utf-8");
|
|
154
154
|
const parsed = await parseAsync(absoluteFilePath, fileContent);
|
|
155
|
-
const variableDeclarations =
|
|
155
|
+
const variableDeclarations = new Map();
|
|
156
156
|
for (const node of parsed.program.body) {
|
|
157
157
|
if (node.type === "VariableDeclaration" && Array.isArray(node.declarations)) {
|
|
158
158
|
for (const decl of node.declarations) if (decl.type === "VariableDeclarator" && decl.id.type === "Identifier") variableDeclarations.set(decl.id.name, decl);
|
|
@@ -224,7 +224,7 @@ async function extractExportEntitiesFromFile(absoluteFilePath, functionExportNam
|
|
|
224
224
|
return exportEntities;
|
|
225
225
|
}
|
|
226
226
|
async function scanSilgiExports(path, packageName, silgiInstance = useSilgiCLI(), scanOptions = {}) {
|
|
227
|
-
const processedFilePaths =
|
|
227
|
+
const processedFilePaths = new Set();
|
|
228
228
|
const alreadyScannedPaths = [];
|
|
229
229
|
const serverDirectory = path || silgiInstance.options.serverDir;
|
|
230
230
|
const functionExportNames = scanOptions.functionExportNames ?? DEFAULT_FUNCTION_EXPORT_NAMES;
|
|
@@ -263,7 +263,7 @@ async function scanSilgiExports(path, packageName, silgiInstance = useSilgiCLI()
|
|
|
263
263
|
if (!silgiInstance.options.extensions?.includes(fileExtension)) continue;
|
|
264
264
|
try {
|
|
265
265
|
const exportEntities = await extractExportEntitiesFromFile(absoluteFilePath, functionExportNames, interfaceExtendsNames);
|
|
266
|
-
const seenServiceSignatures =
|
|
266
|
+
const seenServiceSignatures = new Map();
|
|
267
267
|
for (const entity of exportEntities) if ((entity.funcName === "createService" || entity.funcName === "createWebSocket") && entity.servicePath && entity.serviceMethod) {
|
|
268
268
|
const key = `${entity.serviceMethod}:${entity.servicePath}`;
|
|
269
269
|
if (seenServiceSignatures.has(key)) throw new Error(`Duplicate ${entity.funcName} detected for path "${entity.servicePath}" and method "${entity.serviceMethod}".\nFirst found in: ${seenServiceSignatures.get(key)}\nDuplicate in: ${absoluteFilePath}\nPlease ensure each service path/method combination is unique.`);
|
|
@@ -24,7 +24,7 @@ async function writeTypesAndFiles(silgi) {
|
|
|
24
24
|
await silgi.unimport.init();
|
|
25
25
|
const allImports = await silgi.unimport.getImports();
|
|
26
26
|
autoImportExports = toExports(allImports).replace(/#internal\/nitro/g, relative(typesDir, runtimeDir));
|
|
27
|
-
const resolvedImportPathMap =
|
|
27
|
+
const resolvedImportPathMap = new Map();
|
|
28
28
|
for (const i of allImports.filter((i$1) => !i$1.type)) {
|
|
29
29
|
if (resolvedImportPathMap.has(i.from)) continue;
|
|
30
30
|
let path = resolveAlias$1(i.from, silgi.options.alias);
|