almostnode 0.2.2 → 0.2.4

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,16 @@ 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;
99
+ /**
100
+ * Serve app components for client-side navigation (App Router)
101
+ * Maps /_next/app/app/about/page.js → /app/about/page.tsx (transformed)
102
+ */
103
+ private serveAppComponent;
94
104
  /**
95
105
  * Handle API route requests
96
106
  */
@@ -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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iB;IAiC/B;;OAEG;YACW,aAAa;IAuC3B;;;OAGG;IACH,OAAO,CAAC,eAAe;IAMvB;;OAEG;YACW,mBAAmB;IA8DjC;;OAEG;IACH,OAAO,CAAC,eAAe;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
@@ -12663,6 +12663,12 @@ class NextDevServer extends DevServer {
12663
12663
  if (pathname.startsWith("/_next/shims/")) {
12664
12664
  return this.serveNextShim(pathname);
12665
12665
  }
12666
+ if (pathname.startsWith("/_next/pages/")) {
12667
+ return this.servePageComponent(pathname);
12668
+ }
12669
+ if (pathname.startsWith("/_next/app/")) {
12670
+ return this.serveAppComponent(pathname);
12671
+ }
12666
12672
  if (pathname.startsWith("/_next/static/")) {
12667
12673
  return this.serveStaticAsset(pathname);
12668
12674
  }
@@ -12725,6 +12731,33 @@ class NextDevServer extends DevServer {
12725
12731
  }
12726
12732
  return this.notFound(pathname);
12727
12733
  }
12734
+ /**
12735
+ * Serve page components for client-side navigation
12736
+ * Maps /_next/pages/index.js → /pages/index.jsx (transformed)
12737
+ */
12738
+ async servePageComponent(pathname) {
12739
+ const route = pathname.replace("/_next/pages", "").replace(/\.js$/, "");
12740
+ const pageFile = this.resolvePageFile(route);
12741
+ if (!pageFile) {
12742
+ return this.notFound(pathname);
12743
+ }
12744
+ return this.transformAndServe(pageFile, pageFile);
12745
+ }
12746
+ /**
12747
+ * Serve app components for client-side navigation (App Router)
12748
+ * Maps /_next/app/app/about/page.js → /app/about/page.tsx (transformed)
12749
+ */
12750
+ async serveAppComponent(pathname) {
12751
+ const filePath = pathname.replace("/_next/app", "").replace(/\.js$/, "");
12752
+ const extensions = [".tsx", ".jsx", ".ts", ".js"];
12753
+ for (const ext of extensions) {
12754
+ const fullPath = filePath + ext;
12755
+ if (this.exists(fullPath)) {
12756
+ return this.transformAndServe(fullPath, fullPath);
12757
+ }
12758
+ }
12759
+ return this.notFound(pathname);
12760
+ }
12728
12761
  /**
12729
12762
  * Handle API route requests
12730
12763
  */
@@ -13263,11 +13296,9 @@ class NextDevServer extends DevServer {
13263
13296
  globalCssLinks.push(`<link rel="stylesheet" href="${virtualPrefix}${cssPath}">`);
13264
13297
  }
13265
13298
  }
13266
- const pageModulePath = virtualPrefix + route.page;
13267
- const layoutImports = route.layouts.map((layout, i) => `import Layout${i} from '${virtualPrefix}${layout}';`).join("\n ");
13268
- let nestedJsx = "React.createElement(Page)";
13299
+ virtualPrefix + route.page;
13300
+ route.layouts.map((layout, i) => `import Layout${i} from '${virtualPrefix}${layout}';`).join("\n ");
13269
13301
  for (let i = route.layouts.length - 1; i >= 0; i--) {
13270
- nestedJsx = `React.createElement(Layout${i}, null, ${nestedJsx})`;
13271
13302
  }
13272
13303
  const envScript = this.generateEnvScript();
