almostnode 0.2.3 → 0.2.5
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/__sw__.js +23 -1
- package/dist/assets/{runtime-worker-D9x_Ddwz.js → runtime-worker-B8_LZkBX.js} +85 -32
- package/dist/assets/runtime-worker-B8_LZkBX.js.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +7 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -1
- package/dist/frameworks/vite-dev-server.d.ts +1 -0
- package/dist/frameworks/vite-dev-server.d.ts.map +1 -1
- package/dist/index.cjs +253 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +258 -44
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/types/package-json.d.ts +16 -0
- package/dist/types/package-json.d.ts.map +1 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +1 -0
- package/dist/virtual-fs.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/frameworks/next-dev-server.ts +162 -8
- package/src/frameworks/vite-dev-server.ts +25 -0
- package/src/runtime.ts +84 -25
- package/src/types/package-json.ts +15 -0
- package/src/utils/hash.ts +12 -0
- package/src/virtual-fs.ts +14 -10
- package/dist/assets/runtime-worker-D9x_Ddwz.js.map +0 -1
|
@@ -55,6 +55,8 @@ export declare class NextDevServer extends DevServer {
|
|
|
55
55
|
private hmrTargetWindow;
|
|
56
56
|
/** Store options for later access (e.g., env vars) */
|
|
57
57
|
private options;
|
|
58
|
+
/** Transform result cache for performance */
|
|
59
|
+
private transformCache;
|
|
58
60
|
constructor(vfs: VirtualFS, options: NextDevServerOptions);
|
|
59
61
|
/**
|
|
60
62
|
* Set an environment variable at runtime
|
|
@@ -96,6 +98,11 @@ export declare class NextDevServer extends DevServer {
|
|
|
96
98
|
* Maps /_next/pages/index.js → /pages/index.jsx (transformed)
|
|
97
99
|
*/
|
|
98
100
|
private servePageComponent;
|
|
101
|
+
/**
|
|
102
|
+
* Serve app components for client-side navigation (App Router)
|
|
103
|
+
* Maps /_next/app/app/about/page.js → /app/about/page.tsx (transformed)
|
|
104
|
+
*/
|
|
105
|
+
private serveAppComponent;
|
|
99
106
|
/**
|
|
100
107
|
* Handle API route requests
|
|
101
108
|
*/
|
|
@@ -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;
|
|
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;AA6DzC,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,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|
private watcherCleanup;
|
|
28
28
|
private options;
|
|
29
29
|
private hmrTargetWindow;
|
|
30
|
+
private transformCache;
|
|
30
31
|
constructor(vfs: VirtualFS, options: ViteDevServerOptions);
|
|
31
32
|
/**
|
|
32
33
|
* Set the target window for HMR updates (typically iframe.contentWindow)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-dev-server.d.ts","sourceRoot":"","sources":["../../src/frameworks/vite-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;
|
|
1
|
+
{"version":3,"file":"vite-dev-server.d.ts","sourceRoot":"","sources":["../../src/frameworks/vite-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;AAsEzC,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAqLD,qBAAa,aAAc,SAAQ,SAAS;IAC1C,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,cAAc,CAA0D;gBAEpE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB;IAWzD;;;OAGG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAIxC;;OAEG;IACG,aAAa,CACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC;IA0ExB;;OAEG;IACH,aAAa,IAAI,IAAI;IAqCrB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA2BxB;;OAEG;IACH,IAAI,IAAI,IAAI;IAWZ;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;YACW,iBAAiB;IAwD/B;;OAEG;YACW,aAAa;IAsC3B;;;OAGG;IACH,OAAO,CAAC,eAAe;IA4DvB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;CAyCzB;AAED,eAAe,aAAa,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,8 @@ class VirtualFS {
|
|
|
41
41
|
constructor() {
|
|
42
42
|
this.root = {
|
|
43
43
|
type: "directory",
|
|
44
|
-
children: /* @__PURE__ */ new Map()
|
|
44
|
+
children: /* @__PURE__ */ new Map(),
|
|
45
|
+
mtime: Date.now()
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
on(event, listener) {
|
|
@@ -148,7 +149,8 @@ class VirtualFS {
|
|
|
148
149
|
const content = typeof data === "string" ? this.encoder.encode(data) : data;
|
|
149
150
|
parent.children.set(basename, {
|
|
150
151
|
type: "file",
|
|
151
|
-
content
|
|
152
|
+
content,
|
|
153
|
+
mtime: Date.now()
|
|
152
154
|
});
|
|
153
155
|
if (emitEvent) {
|
|
154
156
|
this.notifyWatchers(normalized, existed ? "change" : "rename");
|
|
@@ -225,7 +227,7 @@ class VirtualFS {
|
|
|
225
227
|
}
|
|
226
228
|
let child = current.children.get(segment);
|
|
227
229
|
if (!child) {
|
|
228
|
-
child = { type: "directory", children: /* @__PURE__ */ new Map() };
|
|
230
|
+
child = { type: "directory", children: /* @__PURE__ */ new Map(), mtime: Date.now() };
|
|
229
231
|
current.children.set(segment, child);
|
|
230
232
|
} else if (child.type !== "directory") {
|
|
231
233
|
throw new Error(`ENOTDIR: not a directory, '${path}'`);
|
|
@@ -248,8 +250,8 @@ class VirtualFS {
|
|
|
248
250
|
if (!node) {
|
|
249
251
|
throw createNodeError("ENOENT", "stat", path);
|
|
250
252
|
}
|
|
251
|
-
const now = Date.now();
|
|
252
253
|
const size = node.type === "file" ? node.content?.length || 0 : 0;
|
|
254
|
+
const mtime = node.mtime;
|
|
253
255
|
return {
|
|
254
256
|
isFile: () => node.type === "file",
|
|
255
257
|
isDirectory: () => node.type === "directory",
|
|
@@ -260,14 +262,14 @@ class VirtualFS {
|
|
|
260
262
|
isSocket: () => false,
|
|
261
263
|
size,
|
|
262
264
|
mode: node.type === "directory" ? 493 : 420,
|
|
263
|
-
mtime: new Date(
|
|
264
|
-
atime: new Date(
|
|
265
|
-
ctime: new Date(
|
|
266
|
-
birthtime: new Date(
|
|
267
|
-
mtimeMs:
|
|
268
|
-
atimeMs:
|
|
269
|
-
ctimeMs:
|
|
270
|
-
birthtimeMs:
|
|
265
|
+
mtime: new Date(mtime),
|
|
266
|
+
atime: new Date(mtime),
|
|
267
|
+
ctime: new Date(mtime),
|
|
268
|
+
birthtime: new Date(mtime),
|
|
269
|
+
mtimeMs: mtime,
|
|
270
|
+
atimeMs: mtime,
|
|
271
|
+
ctimeMs: mtime,
|
|
272
|
+
birthtimeMs: mtime,
|
|
271
273
|
nlink: 1,
|
|
272
274
|
uid: 1e3,
|
|
273
275
|
gid: 1e3,
|
|
@@ -330,7 +332,8 @@ class VirtualFS {
|
|
|
330
332
|
}
|
|
331
333
|
parent.children.set(basename, {
|
|
332
334
|
type: "directory",
|
|
333
|
-
children: /* @__PURE__ */ new Map()
|
|
335
|
+
children: /* @__PURE__ */ new Map(),
|
|
336
|
+
mtime: Date.now()
|
|
334
337
|
});
|
|
335
338
|
}
|
|
336
339
|
/**
|
|
@@ -664,6 +667,15 @@ class VirtualFS {
|
|
|
664
667
|
}
|
|
665
668
|
}
|
|
666
669
|
|
|
670
|
+
function simpleHash(str) {
|
|
671
|
+
let hash = 0;
|
|
672
|
+
for (let i = 0; i < str.length; i++) {
|
|
673
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
674
|
+
hash |= 0;
|
|
675
|
+
}
|
|
676
|
+
return hash.toString(36);
|
|
677
|
+
}
|
|
678
|
+
|
|
667
679
|
class Dirent {
|
|
668
680
|
name;
|
|
669
681
|
_isDirectory;
|
|
@@ -9070,7 +9082,23 @@ const builtinModules = {
|
|
|
9070
9082
|
"@sentry/node": sentryShim,
|
|
9071
9083
|
"@sentry/core": sentryShim
|
|
9072
9084
|
};
|
|
9073
|
-
function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
9085
|
+
function createRequire(vfs, fsShim, process, currentDir, moduleCache, options, processedCodeCache) {
|
|
9086
|
+
const resolutionCache = /* @__PURE__ */ new Map();
|
|
9087
|
+
const packageJsonCache = /* @__PURE__ */ new Map();
|
|
9088
|
+
const getParsedPackageJson = (pkgPath) => {
|
|
9089
|
+
if (packageJsonCache.has(pkgPath)) {
|
|
9090
|
+
return packageJsonCache.get(pkgPath);
|
|
9091
|
+
}
|
|
9092
|
+
try {
|
|
9093
|
+
const content = vfs.readFileSync(pkgPath, "utf8");
|
|
9094
|
+
const parsed = JSON.parse(content);
|
|
9095
|
+
packageJsonCache.set(pkgPath, parsed);
|
|
9096
|
+
return parsed;
|
|
9097
|
+
} catch {
|
|
9098
|
+
packageJsonCache.set(pkgPath, null);
|
|
9099
|
+
return null;
|
|
9100
|
+
}
|
|
9101
|
+
};
|
|
9074
9102
|
const resolveModule = (id, fromDir) => {
|
|
9075
9103
|
if (id.startsWith("node:")) {
|
|
9076
9104
|
id = id.slice(5);
|
|
@@ -9078,15 +9106,25 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
|
9078
9106
|
if (builtinModules[id] || id === "fs" || id === "process" || id === "url" || id === "querystring" || id === "util") {
|
|
9079
9107
|
return id;
|
|
9080
9108
|
}
|
|
9109
|
+
const cacheKey = `${fromDir}|${id}`;
|
|
9110
|
+
const cached = resolutionCache.get(cacheKey);
|
|
9111
|
+
if (cached !== void 0) {
|
|
9112
|
+
if (cached === null) {
|
|
9113
|
+
throw new Error(`Cannot find module '${id}'`);
|
|
9114
|
+
}
|
|
9115
|
+
return cached;
|
|
9116
|
+
}
|
|
9081
9117
|
if (id.startsWith("./") || id.startsWith("../") || id.startsWith("/")) {
|
|
9082
9118
|
const resolved = id.startsWith("/") ? id : resolve$2(fromDir, id);
|
|
9083
9119
|
if (vfs.existsSync(resolved)) {
|
|
9084
9120
|
const stats = vfs.statSync(resolved);
|
|
9085
9121
|
if (stats.isFile()) {
|
|
9122
|
+
resolutionCache.set(cacheKey, resolved);
|
|
9086
9123
|
return resolved;
|
|
9087
9124
|
}
|
|
9088
9125
|
const indexPath = join(resolved, "index.js");
|
|
9089
9126
|
if (vfs.existsSync(indexPath)) {
|
|
9127
|
+
resolutionCache.set(cacheKey, indexPath);
|
|
9090
9128
|
return indexPath;
|
|
9091
9129
|
}
|
|
9092
9130
|
}
|
|
@@ -9094,9 +9132,11 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
|
9094
9132
|
for (const ext of extensions) {
|
|
9095
9133
|
const withExt = resolved + ext;
|
|
9096
9134
|
if (vfs.existsSync(withExt)) {
|
|
9135
|
+
resolutionCache.set(cacheKey, withExt);
|
|
9097
9136
|
return withExt;
|
|
9098
9137
|
}
|
|
9099
9138
|
}
|
|
9139
|
+
resolutionCache.set(cacheKey, null);
|
|
9100
9140
|
throw new Error(`Cannot find module '${id}' from '${fromDir}'`);
|
|
9101
9141
|
}
|
|
9102
9142
|
const tryResolveFile = (basePath) => {
|
|
@@ -9127,9 +9167,8 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
|
9127
9167
|
const pkgName = parts[0].startsWith("@") && parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
9128
9168
|
const pkgRoot = join(nodeModulesDir, pkgName);
|
|
9129
9169
|
const pkgPath = join(pkgRoot, "package.json");
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
const pkg = JSON.parse(pkgContent);
|
|
9170
|
+
const pkg = getParsedPackageJson(pkgPath);
|
|
9171
|
+
if (pkg) {
|
|
9133
9172
|
if (pkg.exports) {
|
|
9134
9173
|
try {
|
|
9135
9174
|
const resolved2 = resolve_exports.resolve(pkg, moduleId, { require: true });
|
|
@@ -9155,11 +9194,18 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
|
9155
9194
|
while (searchDir !== "/") {
|
|
9156
9195
|
const nodeModulesDir = join(searchDir, "node_modules");
|
|
9157
9196
|
const resolved = tryResolveFromNodeModules(nodeModulesDir, id);
|
|
9158
|
-
if (resolved)
|
|
9197
|
+
if (resolved) {
|
|
9198
|
+
resolutionCache.set(cacheKey, resolved);
|
|
9199
|
+
return resolved;
|
|
9200
|
+
}
|
|
9159
9201
|
searchDir = dirname(searchDir);
|
|
9160
9202
|
}
|
|
9161
9203
|
const rootResolved = tryResolveFromNodeModules("/node_modules", id);
|
|
9162
|
-
if (rootResolved)
|
|
9204
|
+
if (rootResolved) {
|
|
9205
|
+
resolutionCache.set(cacheKey, rootResolved);
|
|
9206
|
+
return rootResolved;
|
|
9207
|
+
}
|
|
9208
|
+
resolutionCache.set(cacheKey, null);
|
|
9163
9209
|
throw new Error(`Cannot find module '${id}'`);
|
|
9164
9210
|
};
|
|
9165
9211
|
const loadModule = (resolvedPath) => {
|
|
@@ -9181,25 +9227,32 @@ function createRequire(vfs, fsShim, process, currentDir, moduleCache, options) {
|
|
|
9181
9227
|
module.loaded = true;
|
|
9182
9228
|
return module;
|
|
9183
9229
|
}
|
|
9184
|
-
|
|
9230
|
+
const rawCode = vfs.readFileSync(resolvedPath, "utf8");
|
|
9185
9231
|
const dirname$1 = dirname(resolvedPath);
|
|
9186
|
-
const
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9232
|
+
const codeCacheKey = `${resolvedPath}|${simpleHash(rawCode)}`;
|
|
9233
|
+
let code = processedCodeCache?.get(codeCacheKey);
|
|
9234
|
+
if (!code) {
|
|
9235
|
+
code = rawCode;
|
|
9236
|
+
const isCjsFile = resolvedPath.endsWith(".cjs");
|
|
9237
|
+
const isAlreadyBundledCjs = code.startsWith('"use strict";\nvar __') || code.startsWith("'use strict';\nvar __");
|
|
9238
|
+
const hasEsmImport = /\bimport\s+[\w{*'"]/m.test(code);
|
|
9239
|
+
const hasEsmExport = /\bexport\s+(?:default|const|let|var|function|class|{|\*)/m.test(code);
|
|
9240
|
+
if (!isCjsFile && !isAlreadyBundledCjs) {
|
|
9241
|
+
if (resolvedPath.endsWith(".mjs") || resolvedPath.includes("/esm/") || hasEsmImport || hasEsmExport) {
|
|
9242
|
+
code = transformEsmToCjs(code, resolvedPath);
|
|
9243
|
+
}
|
|
9193
9244
|
}
|
|
9245
|
+
code = transformDynamicImports(code);
|
|
9246
|
+
processedCodeCache?.set(codeCacheKey, code);
|
|
9194
9247
|
}
|
|
9195
|
-
code = transformDynamicImports(code);
|
|
9196
9248
|
const moduleRequire = createRequire(
|
|
9197
9249
|
vfs,
|
|
9198
9250
|
fsShim,
|
|
9199
9251
|
process,
|
|
9200
9252
|
dirname$1,
|
|
9201
9253
|
moduleCache,
|
|
9202
|
-
options
|
|
9254
|
+
options,
|
|
9255
|
+
processedCodeCache
|
|
9203
9256
|
);
|
|
9204
9257
|
moduleRequire.cache = moduleCache;
|
|
9205
9258
|
const consoleWrapper = createConsoleWrapper(options.onConsole);
|
|
@@ -9382,6 +9435,8 @@ class Runtime {
|
|
|
9382
9435
|
process;
|
|
9383
9436
|
moduleCache = {};
|
|
9384
9437
|
options;
|
|
9438
|
+
/** Cache for pre-processed code (after ESM transform) before eval */
|
|
9439
|
+
processedCodeCache = /* @__PURE__ */ new Map();
|
|
9385
9440
|
constructor(vfs2, options2 = {}) {
|
|
9386
9441
|
this.vfs = vfs2;
|
|
9387
9442
|
this.process = createProcess({
|
|
@@ -9475,7 +9530,8 @@ class Runtime {
|
|
|
9475
9530
|
this.process,
|
|
9476
9531
|
dirname$1,
|
|
9477
9532
|
this.moduleCache,
|
|
9478
|
-
this.options
|
|
9533
|
+
this.options,
|
|
9534
|
+
this.processedCodeCache
|
|
9479
9535
|
);
|
|
9480
9536
|
const module = {
|
|
9481
9537
|
id: filename,
|
|
@@ -9589,7 +9645,7 @@ class WorkerRuntime {
|
|
|
9589
9645
|
this.vfs = vfs;
|
|
9590
9646
|
this.options = options;
|
|
9591
9647
|
this.worker = new Worker(
|
|
9592
|
-
new URL(/* @vite-ignore */ "/assets/runtime-worker-
|
|
9648
|
+
new URL(/* @vite-ignore */ "/assets/runtime-worker-B8_LZkBX.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),
|
|
9593
9649
|
{ type: "module" }
|
|
9594
9650
|
);
|
|
9595
9651
|
this.workerApi = comlink.wrap(this.worker);
|
|
@@ -11677,6 +11733,7 @@ class ViteDevServer extends DevServer {
|
|
|
11677
11733
|
watcherCleanup = null;
|
|
11678
11734
|
options;
|
|
11679
11735
|
hmrTargetWindow = null;
|
|
11736
|
+
transformCache = /* @__PURE__ */ new Map();
|
|
11680
11737
|
constructor(vfs, options) {
|
|
11681
11738
|
super(vfs, options);
|
|
11682
11739
|
this.options = {
|
|
@@ -11810,7 +11867,25 @@ class ViteDevServer extends DevServer {
|
|
|
11810
11867
|
async transformAndServe(filePath, urlPath) {
|
|
11811
11868
|
try {
|
|
11812
11869
|
const content = this.vfs.readFileSync(filePath, "utf8");
|
|
11870
|
+
const hash = simpleHash(content);
|
|
11871
|
+
const cached = this.transformCache.get(filePath);
|
|
11872
|
+
if (cached && cached.hash === hash) {
|
|
11873
|
+
const buffer2 = BufferPolyfill.from(cached.code);
|
|
11874
|
+
return {
|
|
11875
|
+
statusCode: 200,
|
|
11876
|
+
statusMessage: "OK",
|
|
11877
|
+
headers: {
|
|
11878
|
+
"Content-Type": "application/javascript; charset=utf-8",
|
|
11879
|
+
"Content-Length": String(buffer2.length),
|
|
11880
|
+
"Cache-Control": "no-cache",
|
|
11881
|
+
"X-Transformed": "true",
|
|
11882
|
+
"X-Cache": "hit"
|
|
11883
|
+
},
|
|
11884
|
+
body: buffer2
|
|
11885
|
+
};
|
|
11886
|
+
}
|
|
11813
11887
|
const transformed = await this.transformCode(content, urlPath);
|
|
11888
|
+
this.transformCache.set(filePath, { code: transformed, hash });
|
|
11814
11889
|
const buffer = BufferPolyfill.from(transformed);
|
|
11815
11890
|
return {
|
|
11816
11891
|
statusCode: 200,
|
|
@@ -12589,6 +12664,8 @@ class NextDevServer extends DevServer {
|
|
|
12589
12664
|
hmrTargetWindow = null;
|
|
12590
12665
|
/** Store options for later access (e.g., env vars) */
|
|
12591
12666
|
options;
|
|
12667
|
+
/** Transform result cache for performance */
|
|
12668
|
+
transformCache = /* @__PURE__ */ new Map();
|
|
12592
12669
|
constructor(vfs, options) {
|
|
12593
12670
|
super(vfs, options);
|
|
12594
12671
|
this.options = options;
|
|
@@ -12666,6 +12743,9 @@ class NextDevServer extends DevServer {
|
|
|
12666
12743
|
if (pathname.startsWith("/_next/pages/")) {
|
|
12667
12744
|
return this.servePageComponent(pathname);
|
|
12668
12745
|
}
|
|
12746
|
+
if (pathname.startsWith("/_next/app/")) {
|
|
12747
|
+
return this.serveAppComponent(pathname);
|
|
12748
|
+
}
|
|
12669
12749
|
if (pathname.startsWith("/_next/static/")) {
|
|
12670
12750
|
return this.serveStaticAsset(pathname);
|
|
12671
12751
|
}
|
|
@@ -12740,6 +12820,21 @@ class NextDevServer extends DevServer {
|
|
|
12740
12820
|
}
|
|
12741
12821
|
return this.transformAndServe(pageFile, pageFile);
|
|
12742
12822
|
}
|
|
12823
|
+
/**
|
|
12824
|
+
* Serve app components for client-side navigation (App Router)
|
|
12825
|
+
* Maps /_next/app/app/about/page.js → /app/about/page.tsx (transformed)
|
|
12826
|
+
*/
|
|
12827
|
+
async serveAppComponent(pathname) {
|
|
12828
|
+
const filePath = pathname.replace("/_next/app", "").replace(/\.js$/, "");
|
|
12829
|
+
const extensions = [".tsx", ".jsx", ".ts", ".js"];
|
|
12830
|
+
for (const ext of extensions) {
|
|
12831
|
+
const fullPath = filePath + ext;
|
|
12832
|
+
if (this.exists(fullPath)) {
|
|
12833
|
+
return this.transformAndServe(fullPath, fullPath);
|
|
12834
|
+
}
|
|
12835
|
+
}
|
|
12836
|
+
return this.notFound(pathname);
|
|
12837
|
+
}
|
|
12743
12838
|
/**
|
|
12744
12839
|
* Handle API route requests
|
|
12745
12840
|
*/
|
|
@@ -13278,11 +13373,9 @@ class NextDevServer extends DevServer {
|
|
|
13278
13373
|
globalCssLinks.push(`<link rel="stylesheet" href="${virtualPrefix}${cssPath}">`);
|
|
13279
13374
|
}
|
|
13280
13375
|
}
|
|
13281
|
-
|
|
13282
|
-
|
|
13283
|
-
let nestedJsx = "React.createElement(Page)";
|
|
13376
|
+
virtualPrefix + route.page;
|
|
13377
|
+
route.layouts.map((layout, i) => `import Layout${i} from '${virtualPrefix}${layout}';`).join("\n ");
|
|
13284
13378
|
for (let i = route.layouts.length - 1; i >= 0; i--) {
|
|
13285
|
-
nestedJsx = `React.createElement(Layout${i}, null, ${nestedJsx})`;
|
|
13286
13379
|
}
|
|
13287
13380
|
const envScript = this.generateEnvScript();
|
|
13288
13381
|
return `<!DOCTYPE html>
|
|
@@ -13326,17 +13419,117 @@ class NextDevServer extends DevServer {
|
|
|
13326
13419
|
<script type="module">
|
|
13327
13420
|
import React from 'react';
|
|
13328
13421
|
import ReactDOM from 'react-dom/client';
|
|
13329
|
-
import Page from '${pageModulePath}';
|
|
13330
|
-
${layoutImports}
|
|
13331
13422
|
|
|
13332
|
-
|
|
13333
|
-
|
|
13423
|
+
const virtualBase = '${virtualPrefix}';
|
|
13424
|
+
|
|
13425
|
+
// Convert URL path to app router page module path
|
|
13426
|
+
function getAppPageModulePath(pathname) {
|
|
13427
|
+
let route = pathname;
|
|
13428
|
+
if (route.startsWith(virtualBase)) {
|
|
13429
|
+
route = route.slice(virtualBase.length);
|
|
13430
|
+
}
|
|
13431
|
+
route = route.replace(/^\\/+/, '/') || '/';
|
|
13432
|
+
// App Router: / -> /app/page, /about -> /app/about/page
|
|
13433
|
+
const pagePath = route === '/' ? '/app/page' : '/app' + route + '/page';
|
|
13434
|
+
return virtualBase + '/_next/app' + pagePath + '.js';
|
|
13435
|
+
}
|
|
13436
|
+
|
|
13437
|
+
// Get layout paths for a route
|
|
13438
|
+
function getLayoutPaths(pathname) {
|
|
13439
|
+
let route = pathname;
|
|
13440
|
+
if (route.startsWith(virtualBase)) {
|
|
13441
|
+
route = route.slice(virtualBase.length);
|
|
13442
|
+
}
|
|
13443
|
+
route = route.replace(/^\\/+/, '/') || '/';
|
|
13444
|
+
|
|
13445
|
+
// Build layout paths from root to current route
|
|
13446
|
+
const layouts = [virtualBase + '/_next/app/app/layout.js'];
|
|
13447
|
+
if (route !== '/') {
|
|
13448
|
+
const segments = route.split('/').filter(Boolean);
|
|
13449
|
+
let currentPath = '/app';
|
|
13450
|
+
for (const segment of segments) {
|
|
13451
|
+
currentPath += '/' + segment;
|
|
13452
|
+
layouts.push(virtualBase + '/_next/app' + currentPath + '/layout.js');
|
|
13453
|
+
}
|
|
13454
|
+
}
|
|
13455
|
+
return layouts;
|
|
13456
|
+
}
|
|
13457
|
+
|
|
13458
|
+
// Dynamic page loader
|
|
13459
|
+
async function loadPage(pathname) {
|
|
13460
|
+
const modulePath = getAppPageModulePath(pathname);
|
|
13461
|
+
try {
|
|
13462
|
+
const module = await import(/* @vite-ignore */ modulePath);
|
|
13463
|
+
return module.default;
|
|
13464
|
+
} catch (e) {
|
|
13465
|
+
console.error('[Navigation] Failed to load page:', modulePath, e);
|
|
13466
|
+
return null;
|
|
13467
|
+
}
|
|
13468
|
+
}
|
|
13469
|
+
|
|
13470
|
+
// Load layouts (with caching)
|
|
13471
|
+
const layoutCache = new Map();
|
|
13472
|
+
async function loadLayouts(pathname) {
|
|
13473
|
+
const layoutPaths = getLayoutPaths(pathname);
|
|
13474
|
+
const layouts = [];
|
|
13475
|
+
for (const path of layoutPaths) {
|
|
13476
|
+
if (layoutCache.has(path)) {
|
|
13477
|
+
layouts.push(layoutCache.get(path));
|
|
13478
|
+
} else {
|
|
13479
|
+
try {
|
|
13480
|
+
const module = await import(/* @vite-ignore */ path);
|
|
13481
|
+
layoutCache.set(path, module.default);
|
|
13482
|
+
layouts.push(module.default);
|
|
13483
|
+
} catch (e) {
|
|
13484
|
+
// Layout might not exist for this segment, skip
|
|
13485
|
+
}
|
|
13486
|
+
}
|
|
13487
|
+
}
|
|
13488
|
+
return layouts;
|
|
13334
13489
|
}
|
|
13335
13490
|
|
|
13491
|
+
// Router component
|
|
13492
|
+
function Router() {
|
|
13493
|
+
const [Page, setPage] = React.useState(null);
|
|
13494
|
+
const [layouts, setLayouts] = React.useState([]);
|
|
13495
|
+
const [path, setPath] = React.useState(window.location.pathname);
|
|
13496
|
+
|
|
13497
|
+
React.useEffect(() => {
|
|
13498
|
+
Promise.all([loadPage(path), loadLayouts(path)]).then(([P, L]) => {
|
|
13499
|
+
if (P) setPage(() => P);
|
|
13500
|
+
setLayouts(L);
|
|
13501
|
+
});
|
|
13502
|
+
}, []);
|
|
13503
|
+
|
|
13504
|
+
React.useEffect(() => {
|
|
13505
|
+
const handleNavigation = async () => {
|
|
13506
|
+
const newPath = window.location.pathname;
|
|
13507
|
+
if (newPath !== path) {
|
|
13508
|
+
setPath(newPath);
|
|
13509
|
+
const [P, L] = await Promise.all([loadPage(newPath), loadLayouts(newPath)]);
|
|
13510
|
+
if (P) setPage(() => P);
|
|
13511
|
+
setLayouts(L);
|
|
13512
|
+
}
|
|
13513
|
+
};
|
|
13514
|
+
window.addEventListener('popstate', handleNavigation);
|
|
13515
|
+
return () => window.removeEventListener('popstate', handleNavigation);
|
|
13516
|
+
}, [path]);
|
|
13517
|
+
|
|
13518
|
+
if (!Page) return null;
|
|
13519
|
+
|
|
13520
|
+
// Build nested layout structure
|
|
13521
|
+
let content = React.createElement(Page);
|
|
13522
|
+
for (let i = layouts.length - 1; i >= 0; i--) {
|
|
13523
|
+
content = React.createElement(layouts[i], null, content);
|
|
13524
|
+
}
|
|
13525
|
+
return content;
|
|
13526
|
+
}
|
|
13527
|
+
|
|
13528
|
+
// Mark that we've initialized (for testing no-reload)
|
|
13529
|
+
window.__NEXT_INITIALIZED__ = Date.now();
|
|
13530
|
+
|
|
13336
13531
|
ReactDOM.createRoot(document.getElementById('__next')).render(
|
|
13337
|
-
React.createElement(React.StrictMode, null,
|
|
13338
|
-
React.createElement(App)
|
|
13339
|
-
)
|
|
13532
|
+
React.createElement(React.StrictMode, null, React.createElement(Router))
|
|
13340
13533
|
);
|
|
13341
13534
|
</script>
|
|
13342
13535
|
</body>
|
|
@@ -13595,7 +13788,25 @@ class NextDevServer extends DevServer {
|
|
|
13595
13788
|
async transformAndServe(filePath, urlPath) {
|
|
13596
13789
|
try {
|
|
13597
13790
|
const content = this.vfs.readFileSync(filePath, "utf8");
|
|
13791
|
+
const hash = simpleHash(content);
|
|
13792
|
+
const cached = this.transformCache.get(filePath);
|
|
13793
|
+
if (cached && cached.hash === hash) {
|
|
13794
|
+
const buffer2 = BufferPolyfill.from(cached.code);
|
|
13795
|
+
return {
|
|
13796
|
+
statusCode: 200,
|
|
13797
|
+
statusMessage: "OK",
|
|
13798
|
+
headers: {
|
|
13799
|
+
"Content-Type": "application/javascript; charset=utf-8",
|
|
13800
|
+
"Content-Length": String(buffer2.length),
|
|
13801
|
+
"Cache-Control": "no-cache",
|
|
13802
|
+
"X-Transformed": "true",
|
|
13803
|
+
"X-Cache": "hit"
|
|
13804
|
+
},
|
|
13805
|
+
body: buffer2
|
|
13806
|
+
};
|
|
13807
|
+
}
|
|
13598
13808
|
const transformed = await this.transformCode(content, urlPath);
|
|
13809
|
+
this.transformCache.set(filePath, { code: transformed, hash });
|
|
13599
13810
|
const buffer = BufferPolyfill.from(transformed);
|
|
13600
13811
|
return {
|
|
13601
13812
|
statusCode: 200,
|