@dreamkit/dev 0.0.6 → 0.0.8
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/adapters/solid-start.d.ts +2 -2
- package/lib/adapters/solid-start.d.ts.map +1 -1
- package/lib/adapters/solid-start.js +71 -53
- package/lib/options.js +1 -1
- package/lib/plugins/dreamkit.d.ts.map +1 -1
- package/lib/plugins/dreamkit.js +6 -3
- 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.js +2 -2
- package/lib/transforms/to-solid-route.d.ts.map +1 -1
- package/lib/transforms/to-solid-route.js +16 -3
- package/lib/utils/ast.d.ts +1 -3
- package/lib/utils/ast.d.ts.map +1 -1
- package/lib/utils/ast.js +2 -9
- package/lib/utils/transform.d.ts.map +1 -1
- package/lib/utils/transform.js +5 -4
- 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;
|
|
1
|
+
{"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDev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|
|
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;AAkB5B,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";
|
|
@@ -8,6 +8,15 @@ import { onChangeVinxiRoutes, } from "../utils/vinxi.js";
|
|
|
8
8
|
import { isRoute, $route } from "@dreamkit/app";
|
|
9
9
|
import { join, resolve } from "path";
|
|
10
10
|
const isEntryRoute = (id, value) => !id.startsWith("/") && isRoute(value);
|
|
11
|
+
// StackBlitz Polyfill
|
|
12
|
+
class $CustomEvent extends Event {
|
|
13
|
+
detail;
|
|
14
|
+
constructor(message, data) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.detail = data?.detail;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const CustomEvent = globalThis.CustomEvent ?? $CustomEvent;
|
|
11
20
|
export async function fetchDreamkitDevOptions(options) {
|
|
12
21
|
const entry = join(options.root, "app.config.ts").replaceAll("\\", "/");
|
|
13
22
|
const dummyDefineConfigSource = "virtual:config";
|
|
@@ -34,7 +43,7 @@ export async function fetchDreamkitDevOptions(options) {
|
|
|
34
43
|
newSource: dummyDefineConfigSource,
|
|
35
44
|
},
|
|
36
45
|
});
|
|
37
|
-
return
|
|
46
|
+
return tryGenerate(ast);
|
|
38
47
|
}
|
|
39
48
|
},
|
|
40
49
|
},
|
|
@@ -49,6 +58,35 @@ export async function fetchDreamkitDevOptions(options) {
|
|
|
49
58
|
...dreamkitPlugin.dreamkitOptions,
|
|
50
59
|
};
|
|
51
60
|
}
|
|
61
|
+
function addVinxiEntryRoutes(vinxiApp, objectId, objectValue, entryPath) {
|
|
62
|
+
for (const config of vinxiApp.config.routers) {
|
|
63
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
64
|
+
const routes = config.internals.routes;
|
|
65
|
+
const vinxiRoute = {
|
|
66
|
+
_dreamkitEntryId: objectId,
|
|
67
|
+
page: true,
|
|
68
|
+
$component: {
|
|
69
|
+
src: `${entryPath}?dk-pick-entry=${objectId}&pick=default&`,
|
|
70
|
+
pick: ["default", "$css"],
|
|
71
|
+
},
|
|
72
|
+
$$route: {
|
|
73
|
+
src: `${entryPath}?dk-pick-entry=${objectId}&pick=route&`,
|
|
74
|
+
pick: ["route"],
|
|
75
|
+
},
|
|
76
|
+
path: objectValue.$options.path ?? "",
|
|
77
|
+
filePath: entryPath,
|
|
78
|
+
};
|
|
79
|
+
if (!objectValue.$options.path) {
|
|
80
|
+
console.warn("Missing route path", { id: objectId });
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
routes._addRoute(vinxiRoute);
|
|
84
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
85
|
+
detail: { route: vinxiRoute, dreamkitRoute: true },
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
52
90
|
export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
53
91
|
const ssrRouter = vinxiApp.config.routers.find((config) => config.name === "ssr").internals.routes;
|
|
54
92
|
const server = new DreamkitDevServer({
|
|
@@ -58,6 +96,11 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
58
96
|
});
|
|
59
97
|
async function onBuildStart() {
|
|
60
98
|
await server.prepare(false);
|
|
99
|
+
for (const route of server.app.routes) {
|
|
100
|
+
const id = server.app.getObjectId(route);
|
|
101
|
+
if (isEntryRoute(id, route))
|
|
102
|
+
addVinxiEntryRoutes(vinxiApp, id, route, server.entry.path);
|
|
103
|
+
}
|
|
61
104
|
for (const router of vinxiApp.config.routers) {
|
|
62
105
|
if (router.name === "ssr" || router.name === "client") {
|
|
63
106
|
const internalRouter = router.internals.routes;
|
|
@@ -77,6 +120,31 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
77
120
|
await server.stop();
|
|
78
121
|
}
|
|
79
122
|
async function onDevStart() {
|
|
123
|
+
const tryGenerate = createDelayedFunction(() => generate(server), 300);
|
|
124
|
+
server.app
|
|
125
|
+
.on("change", (data) => {
|
|
126
|
+
if (isRoute(data.value)) {
|
|
127
|
+
tryGenerate();
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
.on("add", async ({ id, value }) => {
|
|
131
|
+
if (isEntryRoute(id, value)) {
|
|
132
|
+
addVinxiEntryRoutes(vinxiApp, id, value, server.entry.path);
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
.on("remove", ({ id, value }) => {
|
|
136
|
+
if (isEntryRoute(id, value)) {
|
|
137
|
+
for (const config of vinxiApp.config.routers) {
|
|
138
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
139
|
+
const routes = config.internals.routes;
|
|
140
|
+
routes.routes = routes.routes.filter((r) => r._dreamkitEntryId !== id);
|
|
141
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
142
|
+
detail: { dreamkitRoute: true },
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
80
148
|
await server.prepare(true);
|
|
81
149
|
for (const router of vinxiApp.config.routers) {
|
|
82
150
|
const internalRouter = router.internals.routes;
|
|
@@ -113,61 +181,11 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
|
113
181
|
});
|
|
114
182
|
}
|
|
115
183
|
}
|
|
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
184
|
}
|
|
168
185
|
vinxiApp.hooks.hook("app:build:router:start", onBuildStart);
|
|
169
186
|
vinxiApp.hooks.hook("app:build:router:vite:end", onBuildEnd);
|
|
170
187
|
vinxiApp.hooks.hook("app:build:nitro:start", onBuildStart);
|
|
171
188
|
vinxiApp.hooks.hook("app:build:nitro:end", onBuildEnd);
|
|
172
189
|
vinxiApp.hooks.hook("app:dev:start", onDevStart);
|
|
190
|
+
return server;
|
|
173
191
|
}
|
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",
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addImports, defineTransform } from "../utils/ast.js";
|
|
2
2
|
import { traverse } from "../utils/babel.js";
|
|
3
3
|
import * as t from "@babel/types";
|
|
4
4
|
export const toSolidLink = defineTransform({
|
|
@@ -33,6 +33,6 @@ export const toSolidLink = defineTransform({
|
|
|
33
33
|
});
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
|
-
return
|
|
36
|
+
return changes;
|
|
37
37
|
},
|
|
38
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addImports, appendChainCall, createConst, getFirstChain, prependChainCall, } from "../utils/ast.js";
|
|
2
2
|
import { traverse } from "../utils/babel.js";
|
|
3
3
|
import { replaceImportSpec } from "./replace-import-spec.js";
|
|
4
4
|
import * as t from "@babel/types";
|
|
@@ -30,7 +30,19 @@ export function toSolidRoute(ast) {
|
|
|
30
30
|
});
|
|
31
31
|
},
|
|
32
32
|
ExportDefaultDeclaration(path) {
|
|
33
|
-
|
|
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
|
+
}
|
|
34
46
|
// [input]
|
|
35
47
|
// import { $route } from "dreamkit";
|
|
36
48
|
// export default route.params({}).create(() => {});
|
|
@@ -80,6 +92,7 @@ export function toSolidRoute(ast) {
|
|
|
80
92
|
dec.id.name === "route" &&
|
|
81
93
|
dec.init &&
|
|
82
94
|
getFirstChain(dec.init)?.identifier === routeImportName) {
|
|
95
|
+
changes++;
|
|
83
96
|
// [input]
|
|
84
97
|
// export const route = $route.?;
|
|
85
98
|
// [output]
|
|
@@ -120,7 +133,7 @@ export function toSolidRoute(ast) {
|
|
|
120
133
|
});
|
|
121
134
|
},
|
|
122
135
|
});
|
|
123
|
-
return
|
|
136
|
+
return changes;
|
|
124
137
|
}
|
|
125
138
|
function createDepsObject(deps) {
|
|
126
139
|
return t.objectExpression([
|
package/lib/utils/ast.d.ts
CHANGED
|
@@ -6,9 +6,7 @@ import * as lexer from "es-module-lexer";
|
|
|
6
6
|
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
|
-
export declare function
|
|
10
|
-
export declare function getFileChanges(ast: ParseFileResult): number;
|
|
11
|
-
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;
|
|
12
10
|
export declare function getFirstChain(ref: t.Node): {
|
|
13
11
|
identifier: string;
|
|
14
12
|
value: t.MemberExpression;
|
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,
|
|
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,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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
|
@@ -14,15 +14,8 @@ export function parseFile(code) {
|
|
|
14
14
|
plugins: ["typescript", "jsx"],
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
export function
|
|
18
|
-
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
export function getFileChanges(ast) {
|
|
22
|
-
return Number(ast["__changes"]) || 0;
|
|
23
|
-
}
|
|
24
|
-
export function generateIfChanges(ast, log) {
|
|
25
|
-
if (ast && getFileChanges(ast)) {
|
|
17
|
+
export function tryGenerate(ast, log) {
|
|
18
|
+
if (ast) {
|
|
26
19
|
const generated = generator(ast);
|
|
27
20
|
if (log)
|
|
28
21
|
console.log(generated);
|
|
@@ -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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AAC,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
|
@@ -4,7 +4,7 @@ import { pickExport } from "../transforms/pick-export.js";
|
|
|
4
4
|
import { replaceImportSpec } from "../transforms/replace-import-spec.js";
|
|
5
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,
|
|
@@ -15,6 +15,7 @@ const $transforms = {
|
|
|
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.8",
|
|
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": {
|