13273
13304
  return `<!DOCTYPE html>
@@ -13311,17 +13342,117 @@ class NextDevServer extends DevServer {
13311
13342
  <script type="module">
13312
13343
  import React from 'react';
13313
13344
  import ReactDOM from 'react-dom/client';
13314
- import Page from '${pageModulePath}';
13315
- ${layoutImports}
13316
13345
 
13317
- function App() {
13318
- return ${nestedJsx};
13346
+ const virtualBase = '${virtualPrefix}';
13347
+
13348
+ // Convert URL path to app router page module path
13349
+ function getAppPageModulePath(pathname) {
13350
+ let route = pathname;
13351
+ if (route.startsWith(virtualBase)) {
13352
+ route = route.slice(virtualBase.length);
13353
+ }
13354
+ route = route.replace(/^\\/+/, '/') || '/';
13355
+ // App Router: / -> /app/page, /about -> /app/about/page
13356
+ const pagePath = route === '/' ? '/app/page' : '/app' + route + '/page';
13357
+ return virtualBase + '/_next/app' + pagePath + '.js';
13358
+ }
13359
+
13360
+ // Get layout paths for a route
13361
+ function getLayoutPaths(pathname) {
13362
+ let route = pathname;
13363
+ if (route.startsWith(virtualBase)) {
13364
+ route = route.slice(virtualBase.length);
13365
+ }
13366
+ route = route.replace(/^\\/+/, '/') || '/';
13367
+
13368
+ // Build layout paths from root to current route
13369
+ const layouts = [virtualBase + '/_next/app/app/layout.js'];
13370
+ if (route !== '/') {
13371
+ const segments = route.split('/').filter(Boolean);
13372
+ let currentPath = '/app';
13373
+ for (const segment of segments) {
13374
+ currentPath += '/' + segment;
13375
+ layouts.push(virtualBase + '/_next/app' + currentPath + '/layout.js');
13376
+ }
13377
+ }
13378
+ return layouts;
13319
13379
  }
13320
13380
 
13381
+ // Dynamic page loader
13382
+ async function loadPage(pathname) {
13383
+ const modulePath = getAppPageModulePath(pathname);
13384
+ try {
13385
+ const module = await import(/* @vite-ignore */ modulePath);
13386
+ return module.default;
13387
+ } catch (e) {
13388
+ console.error('[Navigation] Failed to load page:', modulePath, e);
13389
+ return null;
13390
+ }
13391
+ }
13392
+
13393
+ // Load layouts (with caching)
13394
+ const layoutCache = new Map();
13395
+ async function loadLayouts(pathname) {
13396
+ const layoutPaths = getLayoutPaths(pathname);
13397
+ const layouts = [];
13398
+ for (const path of layoutPaths) {
13399
+ if (layoutCache.has(path)) {
13400
+ layouts.push(layoutCache.get(path));
13401
+ } else {
13402
+ try {
13403
+ const module = await import(/* @vite-ignore */ path);
13404
+ layoutCache.set(path, module.default);
13405
+ layouts.push(module.default);
13406
+ } catch (e) {
13407
+ // Layout might not exist for this segment, skip
13408
+ }
13409
+ }
13410
+ }
13411
+ return layouts;
13412
+ }
13413
+
13414
+ // Router component
13415
+ function Router() {
13416
+ const [Page, setPage] = React.useState(null);
13417
+ const [layouts, setLayouts] = React.useState([]);
13418
+ const [path, setPath] = React.useState(window.location.pathname);
13419
+
13420
+ React.useEffect(() => {
13421
+ Promise.all([loadPage(path), loadLayouts(path)]).then(([P, L]) => {
13422
+ if (P) setPage(() => P);
13423
+ setLayouts(L);
13424
+ });
13425
+ }, []);
13426
+
13427
+ React.useEffect(() => {
13428
+ const handleNavigation = async () => {
13429
+ const newPath = window.location.pathname;
13430
+ if (newPath !== path) {
13431
+ setPath(newPath);
13432
+ const [P, L] = await Promise.all([loadPage(newPath), loadLayouts(newPath)]);
13433
+ if (P) setPage(() => P);
13434
+ setLayouts(L);
13435
+ }
13436
+ };
13437
+ window.addEventListener('popstate', handleNavigation);
13438
+ return () => window.removeEventListener('popstate', handleNavigation);
13439
+ }, [path]);
13440
+
13441
+ if (!Page) return null;
13442
+
13443
+ // Build nested layout structure
13444
+ let content = React.createElement(Page);
13445
+ for (let i = layouts.length - 1; i >= 0; i--) {
13446
+ content = React.createElement(layouts[i], null, content);
13447
+ }
13448
+ return content;
13449
+ }
13450
+
13451
+ // Mark that we've initialized (for testing no-reload)
13452
+ window.__NEXT_INITIALIZED__ = Date.now();
13453
+
13321
13454
  ReactDOM.createRoot(document.getElementById('__next')).render(
13322
- React.createElement(React.StrictMode, null,
13323
- React.createElement(App)
13324
- )
13455
+ React.createElement(React.StrictMode, null, React.createElement(Router))
13325
13456
  );
13326
13457
  </script>
13327
13458
  </body>
@@ -13419,7 +13550,6 @@ class NextDevServer extends DevServer {
13419
13550
  */
13420
13551
  async generatePageHtml(pageFile, pathname) {
13421
13552
  const virtualPrefix = `/__virtual__/${this.port}`;
13422
- const pageModulePath = virtualPrefix + pageFile;
13423
13553
  const globalCssLinks = [];
13424
13554
  const cssLocations = ["/styles/globals.css", "/styles/global.css", "/app/globals.css"];
13425
13555
  for (const cssPath of cssLocations) {
@@ -13461,30 +13591,63 @@ class NextDevServer extends DevServer {
13461
13591
  <script type="module">
13462
13592
  import React from 'react';
13463
13593
  import ReactDOM from 'react-dom/client';
13464
- import Page from '${pageModulePath}';
13465
13594
 
13466
- // Handle client-side navigation
13467
- function App() {
13468
- const [currentPath, setCurrentPath] = React.useState(window.location.pathname);
13595
+ const virtualBase = '${virtualPrefix}';
13469
13596
 
13470
- React.useEffect(() => {
13471
- const handlePopState = () => {
13472
- setCurrentPath(window.location.pathname);
13473
- // Defer reload outside React's update cycle
13474
- setTimeout(() => window.location.reload(), 0);
13475
- };
13597
+ // Convert URL path to page module path
13598
+ function getPageModulePath(pathname) {
13599
+ let route = pathname;
13600
+ if (route.startsWith(virtualBase)) {
13601
+ route = route.slice(virtualBase.length);
13602
+ }
13603
+ route = route.replace(/^\\/+/, '/') || '/';
13604
+ const modulePath = route === '/' ? '/index' : route;
13605
+ return virtualBase + '/_next/pages' + modulePath + '.js';
13606
+ }
13607
+
13608
+ // Dynamic page loader
13609
+ async function loadPage(pathname) {
13610
+ const modulePath = getPageModulePath(pathname);
13611
+ try {
13612
+ const module = await import(/* @vite-ignore */ modulePath);
13613
+ return module.default;
13614
+ } catch (e) {
13615
+ console.error('[Navigation] Failed to load:', modulePath, e);
13616
+ return null;
13617
+ }
13618
+ }
13619
+
13620
+ // Router component
13621
+ function Router() {
13622
+ const [Page, setPage] = React.useState(null);
13623
+ const [path, setPath] = React.useState(window.location.pathname);
13476
13624
 
13477
- window.addEventListener('popstate', handlePopState);
13478
- return () => window.removeEventListener('popstate', handlePopState);
13625
+ React.useEffect(() => {
13626
+ loadPage(path).then(C => C && setPage(() => C));
13479
13627
  }, []);
13480
13628
 
13629
+ React.useEffect(() => {
13630
+ const handleNavigation = async () => {
13631
+ const newPath = window.location.pathname;
13632
+ if (newPath !== path) {
13633
+ setPath(newPath);
13634
+ const C = await loadPage(newPath);
13635
+ if (C) setPage(() => C);
13636
+ }
13637
+ };
13638
+ window.addEventListener('popstate', handleNavigation);
13639
+ return () => window.removeEventListener('popstate', handleNavigation);
13640
+ }, [path]);
13641
+
13642
+ if (!Page) return null;
13481
13643
  return React.createElement(Page);
13482
13644
  }
13483
13645
 
13646
+ // Mark that we've initialized (for testing no-reload)
13647
+ window.__NEXT_INITIALIZED__ = Date.now();
13648
+
13484
13649
  ReactDOM.createRoot(document.getElementById('__next')).render(
13485
- React.createElement(React.StrictMode, null,
13486
- React.createElement(App)
13487
- )
13650
+ React.createElement(React.StrictMode, null, React.createElement(Router))
13488
13651
  );
13489
13652
  </script>
13490
13653
  </body>