@dreamkit/dev 0.0.9 → 0.0.11

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 (35) hide show
  1. package/lib/DreamkitDevServer.d.ts +4 -0
  2. package/lib/DreamkitDevServer.d.ts.map +1 -1
  3. package/lib/DreamkitDevServer.js +15 -0
  4. package/lib/adapters/solid-start/dev-server.d.ts +8 -0
  5. package/lib/adapters/solid-start/dev-server.d.ts.map +1 -0
  6. package/lib/adapters/{solid-start.js → solid-start/dev-server.js} +53 -13
  7. package/lib/adapters/solid-start/middleware.d.ts +6 -0
  8. package/lib/adapters/solid-start/middleware.d.ts.map +1 -0
  9. package/lib/adapters/solid-start/middleware.js +13 -0
  10. package/lib/adapters/solid-start/prod-server.d.ts +2 -0
  11. package/lib/adapters/solid-start/prod-server.d.ts.map +1 -0
  12. package/lib/adapters/solid-start/prod-server.js +9 -0
  13. package/lib/bin.js +1 -1
  14. package/lib/plugins/dreamkit.d.ts.map +1 -1
  15. package/lib/plugins/dreamkit.js +11 -4
  16. package/lib/transforms/replace-import-spec.d.ts +3 -2
  17. package/lib/transforms/replace-import-spec.d.ts.map +1 -1
  18. package/lib/transforms/replace-import-spec.js +72 -21
  19. package/lib/transforms/to-solid-route.d.ts.map +1 -1
  20. package/lib/transforms/to-solid-route.js +2 -1
  21. package/lib/transforms/to-solid-server-action.d.ts +2 -0
  22. package/lib/transforms/to-solid-server-action.d.ts.map +1 -0
  23. package/lib/transforms/to-solid-server-action.js +111 -0
  24. package/lib/utils/ast.d.ts +10 -0
  25. package/lib/utils/ast.d.ts.map +1 -1
  26. package/lib/utils/ast.js +48 -0
  27. package/lib/utils/transform.d.ts +1 -0
  28. package/lib/utils/transform.d.ts.map +1 -1
  29. package/lib/utils/transform.js +2 -0
  30. package/lib/utils/vinxi.d.ts +18 -3
  31. package/lib/utils/vinxi.d.ts.map +1 -1
  32. package/lib/utils/vinxi.js +15 -0
  33. package/package.json +4 -3
  34. package/lib/adapters/solid-start.d.ts +0 -8
  35. package/lib/adapters/solid-start.d.ts.map +0 -1
@@ -10,18 +10,22 @@ export type DreamkitDevExternalOptions = {
10
10
  export type DreamkitDevInOptions = DreamkitPluginOptions & DreamkitDevExternalOptions;
11
11
  export type DreamkitDevOptions = OutDreamkitPluginOptions & DreamkitDevExternalOptions;
12
12
  export declare class DreamkitDevServer {
13
+ static instanceKey: string;
13
14
  readonly app: App;
14
15
  readonly entry: VirtualShaking;
15
16
  protected runtimeServer: ViteDevServer | undefined;
16
17
  protected runtime: ViteRuntime | undefined;
17
18
  readonly options: DreamkitDevOptions;
18
19
  constructor(inOptions: DreamkitDevInOptions);
20
+ static instance(): DreamkitDevServer;
21
+ static saveInstance(instance: DreamkitDevServer): void;
19
22
  fetch(path: string): Promise<any>;
20
23
  fetchDefault<T>(path: string): Promise<T>;
21
24
  fetchRoute(path: string): Promise<Route>;
22
25
  findRouteObjects(): Promise<Record<string, any>>;
23
26
  fetchEntryObjects(): Promise<Record<string, any>>;
24
27
  prepare(includeRouteFileObjects?: boolean): Promise<void>;
28
+ start(): Promise<void>;
25
29
  stop(): Promise<void>;
26
30
  }
27
31
  //# sourceMappingURL=DreamkitDevServer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMpD,OAAO,EAAE,GAAG,EAAW,KAAK,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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,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GACtD,0BAA0B,CAAC;AAC7B,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,GACvD,0BAA0B,CAAC;AAE7B,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,SAAmB;IACrC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBACzB,SAAS,EAAE,oBAAoB;IA6B3C,MAAM,CAAC,QAAQ,IAAI,iBAAiB;IAKpC,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,iBAAiB;IAGzC,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;IAoCtC,KAAK;IAIL,IAAI;CAKX"}
@@ -10,6 +10,7 @@ import { createServer, createViteRuntime } from "vite";
10
10
  import solidPlugin from "vite-plugin-solid";
11
11
  import tsconfigPlugin from "vite-tsconfig-paths";
12
12
  export class DreamkitDevServer {
13
+ static instanceKey = "dk:dev-server";
13
14
  app;
14
15
  entry;
15
16
  runtimeServer;
@@ -44,6 +45,15 @@ export class DreamkitDevServer {
44
45
  },
45
46
  });
