almostnode 0.2.1 → 0.2.3

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/dist/index.mjs CHANGED
@@ -5,9 +5,6 @@ import pako from "pako";
5
5
  import { defineCommand, Bash } from "just-bash";
6
6
  import { resolve as resolve$3 } from "resolve.exports";
7
7
  import { wrap, proxy } from "comlink";
8
- import * as fs$1 from "fs";
9
- import * as path$1 from "path";
10
- import { fileURLToPath as fileURLToPath$1 } from "url";
11
8
  let DEMO_PACKAGES, PACKAGE_JSON, DevServer, NextDevServer, PackageManager, Runtime, SANDBOX_SETUP_INSTRUCTIONS, SandboxRuntime, ServerBridge, VirtualFS, ViteDevServer, WorkerRuntime, assert$1, chokidarShim, createContainer, createConvexAppProject, createFsShim, createProcess, createRuntime, esbuildShim, events$1, execute, fseventsShim, generateSandboxFiles, getSandboxHtml, getSandboxVercelConfig, getServerBridge, httpShim, initConvexAppDemo, install, moduleShim, netShim, index, pathShim, perfHooksShim, querystringShim, readdirpShim, resetServerBridge, rollupShim, startConvexAppDevServer, stream, urlShim, utilShim, workerThreadsShim, wsShim;
