sdnext 0.0.32 → 0.0.34

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/README.md CHANGED
@@ -20,7 +20,6 @@ export async function addUser() {}
20
20
  "use server"
21
21
 
22
22
  import { createResponseFn } from "@/server/createResponseFn"
23
-
24
23
  import { addUser } from "@/shared/addUser"
25
24
 
26
25
  export const addUserAction = createResponseFn(addUser)
@@ -50,7 +49,6 @@ addUser.route = {}
50
49
 
51
50
  ```ts
52
51
  import { createRoute } from "@/server/createResponseFn"
53
-
54
52
  import { addUser } from "@/shared/addUser"
55
53
 
56
54
  export const { POST } = createRoute(addUser)
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { readFile } from "fs/promises";
3
- import { join } from "path";
4
- import { fileURLToPath } from "url";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
5
  import { Command } from "commander";
6
6
  import { build } from "./utils/build.js";
7
7
  import { dev } from "./utils/dev.js";
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  export declare function buildFolder(dir: string): Promise<void>;
3
3
  export declare function build(options: Record<string, string>, { args }: Command): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { readdir, stat } from "fs/promises";
2
- import { join } from "path";
1
+ import { readdir, stat } from "node:fs/promises";
2
+ import { join } from "node:path";
3
3
  import { runCommand } from "./runCommand.js";
4
4
  import { syncSharedArtifacts } from "./syncSharedArtifacts.js";
5
5
  async function buildFolder(dir) {
@@ -1,4 +1,4 @@
1
- import { join } from "path";
1
+ import { join } from "node:path";
2
2
  import { resolveProjectImportPath } from "./resolveProjectImportPath.js";
3
3
  import { getSharedModuleInfo, isScriptModule, writeGeneratedFile } from "./sharedArtifact.js";
4
4
  async function createAction(path) {
@@ -1,7 +1,12 @@
1
- import { readdir } from "fs/promises";
2
- import { join } from "path";
1
+ import { readdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
3
  import { resolveProjectImportPath } from "./resolveProjectImportPath.js";
4
4
  import { getSharedModuleInfo, isScriptModule, writeGeneratedFile } from "./sharedArtifact.js";
5
+ function getNamedImportStatement(modulePath, specifiers) {
6
+ const allType = specifiers.every((item)=>item.type);
7
+ const names = specifiers.map((item)=>allType || !item.type ? item.name : `type ${item.name}`).join(", ");
8
+ return `import ${allType ? "type " : ""}{ ${names} } from "${modulePath}"`;
9
+ }
5
10
  async function createRoute(path) {
6
11
  if (path) {
7
12
  const info = getSharedModuleInfo(path);
@@ -37,14 +42,40 @@ async function getSharedModules(dir) {
37
42
  }
38
43
  async function getRouteFileContent(items, routePath) {
39
44
  const createRouteFnImportPath = await resolveProjectImportPath(routePath, "server/createResponseFn");
45
+ const nextServerImport = getNamedImportStatement("next/server", [
46
+ {
47
+ name: "NextRequest",
48
+ type: true
49
+ },
50
+ {
51
+ name: "NextResponse"
52
+ }
53
+ ]);
54
+ const createRouteFnImport = getNamedImportStatement(createRouteFnImportPath, [
55
+ {
56
+ name: "OriginalResponseFn",
57
+ type: true
58
+ },
59
+ {
60
+ name: "RouteBodyType",
61
+ type: true
62
+ },
63
+ {
64
+ name: "RouteHandler",
65
+ type: true
66
+ },
67
+ {
68
+ name: "createRouteFn"
69
+ }
70
+ ]);
40
71
  const importLines = (await Promise.all(items.map(async (item)=>{
41
72
  const importPath = await resolveProjectImportPath(routePath, `shared/${item.importPath}`);
42
73
  return `import { ${item.name} } from "${importPath}"`;
43
74
  }))).join("\n");
44
75
  const registerLines = items.map((item)=>`registerRoute(${item.name})`).join("\n");
45
- return `import { NextRequest, NextResponse } from "next/server"
76
+ return `${nextServerImport}
46
77
 
47
- import { createRouteFn, OriginalResponseFn, RouteBodyType, RouteHandler } from "${createRouteFnImportPath}"
78
+ ${createRouteFnImport}
48
79
  ${importLines ? `\n${importLines}\n` : ""}
49
80
  const routeMap = new Map<string, RouteHandler>()
50
81
 
@@ -1,2 +1,2 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  export declare function dev(options: Record<string, string>, { args }: Command): Promise<void>;
package/dist/utils/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import { spawn } from "child_process";
2
- import { fileURLToPath } from "url";
1
+ import { spawn } from "node:child_process";
2
+ import { fileURLToPath } from "node:url";
3
3
  import { buildFolder } from "./build.js";
4
4
  import { spawnCommand } from "./runCommand.js";
5
5
  async function dev(options, { args }) {
@@ -1,4 +1,4 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  export type HookType = "get" | "query" | "mutation";
3
3
  export type OperationType = HookType | "skip";
4
4
  export type HookContentMap = Record<HookType, string>;
@@ -1,6 +1,6 @@
1
- import { readFile, readdir, stat } from "fs/promises";
2
- import { join, parse, relative } from "path";
3
- import { cwd } from "process";
1
+ import { readFile, readdir, stat } from "node:fs/promises";
2
+ import { join, parse, relative } from "node:path";
3
+ import { cwd } from "node:process";
4
4
  import { checkbox as prompts_checkbox, select as prompts_select } from "@inquirer/prompts";
5
5
  import { readSdNextSetting } from "./readSdNextSetting.js";
6
6
  import { resolveProjectImportPath } from "./resolveProjectImportPath.js";
@@ -1,4 +1,4 @@
1
- import { OperationType } from "./hook";
1
+ import type { OperationType } from "./hook";
2
2
  export interface SdNextSetting {
3
3
  hook?: Record<string, OperationType>;
4
4
  }
@@ -143,10 +143,10 @@ function stripComments(content) {
143
143
  escaped = true;
144
144
  continue;
145
145
  }
146
- if ("\"" === char) inString = false;
146
+ if ('"' === char) inString = false;
147
147
  continue;
148
148
  }
149
- if ("\"" === char) {
149
+ if ('"' === char) {
150
150
  inString = true;
151
151
  output.push(char);
152
152
  continue;
@@ -1,4 +1,4 @@
1
- import { ChildProcess } from "child_process";
1
+ import { type ChildProcess } from "node:child_process";
2
2
  export interface SpawnCommandParams {
3
3
  args: string[];
4
4
  }
@@ -1,4 +1,4 @@
1
- import { spawn } from "child_process";
1
+ import { spawn } from "node:child_process";
2
2
  function quotePosixArgument(arg) {
3
3
  if (0 === arg.length) return "''";
4
4
  return `'${arg.replaceAll("'", "'\"'\"'")}'`;
