@dreamkit/dev 0.0.2 → 0.0.4
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/actions/generate.js +2 -2
- package/lib/adapters/solid-start.js +1 -1
- package/lib/plugins/dreamkit.d.ts.map +1 -1
- package/lib/plugins/dreamkit.js +8 -0
- package/lib/transforms/pick-export.d.ts.map +1 -1
- package/lib/transforms/pick-export.js +5 -0
- package/lib/transforms/replace-import-spec.d.ts +1 -1
- package/lib/transforms/replace-import-spec.d.ts.map +1 -1
- package/lib/transforms/replace-import-spec.js +7 -2
- package/lib/transforms/to-solid-route.d.ts.map +1 -1
- package/lib/transforms/to-solid-route.js +95 -68
- package/package.json +3 -3
package/lib/actions/generate.js
CHANGED
|
@@ -27,7 +27,8 @@ export async function generate(server) {
|
|
|
27
27
|
else {
|
|
28
28
|
contents = [
|
|
29
29
|
`// prettier-ignore`,
|
|
30
|
-
`import {
|
|
30
|
+
`import { defineRoutePath } from "dreamkit/presets/common.js";`,
|
|
31
|
+
`import { defineLink } from "dreamkit/presets/solid.js";`,
|
|
31
32
|
"",
|
|
32
33
|
...(options.metaLocalExports
|
|
33
34
|
? [
|
|
@@ -38,7 +39,6 @@ export async function generate(server) {
|
|
|
38
39
|
createInterface("Routing", typeRoutes, 0),
|
|
39
40
|
"export const routePath = defineRoutePath<Routing>();",
|
|
40
41
|
"export const Link = defineLink<Routing>();",
|
|
41
|
-
"export class RequestUrl extends BaseRequestUrl<Routing> {}",
|
|
42
42
|
].join("\n");
|
|
43
43
|
}
|
|
44
44
|
await mkdir(dirname(output), { recursive: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,CAwD5E"}
|
package/lib/plugins/dreamkit.js
CHANGED
|
@@ -24,6 +24,14 @@ export function dreamkitPlugin(inOptions = {}) {
|
|
|
24
24
|
const dreamkitPickEntry = searchParams.get("dk-pick-entry");
|
|
25
25
|
const picks = searchParams.getAll("pick");
|
|
26
26
|
const transforms = [];
|
|
27
|
+
if (code.includes("'dreamkit'") || code.includes('"dreamkit"'))
|
|
28
|
+
transforms.push({
|
|
29
|
+
replaceImportSpec: {
|
|
30
|
+
source: "dreamkit",
|
|
31
|
+
spec: ["Link"],
|
|
32
|
+
newSource: "dreamkit/adapters/solid.js",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
27
35
|
if (dreamkitPickEntry) {
|
|
28
36
|
transforms.push({
|
|
29
37
|
pickExport: [dreamkitPickEntry],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-export.d.ts","sourceRoot":"","sources":["../../src/transforms/pick-export.ts"],"names":[],"mappings":"AAEA,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,
|
|
1
|
+
{"version":3,"file":"pick-export.d.ts","sourceRoot":"","sources":["../../src/transforms/pick-export.ts"],"names":[],"mappings":"AAEA,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,UA4EnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"AAEA,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,CAAC;
|
|
1
|
+
{"version":3,"file":"replace-import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/replace-import-spec.ts"],"names":[],"mappings":"AAEA,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"}
|
|
@@ -10,15 +10,20 @@ export function replaceImportSpec(ast, options) {
|
|
|
10
10
|
node.specifiers = node.specifiers.filter((spec) => {
|
|
11
11
|
if (spec.type === "ImportSpecifier" &&
|
|
12
12
|
spec.imported.type === "Identifier" &&
|
|
13
|
-
spec.imported.name
|
|
13
|
+
options.spec.includes(spec.imported.name)) {
|
|
14
14
|
changes++;
|
|
15
15
|
ast.program.body.unshift(t.importDeclaration([
|
|
16
|
-
t.importSpecifier(t.identifier(
|
|
16
|
+
t.importSpecifier(t.identifier(spec.imported.name), t.identifier(spec.imported.name)),
|
|
17
17
|
], t.stringLiteral(options.newSource)));
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
return true;
|
|
21
21
|
});
|
|
22
|
+
if (changes) {
|
|
23
|
+
if (!node.specifiers.length)
|
|
24
|
+
path.remove();
|
|
25
|
+
path.scope.crawl();
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
},
|
|
24
29
|
});
|
|
@@ -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":"AAGA,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,UA0JpD"}
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import { addFileChanges, getFirstChain } 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;
|
|
6
7
|
let imports;
|
|
7
8
|
let routeImportName;
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const routeSpec = "$route";
|
|
10
|
+
const routeSource = "dreamkit";
|
|
11
|
+
const routeNewSource = "dreamkit/adapters/solid.js";
|
|
12
|
+
replaceImportSpec(ast, {
|
|
13
|
+
newSource: routeNewSource,
|
|
14
|
+
source: routeSource,
|
|
15
|
+
spec: [routeSpec],
|
|
16
|
+
});
|
|
11
17
|
traverse(ast, {
|
|
12
18
|
Program(programPath) {
|
|
13
19
|
traverse(programPath.node, {
|
|
14
20
|
ImportDeclaration(importPath) {
|
|
15
21
|
importPath.traverse({
|
|
16
22
|
ImportSpecifier(path) {
|
|
17
|
-
// import { route as ? } from "dreamkit";
|
|
23
|
+
// import { route as ? } from "dreamkit/adapters/solid.js";
|
|
18
24
|
const isRouteImport = path.node.imported.type === "Identifier" &&
|
|
19
|
-
path.node.imported.name ===
|
|
20
|
-
importPath.node.source.value ===
|
|
25
|
+
path.node.imported.name === routeSpec &&
|
|
26
|
+
importPath.node.source.value === routeNewSource;
|
|
21
27
|
if (isRouteImport)
|
|
22
28
|
routeImportName = path.node.local.name;
|
|
23
|
-
if (reservedExportNames.includes(path.node.local.name)) {
|
|
24
|
-
// import { route } from "?";
|
|
25
|
-
// import { route as _route } from "?";
|
|
26
|
-
const newName = programPath.scope.generateUid(path.node.local.name);
|
|
27
|
-
if (isRouteImport)
|
|
28
|
-
routeImportName = newName;
|
|
29
|
-
path.scope.rename(path.node.local.name, newName);
|
|
30
|
-
}
|
|
31
29
|
},
|
|
32
30
|
});
|
|
33
31
|
},
|
|
34
32
|
ExportDefaultDeclaration(path) {
|
|
35
33
|
const dec = path.node.declaration;
|
|
36
34
|
// [input]
|
|
35
|
+
// import { $route } from "dreamkit";
|
|
37
36
|
// export default route.params({}).create(() => {});
|
|
38
37
|
// [output]
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
38
|
+
// import { $route as _$route } from "dreamkit/adapters/solid.js"
|
|
39
|
+
// import * as $deps from "dreamkit/adapters/solid-deps.js"
|
|
40
|
+
// const selfRoute = _$route.params({});
|
|
41
|
+
// export const route = selfRoute.createRouteDefinition();
|
|
42
|
+
// export default delfRoute.clone({deps: $deps}).create(() => {})
|
|
42
43
|
if (
|
|
43
44
|
// route.?.?.?.create()
|
|
44
45
|
dec.type === "CallExpression" &&
|
|
@@ -52,43 +53,64 @@ export function toSolidRoute(ast) {
|
|
|
52
53
|
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
53
54
|
ast.program.body.splice(ast.program.body.indexOf(path.node), 1,
|
|
54
55
|
// const selfRoute = route.?.?.?
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// export
|
|
59
|
-
|
|
60
|
-
t.variableDeclarator(t.identifier("route"), t.callExpression(t.identifier(imports.createSolidRouteConfig), [t.identifier(selfRoute)])),
|
|
61
|
-
])),
|
|
62
|
-
// export default createSolidRoute(selfRoute.create(() => {}), { useLocation, useParams });
|
|
63
|
-
t.exportDefaultDeclaration(t.callExpression(t.identifier(imports.createSolidRoute), [
|
|
64
|
-
t.callExpression(t.memberExpression(t.identifier(selfRoute), t.identifier("create")), dec.arguments),
|
|
65
|
-
//t.identifier(selfRoute),
|
|
66
|
-
t.objectExpression([
|
|
67
|
-
t.objectProperty(t.identifier("useLocation"), t.identifier(imports.useLocation)),
|
|
68
|
-
t.objectProperty(t.identifier("useParams"), t.identifier(imports.useParams)),
|
|
69
|
-
]),
|
|
70
|
-
])));
|
|
56
|
+
createSelfRoute(selfRoute, dec.callee.object),
|
|
57
|
+
// export const route = selfRoute.createRouteDefinition();
|
|
58
|
+
createExportRouteDefinition(selfRoute),
|
|
59
|
+
// export default selfRoute.clone({ deps }).create(() => {})
|
|
60
|
+
createDefaultExportRoute(selfRoute, imports.deps, dec.arguments[0]));
|
|
71
61
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
62
|
+
},
|
|
63
|
+
// [input]
|
|
64
|
+
// import { $route } from "dreamkit";
|
|
65
|
+
// export const route = $route.params({}).path('/path');
|
|
66
|
+
// export default function Users() { useRoute(route); }
|
|
67
|
+
// [output]
|
|
68
|
+
// import { $route as _$route } from "dreamkit/adapters/solid.js"
|
|
69
|
+
// import * as $deps from "dreamkit/adapters/solid-deps.js"
|
|
70
|
+
// const selfRoute = _$route.params({}).path('/path');
|
|
71
|
+
// export const route = selfRoute.createRouteDefinition();
|
|
72
|
+
// export default selfRoute.create(function Users() { useRoute(selfRoute); });
|
|
73
|
+
ExportNamedDeclaration(path) {
|
|
74
|
+
const node = path.node;
|
|
75
|
+
if (node.declaration?.type === "VariableDeclaration") {
|
|
76
|
+
const [dec] = node.declaration.declarations;
|
|
77
|
+
if (dec.id.type === "Identifier" &&
|
|
78
|
+
dec.id.name === "route" &&
|
|
79
|
+
dec.init &&
|
|
80
|
+
getFirstChain(dec.init)?.identifier === routeImportName) {
|
|
81
|
+
// [input]
|
|
82
|
+
// export const route = $route.?;
|
|
83
|
+
// [output]
|
|
84
|
+
// const _selfRoute = $route.?;
|
|
85
|
+
// export const route = _selfRoute.createRouteDefinition();
|
|
86
|
+
if (!imports)
|
|
87
|
+
imports = addImports(ast, programPath);
|
|
88
|
+
let exportFunction;
|
|
89
|
+
const selfRoute = programPath.scope.generateUid("selfRoute");
|
|
90
|
+
const index = ast.program.body.indexOf(path.node);
|
|
91
|
+
// [input]
|
|
92
|
+
// export const route = ?;
|
|
93
|
+
// [output]
|
|
94
|
+
// const _route = ?;
|
|
95
|
+
path.replaceWith(dec);
|
|
96
|
+
path.scope.rename(dec.id.name, selfRoute);
|
|
97
|
+
ast.program.body = ast.program.body.filter((dec) => {
|
|
98
|
+
if (dec.type === "ExportDefaultDeclaration" &&
|
|
99
|
+
(dec.declaration.type === "FunctionDeclaration" ||
|
|
100
|
+
dec.declaration.type === "ArrowFunctionExpression")) {
|
|
101
|
+
exportFunction = dec.declaration;
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
ast.program.body.splice(index, 1, createSelfRoute(selfRoute, dec.init), createExportRouteDefinition(selfRoute), ...(exportFunction
|
|
107
|
+
? [
|
|
108
|
+
createDefaultExportRoute(selfRoute, imports.deps, exportFunction.type === "FunctionDeclaration"
|
|
109
|
+
? t.functionExpression(exportFunction.id, exportFunction.params, exportFunction.body)
|
|
110
|
+
: exportFunction),
|
|
111
|
+
]
|
|
112
|
+
: []));
|
|
113
|
+
}
|
|
92
114
|
}
|
|
93
115
|
},
|
|
94
116
|
});
|
|
@@ -96,22 +118,27 @@ export function toSolidRoute(ast) {
|
|
|
96
118
|
});
|
|
97
119
|
return addFileChanges(ast, changes);
|
|
98
120
|
}
|
|
121
|
+
function createSelfRoute(name, route) {
|
|
122
|
+
return t.variableDeclaration("const", [
|
|
123
|
+
t.variableDeclarator(t.identifier(name), route),
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
function createExportRouteDefinition(name) {
|
|
127
|
+
return t.exportNamedDeclaration(t.variableDeclaration("const", [
|
|
128
|
+
t.variableDeclarator(t.identifier("route"), t.callExpression(t.memberExpression(t.identifier(name), t.identifier("createRouteDefinition")), [])),
|
|
129
|
+
]));
|
|
130
|
+
}
|
|
131
|
+
function createDefaultExportRoute(name, depsImportName, component) {
|
|
132
|
+
return t.exportDefaultDeclaration(t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.identifier(name), t.identifier("clone")), [
|
|
133
|
+
t.objectExpression([
|
|
134
|
+
t.objectProperty(t.identifier("deps"), t.identifier(depsImportName)),
|
|
135
|
+
]),
|
|
136
|
+
]), t.identifier("create")), [component]));
|
|
137
|
+
}
|
|
99
138
|
function addImports(ast, program) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const createSolidRoute = program.scope.generateUid("createSolidRoute");
|
|
103
|
-
const createSolidRouteConfig = program.scope.generateUid("createSolidRouteConfig");
|
|
104
|
-
ast.program.body.unshift(t.importDeclaration([
|
|
105
|
-
t.importSpecifier(t.identifier(useLocation), t.identifier("useLocation")),
|
|
106
|
-
t.importSpecifier(t.identifier(useParams), t.identifier("useParams")),
|
|
107
|
-
], t.stringLiteral("@solidjs/router")), t.importDeclaration([
|
|
108
|
-
t.importSpecifier(t.identifier(createSolidRoute), t.identifier("createSolidRoute")),
|
|
109
|
-
t.importSpecifier(t.identifier(createSolidRouteConfig), t.identifier("createSolidRouteConfig")),
|
|
110
|
-
], t.stringLiteral("dreamkit/adapters/solid.js")));
|
|
139
|
+
const deps = program.scope.generateUid("deps");
|
|
140
|
+
ast.program.body.unshift(t.importDeclaration([t.importNamespaceSpecifier(t.identifier(deps))], t.stringLiteral("dreamkit/adapters/solid-deps.js")));
|
|
111
141
|
return {
|
|
112
|
-
|
|
113
|
-
useParams,
|
|
114
|
-
createSolidRoute,
|
|
115
|
-
createSolidRouteConfig,
|
|
142
|
+
deps,
|
|
116
143
|
};
|
|
117
144
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamkit/dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Development tools for DreamKit.",
|
|
5
5
|
"homepage": "https://dreamkit.dev",
|
|
6
6
|
"repository": {
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"glob": "^11.0.0",
|
|
45
45
|
"vite-plugin-solid": "^2.10.2",
|
|
46
46
|
"vite-tsconfig-paths": "^5.1.0",
|
|
47
|
-
"@dreamkit/app": "0.0.
|
|
48
|
-
"@dreamkit/schema": "0.0.
|
|
47
|
+
"@dreamkit/app": "0.0.2",
|
|
48
|
+
"@dreamkit/schema": "0.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/debug": "^4.1.12",
|