46
47
  }
48
+ static instance() {
49
+ const value = globalThis[DreamkitDevServer.instanceKey];
50
+ if (!value)
51
+ throw new Error("DreamkitDevServer instance not found");
52
+ return value;
53
+ }
54
+ static saveInstance(instance) {
55
+ globalThis[DreamkitDevServer.instanceKey] = instance;
56
+ }
47
57
  async fetch(path) {
48
58
  //const mod = $server.moduleGraph.getModuleById(shaking.entry);
49
59
  //if (mod) $server.moduleGraph.invalidateModule(mod);
@@ -119,7 +129,12 @@ export class DreamkitDevServer {
119
129
  };
120
130
  await this.app.add(objects);
121
131
  }
132
+ async start() {
133
+ await this.app.start();
134
+ }
122
135
  async stop() {
136
+ if (this.app.started)
137
+ await this.app.stop();
123
138
  await this.runtimeServer?.close();
124
139
  await this.runtime?.destroy();
125
140
  }
@@ -0,0 +1,8 @@
1
+ import { DreamkitDevInOptions, DreamkitDevServer } from "../../DreamkitDevServer.js";
2
+ import { DreamkitPluginOptions } from "../../options.js";
3
+ import { VinxiApp } from "../../utils/vinxi.js";
4
+ export declare function fetchDreamkitDevOptions(options: {
5
+ root: string;
6
+ }): Promise<DreamkitDevInOptions>;
7
+ export declare function createDreamkitDevServer(vinxiApp: VinxiApp, inOptions?: DreamkitPluginOptions): DreamkitDevServer;
8
+ //# sourceMappingURL=dev-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAKzD,OAAO,EAML,QAAQ,EAET,MAAM,sBAAsB,CAAC;AAsB9B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqDhC;AAuCD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,QAAQ,EAClB,SAAS,GAAE,qBAA0B,qBAiKtC"}
@@ -1,12 +1,14 @@
1
- import { DreamkitDevServer, } from "../DreamkitDevServer.js";
2
- import { generate } from "../actions/generate.js";
3
- import { tryGenerate } from "../utils/ast.js";
4
- import { execute } from "../utils/runtime.js";
5
- import { createDelayedFunction } from "../utils/timeout.js";
6
- import { transformCode } from "../utils/transform.js";
7
- import { onChangeVinxiRoutes, } from "../utils/vinxi.js";
8
- import { isRoute, $route } from "@dreamkit/app";
9
- import { join, resolve } from "path";
1
+ import { DreamkitDevServer, } from "../../DreamkitDevServer.js";
2
+ import { generate } from "../../actions/generate.js";
3
+ import { tryGenerate } from "../../utils/ast.js";
4
+ import { execute } from "../../utils/runtime.js";
5
+ import { createDelayedFunction } from "../../utils/timeout.js";
6
+ import { transformCode } from "../../utils/transform.js";
7
+ import { addVinxiPlugin, addVinxiRollupPlugin, isVinxiBuild, onChangeVinxiRoutes, } from "../../utils/vinxi.js";
8
+ import { isRoute, $route, App } from "@dreamkit/app";
9
+ import { existsSync } from "fs";
10
+ import { join, normalize, relative, resolve } from "path";
11
+ import { fileURLToPath } from "url";
10
12
  const isEntryRoute = (id, value) => !id.startsWith("/") && isRoute(value);
11
13
  // StackBlitz Polyfill
