@dreamkit/dev 0.0.5 → 0.0.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 +1 -1
- package/lib/adapters/solid-start.d.ts +2 -2
- package/lib/adapters/solid-start.d.ts.map +1 -1
- package/lib/adapters/solid-start.js +62 -53
- package/lib/options.js +1 -1
- package/lib/plugins/dreamkit.d.ts.map +1 -1
- package/lib/plugins/dreamkit.js +7 -4
- package/lib/transforms/delete-dead-code.d.ts +1 -1
- package/lib/transforms/delete-dead-code.d.ts.map +1 -1
- package/lib/transforms/delete-dead-code.js +1 -0
- package/lib/transforms/export-default.d.ts.map +1 -1
- package/lib/transforms/export-default.js +1 -2
- package/lib/transforms/fix-use-data.d.ts +1 -1
- package/lib/transforms/fix-use-data.d.ts.map +1 -1
- package/lib/transforms/fix-use-data.js +1 -2
- package/lib/transforms/no-export.d.ts.map +1 -1
- package/lib/transforms/no-export.js +1 -2
- package/lib/transforms/pick-export.d.ts.map +1 -1
- package/lib/transforms/pick-export.js +1 -3
- package/lib/transforms/replace-import-spec.d.ts.map +1 -1
- package/lib/transforms/replace-import-spec.js +1 -2
- package/lib/transforms/to-solid-link.d.ts +2 -0
- package/lib/transforms/to-solid-link.d.ts.map +1 -0
- package/lib/transforms/to-solid-link.js +38 -0
- package/lib/transforms/to-solid-route.d.ts.map +1 -1
- package/lib/transforms/to-solid-route.js +54 -28
- package/lib/utils/ast.d.ts +8 -3
- package/lib/utils/ast.d.ts.map +1 -1
- package/lib/utils/ast.js +47 -9
- package/lib/utils/transform.d.ts +1 -1
- package/lib/utils/transform.d.ts.map +1 -1
- package/lib/utils/transform.js +7 -6
- package/package.json +4 -4
- package/lib/transforms/to-solid-import.d.ts +0 -2
- package/lib/transforms/to-solid-import.d.ts.map +0 -1
- package/lib/transforms/to-solid-import.js +0 -18
|
@@ -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;
|
|
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,EAAU,MAAM,eAAe,CAAC;AAE5D,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,oBAAoB,GAAG,qBAAqB,GACtD,0BAA0B,CAAC;AAC7B,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,GACvD,0BAA0B,CAAC;AAE7B,qBAAa,iBAAiB;IAC5B,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,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBACzB,SAAS,EAAE,oBAAoB;IA6BrC,KAAK,CAAC,IAAI,EAAE,MAAM;IAMlB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAKxC,gBAAgB;IAyBhB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAIjD,OAAO,CAAC,uBAAuB,UAAO;IAqCtC,IAAI;CAIX"}
|
package/lib/DreamkitDevServer.js
CHANGED
|
@@ -100,7 +100,7 @@ export class DreamkitDevServer {
|
|
|
100
100
|
enforce: "pre",
|
|
101
101
|
load: (id) => this.entry.tryLoad(id),
|
|
102
102
|
transform(code, id) {
|
|
103
|
-
return transformAndGenerate(code, {
|
|
103
|
+
return transformAndGenerate(code, { toSolidLink: true }, ...getUrlTransforms(id));
|
|
104
104
|
},
|
|
105
105
|
handleHotUpdate: async ({ file, read, modules }) => {
|
|
106
106
|
return this.entry.tryUpdate(file, read, modules);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DreamkitDevInOptions } from "../DreamkitDevServer.js";
|
|
1
|
+
import { DreamkitDevInOptions, DreamkitDevServer } from "../DreamkitDevServer.js";
|
|
2
2
|
import { DreamkitPluginOptions } from "../options.js";
|
|
3
3
|
import { App } from "vinxi";
|
|
4
4
|
export declare function fetchDreamkitDevOptions(options: {
|
|
5
5
|
root: string;
|
|
6
6
|
}): Promise<DreamkitDevInOptions>;
|
|
7
|
-
export declare function createDreamkitDevServer(vinxiApp: App, inOptions?: DreamkitPluginOptions):
|
|
7
|
+
export declare function createDreamkitDevServer(vinxiApp: App, inOptions?: DreamkitPluginOptions): DreamkitDevServer;
|
|
8
8
|
//# sourceMappingURL=solid-start.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solid-start.d.ts","sourceRoot":"","sources":["../../src/adapters/solid-start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,
|
|
1
|
+
{"version":3,"file":"solid-start.d.ts","sourceRoot":"","sources":["../../src/adapters/solid-start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAYtD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAM5B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDhC;AAsCD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,GAAG,EACb,SAAS,GAAE,qBAA0B,qBAoHtC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DreamkitDevServer, } from "../DreamkitDevServer.js";
|
|
2
2
|
import { generate } from "../actions/generate.js";
|
|
3
|
-
import {
|
|
3
|
+
import { tryGenerate } from "../utils/ast.js";
|
|
4
4
|
import { execute } from "../utils/runtime.js";
|
|
5
5
|
import { createDelayedFunction } from "../utils/timeout.js";
|
|
6
6
|
import { transformCode } from "../utils/transform.js";
|
|
@@ -34,7 +34,7 @@ export async function fetchDreamkitDevOptions(options) {
|
|
|
34
34
|
newSource: dummyDefineConfigSource,
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
|
-
return
|
|
37
|
+
return tryGenerate(ast);
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
},
|
|
@@ -49,6 +49,35 @@ export async function fetchDreamkitDevOptions(options) {
|
|
|
49
49
|
...dreamkitPlugin.dreamkitOptions,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
function addVinxiEntryRoutes(vinxiApp, objectId, objectValue, entryPath) {
|
|
53
|
+
for (const config of vinxiApp.config.routers) {
|
|
54
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
55
|
+
const routes = config.internals.routes;
|
|
56
|
+
const vinxiRoute = {
|
|
57
|
+
_dreamkitEntryId: objectId,
|
|
58
|
+
page: true,
|
|
59
|
+
$component: {
|
|
60
|
+
src: `${entryPath}?dk-pick-entry=${objectId}&pick=default&`,
|
|
61
|
+
pick: ["default", "$css"],
|
|
62
|
+
},
|
|
63
|
+
$$route: {
|
|
64
|
+
src: `${entryPath}?dk-pick-entry=${objectId}&pick=route&`,
|
|
65
|
+
pick: ["route"],
|
|
66
|
+
},
|
|
67
|
+
path: objectValue.$options.path ?? "",
|
|
68
|
+
filePath: entryPath,
|
|
69
|
+
};
|
|
70
|
+
if (!objectValue.$options.path) {
|
|
71
|
+
console.warn("Missing route path", { id: objectId });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
routes._addRoute(vinxiRoute);
|
|
75
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
76
|
+
detail: { route: vinxiRoute, dreamkitRoute: true },
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
52
81
|
export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
53
82
|
const ssrRouter = vinxiApp.config.routers.find((config) => config.name === "ssr").internals.routes;
|
|
54
83
|
const server = new DreamkitDevServer({
|
|
@@ -58,6 +87,11 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
58
87
|
});
|
|
59
88
|
async function onBuildStart() {
|
|
60
89
|
await server.prepare(false);
|
|
90
|
+
for (const route of server.app.routes) {
|
|
91
|
+
const id = server.app.getObjectId(route);
|
|
92
|
+
if (isEntryRoute(id, route))
|
|
93
|
+
addVinxiEntryRoutes(vinxiApp, id, route, server.entry.path);
|
|
94
|
+
}
|
|
61
95
|
for (const router of vinxiApp.config.routers) {
|
|
62
96
|
if (router.name === "ssr" || router.name === "client") {
|
|
63
97
|
const internalRouter = router.internals.routes;
|
|
@@ -77,6 +111,31 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
77
111
|
await server.stop();
|
|
78
112
|
}
|
|
79
113
|
async function onDevStart() {
|
|
114
|
+
const tryGenerate = createDelayedFunction(() => generate(server), 300);
|
|
115
|
+
server.app
|
|
116
|
+
.on("change", (data) => {
|
|
117
|
+
if (isRoute(data.value)) {
|
|
118
|
+
tryGenerate();
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
.on("add", async ({ id, value }) => {
|
|
122
|
+
if (isEntryRoute(id, value)) {
|
|
123
|
+
addVinxiEntryRoutes(vinxiApp, id, value, server.entry.path);
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
.on("remove", ({ id, value }) => {
|
|
127
|
+
if (isEntryRoute(id, value)) {
|
|
128
|
+
for (const config of vinxiApp.config.routers) {
|
|
129
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
130
|
+
const routes = config.internals.routes;
|
|
131
|
+
routes.routes = routes.routes.filter((r) => r._dreamkitEntryId !== id);
|
|
132
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
133
|
+
detail: { dreamkitRoute: true },
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
80
139
|
await server.prepare(true);
|
|
81
140
|
for (const router of vinxiApp.config.routers) {
|
|
82
141
|
const internalRouter = router.internals.routes;
|
|
@@ -113,61 +172,11 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
113
172
|
});
|
|
114
173
|
}
|
|
115
174
|
}
|
|
116
|
-
const tryGenerate = createDelayedFunction(() => generate(server), 300);
|
|
117
|
-
server.app
|
|
118
|
-
.on("change", (data) => {
|
|
119
|
-
if (isRoute(data.value)) {
|
|
120
|
-
tryGenerate();
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
.on("add", async ({ id, value }) => {
|
|
124
|
-
if (isEntryRoute(id, value)) {
|
|
125
|
-
for (const config of vinxiApp.config.routers) {
|
|
126
|
-
if (config.name === "ssr" || config.name === "client") {
|
|
127
|
-
const routes = config.internals.routes;
|
|
128
|
-
const vinxiRoute = {
|
|
129
|
-
_dreamkitEntryId: id,
|
|
130
|
-
page: true,
|
|
131
|
-
$component: {
|
|
132
|
-
src: `${server.entry.path}?dk-pick-entry=${id}&pick=default&`,
|
|
133
|
-
pick: ["default", "$css"],
|
|
134
|
-
},
|
|
135
|
-
$$route: {
|
|
136
|
-
src: `${server.entry.path}?dk-pick-entry=${id}&pick=route&`,
|
|
137
|
-
pick: ["route"],
|
|
138
|
-
},
|
|
139
|
-
path: value.$options.path ?? "",
|
|
140
|
-
filePath: server.entry.path,
|
|
141
|
-
};
|
|
142
|
-
if (!value.$options.path) {
|
|
143
|
-
console.warn("Missing route path", { id });
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
routes._addRoute(vinxiRoute);
|
|
147
|
-
routes.dispatchEvent(new CustomEvent("reload", {
|
|
148
|
-
detail: { route: vinxiRoute, dreamkitRoute: true },
|
|
149
|
-
}));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
.on("remove", ({ id, value }) => {
|
|
155
|
-
if (isEntryRoute(id, value)) {
|
|
156
|
-
for (const config of vinxiApp.config.routers) {
|
|
157
|
-
if (config.name === "ssr" || config.name === "client") {
|
|
158
|
-
const routes = config.internals.routes;
|
|
159
|
-
routes.routes = routes.routes.filter((r) => r._id !== id);
|
|
160
|
-
routes.dispatchEvent(new CustomEvent("reload", {
|
|
161
|
-
detail: { dreamkitRoute: true },
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
175
|
}
|
|
168
176
|
vinxiApp.hooks.hook("app:build:router:start", onBuildStart);
|
|
169
177
|
vinxiApp.hooks.hook("app:build:router:vite:end", onBuildEnd);
|
|
170
178
|
vinxiApp.hooks.hook("app:build:nitro:start", onBuildStart);
|
|
171
179
|
vinxiApp.hooks.hook("app:build:nitro:end", onBuildEnd);
|
|
172
180
|
vinxiApp.hooks.hook("app:dev:start", onDevStart);
|
|
181
|
+
return server;
|
|
173
182
|
}
|
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
|
-
metaGlobalOutput: "./src/dreamkit.d.ts",
|
|
5
|
+
metaGlobalOutput: "./src/dreamkit-global.d.ts",
|
|
6
6
|
metaLocalOutput: "./src/dreamkit-local.ts",
|
|
7
7
|
metaLocalExports: true,
|
|
8
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,CAiD5E"}
|
package/lib/plugins/dreamkit.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { createDreamkitDevServer } from "../adapters/solid-start.js";
|
|
2
|
-
import {
|
|
2
|
+
import { tryGenerate } from "../utils/ast.js";
|
|
3
3
|
import { transformCode } from "../utils/transform.js";
|
|
4
4
|
import { onVinxiApp } from "../utils/vinxi.js";
|
|
5
5
|
export function dreamkitPlugin(inOptions = {}) {
|
|
6
6
|
let isSolidStart = false;
|
|
7
|
-
|
|
7
|
+
let server;
|
|
8
|
+
const cleanup = onVinxiApp((app) => {
|
|
9
|
+
server = createDreamkitDevServer(app, inOptions);
|
|
10
|
+
});
|
|
8
11
|
return {
|
|
9
12
|
name: "dreamkit",
|
|
10
13
|
enforce: "pre",
|
|
@@ -23,7 +26,7 @@ export function dreamkitPlugin(inOptions = {}) {
|
|
|
23
26
|
const searchParams = new URLSearchParams(searchString);
|
|
24
27
|
const dreamkitPickEntry = searchParams.get("dk-pick-entry");
|
|
25
28
|
const picks = searchParams.getAll("pick");
|
|
26
|
-
const transforms = [{
|
|
29
|
+
const transforms = [{ toSolidLink: true }];
|
|
27
30
|
if (dreamkitPickEntry) {
|
|
28
31
|
transforms.push({
|
|
29
32
|
pickExport: [dreamkitPickEntry],
|
|
@@ -41,7 +44,7 @@ export function dreamkitPlugin(inOptions = {}) {
|
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
const ast = transformCode(code, ...transforms);
|
|
44
|
-
const result =
|
|
47
|
+
const result = tryGenerate(ast);
|
|
45
48
|
return result;
|
|
46
49
|
},
|
|
47
50
|
};
|
|
@@ -2,5 +2,5 @@ import { ParseFileResult } from "../utils/ast.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* @link https://github.com/pcattori/babel-dead-code-elimination
|
|
4
4
|
*/
|
|
5
|
-
export declare function deleteDeadCode(ast: ParseFileResult):
|
|
5
|
+
export declare function deleteDeadCode(ast: ParseFileResult): number;
|
|
6
6
|
//# sourceMappingURL=delete-dead-code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-dead-code.d.ts","sourceRoot":"","sources":["../../src/transforms/delete-dead-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKlD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"delete-dead-code.d.ts","sourceRoot":"","sources":["../../src/transforms/delete-dead-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKlD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,UA+DlD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-default.d.ts","sourceRoot":"","sources":["../../src/transforms/export-default.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"export-default.d.ts","sourceRoot":"","sources":["../../src/transforms/export-default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,UAWnE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addFileChanges } from "../utils/ast.js";
|
|
2
1
|
import * as t from "@babel/types";
|
|
3
2
|
export function exportDefault(ast, name) {
|
|
4
3
|
let changes = 0;
|
|
@@ -6,5 +5,5 @@ export function exportDefault(ast, name) {
|
|
|
6
5
|
ast.program.body.push(t.exportDefaultDeclaration(t.identifier(name)));
|
|
7
6
|
changes++;
|
|
8
7
|
}
|
|
9
|
-
return
|
|
8
|
+
return changes;
|
|
10
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-use-data.d.ts","sourceRoot":"","sources":["../../src/transforms/fix-use-data.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fix-use-data.d.ts","sourceRoot":"","sources":["../../src/transforms/fix-use-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIlD,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,SA+C9C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addFileChanges } from "../utils/ast.js";
|
|
2
1
|
import { traverse } from "../utils/babel.js";
|
|
3
2
|
export function fixUseData(ast) {
|
|
4
3
|
let routeId;
|
|
@@ -45,5 +44,5 @@ export function fixUseData(ast) {
|
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
46
|
});
|
|
48
|
-
return
|
|
47
|
+
return transformed ? 1 : 0;
|
|
49
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-export.d.ts","sourceRoot":"","sources":["../../src/transforms/no-export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-export.d.ts","sourceRoot":"","sources":["../../src/transforms/no-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAuBjE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addFileChanges } from "../utils/ast.js";
|
|
2
1
|
import * as t from "@babel/types";
|
|
3
2
|
export function noExport(ast, names) {
|
|
4
3
|
let changes = 0;
|
|
@@ -15,5 +14,5 @@ export function noExport(ast, names) {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
return
|
|
17
|
+
return changes;
|
|
19
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-export.d.ts","sourceRoot":"","sources":["../../src/transforms/pick-export.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pick-export.d.ts","sourceRoot":"","sources":["../../src/transforms/pick-export.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UA0EnE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addFileChanges } from "../utils/ast.js";
|
|
2
1
|
import { deleteDeadCode } from "./delete-dead-code.js";
|
|
3
2
|
import * as t from "@babel/types";
|
|
4
3
|
export function pickExport(ast, names) {
|
|
@@ -55,6 +54,5 @@ export function pickExport(ast, names) {
|
|
|
55
54
|
return stm;
|
|
56
55
|
})
|
|
57
56
|
.filter((v) => v !== undefined);
|
|
58
|
-
deleteDeadCode(ast);
|
|
59
|
-
return addFileChanges(ast, changes);
|
|
57
|
+
return changes + deleteDeadCode(ast);
|
|
60
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,EACxB,OAAO,EAAE;IACP,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,UAqCF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addFileChanges } from "../utils/ast.js";
|
|
2
1
|
import { traverse } from "../utils/babel.js";
|
|
3
2
|
import * as t from "@babel/types";
|
|
4
3
|
export function replaceImportSpec(ast, options) {
|
|
@@ -27,5 +26,5 @@ export function replaceImportSpec(ast, options) {
|
|
|
27
26
|
}
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
|
-
return
|
|
29
|
+
return changes;
|
|
31
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-solid-link.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-link.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,oDAkDtB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { addImports, defineTransform } from "../utils/ast.js";
|
|
2
|
+
import { traverse } from "../utils/babel.js";
|
|
3
|
+
import * as t from "@babel/types";
|
|
4
|
+
export const toSolidLink = defineTransform({
|
|
5
|
+
onlyIf: (code) => code.includes("Link"),
|
|
6
|
+
run: (ast) => {
|
|
7
|
+
let changes = 0;
|
|
8
|
+
const addRouterImports = (programPath) => addImports(programPath, ["A"], "@solidjs/router");
|
|
9
|
+
let routeImports;
|
|
10
|
+
let linkSpec;
|
|
11
|
+
traverse(ast, {
|
|
12
|
+
Program(programPath) {
|
|
13
|
+
programPath.traverse({
|
|
14
|
+
ImportDeclaration(path) {
|
|
15
|
+
for (const spec of path.node.specifiers) {
|
|
16
|
+
if (path.node.source.value === "dreamkit" &&
|
|
17
|
+
spec.type === "ImportSpecifier" &&
|
|
18
|
+
spec.imported.type === "Identifier" &&
|
|
19
|
+
spec.imported.name === "Link") {
|
|
20
|
+
linkSpec = spec.local.name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
JSXOpeningElement(path) {
|
|
25
|
+
if (path.node.name.type === "JSXIdentifier" &&
|
|
26
|
+
path.node.name.name === linkSpec) {
|
|
27
|
+
if (!routeImports)
|
|
28
|
+
routeImports = addImports(programPath, ["A"], "@solidjs/router");
|
|
29
|
+
changes++;
|
|
30
|
+
path.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("component"), t.jsxExpressionContainer(t.identifier(routeImports.A))));
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return changes;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,wBAAgB,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,UAgMpD"}
|
|
@@ -1,34 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addImports, appendChainCall, createConst, getFirstChain, prependChainCall, } from "../utils/ast.js";
|
|
2
2
|
import { traverse } from "../utils/babel.js";
|
|
3
|
+
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
3
4
|
import * as t from "@babel/types";
|
|
4
5
|
export function toSolidRoute(ast) {
|
|
5
6
|
let changes = 0;
|
|
7
|
+
let deps;
|
|
6
8
|
let routeImportName;
|
|
7
9
|
const routeSpec = "$route";
|
|
8
|
-
const routeSource = "dreamkit
|
|
10
|
+
const routeSource = "dreamkit";
|
|
11
|
+
const routeNewSource = "dreamkit/adapters/solid.js";
|
|
12
|
+
replaceImportSpec(ast, {
|
|
13
|
+
newSource: routeNewSource,
|
|
14
|
+
source: routeSource,
|
|
15
|
+
spec: [routeSpec],
|
|
16
|
+
});
|
|
9
17
|
traverse(ast, {
|
|
10
18
|
Program(programPath) {
|
|
11
19
|
traverse(programPath.node, {
|
|
12
20
|
ImportDeclaration(importPath) {
|
|
13
21
|
importPath.traverse({
|
|
14
22
|
ImportSpecifier(path) {
|
|
15
|
-
// import { route as ? } from "dreamkit/solid";
|
|
23
|
+
// import { route as ? } from "dreamkit/adapters/solid.js";
|
|
16
24
|
const isRouteImport = path.node.imported.type === "Identifier" &&
|
|
17
25
|
path.node.imported.name === routeSpec &&
|
|
18
|
-
importPath.node.source.value ===
|
|
26
|
+
importPath.node.source.value === routeNewSource;
|
|
19
27
|
if (isRouteImport)
|
|
20
28
|
routeImportName = path.node.local.name;
|
|
21
29
|
},
|
|
22
30
|
});
|
|
23
31
|
},
|
|
24
32
|
ExportDefaultDeclaration(path) {
|
|
25
|
-
|
|
33
|
+
let dec = path.node.declaration;
|
|
34
|
+
if (
|
|
35
|
+
// import { $route } from "dreamkit";
|
|
36
|
+
// const login = $route.create(() => {})
|
|
37
|
+
// export default login
|
|
38
|
+
dec.type === "Identifier") {
|
|
39
|
+
const bind = programPath.scope.bindings[dec.name];
|
|
40
|
+
if (bind.path.node.type === "VariableDeclarator" &&
|
|
41
|
+
bind.path.node.init) {
|
|
42
|
+
dec = bind.path.node.init;
|
|
43
|
+
path.remove();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
26
46
|
// [input]
|
|
27
47
|
// import { $route } from "dreamkit";
|
|
28
48
|
// export default route.params({}).create(() => {});
|
|
29
49
|
// [output]
|
|
30
|
-
// import { $route as _$route } from "dreamkit/solid"
|
|
31
|
-
//
|
|
50
|
+
// import { $route as _$route } from "dreamkit/adapters/solid.js"
|
|
51
|
+
// import { useLocation, useRouter, useParams} from "@solidjs/router"
|
|
52
|
+
// const selfRoute = _$route.params({}).clone({ deps: ? });
|
|
32
53
|
// export const route = selfRoute.createRouteDefinition();
|
|
33
54
|
// export default delfRoute.create(() => {})
|
|
34
55
|
if (
|
|
@@ -39,14 +60,18 @@ export function toSolidRoute(ast) {
|
|
|
39
60
|
dec.callee.property.type == "Identifier" &&
|
|
40
61
|
dec.callee.property.name === "create") {
|
|
41
62
|
changes++;
|
|
63
|
+
if (!deps)
|
|
64
|
+
deps = importDeps(programPath);
|
|
42
65
|
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
43
66
|
ast.program.body.splice(ast.program.body.indexOf(path.node), 1,
|
|
44
67
|
// const selfRoute = route.?.?.?
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
68
|
+
createConst(selfRoute, prependChainCall(dec.callee.object, "clone", [
|
|
69
|
+
createDepsObject(deps),
|
|
70
|
+
])),
|
|
71
|
+
// export const route = selfRoute.createRouteDefinition()
|
|
72
|
+
t.exportNamedDeclaration(createConst("route", appendChainCall(selfRoute, "createRouteDefinition", []))),
|
|
48
73
|
// export default selfRoute.create(() => {})
|
|
49
|
-
|
|
74
|
+
t.exportDefaultDeclaration(appendChainCall(t.identifier(selfRoute), "create", dec.arguments)));
|
|
50
75
|
}
|
|
51
76
|
},
|
|
52
77
|
// [input]
|
|
@@ -54,8 +79,9 @@ export function toSolidRoute(ast) {
|
|
|
54
79
|
// export const route = $route.params({}).path('/path');
|
|
55
80
|
// export default function Users() { useRoute(route); }
|
|
56
81
|
// [output]
|
|
57
|
-
// import { $route as _$route } from "dreamkit/solid"
|
|
58
|
-
//
|
|
82
|
+
// import { $route as _$route } from "dreamkit/adapters/solid.js"
|
|
83
|
+
// import { useLocation, useRouter, useParams } from "@solidjs/router"
|
|
84
|
+
// const selfRoute = _$route.params({}).path('/path').clone({ deps: ? });
|
|
59
85
|
// export const route = selfRoute.createRouteDefinition();
|
|
60
86
|
// export default selfRoute.create(function Users() { useRoute(selfRoute); });
|
|
61
87
|
ExportNamedDeclaration(path) {
|
|
@@ -66,11 +92,14 @@ export function toSolidRoute(ast) {
|
|
|
66
92
|
dec.id.name === "route" &&
|
|
67
93
|
dec.init &&
|
|
68
94
|
getFirstChain(dec.init)?.identifier === routeImportName) {
|
|
95
|
+
changes++;
|
|
69
96
|
// [input]
|
|
70
97
|
// export const route = $route.?;
|
|
71
98
|
// [output]
|
|
72
99
|
// const _selfRoute = $route.?;
|
|
73
100
|
// export const route = _selfRoute.createRouteDefinition();
|
|
101
|
+
if (!deps)
|
|
102
|
+
deps = importDeps(programPath);
|
|
74
103
|
let exportFunction;
|
|
75
104
|
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
76
105
|
const index = ast.program.body.indexOf(path.node);
|
|
@@ -89,11 +118,13 @@ export function toSolidRoute(ast) {
|
|
|
89
118
|
}
|
|
90
119
|
return true;
|
|
91
120
|
});
|
|
92
|
-
ast.program.body.splice(index, 1,
|
|
121
|
+
ast.program.body.splice(index, 1, createConst(selfRoute, prependChainCall(dec.init, "clone", [createDepsObject(deps)])), t.exportNamedDeclaration(createConst("route", appendChainCall(selfRoute, "createRouteDefinition", []))), ...(exportFunction
|
|
93
122
|
? [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
123
|
+
t.exportDefaultDeclaration(appendChainCall(selfRoute, "create", [
|
|
124
|
+
exportFunction.type === "FunctionDeclaration"
|
|
125
|
+
? t.functionExpression(exportFunction.id, exportFunction.params, exportFunction.body)
|
|
126
|
+
: exportFunction,
|
|
127
|
+
])),
|
|
97
128
|
]
|
|
98
129
|
: []));
|
|
99
130
|
}
|
|
@@ -102,18 +133,13 @@ export function toSolidRoute(ast) {
|
|
|
102
133
|
});
|
|
103
134
|
},
|
|
104
135
|
});
|
|
105
|
-
return
|
|
136
|
+
return changes;
|
|
106
137
|
}
|
|
107
|
-
function
|
|
108
|
-
return t.
|
|
109
|
-
t.
|
|
138
|
+
function createDepsObject(deps) {
|
|
139
|
+
return t.objectExpression([
|
|
140
|
+
t.objectProperty(t.identifier("deps"), t.objectExpression(Object.entries(deps).map(([key, value]) => t.objectProperty(t.identifier(key), t.identifier(value))))),
|
|
110
141
|
]);
|
|
111
142
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
114
|
-
t.variableDeclarator(t.identifier("route"), t.callExpression(t.memberExpression(t.identifier(name), t.identifier("createRouteDefinition")), [])),
|
|
115
|
-
]));
|
|
116
|
-
}
|
|
117
|
-
function createDefaultExportRoute(name, component) {
|
|
118
|
-
return t.exportDefaultDeclaration(t.callExpression(t.memberExpression(t.identifier(name), t.identifier("create")), [component]));
|
|
143
|
+
function importDeps(program) {
|
|
144
|
+
return addImports(program, ["useLocation", "useNavigate", "useParams"], "@solidjs/router");
|
|
119
145
|
}
|
package/lib/utils/ast.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { Transform } from "./transform.js";
|
|
2
2
|
import { ParseResult } from "@babel/parser";
|
|
3
|
+
import { NodePath } from "@babel/traverse";
|
|
3
4
|
import * as t from "@babel/types";
|
|
4
5
|
import * as lexer from "es-module-lexer";
|
|
5
6
|
export declare function parseCode(input: string | string[]): t.Statement[];
|
|
6
7
|
export type ParseFileResult = ParseResult<t.File>;
|
|
7
8
|
export declare function parseFile(code: string): ParseResult<t.File>;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function getFileChanges(ast: ParseFileResult): number;
|
|
10
|
-
export declare function generateIfChanges(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
|
|
9
|
+
export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
|
|
11
10
|
export declare function getFirstChain(ref: t.Node): {
|
|
12
11
|
identifier: string;
|
|
13
12
|
value: t.MemberExpression;
|
|
@@ -16,4 +15,10 @@ export declare function analyzeModule(path: string): Promise<readonly [imports:
|
|
|
16
15
|
export declare function findExportedNames(ast: ParseFileResult): string[];
|
|
17
16
|
export declare function findExportedNamesFromFile(path: string): Promise<string[]>;
|
|
18
17
|
export declare function defineTransform<T>(transform: Transform<T>): Transform<T>;
|
|
18
|
+
export declare function createConst(name: string, value: t.Expression): t.VariableDeclaration;
|
|
19
|
+
export declare function appendChainCall(input: t.Expression | string, method: string, args: t.Expression[]): t.CallExpression;
|
|
20
|
+
export declare function prependChainCall(input: t.Expression | string, method: string, args?: t.Expression[]): t.CallExpression;
|
|
21
|
+
export declare function addImports<T extends string>(program: NodePath<t.Program>, specifiers: T[], source: string): {
|
|
22
|
+
[K in T]: string;
|
|
23
|
+
};
|
|
19
24
|
//# sourceMappingURL=ast.d.ts.map
|
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,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,
|
|
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,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,OAAO,0DAM1E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI;gBAGrB,MAAM;WACX,CAAC,CAAC,gBAAgB;cAgBhC;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,uJAQ/C;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,YAkBrD;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,qBAG3D;AACD,wBAAgB,eAAe,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAExE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,yBAI5D;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,EAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,oBAiBrB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,EAC5B,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,CAAC,CAAC,UAAU,EAAO,oBAqB1B;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,CAAC,EAAE,EACf,MAAM,EAAE,MAAM,GACb;KAAG,CAAC,IAAI,CAAC,GAAG,MAAM;CAAE,CAkBtB"}
|
package/lib/utils/ast.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { generator, parser } from "./babel.js";
|
|
2
|
+
import * as t from "@babel/types";
|
|
2
3
|
import * as lexer from "es-module-lexer";
|
|
3
4
|
import { transform } from "esbuild";
|
|
4
5
|
import { readFile } from "fs/promises";
|
|
@@ -13,15 +14,8 @@ export function parseFile(code) {
|
|
|
13
14
|
plugins: ["typescript", "jsx"],
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
export function getFileChanges(ast) {
|
|
21
|
-
return Number(ast["__changes"]) || 0;
|
|
22
|
-
}
|
|
23
|
-
export function generateIfChanges(ast, log) {
|
|
24
|
-
if (ast && getFileChanges(ast)) {
|
|
17
|
+
export function tryGenerate(ast, log) {
|
|
18
|
+
if (ast) {
|
|
25
19
|
const generated = generator(ast);
|
|
26
20
|
if (log)
|
|
27
21
|
console.log(generated);
|
|
@@ -79,3 +73,47 @@ export async function findExportedNamesFromFile(path) {
|
|
|
79
73
|
export function defineTransform(transform) {
|
|
80
74
|
return transform;
|
|
81
75
|
}
|
|
76
|
+
export function createConst(name, value) {
|
|
77
|
+
return t.variableDeclaration("const", [
|
|
78
|
+
t.variableDeclarator(t.identifier(name), value),
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
export function appendChainCall(input, method, args) {
|
|
82
|
+
if (typeof input === "string")
|
|
83
|
+
input = t.identifier(input);
|
|
84
|
+
if (input.type === "Identifier") {
|
|
85
|
+
return t.callExpression(t.memberExpression(input, t.identifier(method)), args);
|
|
86
|
+
}
|
|
87
|
+
else if (input.type === "CallExpression") {
|
|
88
|
+
return t.callExpression(t.memberExpression(input, t.identifier(method)), args);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error("Unsupported route type");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function prependChainCall(input, method, args = []) {
|
|
95
|
+
if (typeof input === "string")
|
|
96
|
+
input = t.identifier(input);
|
|
97
|
+
if (input.type === "Identifier") {
|
|
98
|
+
return t.callExpression(t.memberExpression(input, t.identifier(method)), args);
|
|
99
|
+
}
|
|
100
|
+
else if (input.type === "CallExpression") {
|
|
101
|
+
const cloned = t.cloneNode(input);
|
|
102
|
+
const firstChain = getFirstChain(cloned);
|
|
103
|
+
if (!firstChain)
|
|
104
|
+
throw new Error("Unsupported route type");
|
|
105
|
+
firstChain.value.object = t.callExpression(t.memberExpression(firstChain.value.object, t.identifier(method)), args);
|
|
106
|
+
return cloned;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw new Error("Unsupported route type");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function addImports(program, specifiers, source) {
|
|
113
|
+
const id = specifiers.map((name) => program.scope.generateUid(name));
|
|
114
|
+
program.node.body.unshift(t.importDeclaration(specifiers.map((spec, index) => t.importSpecifier(t.identifier(id[index]), t.identifier(spec))), t.stringLiteral(source)));
|
|
115
|
+
return specifiers.reduce((result, name, index) => {
|
|
116
|
+
result[name] = id[index];
|
|
117
|
+
return result;
|
|
118
|
+
}, {});
|
|
119
|
+
}
|
package/lib/utils/transform.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare const $transforms: {
|
|
|
10
10
|
noExport: typeof noExport;
|
|
11
11
|
replaceImportSpec: typeof replaceImportSpec;
|
|
12
12
|
toSolidRoute: typeof toSolidRoute;
|
|
13
|
-
|
|
13
|
+
toSolidLink: Transform<unknown>;
|
|
14
14
|
};
|
|
15
15
|
export type TransformObject = {
|
|
16
16
|
[K in keyof typeof $transforms]?: TrueIfUndefined<Parameters<(typeof $transforms)[K] extends Transform<any> ? (typeof $transforms)[K]["run"] : (typeof $transforms)[K] extends TransformRun<any> ? (typeof $transforms)[K] : never>[1]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAA0B,eAAe,EAAE,MAAM,UAAU,CAAC;AAEnE,QAAA,MAAM,WAAW;;;;;;;CAOhB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,eAAe,CAC/C,UAAU,CACR,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,CAAC,GAC1C,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAC9B,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAC/C,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,GACvB,KAAK,CACZ,CAAC,CAAC,CAAC,CACL;CACF,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,CAClC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,CAAC,KACP,MAAM,CAAC;AAEZ,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI;IAC/B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC;IAC/C,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CACtB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,+BAuBtE;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,GAAG,KAAK,EAAE,eAAe,EAAE;;;EAI5B;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAG1D;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AAE7D,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,EACV,GAAG,UAAU,EAAE,eAAe,EAAE,UAQjC;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,EAAE,CAK9D"}
|
package/lib/utils/transform.js
CHANGED
|
@@ -2,19 +2,20 @@ import { exportDefault } from "../transforms/export-default.js";
|
|
|
2
2
|
import { noExport } from "../transforms/no-export.js";
|
|
3
3
|
import { pickExport } from "../transforms/pick-export.js";
|
|
4
4
|
import { replaceImportSpec } from "../transforms/replace-import-spec.js";
|
|
5
|
-
import {
|
|
5
|
+
import { toSolidLink } from "../transforms/to-solid-link.js";
|
|
6
6
|
import { toSolidRoute } from "../transforms/to-solid-route.js";
|
|
7
|
-
import {
|
|
7
|
+
import { tryGenerate, parseFile } from "./ast.js";
|
|
8
8
|
const $transforms = {
|
|
9
9
|
pickExport,
|
|
10
10
|
exportDefault,
|
|
11
11
|
noExport,
|
|
12
12
|
replaceImportSpec,
|
|
13
13
|
toSolidRoute,
|
|
14
|
-
|
|
14
|
+
toSolidLink,
|
|
15
15
|
};
|
|
16
16
|
export function transformCode(code, ...input) {
|
|
17
17
|
let ast;
|
|
18
|
+
let changes = 0;
|
|
18
19
|
for (const item of input) {
|
|
19
20
|
for (let [name, options] of Object.entries(item)) {
|
|
20
21
|
if (name in $transforms) {
|
|
@@ -30,15 +31,15 @@ export function transformCode(code, ...input) {
|
|
|
30
31
|
run = $transform;
|
|
31
32
|
}
|
|
32
33
|
ast = ast || parseFile(code);
|
|
33
|
-
run(ast, options);
|
|
34
|
+
changes += run(ast, options) || 0;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
return ast;
|
|
38
|
+
return changes ? ast : undefined;
|
|
38
39
|
}
|
|
39
40
|
export function transformAndGenerate(code, ...input) {
|
|
40
41
|
const ast = transformCode(code, ...input);
|
|
41
|
-
return
|
|
42
|
+
return tryGenerate(ast) || { code: undefined, map: undefined };
|
|
42
43
|
}
|
|
43
44
|
export function transformCodeByUrl(id, code) {
|
|
44
45
|
const transforms = getUrlTransforms(id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamkit/dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Development tools for DreamKit.",
|
|
5
5
|
"homepage": "https://dreamkit.dev",
|
|
6
6
|
"repository": {
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"esbuild": "^0.24.0",
|
|
44
44
|
"glob": "^11.0.0",
|
|
45
45
|
"vite-plugin-solid": "^2.10.2",
|
|
46
|
-
"vite-tsconfig-paths": "^5.1.
|
|
47
|
-
"@dreamkit/app": "0.0.
|
|
46
|
+
"vite-tsconfig-paths": "^5.1.2",
|
|
47
|
+
"@dreamkit/app": "0.0.3",
|
|
48
48
|
"@dreamkit/schema": "0.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/debug": "^4.1.12",
|
|
52
52
|
"@types/node": "^22.9.0",
|
|
53
53
|
"vinxi": "^0.4.3",
|
|
54
|
-
"vite": "^5.4.
|
|
54
|
+
"vite": "^5.4.11",
|
|
55
55
|
"@dreamkit/tsconfig": "0.0.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-solid-import.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-import.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,oDAgBxB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineTransform } from "../utils/ast.js";
|
|
2
|
-
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
3
|
-
export const toSolidImport = defineTransform({
|
|
4
|
-
onlyIf: (code) => code.includes("'dreamkit'") || code.includes('"dreamkit"'),
|
|
5
|
-
run: (ast) => replaceImportSpec(ast, {
|
|
6
|
-
source: "dreamkit",
|
|
7
|
-
newSource: "dreamkit/solid",
|
|
8
|
-
spec: [
|
|
9
|
-
"Link",
|
|
10
|
-
"Input",
|
|
11
|
-
"createAction",
|
|
12
|
-
"useRoute",
|
|
13
|
-
"defineLink",
|
|
14
|
-
"LinkComponent",
|
|
15
|
-
"$route",
|
|
16
|
-
],
|
|
17
|
-
}),
|
|
18
|
-
});
|