@dreamkit/dev 0.0.1

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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/lib/DreamkitDevServer.d.ts +27 -0
  4. package/lib/DreamkitDevServer.d.ts.map +1 -0
  5. package/lib/DreamkitDevServer.js +127 -0
  6. package/lib/actions/generate.d.ts +6 -0
  7. package/lib/actions/generate.d.ts.map +1 -0
  8. package/lib/actions/generate.js +62 -0
  9. package/lib/adapters/solid-start.d.ts +8 -0
  10. package/lib/adapters/solid-start.d.ts.map +1 -0
  11. package/lib/adapters/solid-start.js +173 -0
  12. package/lib/bin.d.ts +4 -0
  13. package/lib/bin.d.ts.map +1 -0
  14. package/lib/bin.js +37 -0
  15. package/lib/index.d.ts +2 -0
  16. package/lib/index.d.ts.map +1 -0
  17. package/lib/index.js +1 -0
  18. package/lib/options.d.ts +18 -0
  19. package/lib/options.d.ts.map +1 -0
  20. package/lib/options.js +8 -0
  21. package/lib/plugins/dreamkit.d.ts +4 -0
  22. package/lib/plugins/dreamkit.d.ts.map +1 -0
  23. package/lib/plugins/dreamkit.js +48 -0
  24. package/lib/transforms/delete-dead-code.d.ts +6 -0
  25. package/lib/transforms/delete-dead-code.d.ts.map +1 -0
  26. package/lib/transforms/delete-dead-code.js +79 -0
  27. package/lib/transforms/export-default.d.ts +4 -0
  28. package/lib/transforms/export-default.d.ts.map +1 -0
  29. package/lib/transforms/export-default.js +10 -0
  30. package/lib/transforms/fix-use-data.d.ts +3 -0
  31. package/lib/transforms/fix-use-data.d.ts.map +1 -0
  32. package/lib/transforms/fix-use-data.js +49 -0
  33. package/lib/transforms/no-export.d.ts +4 -0
  34. package/lib/transforms/no-export.d.ts.map +1 -0
  35. package/lib/transforms/no-export.js +19 -0
  36. package/lib/transforms/pick-export.d.ts +4 -0
  37. package/lib/transforms/pick-export.d.ts.map +1 -0
  38. package/lib/transforms/pick-export.js +55 -0
  39. package/lib/transforms/replace-import-spec.d.ts +8 -0
  40. package/lib/transforms/replace-import-spec.d.ts.map +1 -0
  41. package/lib/transforms/replace-import-spec.js +26 -0
  42. package/lib/transforms/to-solid-route.d.ts +4 -0
  43. package/lib/transforms/to-solid-route.d.ts.map +1 -0
  44. package/lib/transforms/to-solid-route.js +117 -0
  45. package/lib/utils/ast.d.ts +17 -0
  46. package/lib/utils/ast.d.ts.map +1 -0
  47. package/lib/utils/ast.js +78 -0
  48. package/lib/utils/babel.d.ts +7 -0
  49. package/lib/utils/babel.d.ts.map +1 -0
  50. package/lib/utils/babel.js +6 -0
  51. package/lib/utils/fs.d.ts +5 -0
  52. package/lib/utils/fs.d.ts.map +1 -0
  53. package/lib/utils/fs.js +24 -0
  54. package/lib/utils/log.d.ts +3 -0
  55. package/lib/utils/log.d.ts.map +1 -0
  56. package/lib/utils/log.js +2 -0
  57. package/lib/utils/object.d.ts +4 -0
  58. package/lib/utils/object.d.ts.map +1 -0
  59. package/lib/utils/object.js +20 -0
  60. package/lib/utils/path.d.ts +6 -0
  61. package/lib/utils/path.d.ts.map +1 -0
  62. package/lib/utils/path.js +19 -0
  63. package/lib/utils/router.d.ts +7 -0
  64. package/lib/utils/router.d.ts.map +1 -0
  65. package/lib/utils/router.js +37 -0
  66. package/lib/utils/runtime.d.ts +3 -0
  67. package/lib/utils/runtime.d.ts.map +1 -0
  68. package/lib/utils/runtime.js +19 -0
  69. package/lib/utils/shaking.d.ts +24 -0
  70. package/lib/utils/shaking.d.ts.map +1 -0
  71. package/lib/utils/shaking.js +81 -0
  72. package/lib/utils/string.d.ts +2 -0
  73. package/lib/utils/string.d.ts.map +1 -0
  74. package/lib/utils/string.js +3 -0
  75. package/lib/utils/timeout.d.ts +2 -0
  76. package/lib/utils/timeout.d.ts.map +1 -0
  77. package/lib/utils/timeout.js +14 -0
  78. package/lib/utils/transform.d.ts +25 -0
  79. package/lib/utils/transform.d.ts.map +1 -0
  80. package/lib/utils/transform.js +44 -0
  81. package/lib/utils/typescript.d.ts +14 -0
  82. package/lib/utils/typescript.d.ts.map +1 -0
  83. package/lib/utils/typescript.js +78 -0
  84. package/lib/utils/vinxi.d.ts +26 -0
  85. package/lib/utils/vinxi.d.ts.map +1 -0
  86. package/lib/utils/vinxi.js +55 -0
  87. package/package.json +65 -0
