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.
@@ -91,6 +91,11 @@ export declare class NextDevServer extends DevServer {
91
91
  * Serve static assets from /_next/static/
92
92
  */
93
93
  private serveStaticAsset;
94
+ /**
95
+ * Serve page components for client-side navigation
96
+ * Maps /_next/pages/index.js → /pages/index.jsx (transformed)
97
+ */
98
+ private servePageComponent;
94
99
  /**
95
100
  * Handle API route requests
96
101
  */
@@ -1 +1 @@
1
- {"version":3,"file":"next-dev-server.d.ts","sourceRoot":"","sources":["../../src/frameworks/next-dev-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAa,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AA4DzC,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,0FAA0F;IAC1F,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAilBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,iDAAiD;IACjD,OAAO,CAAC,QAAQ,CAAS;IAEzB,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAS;IAEvB,mDAAmD;IACnD,OAAO,CAAC,SAAS,CAAS;IAE1B,+DAA+D;IAC/D,OAAO,CAAC,YAAY,CAAU;IAE9B,yCAAyC;IACz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IAmDvB;;OAEG;IACH,aAAa,IAAI,IAAI;IAgDrB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuBxB;;OAEG;IACH,IAAI,IAAI,IAAI;CAUb;AAED,eAAe,aAAa,CAAC"}
package/dist/index.cjs CHANGED
@@ -6,31 +6,8 @@ const pako = require('pako');
6
6
  const justBash = require('just-bash');
7
7
  const resolve_exports = require('resolve.exports');
8
8
  const comlink = require('comlink');
9
- const fs$1 = require('fs');
10
- const path$1 = require('path');
11
- const url$2 = require('url');
12
9
 
13
10
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
- function _interopNamespaceDefault(e) {
15
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
16
- if (e) {
17
- for (const k in e) {
18
- if (k !== 'default') {
19
- const d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: () => e[k]
23
- });
24
- }
25
- }
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
-
31
- const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
32
- const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
33
-
34
11
  function createNodeError(code, syscall, path, message) {
35
12
  const errno = {
36
13
  ENOENT: -2,
@@ -9932,16 +9909,27 @@ async function createRuntime(vfs, options = {}) {
9932
9909
  return new AsyncRuntimeWrapper(vfs, runtimeOptions);
9933
9910
  }
9934
9911
 
9935
- const __dirname$1 = path__namespace.dirname(url$2.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
9936
9912
  function getServiceWorkerContent() {
9913
+ if (typeof require === "undefined") {
9914
+ return null;
9915
+ }
9937
9916
  try {
9938
- let swPath = path__namespace.join(__dirname$1, "__sw__.js");
9939
- if (fs__namespace.existsSync(swPath)) {
9940
- return fs__namespace.readFileSync(swPath, "utf-8");
9917
+ const fs = require("fs");
9918
+ const path = require("path");
9919
+ let dirname;
9920
+ try {
9921
+ const url = require("url");
9922
+ dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
9923
+ } catch {
9924
+ dirname = __dirname;
9941
9925
  }
9942
- swPath = path__namespace.join(__dirname$1, "../dist/__sw__.js");
9943
- if (fs__namespace.existsSync(swPath)) {
9944
- return fs__namespace.readFileSync(swPath, "utf-8");
9926
+ let swPath = path.join(dirname, "__sw__.js");
9927
+ if (fs.existsSync(swPath)) {
9928
+ return fs.readFileSync(swPath, "utf-8");
9929
+ }
9930
+ swPath = path.join(dirname, "../dist/__sw__.js");
9931
+ if (fs.existsSync(swPath)) {
9932
+ return fs.readFileSync(swPath, "utf-8");
9945
9933
  }
9946
9934
  return null;
9947
9935
  } catch {
@@ -12675,6 +12663,9 @@ class NextDevServer extends DevServer {
12675
12663
  if (pathname.startsWith("/_next/shims/")) {
12676
12664
  return this.serveNextShim(pathname);
12677
12665
  }
12666
+ if (pathname.startsWith("/_next/pages/")) {
12667
+ return this.servePageComponent(pathname);
12668
+ }
12678
12669
  if (pathname.startsWith("/_next/static/")) {
12679
12670
  return this.serveStaticAsset(pathname);
12680
12671
  }
@@ -12737,6 +12728,18 @@ class NextDevServer extends DevServer {
12737
12728
  }
12738
12729
  return this.notFound(pathname);
12739
12730
  }
12731
+ /**
12732
+ * Serve page components for client-side navigation
12733
+ * Maps /_next/pages/index.js → /pages/index.jsx (transformed)
12734
+ */
12735
+ async servePageComponent(pathname) {
12736
+ const route = pathname.replace("/_next/pages", "").replace(/\.js$/, "");
12737
+ const pageFile = this.resolvePageFile(route);
12738
+ if (!pageFile) {
12739
+ return this.notFound(pathname);
12740
+ }
12741
+ return this.transformAndServe(pageFile, pageFile);
12742
+ }
12740
12743
  /**
12741
12744
  * Handle API route requests
12742
12745
  */
@@ -13431,7 +13434,6 @@ class NextDevServer extends DevServer {
13431
13434
  */
13432
13435
  async generatePageHtml(pageFile, pathname) {
13433
13436
  const virtualPrefix = `/__virtual__/${this.port}`;
13434
- const pageModulePath = virtualPrefix + pageFile;
13435
13437
  const globalCssLinks = [];
13436
13438
  const cssLocations = ["/styles/globals.css", "/styles/global.css", "/app/globals.css"];
13437
13439
  for (const cssPath of cssLocations) {
@@ -13473,30 +13475,63 @@ class NextDevServer extends DevServer {
13473
13475
  <script type="module">
13474
13476
  import React from 'react';
13475
13477
  import ReactDOM from 'react-dom/client';
13476
- import Page from '${pageModulePath}';
13477
13478
 
13478
- // Handle client-side navigation
13479
- function App() {
13480
- const [currentPath, setCurrentPath] = React.useState(window.location.pathname);
13479
+ const virtualBase = '${virtualPrefix}';
13481
13480
 
13482
- React.useEffect(() => {
13483
- const handlePopState = () => {
13484
- setCurrentPath(window.location.pathname);
13485
- // Defer reload outside React's update cycle
13486
- setTimeout(() => window.location.reload(), 0);
13487
- };
13481
+ // Convert URL path to page module path
13482
+ function getPageModulePath(pathname) {
13483
+ let route = pathname;
13484
+ if (route.startsWith(virtualBase)) {
13485
+ route = route.slice(virtualBase.length);
13486
+ }
13487
+ route = route.replace(/^\\/+/, '/') || '/';
13488
+ const modulePath = route === '/' ? '/index' : route;
13489
+ return virtualBase + '/_next/pages' + modulePath + '.js';
13490
+ }
13491
+
13492
+ // Dynamic page loader
13493
+ async function loadPage(pathname) {
13494
+ const modulePath = getPageModulePath(pathname);
13495
+ try {
13496
+ const module = await import(/* @vite-ignore */ modulePath);
13497
+ return module.default;
13498
+ } catch (e) {
13499
+ console.error('[Navigation] Failed to load:', modulePath, e);
13500
+ return null;
13501
+ }
13502
+ }
13488
13503
 
13489
- window.addEventListener('popstate', handlePopState);
13490
- return () => window.removeEventListener('popstate', handlePopState);
13504
+ // Router component
13505
+ function Router() {
13506
+ const [Page, setPage] = React.useState(null);
13507
+ const [path, setPath] = React.useState(window.location.pathname);
13508
+
13509
+ React.useEffect(() => {
13510
+ loadPage(path).then(C => C && setPage(() => C));
13491
13511
  }, []);
13492
13512
 
13513
+ React.useEffect(() => {
13514
+ const handleNavigation = async () => {
13515
+ const newPath = window.location.pathname;
13516
+ if (newPath !== path) {
13517
+ setPath(newPath);
13518
+ const C = await loadPage(newPath);
13519
+ if (C) setPage(() => C);
13520
+ }
13521
+ };
13522
+ window.addEventListener('popstate', handleNavigation);
13523
+ return () => window.removeEventListener('popstate', handleNavigation);
13524
+ }, [path]);
13525
+
13526
+ if (!Page) return null;
13493
13527
  return React.createElement(Page);
13494
13528
  }
13495
13529
 
13530
+ // Mark that we've initialized (for testing no-reload)
13531
+ window.__NEXT_INITIALIZED__ = Date.now();
13532
+
13496
13533
  ReactDOM.createRoot(document.getElementById('__next')).render(
13497
- React.createElement(React.StrictMode, null,
13498
- React.createElement(App)
13499
- )
13534
+ React.createElement(React.StrictMode, null, React.createElement(Router))
13500
13535
  );
13501
13536
  </script>
13502
13537
  </body>