12
14
  class $CustomEvent extends Event {
@@ -77,7 +79,7 @@ function addVinxiEntryRoutes(vinxiApp, objectId, objectValue, entryPath) {
77
79
  filePath: entryPath,
78
80
  };
79
81
  if (!objectValue.$options.path) {
80
- console.warn("Missing route path", { id: objectId });
82
+ console.warn("Missing route path at dreamkit entry", { id: objectId });
81
83
  continue;
82
84
  }
83
85
  routes._addRoute(vinxiRoute);
@@ -88,12 +90,18 @@ function addVinxiEntryRoutes(vinxiApp, objectId, objectValue, entryPath) {
88
90
  }
89
91
  }
90
92
  export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
91
- const ssrRouter = vinxiApp.config.routers.find((config) => config.name === "ssr").internals.routes;
93
+ const ssrFileRouter = vinxiApp.config.routers.find((config) => config.name === "ssr").internals.routes;
92
94
  const server = new DreamkitDevServer({
93
95
  root: resolve(vinxiApp.config.root ?? "."),
94
- routeDir: ssrRouter.config.dir,
96
+ routeDir: ssrFileRouter.config.dir,
95
97
  ...inOptions,
96
98
  });
99
+ DreamkitDevServer.saveInstance(server);
100
+ App.saveInstance(server.app);
101
+ const selfPath = (file, rel) => {
102
+ const path = fileURLToPath(new URL(`./${file}`, import.meta.url));
103
+ return normalize(rel ? relative(server.options.root, path) : path);
104
+ };
97
105
  async function onBuildStart() {
98
106
  await server.prepare(false);
99
107
  for (const route of server.app.routes) {
@@ -120,7 +128,19 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
120
128
  await server.stop();
121
129
  }
122
130
  async function onDevStart() {
123
- const tryGenerate = createDelayedFunction(() => generate(server), 300);
131
+ const tryGenerate = createDelayedFunction(async () => {
132
+ const paths = new Set();
133
+ server.app.routes.forEach(async (route) => {
134
+ const path = route.$options.path;
135
+ if (path) {
136
+ if (paths.has(path)) {
137
+ console.warn("Duplicated route path", { path });
138
+ }
139
+ paths.add(path);
140
+ }
141
+ });
142
+ await generate(server);
143
+ }, 300);
124
144
  server.app
125
145
  .on("change", (data) => {
126
146
  if (isRoute(data.value)) {
@@ -180,6 +200,26 @@ export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
180
200
  }
181
201
  }
182
202
  }
203
+ const ssrRouter = vinxiApp.getRouter("ssr");
204
+ ssrRouter.middleware = selfPath("middleware.js", true);
205
+ if (isVinxiBuild()) {
206
+ const dreamkitEntryId = "dk:entry";
207
+ const dreamkitEntry = join(server.options.root, "src/dreamkit.tsx").replaceAll("\\", "/");
208
+ const existsDreamkitEntry = existsSync(dreamkitEntry);
209
+ addVinxiPlugin(vinxiApp, selfPath("prod-server.js"));
210
+ addVinxiRollupPlugin(vinxiApp, {
211
+ name: "dk:entry",
212
+ resolveId(id) {
213
+ if (id === dreamkitEntryId) {
214
+ return existsDreamkitEntry ? dreamkitEntry : `\0${dreamkitEntryId}`;
215
+ }
216
+ },
217
+ load(id) {
218
+ if (!existsDreamkitEntry && id === `\0${dreamkitEntryId}`)
219
+ return { code: "export {}" };
220
+ },
221
+ });
222
+ }
183
223
  vinxiApp.hooks.hook("app:build:router:start", onBuildStart);
184
224
  vinxiApp.hooks.hook("app:build:router:vite:end", onBuildEnd);
185
225
  vinxiApp.hooks.hook("app:build:nitro:start", onBuildStart);
@@ -0,0 +1,6 @@
1
+ import { type HTTPEvent } from "vinxi/http";
2
+ declare const _default: {
3
+ onRequest: ((event: HTTPEvent) => Promise<void>)[];
4
+ };
5
+ export default _default;
6
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAkC,MAAM,YAAY,CAAC;;wBAI1D,SAAS;;AAF3B,wBASE"}
@@ -0,0 +1,13 @@
1
+ import { App } from "@dreamkit/app";
2
+ import { getWebRequest, sendWebResponse } from "vinxi/http";
3
+ export default {
4
+ onRequest: [
5
+ async (event) => {
6
+ const app = App.instance();
7
+ const request = getWebRequest(event);
8
+ const response = await app.request(request);
9
+ if (response)
10
+ await sendWebResponse(event, response);
11
+ },
12
+ ],
13
+ };
@@ -0,0 +1,2 @@
1
+ export default function (_nitro: any): Promise<void>;
2
+ //# sourceMappingURL=prod-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prod-server.d.ts","sourceRoot":"","sources":["../../../src/adapters/solid-start/prod-server.ts"],"names":[],"mappings":"AAIA,yBAA+B,MAAM,EAAE,GAAG,iBAKzC"}
@@ -0,0 +1,9 @@
1
+ import { App } from "@dreamkit/app";
2
+ // @ts-ignore
3
+ import * as objects from "dk:entry";
4
+ export default async function (_nitro) {
5
+ const app = new App();
6
+ App.saveInstance(app);
7
+ await app.add(objects);
8
+ await app.start();
9
+ }
package/lib/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DreamkitDevServer } from "./DreamkitDevServer.js";
2
2
  import { generate } from "./actions/generate.js";
3
- import { fetchDreamkitDevOptions } from "./adapters/solid-start.js";
3
+ import { fetchDreamkitDevOptions } from "./adapters/solid-start/dev-server.js";
4
4
  import { createCommand } from "commander";
5
5
  import { relative, resolve } from "path";
6
6
  const program = createCommand();
@@ -1 +1 @@
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"}
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,CAuD5E"}
@@ -1,12 +1,14 @@
1
- import { createDreamkitDevServer } from "../adapters/solid-start.js";
1
+ import { createDreamkitDevServer } from "../adapters/solid-start/dev-server.js";
2
2
  import { tryGenerate } from "../utils/ast.js";
3
3
  import { transformCode } from "../utils/transform.js";
4
- import { onVinxiApp } from "../utils/vinxi.js";
4
+ import { isVinxiBuild, 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) => {
8
+ const cleanup = onVinxiApp(async (app) => {
9
9
  server = createDreamkitDevServer(app, inOptions);
10
+ if (!isVinxiBuild())
11
+ await server.start();
10
12
  });
11
13
  return {
12
14
  name: "dreamkit",
@@ -26,7 +28,12 @@ export function dreamkitPlugin(inOptions = {}) {
26
28
  const searchParams = new URLSearchParams(searchString);
27
29
  const dreamkitPickEntry = searchParams.get("dk-pick-entry");
28
30
  const picks = searchParams.getAll("pick");
29
- const transforms = [{ toSolidLink: true }];
31
+ const transforms = [
32
+ {
33
+ toSolidLink: true,
34
+ toSolidServerAction: true,
35
+ },
36
+ ];
30
37
  if (dreamkitPickEntry) {
31
38
  transforms.push({
32
39
  pickExport: [dreamkitPickEntry],
@@ -1,8 +1,9 @@
1
1
  import { ParseResult } from "@babel/parser";
2
2
  import * as t from "@babel/types";
3
3
  export declare function replaceImportSpec(ast: ParseResult<t.File>, options: {
4
- spec: string[];
4
+ spec?: string[] | Record<string, string>;
5
5
  source: string;
6
- newSource: string;
6
+ newSource?: string;
7
+ onRenameSpec?: (prev: string, next: string) => void;
7
8
  }): number;
8
9
  //# sourceMappingURL=replace-import-spec.d.ts.map
@@ -1 +1 @@
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
+ {"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,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD,UA6FF"}
@@ -2,29 +2,80 @@ import { traverse } from "../utils/babel.js";
2
2
  import * as t from "@babel/types";
3
3
  export function replaceImportSpec(ast, options) {
4
4
  let changes = 0;
5
- traverse(ast, {
6
- ImportDeclaration(path) {
7
- const { node } = path;
8
- if (node.source.value === options.source) {
9
- node.specifiers = node.specifiers.filter((spec) => {
10
- if (spec.type === "ImportSpecifier" &&
11
- spec.imported.type === "Identifier" &&
12
- options.spec.includes(spec.imported.name)) {
13
- changes++;
14
- ast.program.body.unshift(t.importDeclaration([
15
- t.importSpecifier(t.identifier(spec.imported.name), t.identifier(spec.imported.name)),
16
- ], t.stringLiteral(options.newSource)));
17
- return false;
5
+ if (Array.isArray(options.spec) && options.newSource) {
6
+ const specArray = options.spec;
7
+ traverse(ast, {
8
+ ImportDeclaration(path) {
9
+ const { node } = path;
10
+ if (node.source.value === options.source) {
11
+ node.specifiers = node.specifiers.filter((spec) => {
12
+ if (spec.type === "ImportSpecifier" &&
13
+ spec.imported.type === "Identifier" &&
14
+ specArray.includes(spec.imported.name)) {
15
+ changes++;
16
+ ast.program.body.unshift(t.importDeclaration([
17
+ t.importSpecifier(t.identifier(spec.imported.name), t.identifier(spec.imported.name)),
18
+ ], t.stringLiteral(options.newSource)));
19
+ return false;
20
+ }
21
+ return true;
22
+ });
23
+ if (changes) {
24
+ if (!node.specifiers.length)
25
+ path.remove();
18
26
  }
19
- return true;
20
- });
21
- if (changes) {
22
- if (!node.specifiers.length)
27
+ }
28
+ },
29
+ });
30
+ }
31
+ else if (options.spec) {
32
+ const specMap = options.spec;
33
+ traverse(ast, {
34
+ ImportDeclaration(path) {
35
+ const { node } = path;
36
+ if (node.source.value === options.source) {
37
+ path.traverse({
38
+ ImportSpecifier(spec) {
39
+ if (spec.node.imported.type === "Identifier") {
40
+ const specName = spec.node.imported.name;
41
+ if (specMap[specName]) {
42
+ const newSpecName = specMap[specName];
43
+ const newSpecNameAlias = spec.scope.generateUid(newSpecName);
44
+ options.onRenameSpec?.(specName, newSpecNameAlias);
45
+ changes++;
46
+ spec.scope.rename(specName, newSpecNameAlias);
47
+ spec.node.imported = t.identifier(newSpecName);
48
+ if (options.newSource) {
49
+ spec.remove();
50
+ ast.program.body.unshift(t.importDeclaration([
51
+ t.importSpecifier(t.identifier(newSpecNameAlias), t.identifier(newSpecName)),
52
+ ], t.stringLiteral(options.newSource)));
53
+ }
54
+ }
55
+ }
56
+ },
57
+ });
58
+ if (changes && !node.specifiers.length)
23
59
  path.remove();
24
- path.scope.crawl();
25
60
  }
26
- }
27
- },
28
- });
61
+ },
62
+ });
63
+ }
64
+ else if (options.newSource) {
65
+ traverse(ast, {
66
+ ImportDeclaration(path) {
67
+ if (path.node.source.value === options.source) {
68
+ changes++;
69
+ path.node.source = t.stringLiteral(options.newSource);
70
+ }
71
+ },
72
+ });
73
+ }
74
+ if (changes)
75
+ traverse(ast, {
76
+ Program(programPath) {
77
+ programPath.scope.crawl();
78
+ },
79
+ });
29
80
  return changes;
30
81
  }
@@ -1 +1 @@
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
+ {"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,UAiMpD"}
@@ -37,7 +37,8 @@ export function toSolidRoute(ast) {
37
37
  // export default login
38
38
  dec.type === "Identifier") {
39
39
  const bind = programPath.scope.bindings[dec.name];
40
- if (bind.path.node.type === "VariableDeclarator" &&
40
+ if (bind &&
41
+ bind.path.node.type === "VariableDeclarator" &&
41
42
  bind.path.node.init) {
42
43
  dec = bind.path.node.init;
43
44
  path.remove();
@@ -0,0 +1,2 @@
1
+ export declare const toSolidServerAction: import("../utils/transform.js").Transform<unknown>;
2
+ //# sourceMappingURL=to-solid-server-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-solid-server-action.d.ts","sourceRoot":"","sources":["../../src/transforms/to-solid-server-action.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,mBAAmB,oDAwD9B,CAAC"}
@@ -0,0 +1,111 @@
1
+ import { createCallChains, createConst, defineTransform, getFirstChain, parseCallsChain, } from "../utils/ast.js";
2
+ import { traverse } from "../utils/babel.js";
3
+ import { replaceImportSpec } from "./replace-import-spec.js";
4
+ import * as t from "@babel/types";
5
+ export const toSolidServerAction = defineTransform({
6
+ onlyIf: (code) => code.includes("$api") && code.includes("dreamkit"),
7
+ run: (ast) => {
8
+ let apiId;
9
+ let changes = replaceImportSpec(ast, {
10
+ spec: { $api: "$serverApi" },
11
+ source: "dreamkit",
12
+ newSource: "dreamkit/adapters/solid.js",
13
+ onRenameSpec(prev, next) {
14
+ apiId = next;
15
+ },
16
+ });
17
+ if (apiId) {
18
+ let clientApiLoc = [];
19
+ traverse(ast, {
20
+ Program(programPath) {
21
+ const binds = programPath.scope.bindings[apiId];
22
+ programPath.traverse;
23
+ binds.referencePaths.forEach((path) => {
24
+ if (path.node.loc)
25
+ clientApiLoc.push(path.node.loc);
26
+ });
27
+ programPath.traverse({
28
+ ExportNamedDeclaration(path) {
29
+ if (path.node.declaration) {
30
+ if (path.node.declaration.type === "VariableDeclaration") {
31
+ const [dec] = path.node.declaration.declarations;
32
+ const init = dec.init;
33
+ if (dec.id.type === "Identifier" &&
34
+ init?.type === "CallExpression") {
35
+ const first = getFirstChain(init);
36
+ if (clientApiLoc.includes(first?.value.object.loc)) {
37
+ changes++;
38
+ const replaced = createServerAction(programPath, dec.id.name, init, true);
39
+ const index = programPath.node.body.findIndex((node) => node === path.node);
40
+ programPath.node.body.splice(index, 1, ...replaced);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ },
46
+ });
47
+ },
48
+ });
49
+ }
50
+ return changes;
51
+ },
52
+ });
53
+ function createServerAction(program, name, call, exported = false) {
54
+ const commonApi = program.scope.generateUid(`base_${name}`);
55
+ const originalFunc = program.scope.generateUid(`original_${name}`);
56
+ const serverApi = program.scope.generateUid(`server_${name}`);
57
+ const chain = parseCallsChain(call);
58
+ const serverMethods = ["self", "create"];
59
+ return [
60
+ // const baseFetchData = $api.params({});
61
+ createConst(commonApi, createCallChains({
62
+ ...chain,
63
+ calls: chain.calls.filter(({ name }) => !serverMethods.includes(name)),
64
+ })),
65
+ t.variableDeclaration("let", [
66
+ t.variableDeclarator(t.identifier(name), t.arrowFunctionExpression([t.identifier("params")], t.blockStatement([
67
+ // const serverApi = $serverApi.clone(baseFetchData.options).self({}).create(() => {})
68
+ createConst(serverApi, createCallChains({
69
+ ...chain,
70
+ calls: [
71
+ {
72
+ name: "clone",
73
+ arguments: [
74
+ t.memberExpression(t.identifier(commonApi), t.identifier("options")),
75
+ ],
76
+ },
77
+ ...chain.calls.filter(({ name }) => serverMethods.includes(name)),
78
+ ],
79
+ })),
80
+ // return await serverApi(params);
81
+ t.returnStatement(t.awaitExpression(t.callExpression(t.identifier(serverApi), [
82
+ t.identifier("params"),
83
+ ]))),
84
+ ], [t.directive(t.directiveLiteral("use server"))]), true)),
85
+ ]),
86
+ // const originalFetchData = fetchData;
87
+ createConst(originalFunc, t.identifier(name)),
88
+ // fetchData = baseFetchData.create(originalFetchData);
89
+ t.expressionStatement(t.assignmentExpression("=", t.identifier(name), createCallChains({
90
+ rootName: commonApi,
91
+ calls: [
92
+ {
93
+ name: "clone",
94
+ arguments: [
95
+ t.objectExpression([
96
+ t.objectProperty(t.identifier("context"), t.nullLiteral()),
97
+ ]),
98
+ ],
99
+ },
100
+ {
101
+ name: "create",
102
+ arguments: [t.identifier(originalFunc)],
103
+ },
104
+ ],
105
+ }))),
106
+ exported &&
107
+ t.exportNamedDeclaration(null, [
108
+ t.exportSpecifier(t.identifier(name), t.identifier(name)),
109
+ ]),
110
+ ].filter((v) => !!v);
111
+ }
@@ -7,6 +7,16 @@ export declare function parseCode(input: string | string[]): t.Statement[];
7
7
  export type ParseFileResult = ParseResult<t.File>;
8
8
  export declare function parseFile(code: string): ParseResult<t.File>;
9
9
  export declare function tryGenerate(ast: ParseFileResult | undefined, log?: boolean): import("@babel/generator").GeneratorResult | undefined;
10
+ export type Chain = {
11
+ rootName: string;
12
+ calls: {
13
+ name: string;
14
+ arguments: any[];
15
+ }[];
16
+ };
17
+ export declare function parseCallsChain(input: t.CallExpression): Chain;
18
+ export declare function createCallChains(chain: Chain): t.CallExpression | t.Identifier;
19
+ export declare function removeChainCalls(input: t.CallExpression, names: string[]): t.CallExpression;
10
20
  export declare function getFirstChain(ref: t.Node): {
11
21
  identifier: string;
12
22
  value: t.MemberExpression;
@@ -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,CA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AS,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
@@ -22,6 +22,54 @@ export function tryGenerate(ast, log) {
22
22
  return generated;
23
23
  }
24
24
  }
25
+ export function parseCallsChain(input) {
26
+ let ref = input;
27
+ let rootName;
28
+ let calls = [];
29
+ while (true) {
30
+ if (ref.callee.type === "MemberExpression") {
31
+ if (ref.callee.property.type !== "Identifier")
32
+ throw new Error("Invalid chain");
33
+ calls.push({
34
+ name: ref.callee.property.name,
35
+ arguments: ref.arguments,
36
+ });
37
+ if (ref.callee.object.type === "Identifier") {
38
+ rootName = ref.callee.object.name;
39
+ break;
40
+ }
41
+ else if (ref.callee.object.type === "CallExpression") {
42
+ ref = ref.callee.object;
43
+ }
44
+ else {
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ return { rootName, calls: calls.reverse() };
50
+ }
51
+ export function createCallChains(chain) {
52
+ let ref = t.identifier(chain.rootName);
53
+ for (const call of chain.calls) {
54
+ ref = t.callExpression(t.memberExpression(ref, t.identifier(call.name)), call.arguments);
55
+ }
56
+ return ref;
57
+ }
58
+ export function removeChainCalls(input, names) {
59
+ const root = t.cloneNode(input);
60
+ let ref = root;
61
+ while (ref.type === "CallExpression") {
62
+ ref = t.callExpression(ref.callee, ref.arguments);
63
+ if (ref.callee.type === "MemberExpression") {
64
+ if (ref.callee.property.type === "Identifier") {
65
+ if (names.includes(ref.callee.property.name))
66
+ continue;
67
+ }
68
+ ref = ref.callee.object;
69
+ }
70
+ }
71
+ return root;
72
+ }
25
73
  export function getFirstChain(ref) {
26
74
  let lastMember;
27
75
  while (ref.type === "CallExpression") {
@@ -11,6 +11,7 @@ declare const $transforms: {
11
11
  replaceImportSpec: typeof replaceImportSpec;
12
12
  toSolidRoute: typeof toSolidRoute;
13
13
  toSolidLink: Transform<unknown>;
14
+ toSolidServerAction: Transform<unknown>;
14
15
  };
15
16
  export type TransformObject = {
16
17
  [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,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,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AE,+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"}
@@ -4,6 +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 { toSolidServerAction } from "../transforms/to-solid-server-action.js";
7
8
  import { tryGenerate, parseFile } from "./ast.js";
8
9
  const $transforms = {
9
10
  pickExport,
@@ -12,6 +13,7 @@ const $transforms = {
12
13
  replaceImportSpec,
13
14
  toSolidRoute,
14
15
  toSolidLink,
16
+ toSolidServerAction,
15
17
  };
16
18
  export function transformCode(code, ...input) {
17
19
  let ast;
@@ -1,5 +1,17 @@
1
- import type { Internals } from "vinxi";
2
- import type { App } from "vinxi";
1
+ import type { InputOptionsWithPlugins, Plugin } from "rollup";
2
+ import type { App, Internals } from "vinxi";
3
+ import type { Router } from "vinxi/http";
4
+ export type VinxiApp = Omit<App, "getRouter"> & {
5
+ config: {
6
+ server?: App["config"]["server"] & {
7
+ plugins?: string[];
8
+ rollupConfig?: InputOptionsWithPlugins;
9
+ };
10
+ };
11
+ getRouter(name: string): Router & {
12
+ middleware?: string;
13
+ };
14
+ };
3
15
  export type VinxiRoute = {
4
16
  _dreamkitEntryId?: string;
5
17
  page: boolean;
@@ -21,6 +33,9 @@ export type BaseFileSystemRouter = Omit<Internals["routes"] & {}, "getRoutes"> &
21
33
  buildRoutes(): Promise<VinxiRoute[]>;
22
34
  buildRoutesPromise: Promise<any> | undefined;
23
35
  };
24
- export declare function onVinxiApp(cb: (app: App) => void): () => void;
36
+ export declare function isVinxiBuild(): boolean;
37
+ export declare function onVinxiApp(cb: (app: VinxiApp) => void): () => void;
38
+ export declare function addVinxiPlugin(vinxiApp: VinxiApp, path: string): void;
39
+ export declare function addVinxiRollupPlugin(vinxiApp: VinxiApp, plugin: Plugin): void;
25
40
  export declare function onChangeVinxiRoutes(router: BaseFileSystemRouter, cb: (action: "add" | "update" | "remove", route: VinxiRoute) => any): () => void;
26
41
  //# sourceMappingURL=vinxi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vinxi.d.ts","sourceRoot":"","sources":["../../src/utils/vinxi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,MAAM,MAAM,UAAU,GAAG;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,GAAG,CAAC;KACd,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,EACxB,WAAW,CACZ,GA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,MAAM,CAAC;IACb,UAAU,EAAE;QACV,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,GAAG,CAAC;KACd,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,EACxB,WAAW,CACZ,GAAG;IACF,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACnC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACrC,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CAC9C,CAAC;AAEF,wBAAgB,YAAY,YAE3B;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,cAiBrD;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAG9D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAMtE;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,UAAU,KAAK,GAAG,cAmCpE"}
@@ -1,4 +1,7 @@
1
1
  import { normalize } from "path";
2
+ export function isVinxiBuild() {
3
+ return process.argv.slice(2).includes("build");
4
+ }
2
5
  export function onVinxiApp(cb) {
3
6
  Object.defineProperty(globalThis, "app", {
4
7
  configurable: true,
@@ -17,6 +20,18 @@ export function onVinxiApp(cb) {
17
20
  });
18
21
  };
19
22
  }
23
+ export function addVinxiPlugin(vinxiApp, path) {
24
+ if (!vinxiApp.config.server.plugins)
25
+ vinxiApp.config.server.plugins = [];
26
+ vinxiApp.config.server.plugins.push(path);
27
+ }
28
+ export function addVinxiRollupPlugin(vinxiApp, plugin) {
29
+ if (!vinxiApp.config.server.rollupConfig)
30
+ vinxiApp.config.server.rollupConfig = { plugins: [] };
31
+ if (!vinxiApp.config.server.rollupConfig.plugins)
32
+ vinxiApp.config.server.rollupConfig.plugins = [];
33
+ vinxiApp.config.server.rollupConfig.plugins.push(plugin);
34
+ }
20
35
  export function onChangeVinxiRoutes(router, cb) {
21
36
  const addRoute = router._addRoute.bind(router);
22
37
  const removeRoute = router.removeRoute.bind(router);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamkit/dev",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Development tools for DreamKit.",
5
5
  "homepage": "https://dreamkit.dev",
6
6
  "repository": {
@@ -42,10 +42,11 @@
42
42
  "es-module-lexer": "^1.5.4",
43
43
  "esbuild": "^0.24.0",
44
44
  "glob": "^11.0.0",
45
+ "rollup": "^4.26.0",
45
46
  "vite-plugin-solid": "^2.10.2",
46
47
  "vite-tsconfig-paths": "^5.1.2",
47
- "@dreamkit/app": "0.0.3",
48
- "@dreamkit/schema": "0.0.2"
48
+ "@dreamkit/app": "0.0.5",
49
+ "@dreamkit/schema": "0.0.4"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@types/debug": "^4.1.12",
@@ -1,8 +0,0 @@
1
- import { DreamkitDevInOptions, DreamkitDevServer } from "../DreamkitDevServer.js";
2
- import { DreamkitPluginOptions } from "../options.js";
3
- import { App } from "vinxi";
4
- export declare function fetchDreamkitDevOptions(options: {
5
- root: string;
6
- }): Promise<DreamkitDevInOptions>;
7
- export declare function createDreamkitDevServer(vinxiApp: App, inOptions?: DreamkitPluginOptions): DreamkitDevServer;
8
- //# sourceMappingURL=solid-start.d.ts.map
@@ -1 +0,0 @@
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"}