@@ -0,0 +1,79 @@
1
+ import { traverse } from "../utils/babel.js";
2
+ import * as t from "@babel/types";
3
+ /**
4
+ * @link https://github.com/pcattori/babel-dead-code-elimination
5
+ */
6
+ export function deleteDeadCode(ast) {
7
+ let removals;
8
+ do {
9
+ removals = 0;
10
+ traverse(ast, {
11
+ Program(path) {
12
+ path.scope.crawl();
13
+ },
14
+ ImportDeclaration(path) {
15
+ const removalsBefore = removals;
16
+ for (let specifier of path.get("specifiers")) {
17
+ let local = specifier.get("local");
18
+ if (!isReferenced(local)) {
19
+ specifier.remove();
20
+ removals++;
21
+ }
22
+ }
23
+ if (removals > removalsBefore && path.node.specifiers.length === 0) {
24
+ path.remove();
25
+ }
26
+ },
27
+ VariableDeclarator(path) {
28
+ const id = path.get("id");
29
+ if (id.isIdentifier()) {
30
+ if (!isReferenced(id)) {
31
+ path.remove();
32
+ removals++;
33
+ }
34
+ }
35
+ },
36
+ FunctionDeclaration(path) {
37
+ const id = path.get("id");
38
+ if (id.isIdentifier() && !isReferenced(id)) {
39
+ removals++;
40
+ if (t.isAssignmentExpression(path.parentPath.node) ||
41
+ t.isVariableDeclarator(path.parentPath.node)) {
42
+ path.parentPath.remove();
43
+ }
44
+ else {
45
+ path.remove();
46
+ }
47
+ }
48
+ },
49
+ ClassDeclaration(path) {
50
+ const id = path.get("id");
51
+ if (id.isIdentifier() && !isReferenced(id)) {
52
+ removals++;
53
+ if (t.isAssignmentExpression(path.parentPath.node) ||
54
+ t.isVariableDeclarator(path.parentPath.node)) {
55
+ path.parentPath.remove();
56
+ }
57
+ else {
58
+ path.remove();
59
+ }
60
+ }
61
+ },
62
+ });
63
+ } while (removals > 0);
64
+ }
65
+ function isReferenced(ident) {
66
+ let binding = ident.scope.getBinding(ident.node.name);
67
+ if (binding?.referenced) {
68
+ // Functions can reference themselves, so we need to check if there's a
69
+ // binding outside the function scope or not.
70
+ if (binding.path.type === "FunctionDeclaration") {
71
+ return !binding.constantViolations
72
+ .concat(binding.referencePaths)
73
+ // Check that every reference is contained within the function:
74
+ .every((ref) => ref.findParent((parent) => parent === binding?.path));
75
+ }
76
+ return true;
77
+ }
78
+ return false;
79
+ }
@@ -0,0 +1,4 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ export declare function exportDefault(ast: ParseResult<t.File>, name: string): number;
4
+ //# sourceMappingURL=export-default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-default.d.ts","sourceRoot":"","sources":["../../src/transforms/export-default.ts"],"names":[],"mappings":"AACA,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"}
@@ -0,0 +1,10 @@
1
+ import { addFileChanges } from "../utils/ast.js";
2
+ import * as t from "@babel/types";
3
+ export function exportDefault(ast, name) {
4
+ let changes = 0;
5
+ if (!ast.program.body.some((node) => node.type === "ExportDefaultDeclaration")) {
6
+ ast.program.body.push(t.exportDefaultDeclaration(t.identifier(name)));
7
+ changes++;
8
+ }
9
+ return addFileChanges(ast, changes);
10
+ }
@@ -0,0 +1,3 @@
1
+ import { ParseFileResult } from "../utils/ast.js";
2
+ export declare function fixUseData(ast: ParseFileResult): number;
3
+ //# sourceMappingURL=fix-use-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-use-data.d.ts","sourceRoot":"","sources":["../../src/transforms/fix-use-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIlE,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,UA+C9C"}
@@ -0,0 +1,49 @@
1
+ import { addFileChanges } from "../utils/ast.js";
2
+ import { traverse } from "../utils/babel.js";
3
+ export function fixUseData(ast) {
4
+ let routeId;
5
+ let transformed = false;
6
+ traverse(ast, {
7
+ ExportNamedDeclaration(path) {
8
+ const dec = path.node.declaration;
9
+ if (dec?.type === "VariableDeclaration") {
10
+ if (dec.declarations[0].id.type === "Identifier") {
11
+ if (dec.declarations[0].id.name === "route") {
12
+ routeId = dec.declarations[0].id;
13
+ }
14
+ }
15
+ }
16
+ },
17
+ ExportDefaultDeclaration(path) {
18
+ const dec = path.node.declaration;
19
+ if (dec.type === "FunctionDeclaration") {
20
+ let propsId;
21
+ if (!dec.params.length) {
22
+ propsId = path.scope.generateUidIdentifier("props");
23
+ dec.params.push(propsId);
24
+ }
25
+ else if (dec.params[0].type === "Identifier") {
26
+ propsId = dec.params[0];
27
+ }
28
+ if (propsId) {
29
+ path.traverse({
30
+ CallExpression(path) {
31
+ const callee = path.node.callee;
32
+ if (!path.node.arguments.length &&
33
+ callee.type === "MemberExpression" &&
34
+ callee.object.type === "Identifier" &&
35
+ //callee.object === routeId &&
36
+ callee.property.type === "Identifier" &&
37
+ callee.object.name === "route" &&
38
+ callee.property.name === "useData") {
39
+ transformed = true;
40
+ path.node.arguments.push(propsId);
41
+ }
42
+ },
43
+ });
44
+ }
45
+ }
46
+ },
47
+ });
48
+ return addFileChanges(ast, transformed ? 1 : 0);
49
+ }
@@ -0,0 +1,4 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ export declare function noExport(ast: ParseResult<t.File>, names: string[]): number;
4
+ //# sourceMappingURL=no-export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-export.d.ts","sourceRoot":"","sources":["../../src/transforms/no-export.ts"],"names":[],"mappings":"AACA,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"}
@@ -0,0 +1,19 @@
1
+ import { addFileChanges } from "../utils/ast.js";
2
+ import * as t from "@babel/types";
3
+ export function noExport(ast, names) {
4
+ let changes = 0;
5
+ for (const node of ast.program.body) {
6
+ if (node.type === "ExportNamedDeclaration") {
7
+ const mainDec = node.declaration;
8
+ if (mainDec && mainDec.type === "VariableDeclaration") {
9
+ const [dec] = mainDec.declarations;
10
+ if (dec.id.type === "Identifier" && names.includes(dec.id.name)) {
11
+ changes++;
12
+ const index = ast.program.body.indexOf(node);
13
+ ast.program.body.splice(index, 1, t.variableDeclaration("const", [dec]));
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return addFileChanges(ast, changes);
19
+ }
@@ -0,0 +1,4 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ export declare function pickExport(ast: ParseResult<t.File>, names: string[]): number;
4
+ //# sourceMappingURL=pick-export.d.ts.map
@@ -0,0 +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,UAsEnE"}
@@ -0,0 +1,55 @@
1
+ import { addFileChanges } from "../utils/ast.js";
2
+ import { deleteDeadCode } from "./delete-dead-code.js";
3
+ import * as t from "@babel/types";
4
+ export function pickExport(ast, names) {
5
+ let changes = 0;
6
+ for (const node of ast.program.body) {
7
+ if (node.type === "VariableDeclaration") {
8
+ const [dec, ...decs] = node.declarations;
9
+ if (dec &&
10
+ !decs.length &&
11
+ dec.id.type === "Identifier" &&
12
+ names.includes(dec.id.name)) {
13
+ changes++;
14
+ const index = ast.program.body.indexOf(node);
15
+ ast.program.body.splice(index, 1, t.exportNamedDeclaration(t.variableDeclaration("const", [dec])));
16
+ }
17
+ }
18
+ }
19
+ ast.program.body = ast.program.body
20
+ .map((stm) => {
21
+ if (stm.type === "ExportNamedDeclaration" && stm.declaration) {
22
+ if (stm.declaration.type === "VariableDeclaration" &&
23
+ stm.declaration.declarations.length) {
24
+ const [dec] = stm.declaration.declarations;
25
+ if (dec.id.type === "Identifier" && !names.includes(dec.id.name)) {
26
+ changes++;
27
+ return t.variableDeclaration("const", [dec]);
28
+ }
29
+ }
30
+ else if (stm.declaration.type === "VariableDeclaration" &&
31
+ stm.specifiers.length) {
32
+ const newSpecifiers = stm.specifiers.filter((spec) => spec.exported.type === "Identifier" &&
33
+ !names.includes(spec.exported.name));
34
+ if (newSpecifiers.length !== stm.specifiers.length) {
35
+ changes++;
36
+ stm.specifiers = newSpecifiers;
37
+ if (!newSpecifiers.length)
38
+ return;
39
+ }
40
+ }
41
+ else if (stm.declaration.type === "FunctionDeclaration" ||
42
+ stm.declaration.type === "ClassDeclaration") {
43
+ if (stm.declaration.id?.type === "Identifier" &&
44
+ !names.includes(stm.declaration.id.name)) {
45
+ changes++;
46
+ return stm.declaration;
47
+ }
48
+ }
49
+ }
50
+ return stm;
51
+ })
52
+ .filter((v) => v !== undefined);
53
+ deleteDeadCode(ast);
54
+ return addFileChanges(ast, changes);
55
+ }
@@ -0,0 +1,8 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ export declare function replaceImportSpec(ast: ParseResult<t.File>, options: {
4
+ spec: string;
5
+ source: string;
6
+ newSource: string;
7
+ }): number;
8
+ //# sourceMappingURL=replace-import-spec.d.ts.map
@@ -0,0 +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;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,UAiCF"}
@@ -0,0 +1,26 @@
1
+ import { addFileChanges } from "../utils/ast.js";
2
+ import { traverse } from "../utils/babel.js";
3
+ import * as t from "@babel/types";
4
+ export function replaceImportSpec(ast, options) {
5
+ let changes = 0;
6
+ traverse(ast, {
7
+ ImportDeclaration(path) {
8
+ const { node } = path;
9
+ if (node.source.value === options.source) {
10
+ node.specifiers = node.specifiers.filter((spec) => {
11
+ if (spec.type === "ImportSpecifier" &&
12
+ spec.imported.type === "Identifier" &&
13
+ spec.imported.name === options.spec) {
14
+ changes++;
15
+ ast.program.body.unshift(t.importDeclaration([
16
+ t.importSpecifier(t.identifier(options.spec), t.identifier(options.spec)),
17
+ ], t.stringLiteral(options.newSource)));
18
+ return false;
19
+ }
20
+ return true;
21
+ });
22
+ }
23
+ },
24
+ });
25
+ return addFileChanges(ast, changes);
26
+ }
@@ -0,0 +1,4 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ export declare function toSolidRoute(ast: ParseResult<t.File>): number;
4
+ //# sourceMappingURL=to-solid-route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-solid-route.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-route.ts"],"names":[],"mappings":"AAEA,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,UAmJpD"}
@@ -0,0 +1,117 @@
1
+ import { addFileChanges, getFirstChain } from "../utils/ast.js";
2
+ import { traverse } from "../utils/babel.js";
3
+ import * as t from "@babel/types";
4
+ export function toSolidRoute(ast) {
5
+ let changes = 0;
6
+ let imports;
7
+ let routeImportName;
8
+ // reserved by solid-start
9
+ const reservedExportNames = ["route"];
10
+ const dkRouteImportSpec = "$route";
11
+ traverse(ast, {
12
+ Program(programPath) {
13
+ traverse(programPath.node, {
14
+ ImportDeclaration(importPath) {
15
+ importPath.traverse({
16
+ ImportSpecifier(path) {
17
+ // import { route as ? } from "dreamkit";
18
+ const isRouteImport = path.node.imported.type === "Identifier" &&
19
+ path.node.imported.name === dkRouteImportSpec &&
20
+ importPath.node.source.value === "dreamkit";
21
+ if (isRouteImport)
22
+ 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
+ },
32
+ });
33
+ },
34
+ ExportDefaultDeclaration(path) {
35
+ const dec = path.node.declaration;
36
+ // [input]
37
+ // export default route.params({}).create(() => {});
38
+ // [output]
39
+ // const selfRoute = route.params({});
40
+ // export const route = createSolidRouteConfig(selfRoute);
41
+ // export default = createSolidRoute(selfRoute.create(() => {}), { useLocation, useParams })
42
+ if (
43
+ // route.?.?.?.create()
44
+ dec.type === "CallExpression" &&
45
+ getFirstChain(dec)?.identifier === routeImportName &&
46
+ dec.callee.type === "MemberExpression" &&
47
+ dec.callee.property.type == "Identifier" &&
48
+ dec.callee.property.name === "create") {
49
+ changes++;
50
+ if (!imports)
51
+ imports = addImports(ast, programPath);
52
+ const selfRoute = programPath.scope.generateUid("selfRoute");
53
+ ast.program.body.splice(ast.program.body.indexOf(path.node), 1,
54
+ // const selfRoute = route.?.?.?
55
+ t.variableDeclaration("const", [
56
+ t.variableDeclarator(t.identifier(selfRoute), dec.callee.object),
57
+ ]),
58
+ // export const route = createSolidRouteConfig(selfRoute)
59
+ t.exportNamedDeclaration(t.variableDeclaration("const", [
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
+ ])));
71
+ }
72
+ else if (
73
+ // export default myRoute
74
+ dec.type === "Identifier") {
75
+ changes++;
76
+ if (!imports)
77
+ imports = addImports(ast, programPath);
78
+ const selfRoute = dec.name;
79
+ ast.program.body.splice(ast.program.body.indexOf(path.node), 1,
80
+ // export const route = createSolidRouteConfig(selfRoute)
81
+ t.exportNamedDeclaration(t.variableDeclaration("const", [
82
+ t.variableDeclarator(t.identifier("route"), t.callExpression(t.identifier(imports.createSolidRouteConfig), [t.identifier(selfRoute)])),
83
+ ])),
84
+ // export default createSolidRoute(selfRoute, { useLocation, useParams });
85
+ t.exportDefaultDeclaration(t.callExpression(t.identifier(imports.createSolidRoute), [
86
+ t.identifier(selfRoute),
87
+ t.objectExpression([
88
+ t.objectProperty(t.identifier("useLocation"), t.identifier(imports.useLocation)),
89
+ t.objectProperty(t.identifier("useParams"), t.identifier(imports.useParams)),
90
+ ]),
91
+ ])));
92
+ }
93
+ },
94
+ });
95
+ },
96
+ });
97
+ return addFileChanges(ast, changes);
98
+ }
99
+ function addImports(ast, program) {
100
+ const useLocation = program.scope.generateUid("useLocation");
101
+ const useParams = program.scope.generateUid("useParams");
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")));
111
+ return {
112
+ useLocation,
113
+ useParams,
114
+ createSolidRoute,
115
+ createSolidRouteConfig,
116
+ };
117
+ }
@@ -0,0 +1,17 @@
1
+ import { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ import * as lexer from "es-module-lexer";
4
+ export declare function parseCode(input: string | string[]): t.Statement[];
5
+ export type ParseFileResult = ParseResult<t.File>;
6
+ export declare function parseFile(code: string): ParseResult<t.File>;
7
+ export declare function addFileChanges(ast: ParseFileResult, value: number): number;
8
+ export declare function getFileChanges(ast: ParseFileResult): number;
9
+ export declare function generateIfChanges(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
10
+ export declare function getFirstChain(ref: t.Node): {
11
+ identifier: string;
12
+ value: t.MemberExpression;
13
+ } | undefined;
14
+ export declare function analyzeModule(path: string): Promise<readonly [imports: readonly lexer.ImportSpecifier[], exports: readonly lexer.ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean]>;
15
+ export declare function findExportedNames(ast: ParseFileResult): string[];
16
+ export declare function findExportedNamesFromFile(path: string): Promise<string[]>;
17
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/utils/ast.ts"],"names":[],"mappings":"AACA,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,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,UAGjE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,UAElD;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,eAAe,GAAG,SAAS,EAChC,GAAG,CAAC,EAAE,OAAO,0DAOd;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"}
@@ -0,0 +1,78 @@
1
+ import { generator, parser } from "./babel.js";
2
+ import * as lexer from "es-module-lexer";
3
+ import { transform } from "esbuild";
4
+ import { readFile } from "fs/promises";
5
+ export function parseCode(input) {
6
+ return parser.parse(Array.isArray(input) ? input.join("\n") : input, {
7
+ sourceType: "module",
8
+ }).program.body;
9
+ }
10
+ export function parseFile(code) {
11
+ return parser.parse(code, {
12
+ sourceType: "module",
13
+ plugins: ["typescript", "jsx"],
14
+ });
15
+ }
16
+ export function addFileChanges(ast, value) {
17
+ ast["__changes"] = (ast["__changes"] || 0) + value;
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)) {
25
+ const generated = generator(ast);
26
+ if (log)
27
+ console.log(generated);
28
+ return generated;
29
+ }
30
+ }
31
+ export function getFirstChain(ref) {
32
+ let lastMember;
33
+ while (ref.type === "CallExpression") {
34
+ if (ref.callee.type === "MemberExpression") {
35
+ if (ref.callee.object.type === "Identifier") {
36
+ lastMember = {
37
+ identifier: ref.callee.object.name,
38
+ value: ref.callee,
39
+ };
40
+ break;
41
+ }
42
+ ref = ref.callee.object;
43
+ }
44
+ }
45
+ return lastMember;
46
+ }
47
+ export async function analyzeModule(path) {
48
+ const [buffer] = await Promise.all([readFile(path), lexer.init]);
49
+ const ast = await transform(buffer.toString(), {
50
+ jsx: "transform",
51
+ format: "esm",
52
+ loader: "tsx",
53
+ });
54
+ return lexer.parse(ast.code, path);
55
+ }
56
+ export function findExportedNames(ast) {
57
+ return ast.program.body
58
+ .map((stm) => {
59
+ if (stm.type === "ExportNamedDeclaration" && stm.declaration) {
60
+ if (stm.declaration.type === "VariableDeclaration") {
61
+ const [dec] = stm.declaration.declarations;
62
+ if (dec.id.type === "Identifier")
63
+ return dec.id.name;
64
+ }
65
+ else if (stm.declaration.type === "FunctionDeclaration" ||
66
+ stm.declaration.type === "ClassDeclaration") {
67
+ if (stm.declaration.id?.type === "Identifier") {
68
+ return stm.declaration.id.name;
69
+ }
70
+ }
71
+ }
72
+ })
73
+ .filter((v) => typeof v === "string");
74
+ }
75
+ export async function findExportedNamesFromFile(path) {
76
+ const [, exports] = await analyzeModule(path);
77
+ return exports.map((item) => item.n);
78
+ }
@@ -0,0 +1,7 @@
1
+ import $generator from "@babel/generator";
2
+ import $parser from "@babel/parser";
3
+ import $traverse from "@babel/traverse";
4
+ export declare const generator: typeof $generator.default;
5
+ export declare const parser: typeof $parser;
6
+ export declare const traverse: typeof $traverse.default;
7
+ //# sourceMappingURL=babel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.d.ts","sourceRoot":"","sources":["../../src/utils/babel.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,OAAO,MAAM,eAAe,CAAC;AACpC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AAExC,eAAO,MAAM,SAAS,EAAE,OAAO,UAAU,CAAC,OAC0B,CAAC;AAErE,eAAO,MAAM,MAAM,EAAE,OAAO,OACuB,CAAC;AAEpD,eAAO,MAAM,QAAQ,EAAE,OAAO,SAAS,CAAC,OACyB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import $generator from "@babel/generator";
2
+ import $parser from "@babel/parser";
3
+ import $traverse from "@babel/traverse";
4
+ export const generator = typeof $generator === "function" ? $generator : $generator.default;
5
+ export const parser = typeof $parser === "function" ? $parser : $parser;
6
+ export const traverse = typeof $traverse === "function" ? $traverse : $traverse.default;
@@ -0,0 +1,5 @@
1
+ export declare function writeFileIfDifferent(path: string, content: string, prev?: string): Promise<boolean>;
2
+ export declare function tryReadFile(path: string): Promise<string | undefined>;
3
+ export declare function tryReadTextFile(path: string): Promise<string | undefined>;
4
+ export declare function tryReadJsonFile<T>(path: string): Promise<T | undefined>;
5
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAEA,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,oBAMd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,+BAM7C;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,+BAEjD;AAED,wBAAsB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAG7E"}
@@ -0,0 +1,24 @@
1
+ import { readFile, writeFile } from "fs/promises";
2
+ export async function writeFileIfDifferent(path, content, prev) {
3
+ if (!prev)
4
+ prev = await tryReadFile(path);
5
+ const write = prev !== content;
6
+ if (write)
7
+ await writeFile(path, content);
8
+ return write;
9
+ }
10
+ export async function tryReadFile(path) {
11
+ try {
12
+ return (await readFile(path)).toString();
13
+ }
14
+ catch (_) {
15
+ return;
16
+ }
17
+ }
18
+ export async function tryReadTextFile(path) {
19
+ return (await tryReadFile(path))?.toString();
20
+ }
21
+ export async function tryReadJsonFile(path) {
22
+ const json = (await tryReadFile(path))?.toString();
23
+ return typeof json === "string" ? JSON.parse(json) : undefined;
24
+ }
@@ -0,0 +1,3 @@
1
+ import debug from "debug";
2
+ export declare const log: debug.Debugger;
3
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAO,MAAM,GAAG,gBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import debug from "debug";
2
+ export const log = debug("dk:dev");
@@ -0,0 +1,4 @@
1
+ export type Obj = Record<string, any>;
2
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
3
+ export declare function merge(object: Obj, patch: Obj): Obj;
4
+ //# sourceMappingURL=object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/utils/object.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEtC,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMlC;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAYlD"}
@@ -0,0 +1,20 @@
1
+ export function isPlainObject(value) {
2
+ return (!!value &&
3
+ !!(value = Object.getPrototypeOf(value)) &&
4
+ !Object.getPrototypeOf(value));
5
+ }
6
+ export function merge(object, patch) {
7
+ for (const key in patch) {
8
+ const value = patch[key];
9
+ if (isPlainObject(object[key]) && isPlainObject(value)) {
10
+ merge(object[key], value);
11
+ }
12
+ else if (value === undefined) {
13
+ delete object[key];
14
+ }
15
+ else {
16
+ object[key] = value;
17
+ }
18
+ }
19
+ return object;
20
+ }
@@ -0,0 +1,6 @@
1
+ export declare function resolvePath(inPath: string, vars: Record<string, string> & {
2
+ defaults: string;
3
+ }): string;
4
+ export declare function getExt(path: string): string | undefined;
5
+ export declare function getVariantPath(path: string, variant: string): string;
6
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,UAKpD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,sBAIlC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAS3D"}