@@ -1,5 +1,5 @@
1
- import { mkdir, readFile, readdir, rm, writeFile } from "fs/promises";
2
- import { dirname, join, parse, relative } from "path";
1
+ import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
2
+ import { dirname, join, parse, relative } from "node:path";
3
3
  const scriptModuleExtensions = [
4
4
  ".ts",
5
5
  ".tsx",
@@ -1,4 +1,4 @@
1
- import { join } from "path";
1
+ import { join } from "node:path";
2
2
  import { createAction } from "./createAction.js";
3
3
  import { createRoute } from "./createRoute.js";
4
4
  import { getSharedModuleInfo, isScriptModule, normalizeSharedPath, removeGeneratedFile } from "./sharedArtifact.js";
@@ -1,2 +1,2 @@
1
- import { SdNextSetting } from "./readSdNextSetting";
1
+ import type { SdNextSetting } from "./readSdNextSetting";
2
2
  export declare function writeSdNextSetting(setting: SdNextSetting): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdnext",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,14 +38,14 @@
38
38
  },
39
39
  "homepage": "https://github.com/1adybug/deepsea/tree/main/packages/sdnext",
40
40
  "dependencies": {
41
- "@inquirer/prompts": "^8.1.0",
41
+ "@inquirer/prompts": "^8.5.2",
42
42
  "chokidar": "^5.0.0",
43
43
  "commander": "^14.0.2",
44
- "deepsea-tools": "5.48.0"
44
+ "deepsea-tools": "5.48.2"
45
45
  },
46
46
  "devDependencies": {
47
- "@types/node": "^24.12.4",
48
- "typescript": ">=5.8.3"
47
+ "@types/node": "^24.13.1",
48
+ "typescript": "^6.0.3"
49
49
  },
50
50
  "scripts": {
51
51
  "dev": "rslib build --watch",
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { readFile } from "fs/promises"
4
- import { join } from "path"
5
- import { fileURLToPath } from "url"
3
+ import { readFile } from "node:fs/promises"
4
+ import { join } from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
6
 
7
7
  import { Command } from "commander"
8
8
 
@@ -1,7 +1,7 @@
1
- import { readdir, stat } from "fs/promises"
2
- import { join } from "path"
1
+ import { readdir, stat } from "node:fs/promises"
2
+ import { join } from "node:path"
3
3
 
4
- import { Command } from "commander"
4
+ import type { Command } from "commander"
5
5
 
6
6
  import { runCommand } from "./runCommand"
7
7
  import { syncSharedArtifacts } from "./syncSharedArtifacts"
@@ -1,4 +1,4 @@
1
- import { join } from "path"
1
+ import { join } from "node:path"
2
2
 
3
3
  import { resolveProjectImportPath } from "./resolveProjectImportPath"
4
4
  import { getSharedModuleInfo, isScriptModule, writeGeneratedFile } from "./sharedArtifact"
@@ -21,6 +21,6 @@ import { createResponseFn } from "${createResponseFnImportPath}"
21
21
  import { ${info.name} } from "${sharedImportPath}"
22
22
 
23
23
  export const ${info.name}Action = createResponseFn(${info.name})
24
- `
24
+ `,
25
25
  })