12
9
  let __tla = (async () => {
13
10
  var _a, _b;
@@ -9928,16 +9925,27 @@ ${code}
9928
9925
  console.log("[createRuntime] Creating main-thread Runtime (same-origin, least secure)");
9929
9926
  return new AsyncRuntimeWrapper(vfs2, runtimeOptions);
9930
9927
  };
9931
- const __dirname$1 = path$1.dirname(fileURLToPath$1(import.meta.url));
9932
9928
  function getServiceWorkerContent() {
9929
+ if (typeof require === "undefined") {
9930
+ return null;
9931
+ }
9933
9932
  try {
9934
- let swPath = path$1.join(__dirname$1, "__sw__.js");
9935
- if (fs$1.existsSync(swPath)) {
9936
- return fs$1.readFileSync(swPath, "utf-8");
9933
+ const fs2 = require("fs");
9934
+ const path2 = require("path");
9935
+ let dirname2;
9936
+ try {
9937
+ const url2 = require("url");
9938
+ dirname2 = path2.dirname(url2.fileURLToPath(import.meta.url));
9939
+ } catch {
9940
+ dirname2 = __dirname;
9937
9941
  }
9938
- swPath = path$1.join(__dirname$1, "../dist/__sw__.js");
9939
- if (fs$1.existsSync(swPath)) {
9940
- return fs$1.readFileSync(swPath, "utf-8");
9942
+ let swPath = path2.join(dirname2, "__sw__.js");
9943
+ if (fs2.existsSync(swPath)) {
9944
+ return fs2.readFileSync(swPath, "utf-8");
9945
+ }
9946
+ swPath = path2.join(dirname2, "../dist/__sw__.js");
9947
+ if (fs2.existsSync(swPath)) {
9948
+ return fs2.readFileSync(swPath, "utf-8");
9941
9949
  }
9942
9950
  return null;
9943
9951
  } catch {
@@ -12546,6 +12554,9 @@ export default function Head({ children }) {
12546
12554
  if (pathname.startsWith("/_next/shims/")) {
12547
12555
  return this.serveNextShim(pathname);
12548
12556
  }
12557
+ if (pathname.startsWith("/_next/pages/")) {
12558
+ return this.servePageComponent(pathname);
12559
+ }
12549
12560
  if (pathname.startsWith("/_next/static/")) {
12550
12561
  return this.serveStaticAsset(pathname);
12551
12562
  }
@@ -12602,6 +12613,14 @@ export default function Head({ children }) {
12602
12613
  }
12603
12614
  return this.notFound(pathname);
12604
12615
  }
12616
+ async servePageComponent(pathname) {
12617
+ const route = pathname.replace("/_next/pages", "").replace(/\.js$/, "");
12618
+ const pageFile = this.resolvePageFile(route);
12619
+ if (!pageFile) {
12620
+ return this.notFound(pathname);
12621
+ }
12622
+ return this.transformAndServe(pageFile, pageFile);
12623
+ }
12605
12624
  async handleApiRoute(method, pathname, headers, body) {
12606
12625
  const apiFile = this.resolveApiFile(pathname);
12607
12626
  if (!apiFile) {
@@ -13315,7 +13334,6 @@ export default function Head({ children }) {
13315
13334
  }
13316
13335
  async generatePageHtml(pageFile, pathname) {
13317
13336
  const virtualPrefix = `/__virtual__/${this.port}`;
13318
- const pageModulePath = virtualPrefix + pageFile;
13319
13337
  const globalCssLinks = [];
13320
13338
  const cssLocations = [
13321
13339
  "/styles/globals.css",
@@ -13361,30 +13379,63 @@ export default function Head({ children }) {
13361
13379
  <script type="module">
13362
13380
  import React from 'react';
13363
13381
  import ReactDOM from 'react-dom/client';
13364
- import Page from '${pageModulePath}';
13365
13382
 
13366
- // Handle client-side navigation
13367
- function App() {
13368
- const [currentPath, setCurrentPath] = React.useState(window.location.pathname);
13383
+ const virtualBase = '${virtualPrefix}';
13369
13384
 
13370
- React.useEffect(() => {
13371
- const handlePopState = () => {
13372
- setCurrentPath(window.location.pathname);
13373
- // Defer reload outside React's update cycle
13374
- setTimeout(() => window.location.reload(), 0);
13375
- };
13385
+ // Convert URL path to page module path
13386
+ function getPageModulePath(pathname) {
13387
+ let route = pathname;
13388
+ if (route.startsWith(virtualBase)) {
13389
+ route = route.slice(virtualBase.length);
13390
+ }
13391
+ route = route.replace(/^\\/+/, '/') || '/';
13392
+ const modulePath = route === '/' ? '/index' : route;
13393
+ return virtualBase + '/_next/pages' + modulePath + '.js';
13394
+ }
13376
13395
 
13377
- window.addEventListener('popstate', handlePopState);
13378
- return () => window.removeEventListener('popstate', handlePopState);
13396
+ // Dynamic page loader
13397
+ async function loadPage(pathname) {
13398
+ const modulePath = getPageModulePath(pathname);
13399
+ try {
13400
+ const module = await import(/* @vite-ignore */ modulePath);
13401
+ return module.default;
13402
+ } catch (e) {
13403
+ console.error('[Navigation] Failed to load:', modulePath, e);
13404
+ return null;
13405
+ }
13406
+ }
13407
+
13408
+ // Router component
13409
+ function Router() {
13410
+ const [Page, setPage] = React.useState(null);
13411
+ const [path, setPath] = React.useState(window.location.pathname);
13412
+
13413
+ React.useEffect(() => {
13414
+ loadPage(path).then(C => C && setPage(() => C));
13379
13415
  }, []);
13380
13416
 
13417
+ React.useEffect(() => {
13418
+ const handleNavigation = async () => {
13419
+ const newPath = window.location.pathname;
13420
+ if (newPath !== path) {
13421
+ setPath(newPath);
13422
+ const C = await loadPage(newPath);
13423
+ if (C) setPage(() => C);
13424
+ }
13425
+ };
13426
+ window.addEventListener('popstate', handleNavigation);
13427
+ return () => window.removeEventListener('popstate', handleNavigation);
13428
+ }, [path]);
13429
+
13430
+ if (!Page) return null;
13381
13431
  return React.createElement(Page);
13382
13432
  }
13383
13433
 
13434
+ // Mark that we've initialized (for testing no-reload)
13435
+ window.__NEXT_INITIALIZED__ = Date.now();
13436
+
13384
13437
  ReactDOM.createRoot(document.getElementById('__next')).render(
13385
- React.createElement(React.StrictMode, null,
13386
- React.createElement(App)
13387
- )
13438
+ React.createElement(React.StrictMode, null, React.createElement(Router))
13388
13439
  );
13389
13440
  <\/script>
13390
13441
  </body>