@spirobel/mininext 0.4.3 → 0.5.0

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.
@@ -12,4 +12,5 @@ declare function makeEntrypoint(): Promise<{
12
12
  fetch: (req: Request, server: Server) => Promise<Response>;
13
13
  websocket: WebSocketHandler;
14
14
  }>;
15
+ export declare function getCallerFilePath(): string;
15
16
  export { has, html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
package/dist/mininext.js CHANGED
@@ -53,7 +53,12 @@ async function buildBackend(backendPath = "backend/backend.ts") {
53
53
  global.bundledSVGs = {};
54
54
  const i = await import(path.resolve(projectRoot(), backendPath));
55
55
  for (const frontend of url.getFrontends()) {
56
- const f = await buildFrontend(frontend);
56
+ const firstPlaceToLook = path.resolve(path.dirname(frontend.callerPath), `frontend/${frontend.path}`);
57
+ const secondPlaceToLook = path.resolve(projectRoot(), `frontend/${frontend.path}`);
58
+ const frontEndPath = (await Bun.file(firstPlaceToLook).exists())
59
+ ? firstPlaceToLook
60
+ : secondPlaceToLook;
61
+ const f = await buildFrontend(frontEndPath);
57
62
  FrontendScriptUrls.push("/" + f.url);
58
63
  FrontendScripts.push(f.script);
59
64
  }
@@ -82,7 +87,7 @@ async function buildBackend(backendPath = "backend/backend.ts") {
82
87
  }
83
88
  async function buildFrontend(file) {
84
89
  const result = await Bun.build({
85
- entrypoints: [path.resolve(projectRoot(), `frontend/${file}`)],
90
+ entrypoints: [file],
86
91
  outdir: path.resolve(projectRoot(), "dist"),
87
92
  naming: "[name]-[hash].[ext]",
88
93
  minify: Bun.argv[2] === "dev" ? false : true, //production
@@ -182,4 +187,14 @@ async function makeEntrypoint() {
182
187
  }
183
188
  return module.default();
184
189
  }
190
+ export function getCallerFilePath() {
191
+ // const stack = new Error().stack?.split("\n");
192
+ // //console.log(stack);
193
+ // if (!stack) return "";
194
+ // return stack[2].slice(
195
+ // stack[2].lastIndexOf("(") + 1,
196
+ // stack[2].lastIndexOf(")") + 3
197
+ // );
198
+ return __dirname;
199
+ }
185
200
  export { has, html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
package/dist/url.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// <reference types="bun-types" />
3
3
  import type { Server, WebSocketHandler } from "bun";
4
4
  import { html, json, dangerjson, HtmlString } from "./html";
5
- import type { BasedHtml, DangerJsonInHtml, JsonString, JsonStringValues } from "./html";
5
+ import { BasedHtml, type DangerJsonInHtml, type JsonString, type JsonStringValues } from "./html";
6
6
  /**
7
7
  * A helper function that helps narrow unknown objects
8
8
  * @param object - the object of type unknown that is to be narrowed
@@ -92,11 +92,15 @@ export declare class url {
92
92
  private static frontends;
93
93
  private static svgs;
94
94
  static svg(path: string, options?: ResponseInit): string | undefined;
95
- static frontend(path: string, snippet?: HtmlHandler | BasedHtml): HtmlString;
95
+ static frontend<X>(path: string, snippet?: BasedHtml): HtmlString;
96
+ static frontend<X>(path: string, snippet?: HtmlHandler<X>): (mini: Mini<X>) => HtmlString;
96
97
  /**
97
98
  * This is used by the frontend bundler in order to find all frontends and their corresponding script files.
98
99
  */
99
- static getFrontends(): string[];
100
+ static getFrontends(): {
101
+ path: string;
102
+ callerPath: string;
103
+ }[];
100
104
  static getSvgPaths(): string[];
101
105
  static serveFrontend(req: Request): Response | undefined;
102
106
  static serveSvg(req: Request): Response | undefined;
package/dist/url.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { htmlResponder, html, json, dangerjson, HtmlString } from "./html";
2
+ import { BasedHtml, } from "./html";
2
3
  /**
3
4
  * A helper function that helps narrow unknown objects
4
5
  * @param object - the object of type unknown that is to be narrowed
@@ -82,10 +83,21 @@ export class url {
82
83
  return foundEntry && foundEntry[0];
83
84
  }
84
85
  static frontend(path, snippet) {
85
- const frontendIndex = url.frontends.push(path) - 1;
86
+ const stack = new Error().stack?.split("\n");
87
+ let callerPath = "";
88
+ if (stack) {
89
+ callerPath = stack[2].slice(stack[2].lastIndexOf("(") + 1, stack[2].lastIndexOf(".") + 3);
90
+ }
91
+ const frontendIndex = url.frontends.push({ path, callerPath }) - 1;
86
92
  const scriptUrl = FrontendScriptUrls[frontendIndex];
87
- return html ` ${snippet}
88
- <script type="module" src="${scriptUrl}"></script>`; // return an html script tag with the index hash
93
+ if (snippet instanceof BasedHtml || !snippet) {
94
+ return html ` ${snippet}
95
+ <script type="module" src="${scriptUrl}"></script>`; // return an html script tag with the index hash
96
+ }
97
+ return (mini) => {
98
+ return mini.html `${snippet}
99
+ <script type="module" src="${scriptUrl}"></script>`;
100
+ };
89
101
  }
90
102
  /**
91
103
  * This is used by the frontend bundler in order to find all frontends and their corresponding script files.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "clean":"rm -rf ./dist"
12
12
  },
13
13
  "files": ["dist"],
14
- "version": "0.4.3",
14
+ "version": "0.5.0",
15
15
  "devDependencies": {
16
16
  "@types/bun": "latest"
17
17
  },