@dreamkit/dev 0.0.14-next.5 → 0.0.14-next.7
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/DreamkitDevServer.d.ts.map +1 -1
- package/lib/DreamkitDevServer.js +3 -2
- package/lib/actions/generate-code.d.ts +9 -0
- package/lib/actions/generate-code.d.ts.map +1 -0
- package/lib/actions/generate-code.js +78 -0
- package/lib/actions/generate-meta.js +5 -5
- package/lib/actions/generate.d.ts.map +1 -1
- package/lib/actions/generate.js +5 -1
- package/lib/adapters/solid-start/dev-server.d.ts.map +1 -1
- package/lib/adapters/solid-start/dev-server.js +13 -6
- package/lib/adapters/solid-start/prod-server.js +3 -3
- package/lib/options.d.ts +2 -2
- package/lib/options.d.ts.map +1 -1
- package/lib/options.js +1 -1
- package/lib/transforms/to-solid-route.js +4 -4
- package/lib/transforms/to-solid-server-action.js +1 -1
- package/lib/utils/ast.d.ts +25 -1
- package/lib/utils/ast.d.ts.map +1 -1
- package/lib/utils/ast.js +69 -2
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMpD,OAAO,EAAE,GAAG,EAAW,KAAK,EAA2B,MAAM,eAAe,CAAC;AAM7E,OAAO,EAAE,SAAS,EAAS,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAmC,aAAa,EAAE,MAAM,MAAM,CAAC;AAGtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBA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;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GACtD,0BAA0B,CAAC;AAC7B,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,GACvD,0BAA0B,CAAC;AAE7B,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,SAAmB;IACrC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAC3C,SAAS,CAAC,mBAAmB,EAAE,SAAS,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBACzB,SAAS,EAAE,oBAAoB;IA+B3C,MAAM,CAAC,QAAQ,IAAI,iBAAiB;IAKpC,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,iBAAiB;IAGzC,KAAK,CAAC,IAAI,EAAE,MAAM;IAWlB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAIxC,gBAAgB;IA0BhB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAIjD,OAAO,CAAC,uBAAuB,UAAO;IAiDtC,KAAK;IAGL,IAAI;CAMX"}
|
package/lib/DreamkitDevServer.js
CHANGED
|
@@ -31,7 +31,7 @@ export class DreamkitDevServer {
|
|
|
31
31
|
options.settingsPath = resolvePath(options.settingsPath, vars);
|
|
32
32
|
options.metaGlobalOutput = resolvePath(options.metaGlobalOutput, vars);
|
|
33
33
|
options.metaLocalOutput = resolvePath(options.metaLocalOutput, vars);
|
|
34
|
-
options.
|
|
34
|
+
options.presets = options.presets?.map((v) => resolvePath(v, vars));
|
|
35
35
|
this.entry = new VirtualShaking({
|
|
36
36
|
entry: options.entry,
|
|
37
37
|
onChange: async (changes) => {
|
|
@@ -94,6 +94,7 @@ export class DreamkitDevServer {
|
|
|
94
94
|
? $route
|
|
95
95
|
: $route["clone"]({
|
|
96
96
|
...value.$options,
|
|
97
|
+
filePath: item.filePath.replaceAll("\\", "/"),
|
|
97
98
|
path: item.path,
|
|
98
99
|
}).create(value.$options.component);
|
|
99
100
|
}
|
|
@@ -134,7 +135,7 @@ export class DreamkitDevServer {
|
|
|
134
135
|
hmr: { logger: false },
|
|
135
136
|
});
|
|
136
137
|
this.entry.init();
|
|
137
|
-
for (const path of this.options.
|
|
138
|
+
for (const path of this.options.presets || [])
|
|
138
139
|
await this.app.add(await this.fetch(path));
|
|
139
140
|
await this.app.add({
|
|
140
141
|
...(await this.fetchEntryObjects()),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DreamkitDevServer } from "../DreamkitDevServer.js";
|
|
2
|
+
export declare function generateCode(server: DreamkitDevServer, input?: {
|
|
3
|
+
filePath: string;
|
|
4
|
+
read?: () => string | Promise<string>;
|
|
5
|
+
}): Promise<Record<string, {
|
|
6
|
+
path: string;
|
|
7
|
+
changed: boolean;
|
|
8
|
+
}>>;
|
|
9
|
+
//# sourceMappingURL=generate-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-code.d.ts","sourceRoot":"","sources":["../../src/actions/generate-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAY5D,wBAAsB,YAAY,CAChC,MAAM,EAAE,iBAAiB,EACzB,KAAK,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE;UAE9B,MAAM;aAAW,OAAO;IA2C9D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getImportLocations, getExports, parseCallsChain, parseFile, } from "../utils/ast.js";
|
|
2
|
+
import { writeFileIfDifferent } from "../utils/fs.js";
|
|
3
|
+
import { replaceText } from "../utils/string.js";
|
|
4
|
+
import { extractPathParams } from "@dreamkit/app/utils/routing.js";
|
|
5
|
+
import { readFile } from "fs/promises";
|
|
6
|
+
export async function generateCode(server, input) {
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const route of server.app.routes) {
|
|
9
|
+
const filePath = route.$options.filePath;
|
|
10
|
+
if (input && filePath !== input.filePath)
|
|
11
|
+
continue;
|
|
12
|
+
if (!filePath || !route.$options.path)
|
|
13
|
+
continue;
|
|
14
|
+
const pathParams = extractPathParams(route.$options.path).map((param) => param.name);
|
|
15
|
+
if (!pathParams.length)
|
|
16
|
+
continue;
|
|
17
|
+
const code = input?.read
|
|
18
|
+
? await input.read()
|
|
19
|
+
: (await readFile(filePath)).toString();
|
|
20
|
+
let action;
|
|
21
|
+
try {
|
|
22
|
+
action = getTransformAction(code);
|
|
23
|
+
}
|
|
24
|
+
catch (_) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
let next;
|
|
28
|
+
if (action) {
|
|
29
|
+
const newParamNames = pathParams.map((name) => JSON.stringify(name));
|
|
30
|
+
if (action.type === "replace") {
|
|
31
|
+
if (!checkChanges(code, action.start, action.end, pathParams))
|
|
32
|
+
next = replaceText(code, action.start, action.end, `(${newParamNames.join(", ")})`);
|
|
33
|
+
}
|
|
34
|
+
else if (action.type === "add") {
|
|
35
|
+
next = replaceText(code, action.start, action.start, `.pathParams(${newParamNames})`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (next && (await writeFileIfDifferent(filePath, next, code))) {
|
|
39
|
+
result[filePath] = { path: filePath, changed: true };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function checkChanges(code, start, end, newPathParams) {
|
|
45
|
+
const currentArgs = code.slice(start, end);
|
|
46
|
+
const json = `[${currentArgs.slice(1, -1)}]`;
|
|
47
|
+
let currentParamNames = [];
|
|
48
|
+
try {
|
|
49
|
+
currentParamNames = JSON.parse(json).sort();
|
|
50
|
+
}
|
|
51
|
+
catch (_) { }
|
|
52
|
+
return (currentParamNames.sort().join(",") === [...newPathParams].sort().join(","));
|
|
53
|
+
}
|
|
54
|
+
function getTransformAction(code) {
|
|
55
|
+
const ast = parseFile(code);
|
|
56
|
+
const ref = getImportLocations(ast, "dreamkit", ["$route"]);
|
|
57
|
+
for (const item of getExports(ast)) {
|
|
58
|
+
if (item.dec.type === "CallExpression") {
|
|
59
|
+
const chain = parseCallsChain(item.dec);
|
|
60
|
+
if (ref.$route.includes(chain.root.loc)) {
|
|
61
|
+
const pathParams = chain.calls.find((call) => call.name === "pathParams");
|
|
62
|
+
if (!pathParams) {
|
|
63
|
+
return {
|
|
64
|
+
type: "add",
|
|
65
|
+
start: chain.root.end,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return {
|
|
70
|
+
type: "replace",
|
|
71
|
+
start: pathParams.property.end,
|
|
72
|
+
end: pathParams.node.end,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -17,7 +17,7 @@ export async function generateMeta(server) {
|
|
|
17
17
|
let contents;
|
|
18
18
|
if (options.metaFormat === "global") {
|
|
19
19
|
const declarations = {
|
|
20
|
-
["dreamkit/
|
|
20
|
+
["dreamkit/scopes/global.override.js"]: createInterface("Routing", typeRoutes, 1),
|
|
21
21
|
};
|
|
22
22
|
contents =
|
|
23
23
|
Object.entries(declarations)
|
|
@@ -27,13 +27,13 @@ export async function generateMeta(server) {
|
|
|
27
27
|
else {
|
|
28
28
|
contents = [
|
|
29
29
|
`// prettier-ignore`,
|
|
30
|
-
`import { defineRoutePath } from "dreamkit/
|
|
31
|
-
`import { defineLink } from "dreamkit/
|
|
30
|
+
`import { defineRoutePath } from "dreamkit/scopes/common.js";`,
|
|
31
|
+
`import { defineLink } from "dreamkit/scopes/solid.js";`,
|
|
32
32
|
"",
|
|
33
33
|
...(options.metaLocalExports
|
|
34
34
|
? [
|
|
35
|
-
'export * from "dreamkit/
|
|
36
|
-
'export * from "dreamkit/
|
|
35
|
+
'export * from "dreamkit/scopes/common.js";',
|
|
36
|
+
'export * from "dreamkit/scopes/solid.js";',
|
|
37
37
|
]
|
|
38
38
|
: []),
|
|
39
39
|
createInterface("Routing", typeRoutes, 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/actions/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/actions/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAK5D,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,CAY7D"}
|
package/lib/actions/generate.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { generateCode } from "./generate-code.js";
|
|
1
2
|
import { generateMeta } from "./generate-meta.js";
|
|
2
3
|
import { generateSettings } from "./generate-settings.js";
|
|
3
4
|
export async function generate(server) {
|
|
4
|
-
const [meta, settings] = await Promise.all([
|
|
5
|
+
const [meta, settings, code] = await Promise.all([
|
|
5
6
|
generateMeta(server),
|
|
6
7
|
generateSettings(server),
|
|
8
|
+
generateCode(server),
|
|
7
9
|
]);
|
|
10
|
+
await generateCode(server);
|
|
8
11
|
return {
|
|
9
12
|
meta,
|
|
10
13
|
...settings,
|
|
14
|
+
...code,
|
|
11
15
|
};
|
|
12
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAMzD,OAAO,EAML,QAAQ,EAET,MAAM,sBAAsB,CAAC;AAsB9B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDhC;AAuCD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,qBAA0B,qBA4LtC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DreamkitDevServer, } from "../../DreamkitDevServer.js";
|
|
2
|
+
import { generateCode } from "../../actions/generate-code.js";
|
|
2
3
|
import { generateMeta } from "../../actions/generate-meta.js";
|
|
3
4
|
import { generateSettings } from "../../actions/generate-settings.js";
|
|
4
5
|
import { tryGenerate } from "../../utils/ast.js";
|
|
@@ -149,10 +150,15 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
149
150
|
await generateSettings(server);
|
|
150
151
|
}, 300);
|
|
151
152
|
server.app
|
|
152
|
-
.on("change", (data) => {
|
|
153
|
+
.on("change", async (data) => {
|
|
153
154
|
log("change detected", { action: data.action, id: data.id });
|
|
154
155
|
if (isRoute(data.value)) {
|
|
155
156
|
tryGenerateMeta();
|
|
157
|
+
if (data.action === "add" && data.value.$options.filePath) {
|
|
158
|
+
await generateCode(server, {
|
|
159
|
+
filePath: data.value.$options.filePath,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
156
162
|
}
|
|
157
163
|
else if (isSettings(data.value)) {
|
|
158
164
|
tryGenerateSettings();
|
|
@@ -177,6 +183,7 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
177
183
|
}
|
|
178
184
|
});
|
|
179
185
|
await server.prepare(true);
|
|
186
|
+
await generateCode(server);
|
|
180
187
|
for (const router of vinxiApp.config.routers) {
|
|
181
188
|
const internalRouter = router.internals.routes;
|
|
182
189
|
if (internalRouter) {
|
|
@@ -216,7 +223,7 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
216
223
|
ssrRouter.middleware = selfPath("middleware.js", true);
|
|
217
224
|
if (isVinxiBuild()) {
|
|
218
225
|
const dreamkitEntryId = "dk:entry";
|
|
219
|
-
const
|
|
226
|
+
const dreamkitPresetsId = "dk:presets";
|
|
220
227
|
const dreamkitEntry = join(server.options.root, "src/dreamkit.tsx").replaceAll("\\", "/");
|
|
221
228
|
const existsDreamkitEntry = existsSync(dreamkitEntry);
|
|
222
229
|
addVinxiPlugin(vinxiApp, selfPath("prod-server.js"));
|
|
@@ -226,15 +233,15 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
226
233
|
if (id === dreamkitEntryId) {
|
|
227
234
|
return existsDreamkitEntry ? dreamkitEntry : `\0${dreamkitEntryId}`;
|
|
228
235
|
}
|
|
229
|
-
else if (id ===
|
|
230
|
-
return `\0${
|
|
236
|
+
else if (id === dreamkitPresetsId) {
|
|
237
|
+
return `\0${dreamkitPresetsId}`;
|
|
231
238
|
}
|
|
232
239
|
},
|
|
233
240
|
load(id) {
|
|
234
241
|
if (!existsDreamkitEntry && id === `\0${dreamkitEntryId}`)
|
|
235
242
|
return { code: "export {}" };
|
|
236
|
-
if (id === `\0${
|
|
237
|
-
const exports = server.options.
|
|
243
|
+
if (id === `\0${dreamkitPresetsId}`) {
|
|
244
|
+
const exports = server.options.presets?.map((entry, index) => `export * as entry_${index} from ${JSON.stringify(entry)};`);
|
|
238
245
|
return { code: [...exports, `export {};`].join("\n") };
|
|
239
246
|
}
|
|
240
247
|
},
|
|
@@ -2,11 +2,11 @@ import { App } from "@dreamkit/app";
|
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import * as objects from "dk:entry";
|
|
4
4
|
// @ts-ignore
|
|
5
|
-
import * as
|
|
5
|
+
import * as presets from "dk:presets";
|
|
6
6
|
export default async function (_nitro) {
|
|
7
7
|
const app = App.createGlobalInstance();
|
|
8
|
-
for (const id in
|
|
9
|
-
await app.add(
|
|
8
|
+
for (const id in presets)
|
|
9
|
+
await app.add(presets[id]);
|
|
10
10
|
await app.add(objects);
|
|
11
11
|
await app.start();
|
|
12
12
|
}
|
package/lib/options.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type DreamkitPluginOptions = {
|
|
2
2
|
entry?: string;
|
|
3
|
-
|
|
3
|
+
presets?: string[];
|
|
4
4
|
metaFormat?: "global" | "local";
|
|
5
5
|
metaRouting?: boolean;
|
|
6
6
|
metaGlobalOutput?: string;
|
|
@@ -12,7 +12,7 @@ export declare const dreamkitPluginOptions: {
|
|
|
12
12
|
metaFormat: "global";
|
|
13
13
|
metaRouting: true;
|
|
14
14
|
entry: string;
|
|
15
|
-
|
|
15
|
+
presets: string[];
|
|
16
16
|
metaGlobalOutput: string;
|
|
17
17
|
metaLocalOutput: string;
|
|
18
18
|
metaLocalExports: true;
|
package/lib/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAChC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;;;;;CASD,CAAC;AAElC,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,IAAI,CAAC,qBAAqB,EAAE,MAAM,OAAO,qBAAqB,CAAC,CAChE,GACC,IAAI,CAAC,qBAAqB,EAAE,MAAM,OAAO,qBAAqB,CAAC,CAAC"}
|
package/lib/options.js
CHANGED
|
@@ -2,7 +2,7 @@ export const dreamkitPluginOptions = {
|
|
|
2
2
|
metaFormat: "global",
|
|
3
3
|
metaRouting: true,
|
|
4
4
|
entry: "./src/dreamkit.tsx",
|
|
5
|
-
|
|
5
|
+
presets: ["dreamkit/presets/solid-start.js"],
|
|
6
6
|
metaGlobalOutput: "./src/dreamkit-global.d.ts",
|
|
7
7
|
metaLocalOutput: "./src/dreamkit-local.ts",
|
|
8
8
|
metaLocalExports: true,
|
|
@@ -8,7 +8,7 @@ export function toSolidRoute(ast) {
|
|
|
8
8
|
let routeImportName;
|
|
9
9
|
const routeSpec = "$route";
|
|
10
10
|
const routeSource = "dreamkit";
|
|
11
|
-
const routeNewSource = "dreamkit/
|
|
11
|
+
const routeNewSource = "dreamkit/scopes/solid-import.js";
|
|
12
12
|
replaceImportSpec(ast, {
|
|
13
13
|
newSource: routeNewSource,
|
|
14
14
|
source: routeSource,
|
|
@@ -20,7 +20,7 @@ export function toSolidRoute(ast) {
|
|
|
20
20
|
ImportDeclaration(importPath) {
|
|
21
21
|
importPath.traverse({
|
|
22
22
|
ImportSpecifier(path) {
|
|
23
|
-
// import { route as ? } from "dreamkit/
|
|
23
|
+
// import { route as ? } from "dreamkit/scopes/solid-import.js";
|
|
24
24
|
const isRouteImport = path.node.imported.type === "Identifier" &&
|
|
25
25
|
path.node.imported.name === routeSpec &&
|
|
26
26
|
importPath.node.source.value === routeNewSource;
|
|
@@ -48,7 +48,7 @@ export function toSolidRoute(ast) {
|
|
|
48
48
|
// import { $route } from "dreamkit";
|
|
49
49
|
// export default route.params({}).create(() => {});
|
|
50
50
|
// [output]
|
|
51
|
-
// import { $route as _$route } from "dreamkit/
|
|
51
|
+
// import { $route as _$route } from "dreamkit/scopes/solid-import.js"
|
|
52
52
|
// import { useLocation, useRouter, useParams} from "@solidjs/router"
|
|
53
53
|
// const selfRoute = _$route.params({}).clone({ deps: ? });
|
|
54
54
|
// export const route = selfRoute.createRouteDefinition();
|
|
@@ -80,7 +80,7 @@ export function toSolidRoute(ast) {
|
|
|
80
80
|
// export const route = $route.params({}).path('/path');
|
|
81
81
|
// export default function Users() { useRoute(route); }
|
|
82
82
|
// [output]
|
|
83
|
-
// import { $route as _$route } from "dreamkit/
|
|
83
|
+
// import { $route as _$route } from "dreamkit/scopes/solid-import.js"
|
|
84
84
|
// import { useLocation, useRouter, useParams } from "@solidjs/router"
|
|
85
85
|
// const selfRoute = _$route.params({}).path('/path').clone({ deps: ? });
|
|
86
86
|
// export const route = selfRoute.createRouteDefinition();
|
|
@@ -9,7 +9,7 @@ export const toSolidServerAction = defineTransform({
|
|
|
9
9
|
let changes = replaceImportSpec(ast, {
|
|
10
10
|
spec: { $api: "$serverApi" },
|
|
11
11
|
source: "dreamkit",
|
|
12
|
-
newSource: "dreamkit/
|
|
12
|
+
newSource: "dreamkit/scopes/solid-import.js",
|
|
13
13
|
onRenameSpec(prev, next) {
|
|
14
14
|
apiId = next;
|
|
15
15
|
},
|
package/lib/utils/ast.d.ts
CHANGED
|
@@ -7,15 +7,25 @@ export declare function parseCode(input: string | string[]): t.Statement[];
|
|
|
7
7
|
export type ParseFileResult = ParseResult<t.File>;
|
|
8
8
|
export declare function parseFile(code: string): ParseResult<t.File>;
|
|
9
9
|
export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean | string): import("@babel/generator").GeneratorResult | undefined;
|
|
10
|
+
export type InputChain = {
|
|
11
|
+
rootName: string;
|
|
12
|
+
calls: {
|
|
13
|
+
name: string;
|
|
14
|
+
arguments: any[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
10
17
|
export type Chain = {
|
|
11
18
|
rootName: string;
|
|
19
|
+
root: t.Identifier;
|
|
12
20
|
calls: {
|
|
21
|
+
node: t.CallExpression;
|
|
22
|
+
property: t.Identifier;
|
|
13
23
|
name: string;
|
|
14
24
|
arguments: any[];
|
|
15
25
|
}[];
|
|
16
26
|
};
|
|
17
27
|
export declare function parseCallsChain(input: t.CallExpression): Chain;
|
|
18
|
-
export declare function createCallChains(chain:
|
|
28
|
+
export declare function createCallChains(chain: InputChain): t.CallExpression | t.Identifier;
|
|
19
29
|
export declare function removeChainCalls(input: t.CallExpression, names: string[]): t.CallExpression;
|
|
20
30
|
export declare function getFirstChain(ref: t.Node): {
|
|
21
31
|
identifier: string;
|
|
@@ -26,6 +36,20 @@ export declare function findExportedNames(ast: ParseFileResult): string[];
|
|
|
26
36
|
export declare function findExportedNamesFromFile(path: string): Promise<string[]>;
|
|
27
37
|
export declare function defineTransform<T>(transform: Transform<T>): Transform<T>;
|
|
28
38
|
export declare function createConst(name: string, value: t.Expression): t.VariableDeclaration;
|
|
39
|
+
export declare function getExports(ast: ParseFileResult): {
|
|
40
|
+
name: string;
|
|
41
|
+
dec: t.Node;
|
|
42
|
+
}[];
|
|
43
|
+
export declare function getImportSpecs(ast: ParseFileResult): {
|
|
44
|
+
source: string;
|
|
45
|
+
spec: {
|
|
46
|
+
imported: string;
|
|
47
|
+
local: string;
|
|
48
|
+
}[];
|
|
49
|
+
}[];
|
|
50
|
+
export declare function getImportLocations<T extends string>(ast: ParseFileResult, source: string, specifiers: T[]): {
|
|
51
|
+
[K in T]: t.SourceLocation[];
|
|
52
|
+
};
|
|
29
53
|
export declare function appendChainCall(input: t.Expression | string, method: string, args: t.Expression[]): t.CallExpression;
|
|
30
54
|
export declare function prependChainCall(input: t.Expression | string, method: string, args?: t.Expression[]): t.CallExpression;
|
|
31
55
|
export declare function addImports<T extends string>(program: NodePath<t.Program> & {
|
package/lib/utils/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AAIzC,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,iBAIjD;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAElD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,uBAKrC;AAED,wBAAgB,WAAW,CACzB,GAAG,EAAE,eAAe,GAAG,SAAS,EAChC,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,0DAavB;AAED,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE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CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD,EACD,UAAU,EAAE,CAAC,EAAE,EACf,MAAM,EAAE,MAAM,GACb;KAAG,CAAC,IAAI,CAAC,GAAG,MAAM;CAAE,CAwBtB"}
|
package/lib/utils/ast.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generator, parser } from "./babel.js";
|
|
1
|
+
import { generator, parser, traverse } from "./babel.js";
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
import * as lexer from "es-module-lexer";
|
|
4
4
|
import { transform } from "esbuild";
|
|
@@ -31,16 +31,20 @@ export function tryGenerate(ast, log) {
|
|
|
31
31
|
export function parseCallsChain(input) {
|
|
32
32
|
let ref = input;
|
|
33
33
|
let rootName;
|
|
34
|
+
let root;
|
|
34
35
|
let calls = [];
|
|
35
36
|
while (true) {
|
|
36
37
|
if (ref.callee.type === "MemberExpression") {
|
|
37
38
|
if (ref.callee.property.type !== "Identifier")
|
|
38
39
|
throw new Error("Invalid chain");
|
|
39
40
|
calls.push({
|
|
41
|
+
node: ref,
|
|
40
42
|
name: ref.callee.property.name,
|
|
43
|
+
property: ref.callee.property,
|
|
41
44
|
arguments: ref.arguments,
|
|
42
45
|
});
|
|
43
46
|
if (ref.callee.object.type === "Identifier") {
|
|
47
|
+
root = ref.callee.object;
|
|
44
48
|
rootName = ref.callee.object.name;
|
|
45
49
|
break;
|
|
46
50
|
}
|
|
@@ -52,7 +56,7 @@ export function parseCallsChain(input) {
|
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
|
-
return { rootName, calls: calls.reverse() };
|
|
59
|
+
return { root, rootName, calls: calls.reverse() };
|
|
56
60
|
}
|
|
57
61
|
export function createCallChains(chain) {
|
|
58
62
|
let ref = t.identifier(chain.rootName);
|
|
@@ -142,6 +146,69 @@ export function createConst(name, value) {
|
|
|
142
146
|
t.variableDeclarator(t.identifier(name), value),
|
|
143
147
|
]);
|
|
144
148
|
}
|
|
149
|
+
export function getExports(ast) {
|
|
150
|
+
const result = [];
|
|
151
|
+
traverse(ast, {
|
|
152
|
+
ExportDefaultDeclaration(path) {
|
|
153
|
+
let dec = path.node.declaration;
|
|
154
|
+
result.push({ name: "default", dec });
|
|
155
|
+
},
|
|
156
|
+
ExportNamedDeclaration(path) {
|
|
157
|
+
if (path.node.declaration?.type === "VariableDeclaration") {
|
|
158
|
+
const [dec] = path.node.declaration.declarations;
|
|
159
|
+
const { init } = dec;
|
|
160
|
+
if (dec.id.type === "Identifier" && init) {
|
|
161
|
+
result.push({ name: dec.id.name, dec: init });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
export function getImportSpecs(ast) {
|
|
169
|
+
const imports = [];
|
|
170
|
+
traverse(ast, {
|
|
171
|
+
ImportDeclaration(path) {
|
|
172
|
+
imports.push({
|
|
173
|
+
source: path.node.source.value,
|
|
174
|
+
spec: path.node.specifiers
|
|
175
|
+
.map((spec) => {
|
|
176
|
+
if (spec.type === "ImportSpecifier" &&
|
|
177
|
+
spec.imported.type === "Identifier") {
|
|
178
|
+
return { imported: spec.imported.name, local: spec.local.name };
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.filter((v) => !!v),
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
return imports;
|
|
186
|
+
}
|
|
187
|
+
export function getImportLocations(ast, source, specifiers) {
|
|
188
|
+
const imports = getImportSpecs(ast).filter((item) => item.source === source);
|
|
189
|
+
const locations = {};
|
|
190
|
+
traverse(ast, {
|
|
191
|
+
Program(programPath) {
|
|
192
|
+
for (const name of specifiers) {
|
|
193
|
+
locations[name] = [];
|
|
194
|
+
let bindingName;
|
|
195
|
+
for (const item of imports) {
|
|
196
|
+
const spec = item.spec.find((spec) => spec.imported === name);
|
|
197
|
+
if (spec)
|
|
198
|
+
bindingName = spec.local;
|
|
199
|
+
}
|
|
200
|
+
if (!bindingName)
|
|
201
|
+
continue;
|
|
202
|
+
const binds = programPath.scope.bindings[bindingName];
|
|
203
|
+
for (const path of binds.referencePaths) {
|
|
204
|
+
if (path.node.loc)
|
|
205
|
+
locations[name].push(path.node.loc);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
return locations;
|
|
211
|
+
}
|
|
145
212
|
export function appendChainCall(input, method, args) {
|
|
146
213
|
if (typeof input === "string")
|
|
147
214
|
input = t.identifier(input);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamkit/dev",
|
|
3
|
-
"version": "0.0.14-next.
|
|
3
|
+
"version": "0.0.14-next.7",
|
|
4
4
|
"description": "Development tools for DreamKit.",
|
|
5
5
|
"homepage": "https://dreamkit.dev",
|
|
6
6
|
"repository": {
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"rollup": "^4.26.0",
|
|
47
47
|
"vite-plugin-solid": "^2.10.2",
|
|
48
48
|
"vite-tsconfig-paths": "^5.1.2",
|
|
49
|
-
"@dreamkit/app": "0.0.7-next.
|
|
49
|
+
"@dreamkit/app": "0.0.7-next.6",
|
|
50
50
|
"@dreamkit/kind": "0.0.2",
|
|
51
|
-
"@dreamkit/node-app": "0.0.2-next.
|
|
52
|
-
"@dreamkit/schema": "0.0.5-next.
|
|
51
|
+
"@dreamkit/node-app": "0.0.2-next.5",
|
|
52
|
+
"@dreamkit/schema": "0.0.5-next.3",
|
|
53
53
|
"@dreamkit/utils": "0.0.5-next.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|