sdnext 0.0.31 → 0.0.33
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 +0 -2
- package/dist/index.js +15 -145
- package/dist/utils/build.d.ts +1 -1
- package/dist/utils/build.js +2 -2
- package/dist/utils/createAction.js +1 -1
- package/dist/utils/createRoute.js +35 -4
- package/dist/utils/dev.d.ts +1 -1
- package/dist/utils/dev.js +2 -2
- package/dist/utils/hook.d.ts +1 -1
- package/dist/utils/hook.js +3 -3
- package/dist/utils/readSdNextSetting.d.ts +1 -1
- package/dist/utils/resolveProjectImportPath.js +2 -2
- package/dist/utils/runCommand.d.ts +1 -1
- package/dist/utils/runCommand.js +1 -1
- package/dist/utils/sharedArtifact.js +2 -2
- package/dist/utils/syncSharedArtifacts.js +1 -1
- package/dist/utils/writeSdNextSetting.d.ts +1 -1
- package/package.json +5 -5
- package/src/index.ts +3 -3
- package/src/utils/build.ts +3 -3
- package/src/utils/createAction.ts +2 -2
- package/src/utils/createRoute.ts +34 -9
- package/src/utils/dev.ts +3 -3
- package/src/utils/hook.ts +5 -5
- package/src/utils/readSdNextSetting.ts +1 -1
- package/src/utils/resolveProjectImportPath.ts +5 -2
- package/src/utils/runCommand.ts +3 -4
- package/src/utils/sharedArtifact.ts +2 -2
- package/src/utils/syncSharedArtifacts.ts +2 -2
- package/src/utils/writeSdNextSetting.ts +1 -1
- package/tsconfig.json +3 -0
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,146 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var commander__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("commander");
|
|
18
|
-
var _utils_build__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./utils/build");
|
|
19
|
-
var _utils_dev__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./utils/dev");
|
|
20
|
-
var _utils_hook__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./utils/hook");
|
|
21
|
-
const program = new commander__WEBPACK_IMPORTED_MODULE_3__.Command();
|
|
22
|
-
const path = (0, url__WEBPACK_IMPORTED_MODULE_2__.fileURLToPath)(new URL("../", import.meta.url));
|
|
23
|
-
const packageJson = JSON.parse(await (0, fs_promises__WEBPACK_IMPORTED_MODULE_0__.readFile)((0, path__WEBPACK_IMPORTED_MODULE_1__.join)(path, "package.json"), "utf-8"));
|
|
24
|
-
program.name("soda next").version(packageJson.version);
|
|
25
|
-
program.command("build").allowUnknownOption(true).allowExcessArguments(true).action(_utils_build__WEBPACK_IMPORTED_MODULE_4__.build);
|
|
26
|
-
program.command("dev").allowUnknownOption(true).allowExcessArguments(true).action(_utils_dev__WEBPACK_IMPORTED_MODULE_5__.dev);
|
|
27
|
-
program.command("hook").action(_utils_hook__WEBPACK_IMPORTED_MODULE_6__.hook);
|
|
28
|
-
program.parse();
|
|
29
|
-
__webpack_async_result__();
|
|
30
|
-
} catch (e) {
|
|
31
|
-
__webpack_async_result__(e);
|
|
32
|
-
}
|
|
33
|
-
}, 1);
|
|
34
|
-
},
|
|
35
|
-
"./utils/build": function(module) {
|
|
36
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__utils_build_js_f9ba07bf__;
|
|
37
|
-
},
|
|
38
|
-
"./utils/dev": function(module) {
|
|
39
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__utils_dev_js_df994271__;
|
|
40
|
-
},
|
|
41
|
-
"./utils/hook": function(module) {
|
|
42
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__utils_hook_js_8cbfab27__;
|
|
43
|
-
},
|
|
44
|
-
commander: function(module) {
|
|
45
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_commander__;
|
|
46
|
-
},
|
|
47
|
-
"fs/promises": function(module) {
|
|
48
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__;
|
|
49
|
-
},
|
|
50
|
-
path: function(module) {
|
|
51
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
52
|
-
},
|
|
53
|
-
url: function(module) {
|
|
54
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_url__;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var __webpack_module_cache__ = {};
|
|
58
|
-
function __webpack_require__(moduleId) {
|
|
59
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
60
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
61
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
62
|
-
exports: {}
|
|
63
|
-
};
|
|
64
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
65
|
-
return module.exports;
|
|
66
|
-
}
|
|
67
|
-
(()=>{
|
|
68
|
-
var webpackQueues = "function" == typeof Symbol ? Symbol("webpack queues") : "__webpack_queues__";
|
|
69
|
-
var webpackExports = "function" == typeof Symbol ? Symbol("webpack exports") : "__webpack_exports__";
|
|
70
|
-
var webpackError = "function" == typeof Symbol ? Symbol("webpack error") : "__webpack_error__";
|
|
71
|
-
var resolveQueue = (queue)=>{
|
|
72
|
-
if (queue && queue.d < 1) {
|
|
73
|
-
queue.d = 1;
|
|
74
|
-
queue.forEach((fn)=>fn.r--);
|
|
75
|
-
queue.forEach((fn)=>fn.r-- ? fn.r++ : fn());
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var wrapDeps = (deps)=>deps.map((dep)=>{
|
|
79
|
-
if (null !== dep && "object" == typeof dep) {
|
|
80
|
-
if (dep[webpackQueues]) return dep;
|
|
81
|
-
if (dep.then) {
|
|
82
|
-
var queue = [];
|
|
83
|
-
queue.d = 0;
|
|
84
|
-
dep.then((r)=>{
|
|
85
|
-
obj[webpackExports] = r;
|
|
86
|
-
resolveQueue(queue);
|
|
87
|
-
}, (e)=>{
|
|
88
|
-
obj[webpackError] = e;
|
|
89
|
-
resolveQueue(queue);
|
|
90
|
-
});
|
|
91
|
-
var obj = {};
|
|
92
|
-
obj[webpackQueues] = (fn)=>fn(queue);
|
|
93
|
-
return obj;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
var ret = {};
|
|
97
|
-
ret[webpackQueues] = function() {};
|
|
98
|
-
ret[webpackExports] = dep;
|
|
99
|
-
return ret;
|
|
100
|
-
});
|
|
101
|
-
__webpack_require__.a = (module, body, hasAwait)=>{
|
|
102
|
-
var queue;
|
|
103
|
-
hasAwait && ((queue = []).d = -1);
|
|
104
|
-
var depQueues = new Set();
|
|
105
|
-
var exports = module.exports;
|
|
106
|
-
var currentDeps;
|
|
107
|
-
var outerResolve;
|
|
108
|
-
var reject;
|
|
109
|
-
var promise = new Promise((resolve, rej)=>{
|
|
110
|
-
reject = rej;
|
|
111
|
-
outerResolve = resolve;
|
|
112
|
-
});
|
|
113
|
-
promise[webpackExports] = exports;
|
|
114
|
-
promise[webpackQueues] = (fn)=>{
|
|
115
|
-
queue && fn(queue), depQueues.forEach(fn), promise["catch"](function() {});
|
|
116
|
-
};
|
|
117
|
-
module.exports = promise;
|
|
118
|
-
body((deps)=>{
|
|
119
|
-
currentDeps = wrapDeps(deps);
|
|
120
|
-
var fn;
|
|
121
|
-
var getResult = ()=>currentDeps.map((d)=>{
|
|
122
|
-
if (d[webpackError]) throw d[webpackError];
|
|
123
|
-
return d[webpackExports];
|
|
124
|
-
});
|
|
125
|
-
var promise = new Promise((resolve)=>{
|
|
126
|
-
fn = ()=>resolve(getResult);
|
|
127
|
-
fn.r = 0;
|
|
128
|
-
var fnQueue = (q)=>q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn)));
|
|
129
|
-
currentDeps.map((dep)=>dep[webpackQueues](fnQueue));
|
|
130
|
-
});
|
|
131
|
-
return fn.r ? promise : getResult();
|
|
132
|
-
}, (err)=>(err ? reject(promise[webpackError] = err) : outerResolve(exports), resolveQueue(queue)));
|
|
133
|
-
queue && queue.d < 0 && (queue.d = 0);
|
|
134
|
-
};
|
|
135
|
-
})();
|
|
136
|
-
(()=>{
|
|
137
|
-
__webpack_require__.r = (exports)=>{
|
|
138
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
|
|
139
|
-
value: 'Module'
|
|
140
|
-
});
|
|
141
|
-
Object.defineProperty(exports, '__esModule', {
|
|
142
|
-
value: true
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
})();
|
|
146
|
-
__webpack_require__("./src/index.ts");
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { build } from "./utils/build.js";
|
|
7
|
+
import { dev } from "./utils/dev.js";
|
|
8
|
+
import { hook } from "./utils/hook.js";
|
|
9
|
+
const program = new Command();
|
|
10
|
+
const path = fileURLToPath(new URL("../", import.meta.url));
|
|
11
|
+
const packageJson = JSON.parse(await readFile(join(path, "package.json"), "utf-8"));
|
|
12
|
+
program.name("soda next").version(packageJson.version);
|
|
13
|
+
program.command("build").allowUnknownOption(true).allowExcessArguments(true).action(build);
|
|
14
|
+
program.command("dev").allowUnknownOption(true).allowExcessArguments(true).action(dev);
|
|
15
|
+
program.command("hook").action(hook);
|
|
16
|
+
program.parse();
|
package/dist/utils/build.d.ts
CHANGED
package/dist/utils/build.js
CHANGED
|
@@ -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
|
|
76
|
+
return `${nextServerImport}
|
|
46
77
|
|
|
47
|
-
|
|
78
|
+
${createRouteFnImport}
|
|
48
79
|
${importLines ? `\n${importLines}\n` : ""}
|
|
49
80
|
const routeMap = new Map<string, RouteHandler>()
|
|
50
81
|
|
package/dist/utils/dev.d.ts
CHANGED
|
@@ -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 }) {
|
package/dist/utils/hook.d.ts
CHANGED
package/dist/utils/hook.js
CHANGED
|
@@ -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";
|
|
@@ -143,10 +143,10 @@ function stripComments(content) {
|
|
|
143
143
|
escaped = true;
|
|
144
144
|
continue;
|
|
145
145
|
}
|
|
146
|
-
if ("
|
|
146
|
+
if ('"' === char) inString = false;
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
-
if ("
|
|
149
|
+
if ('"' === char) {
|
|
150
150
|
inString = true;
|
|
151
151
|
output.push(char);
|
|
152
152
|
continue;
|
package/dist/utils/runCommand.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.0.33",
|
|
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.
|
|
41
|
+
"@inquirer/prompts": "^8.5.0",
|
|
42
42
|
"chokidar": "^5.0.0",
|
|
43
43
|
"commander": "^14.0.2",
|
|
44
|
-
"deepsea-tools": "5.
|
|
44
|
+
"deepsea-tools": "5.48.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^24.
|
|
48
|
-
"typescript": "
|
|
47
|
+
"@types/node": "^24.12.4",
|
|
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
|
|
package/src/utils/build.ts
CHANGED
|
@@ -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
|
}
|
package/src/utils/createRoute.ts
CHANGED
|
@@ -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
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
93
|
+
return `${nextServerImport}
|
|
69
94
|
|
|
70
|
-
|
|
95
|
+
${createRouteFnImport}
|
|
71
96
|
${importLines ? `\n${importLines}\n` : ""}
|
|
72
97
|
const routeMap = new Map<string, RouteHandler>()
|
|
73
98
|
|
|
@@ -89,4 +114,4 @@ ${registerLines ? `${registerLines}\n\n` : ""}export function POST(request: Next
|
|
|
89
114
|
return routeHandler(request)
|
|
90
115
|
}
|
|
91
116
|
`
|
|
92
|
-
}
|
|
117
|
+
}
|
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 {
|
|
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 === "
|
|
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
|
package/src/utils/runCommand.ts
CHANGED
|
@@ -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,
|
|
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"
|
|
@@ -35,4 +35,4 @@ export async function removeSharedArtifactDirectory(path: string) {
|
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
await createRoute()
|
|
38
|
-
}
|
|
38
|
+
}
|
|
@@ -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
|
}
|