26
26
  }
@@ -1,9 +1,21 @@
1
- import { readdir } from "fs/promises"
2
- import { join } from "path"
1
+ import { readdir } from "node:fs/promises"
2
+ import { join } from "node:path"
3
3
 
4
4
  import { resolveProjectImportPath } from "./resolveProjectImportPath"
5
5
  import { getSharedModuleInfo, isScriptModule, writeGeneratedFile } from "./sharedArtifact"
6
6
 
7
+ interface NamedImportSpecifier {
8
+ name: string
9
+ type?: boolean
10
+ }
11
+
12
+ function getNamedImportStatement(modulePath: string, specifiers: NamedImportSpecifier[]) {
13
+ const allType = specifiers.every(item => item.type)
14
+ const names = specifiers.map(item => (allType || !item.type ? item.name : `type ${item.name}`)).join(", ")
15
+
16
+ return `import ${allType ? "type " : ""}{ ${names} } from "${modulePath}"`
17
+ }
18
+
7
19
  export async function createRoute(path?: string) {
8
20
  if (path) {
9
21
  const info = getSharedModuleInfo(path)
@@ -59,15 +71,28 @@ export interface GetRouteFileContentParamsItem {
59
71
 
60
72
  async function getRouteFileContent(items: GetRouteFileContentParamsItem[], routePath: string) {
61
73
  const createRouteFnImportPath = await resolveProjectImportPath(routePath, "server/createResponseFn")
62
- const importLines = (await Promise.all(items.map(async (item) => {
63
- const importPath = await resolveProjectImportPath(routePath, `shared/${item.importPath}`)
64
- return `import { ${item.name} } from "${importPath}"`
65
- }))).join("\n")
74
+ const nextServerImport = getNamedImportStatement("next/server", [{ name: "NextRequest", type: true }, { name: "NextResponse" }])
75
+ const createRouteFnImport = getNamedImportStatement(createRouteFnImportPath, [
76
+ { name: "OriginalResponseFn", type: true },
77
+ { name: "RouteBodyType", type: true },
78
+ { name: "RouteHandler", type: true },
79
+ { name: "createRouteFn" },
80
+ ])
81
+
82
+ const importLines = (
83
+ await Promise.all(
84
+ items.map(async item => {
85
+ const importPath = await resolveProjectImportPath(routePath, `shared/${item.importPath}`)
86
+ return `import { ${item.name} } from "${importPath}"`
87
+ }),
88
+ )
89
+ ).join("\n")
90
+
66
91
  const registerLines = items.map(item => `registerRoute(${item.name})`).join("\n")
67
92
 
68
- return `import { NextRequest, NextResponse } from "next/server"
93
+ return `${nextServerImport}
69
94
 
70
- import { createRouteFn, OriginalResponseFn, RouteBodyType, RouteHandler } from "${createRouteFnImportPath}"
95
+ ${createRouteFnImport}
71
96
  ${importLines ? `\n${importLines}\n` : ""}
72
97
  const routeMap = new Map<string, RouteHandler>()
73
98
 
package/src/utils/dev.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { spawn } from "child_process"
2
- import { fileURLToPath } from "url"
1
+ import { spawn } from "node:child_process"
2
+ import { fileURLToPath } from "node:url"
3
3
 
4
- import { Command } from "commander"
4
+ import type { Command } from "commander"
5
5
 
6
6
  import { buildFolder } from "./build"
7
7
  import { spawnCommand } from "./runCommand"
package/src/utils/hook.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { readdir, readFile, stat } from "fs/promises"
2
- import { join, parse, relative } from "path"
3
- import { cwd } from "process"
1
+ import { readdir, readFile, stat } from "node:fs/promises"
2
+ import { join, parse, relative } from "node:path"
3
+ import { cwd } from "node:process"
4
4
 
5
5
  import { checkbox, select } from "@inquirer/prompts"
6
- import { Command } from "commander"
6
+ import type { Command } from "commander"
7
7
 
8
- import { readSdNextSetting, SdNextSetting } from "./readSdNextSetting"
8
+ import { type SdNextSetting, readSdNextSetting } from "./readSdNextSetting"
9
9
  import { resolveProjectImportPath } from "./resolveProjectImportPath"
10
10
  import { isScriptModule, normalizePathSeparator, writeGeneratedFile } from "./sharedArtifact"
11
11
  import { writeSdNextSetting } from "./writeSdNextSetting"
@@ -2,7 +2,7 @@ import { readFile } from "node:fs/promises"
2
2
  import { homedir } from "node:os"
3
3
  import { join } from "node:path"
4
4
 
5
- import { OperationType } from "./hook"
5
+ import type { OperationType } from "./hook"
6
6
 
7
7
  export interface SdNextSetting {
8
8
  hook?: Record<string, OperationType>
@@ -129,6 +129,7 @@ function splitWildcard(value: string) {
129
129
  async function resolveExtendsPath(extendsValue: string, baseDir: string) {
130
130
  if (isAbsolute(extendsValue) || extendsValue.startsWith(".")) {
131
131
  const relativeCandidates = getRelativeCandidates(resolve(baseDir, extendsValue))
132
+
132
133
  for (const candidate of relativeCandidates) {
133
134
  if (await exists(candidate)) return candidate
134
135
  }
@@ -165,6 +166,7 @@ async function readJsonConfig(path: string): Promise<JsonObject> {
165
166
 
166
167
  function stripComments(content: string) {
167
168
  const output: string[] = []
169
+
168
170
  let inString = false
169
171
  let escaped = false
170
172
 
@@ -174,6 +176,7 @@ function stripComments(content: string) {
174
176
 
175
177
  if (inString) {
176
178
  output.push(char)
179
+
177
180
  if (escaped) {
178
181
  escaped = false
179
182
  continue
@@ -184,12 +187,12 @@ function stripComments(content: string) {
184
187
  continue
185
188
  }
186
189
 
187
- if (char === "\"") inString = false
190
+ if (char === '"') inString = false
188
191
 
189
192
  continue
190
193
  }
191
194
 
192
- if (char === "\"") {
195
+ if (char === '"') {
193
196
  inString = true
194
197
  output.push(char)
195
198
  continue
@@ -1,4 +1,4 @@
1
- import { ChildProcess, spawn } from "child_process"
1
+ import { type ChildProcess, spawn } from "node:child_process"
2
2
 
3
3
  export interface SpawnCommandParams {
4
4
  args: string[]
@@ -26,9 +26,7 @@ function formatShellCommand(args: string[]) {
26
26
  const [command, ...commandArgs] = args
27
27
  const quoteArgument = process.platform === "win32" ? quoteWindowsArgument : quotePosixArgument
28
28
 
29
- if (process.platform === "win32") {
30
- return [quoteWindowsCommand(command), ...commandArgs.map(quoteArgument)].join(" ")
31
- }
29
+ if (process.platform === "win32") return [quoteWindowsCommand(command), ...commandArgs.map(quoteArgument)].join(" ")
32
30
 
33
31
  return args.map(quoteArgument).join(" ")
34
32
  }
@@ -52,6 +50,7 @@ export async function runCommand({ args }: SpawnCommandParams) {
52
50
  export async function waitForChild(child: ChildProcess) {
53
51
  return await new Promise<number>((resolve, reject) => {
54
52
  child.once("error", reject)
53
+
55
54
  child.once("close", (code, signal) => {
56
55
  if (typeof code === "number") {
57
56
  resolve(code)
@@ -1,5 +1,5 @@
1
- import { mkdir, readFile, readdir, rm, writeFile } from "fs/promises"
2
- import { dirname, join, parse, relative } from "path"
1
+ import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises"
2
+ import { dirname, join, parse, relative } from "node:path"
3
3
 
4
4
  export interface SharedModuleInfo {
5
5
  dir: string
@@ -1,4 +1,4 @@
1
- import { join } from "path"
1
+ import { join } from "node:path"
2
2
 
3
3
  import { createAction } from "./createAction"
4
4
  import { createRoute } from "./createRoute"
@@ -2,7 +2,7 @@ import { writeFile } from "node:fs/promises"
2
2
  import { homedir } from "node:os"
3
3
  import { join } from "node:path"
4
4
 
5
- import { SdNextSetting } from "./readSdNextSetting"
5
+ import type { SdNextSetting } from "./readSdNextSetting"
6
6
 
7
7
  export async function writeSdNextSetting(setting: SdNextSetting) {
8
8
  const userDir = homedir()
package/tsconfig.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "rootDir": "src",
3
4
  "strict": true,
4
5
  "declaration": true,
5
6
  "skipLibCheck": true,
6
7
  "target": "ESNext",
7
8
  "module": "ESNext",
8
9
  "moduleResolution": "Bundler",
10
+ "verbatimModuleSyntax": true,
11
+ "types": ["node"],
9
12
  "paths": {
10
13
  "@/*": ["./src/*"]
11
14
  }