almostnode 0.2.4 → 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 +2 -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 +126 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +130 -33
- 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 +27 -0
- 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
|
|
@@ -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,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;IACzC,OAAO,CAAC,cAAc,CAA6B;IAEnD,2DAA2D;IAC3D,OAAO,CAAC,eAAe,CAAuB;IAE9C,sDAAsD;IACtD,OAAO,CAAC,OAA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6GnC;;OAEG;IACH,OAAO,CAAC,cAAc;IAwBtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;OAEG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAkG1B;;OAEG;YACW,iBAAiB;IA2E/B;;OAEG;YACW,eAAe;IA6C7B;;OAEG;YACW,mBAAmB;IAkCjC;;OAEG;IACH,OAAO,CAAC,eAAe;IA2CvB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAuE9B;;OAEG;YACW,qBAAqB;IA8LnC;;OAEG;IACH,OAAO,CAAC,eAAe;IA4BvB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAsF3B;;OAEG;YACW,gBAAgB;IAmH9B;;OAEG;IACH,OAAO,CAAC,YAAY;IA6CpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;YACW,iBAAiB;IAwD/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"}
|
|
@@ -27,6 +27,7 @@ export declare class ViteDevServer extends DevServer {
|
|
|
27
27
|
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,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BxB;;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;
|
|
@@ -13711,7 +13788,25 @@ class NextDevServer extends DevServer {
|
|
|
13711
13788
|
async transformAndServe(filePath, urlPath) {
|
|
13712
13789
|
try {
|
|
13713
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
|
+
}
|
|
13714
13808
|
const transformed = await this.transformCode(content, urlPath);
|
|
13809
|
+
this.transformCache.set(filePath, { code: transformed, hash });
|
|
13715
13810
|
const buffer = BufferPolyfill.from(transformed);
|
|
13716
13811
|
return {
|
|
13717
13812
|
statusCode: 200,
|