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
package/dist/runtime.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare class Runtime {
|
|
|
36
36
|
private process;
|
|
37
37
|
private moduleCache;
|
|
38
38
|
private options;
|
|
39
|
+
/** Cache for pre-processed code (after ESM transform) before eval */
|
|
40
|
+
private processedCodeCache;
|
|
39
41
|
constructor(vfs: VirtualFS, options?: RuntimeOptions);
|
|
40
42
|
/**
|
|
41
43
|
* Set up a polyfilled TextDecoder that handles binary encodings
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAY,cAAc,EAAmB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAY,cAAc,EAAmB,MAAM,qBAAqB,CAAC;AAKrF,OAAO,EAAiB,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAqLzD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAqmBD;;;;GAIG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,GAAG,CAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAU;IACzB,OA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EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAErF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for package.json files
|
|
3
|
+
*/
|
|
4
|
+
export interface PackageJson {
|
|
5
|
+
name?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
main?: string;
|
|
8
|
+
module?: string;
|
|
9
|
+
types?: string;
|
|
10
|
+
exports?: Record<string, unknown> | string;
|
|
11
|
+
dependencies?: Record<string, string>;
|
|
12
|
+
devDependencies?: Record<string, string>;
|
|
13
|
+
peerDependencies?: Record<string, string>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=package-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../../src/types/package-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C"}
|
package/dist/virtual-fs.d.ts
CHANGED
package/dist/virtual-fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-fs.d.ts","sourceRoot":"","sources":["../src/virtual-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAErE,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"virtual-fs.d.ts","sourceRoot":"","sources":["../src/virtual-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAErE,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,KAAK,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AACjE,KAAK,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAGhD,MAAM,WAAW,KAAK;IACpB,MAAM,IAAI,OAAO,CAAC;IAClB,WAAW,IAAI,OAAO,CAAC;IACvB,cAAc,IAAI,OAAO,CAAC;IAC1B,aAAa,IAAI,OAAO,CAAC;IACzB,iBAAiB,IAAI,OAAO,CAAC;IAC7B,MAAM,IAAI,OAAO,CAAC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,MAAM,GAAG,IAAI;IAK7C;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;QAC9B,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;QAC9D,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;KAClC;IA6BD;;OAEG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG;QAC/B,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,KAAK,OAAO,CAAC;QAC9C,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,KAAK,IAAI,CAAC;QAC1C,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;KAC/D;CAoCF"}
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { DevServer, DevServerOptions, ResponseData, HMRUpdate } from '../dev-server';
|
|
7
7
|
import { VirtualFS } from '../virtual-fs';
|
|
8
8
|
import { Buffer } from '../shims/stream';
|
|
9
|
+
import { simpleHash } from '../utils/hash';
|
|
9
10
|
|
|
10
11
|
// Check if we're in a real browser environment (not jsdom or Node.js)
|
|
11
12
|
const isBrowser = typeof window !== 'undefined' &&
|
|
@@ -714,6 +715,9 @@ export class NextDevServer extends DevServer {
|
|
|
714
715
|
/** Store options for later access (e.g., env vars) */
|
|
715
716
|
private options: NextDevServerOptions;
|
|
716
717
|
|
|
718
|
+
/** Transform result cache for performance */
|
|
719
|
+
private transformCache: Map<string, { code: string; hash: string }> = new Map();
|
|
720
|
+
|
|
717
721
|
constructor(vfs: VirtualFS, options: NextDevServerOptions) {
|
|
718
722
|
super(vfs, options);
|
|
719
723
|
this.options = options;
|
|
@@ -2115,8 +2119,31 @@ export class NextDevServer extends DevServer {
|
|
|
2115
2119
|
private async transformAndServe(filePath: string, urlPath: string): Promise<ResponseData> {
|
|
2116
2120
|
try {
|
|
2117
2121
|
const content = this.vfs.readFileSync(filePath, 'utf8');
|
|
2122
|
+
const hash = simpleHash(content);
|
|
2123
|
+
|
|
2124
|
+
// Check transform cache
|
|
2125
|
+
const cached = this.transformCache.get(filePath);
|
|
2126
|
+
if (cached && cached.hash === hash) {
|
|
2127
|
+
const buffer = Buffer.from(cached.code);
|
|
2128
|
+
return {
|
|
2129
|
+
statusCode: 200,
|
|
2130
|
+
statusMessage: 'OK',
|
|
2131
|
+
headers: {
|
|
2132
|
+
'Content-Type': 'application/javascript; charset=utf-8',
|
|
2133
|
+
'Content-Length': String(buffer.length),
|
|
2134
|
+
'Cache-Control': 'no-cache',
|
|
2135
|
+
'X-Transformed': 'true',
|
|
2136
|
+
'X-Cache': 'hit',
|
|
2137
|
+
},
|
|
2138
|
+
body: buffer,
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2118
2142
|
const transformed = await this.transformCode(content, urlPath);
|
|
2119
2143
|
|
|
2144
|
+
// Cache the transform result
|
|
2145
|
+
this.transformCache.set(filePath, { code: transformed, hash });
|
|
2146
|
+
|
|
2120
2147
|
const buffer = Buffer.from(transformed);
|
|
2121
2148
|
return {
|
|
2122
2149
|
statusCode: 200,
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { DevServer, DevServerOptions, ResponseData, HMRUpdate } from '../dev-server';
|
|
7
7
|
import { VirtualFS } from '../virtual-fs';
|
|
8
8
|
import { Buffer } from '../shims/stream';
|
|
9
|
+
import { simpleHash } from '../utils/hash';
|
|
9
10
|
|
|
10
11
|
// Check if we're in a real browser environment (not jsdom or Node.js)
|
|
11
12
|
// jsdom has window but doesn't have ServiceWorker or SharedArrayBuffer
|
|
@@ -279,6 +280,7 @@ export class ViteDevServer extends DevServer {
|
|
|
279
280
|
private watcherCleanup: (() => void) | null = null;
|
|
280
281
|
private options: ViteDevServerOptions;
|
|
281
282
|
private hmrTargetWindow: Window | null = null;
|
|
283
|
+
private transformCache: Map<string, { code: string; hash: string }> = new Map();
|
|
282
284
|
|
|
283
285
|
constructor(vfs: VirtualFS, options: ViteDevServerOptions) {
|
|
284
286
|
super(vfs, options);
|
|
@@ -478,8 +480,31 @@ export class ViteDevServer extends DevServer {
|
|
|
478
480
|
private async transformAndServe(filePath: string, urlPath: string): Promise<ResponseData> {
|
|
479
481
|
try {
|
|
480
482
|
const content = this.vfs.readFileSync(filePath, 'utf8');
|
|
483
|
+
const hash = simpleHash(content);
|
|
484
|
+
|
|
485
|
+
// Check transform cache
|
|
486
|
+
const cached = this.transformCache.get(filePath);
|
|
487
|
+
if (cached && cached.hash === hash) {
|
|
488
|
+
const buffer = Buffer.from(cached.code);
|
|
489
|
+
return {
|
|
490
|
+
statusCode: 200,
|
|
491
|
+
statusMessage: 'OK',
|
|
492
|
+
headers: {
|
|
493
|
+
'Content-Type': 'application/javascript; charset=utf-8',
|
|
494
|
+
'Content-Length': String(buffer.length),
|
|
495
|
+
'Cache-Control': 'no-cache',
|
|
496
|
+
'X-Transformed': 'true',
|
|
497
|
+
'X-Cache': 'hit',
|
|
498
|
+
},
|
|
499
|
+
body: buffer,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
481
503
|
const transformed = await this.transformCode(content, urlPath);
|
|
482
504
|
|
|
505
|
+
// Cache the transform result
|
|
506
|
+
this.transformCache.set(filePath, { code: transformed, hash });
|
|
507
|
+
|
|
483
508
|
const buffer = Buffer.from(transformed);
|
|
484
509
|
return {
|
|
485
510
|
statusCode: 200,
|
package/src/runtime.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import { VirtualFS } from './virtual-fs';
|
|
9
9
|
import type { IRuntime, IExecuteResult, IRuntimeOptions } from './runtime-interface';
|
|
10
|
+
import type { PackageJson } from './types/package-json';
|
|
11
|
+
import { simpleHash } from './utils/hash';
|
|
10
12
|
import { createFsShim, FsShim } from './shims/fs';
|
|
11
13
|
import * as pathShim from './shims/path';
|
|
12
14
|
import { createProcess, Process } from './shims/process';
|
|
@@ -347,8 +349,30 @@ function createRequire(
|
|
|
347
349
|
process: Process,
|
|
348
350
|
currentDir: string,
|
|
349
351
|
moduleCache: Record<string, Module>,
|
|
350
|
-
options: RuntimeOptions
|
|
352
|
+
options: RuntimeOptions,
|
|
353
|
+
processedCodeCache?: Map<string, string>
|
|
351
354
|
): RequireFunction {
|
|
355
|
+
// Module resolution cache for faster repeated imports
|
|
356
|
+
const resolutionCache: Map<string, string | null> = new Map();
|
|
357
|
+
|
|
358
|
+
// Package.json parsing cache
|
|
359
|
+
const packageJsonCache: Map<string, PackageJson | null> = new Map();
|
|
360
|
+
|
|
361
|
+
const getParsedPackageJson = (pkgPath: string): PackageJson | null => {
|
|
362
|
+
if (packageJsonCache.has(pkgPath)) {
|
|
363
|
+
return packageJsonCache.get(pkgPath)!;
|
|
364
|
+
}
|
|
365
|
+
try {
|
|
366
|
+
const content = vfs.readFileSync(pkgPath, 'utf8');
|
|
367
|
+
const parsed = JSON.parse(content) as PackageJson;
|
|
368
|
+
packageJsonCache.set(pkgPath, parsed);
|
|
369
|
+
return parsed;
|
|
370
|
+
} catch {
|
|
371
|
+
packageJsonCache.set(pkgPath, null);
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
352
376
|
const resolveModule = (id: string, fromDir: string): string => {
|
|
353
377
|
// Handle node: protocol prefix (Node.js 16+)
|
|
354
378
|
if (id.startsWith('node:')) {
|
|
@@ -360,6 +384,16 @@ function createRequire(
|
|
|
360
384
|
return id;
|
|
361
385
|
}
|
|
362
386
|
|
|
387
|
+
// Check resolution cache
|
|
388
|
+
const cacheKey = `${fromDir}|${id}`;
|
|
389
|
+
const cached = resolutionCache.get(cacheKey);
|
|
390
|
+
if (cached !== undefined) {
|
|
391
|
+
if (cached === null) {
|
|
392
|
+
throw new Error(`Cannot find module '${id}'`);
|
|
393
|
+
}
|
|
394
|
+
return cached;
|
|
395
|
+
}
|
|
396
|
+
|
|
363
397
|
// Relative paths
|
|
364
398
|
if (id.startsWith('./') || id.startsWith('../') || id.startsWith('/')) {
|
|
365
399
|
const resolved = id.startsWith('/')
|
|
@@ -370,11 +404,13 @@ function createRequire(
|
|
|
370
404
|
if (vfs.existsSync(resolved)) {
|
|
371
405
|
const stats = vfs.statSync(resolved);
|
|
372
406
|
if (stats.isFile()) {
|
|
407
|
+
resolutionCache.set(cacheKey, resolved);
|
|
373
408
|
return resolved;
|
|
374
409
|
}
|
|
375
410
|
// Directory - look for index.js
|
|
376
411
|
const indexPath = pathShim.join(resolved, 'index.js');
|
|
377
412
|
if (vfs.existsSync(indexPath)) {
|
|
413
|
+
resolutionCache.set(cacheKey, indexPath);
|
|
378
414
|
return indexPath;
|
|
379
415
|
}
|
|
380
416
|
}
|
|
@@ -384,10 +420,12 @@ function createRequire(
|
|
|
384
420
|
for (const ext of extensions) {
|
|
385
421
|
const withExt = resolved + ext;
|
|
386
422
|
if (vfs.existsSync(withExt)) {
|
|
423
|
+
resolutionCache.set(cacheKey, withExt);
|
|
387
424
|
return withExt;
|
|
388
425
|
}
|
|
389
426
|
}
|
|
390
427
|
|
|
428
|
+
resolutionCache.set(cacheKey, null);
|
|
391
429
|
throw new Error(`Cannot find module '${id}' from '${fromDir}'`);
|
|
392
430
|
}
|
|
393
431
|
|
|
@@ -436,10 +474,8 @@ function createRequire(
|
|
|
436
474
|
const pkgRoot = pathShim.join(nodeModulesDir, pkgName);
|
|
437
475
|
const pkgPath = pathShim.join(pkgRoot, 'package.json');
|
|
438
476
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const pkg = JSON.parse(pkgContent);
|
|
442
|
-
|
|
477
|
+
const pkg = getParsedPackageJson(pkgPath);
|
|
478
|
+
if (pkg) {
|
|
443
479
|
// Use resolve.exports to handle the exports field
|
|
444
480
|
if (pkg.exports) {
|
|
445
481
|
try {
|
|
@@ -474,15 +510,22 @@ function createRequire(
|
|
|
474
510
|
while (searchDir !== '/') {
|
|
475
511
|
const nodeModulesDir = pathShim.join(searchDir, 'node_modules');
|
|
476
512
|
const resolved = tryResolveFromNodeModules(nodeModulesDir, id);
|
|
477
|
-
if (resolved)
|
|
513
|
+
if (resolved) {
|
|
514
|
+
resolutionCache.set(cacheKey, resolved);
|
|
515
|
+
return resolved;
|
|
516
|
+
}
|
|
478
517
|
|
|
479
518
|
searchDir = pathShim.dirname(searchDir);
|
|
480
519
|
}
|
|
481
520
|
|
|
482
521
|
// Try root node_modules as last resort
|
|
483
522
|
const rootResolved = tryResolveFromNodeModules('/node_modules', id);
|
|
484
|
-
if (rootResolved)
|
|
523
|
+
if (rootResolved) {
|
|
524
|
+
resolutionCache.set(cacheKey, rootResolved);
|
|
525
|
+
return rootResolved;
|
|
526
|
+
}
|
|
485
527
|
|
|
528
|
+
resolutionCache.set(cacheKey, null);
|
|
486
529
|
throw new Error(`Cannot find module '${id}'`);
|
|
487
530
|
};
|
|
488
531
|
|
|
@@ -514,28 +557,40 @@ function createRequire(
|
|
|
514
557
|
}
|
|
515
558
|
|
|
516
559
|
// Read and execute JS file
|
|
517
|
-
|
|
560
|
+
const rawCode = vfs.readFileSync(resolvedPath, 'utf8');
|
|
518
561
|
const dirname = pathShim.dirname(resolvedPath);
|
|
519
562
|
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
563
|
+
// Check processed code cache (useful for HMR when module cache is cleared but code hasn't changed)
|
|
564
|
+
// Use a simple hash of the content for cache key to handle content changes
|
|
565
|
+
const codeCacheKey = `${resolvedPath}|${simpleHash(rawCode)}`;
|
|
566
|
+
let code = processedCodeCache?.get(codeCacheKey);
|
|
567
|
+
|
|
568
|
+
if (!code) {
|
|
569
|
+
code = rawCode;
|
|
526
570
|
|
|
527
|
-
|
|
528
|
-
|
|
571
|
+
// Transform ESM to CJS if needed (for .mjs files or ESM that wasn't pre-transformed)
|
|
572
|
+
// This handles files that weren't transformed during npm install
|
|
573
|
+
// BUT skip .cjs files and already-bundled CJS code
|
|
574
|
+
const isCjsFile = resolvedPath.endsWith('.cjs');
|
|
575
|
+
const isAlreadyBundledCjs = code.startsWith('"use strict";\nvar __') ||
|
|
576
|
+
code.startsWith("'use strict';\nvar __");
|
|
529
577
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
578
|
+
const hasEsmImport = /\bimport\s+[\w{*'"]/m.test(code);
|
|
579
|
+
const hasEsmExport = /\bexport\s+(?:default|const|let|var|function|class|{|\*)/m.test(code);
|
|
580
|
+
|
|
581
|
+
if (!isCjsFile && !isAlreadyBundledCjs) {
|
|
582
|
+
if (resolvedPath.endsWith('.mjs') || resolvedPath.includes('/esm/') || hasEsmImport || hasEsmExport) {
|
|
583
|
+
code = transformEsmToCjs(code, resolvedPath);
|
|
584
|
+
}
|
|
533
585
|
}
|
|
534
|
-
}
|
|
535
586
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
587
|
+
// Transform dynamic imports: import('x') -> __dynamicImport('x')
|
|
588
|
+
// This allows dynamic imports to work in our eval-based runtime
|
|
589
|
+
code = transformDynamicImports(code);
|
|
590
|
+
|
|
591
|
+
// Cache the processed code
|
|
592
|
+
processedCodeCache?.set(codeCacheKey, code);
|
|
593
|
+
}
|
|
539
594
|
|
|
540
595
|
// Create require for this module
|
|
541
596
|
const moduleRequire = createRequire(
|
|
@@ -544,7 +599,8 @@ function createRequire(
|
|
|
544
599
|
process,
|
|
545
600
|
dirname,
|
|
546
601
|
moduleCache,
|
|
547
|
-
options
|
|
602
|
+
options,
|
|
603
|
+
processedCodeCache
|
|
548
604
|
);
|
|
549
605
|
moduleRequire.cache = moduleCache;
|
|
550
606
|
|
|
@@ -779,6 +835,8 @@ export class Runtime {
|
|
|
779
835
|
private process: Process;
|
|
780
836
|
private moduleCache: Record<string, Module> = {};
|
|
781
837
|
private options: RuntimeOptions;
|
|
838
|
+
/** Cache for pre-processed code (after ESM transform) before eval */
|
|
839
|
+
private processedCodeCache: Map<string, string> = new Map();
|
|
782
840
|
|
|
783
841
|
constructor(vfs: VirtualFS, options: RuntimeOptions = {}) {
|
|
784
842
|
this.vfs = vfs;
|
|
@@ -907,7 +965,8 @@ export class Runtime {
|
|
|
907
965
|
this.process,
|
|
908
966
|
dirname,
|
|
909
967
|
this.moduleCache,
|
|
910
|
-
this.options
|
|
968
|
+
this.options,
|
|
969
|
+
this.processedCodeCache
|
|
911
970
|
);
|
|
912
971
|
|
|
913
972
|
// Create module object
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for package.json files
|
|
3
|
+
*/
|
|
4
|
+
export interface PackageJson {
|
|
5
|
+
name?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
main?: string;
|
|
8
|
+
module?: string;
|
|
9
|
+
types?: string;
|
|
10
|
+
exports?: Record<string, unknown> | string;
|
|
11
|
+
dependencies?: Record<string, string>;
|
|
12
|
+
devDependencies?: Record<string, string>;
|
|
13
|
+
peerDependencies?: Record<string, string>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple hash function for content-based cache invalidation.
|
|
3
|
+
* Uses djb2-style hashing for fast string hashing.
|
|
4
|
+
*/
|
|
5
|
+
export function simpleHash(str: string): string {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
for (let i = 0; i < str.length; i++) {
|
|
8
|
+
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
|
9
|
+
hash |= 0;
|
|
10
|
+
}
|
|
11
|
+
return hash.toString(36);
|
|
12
|
+
}
|
package/src/virtual-fs.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface FSNode {
|
|
|
8
8
|
type: 'file' | 'directory';
|
|
9
9
|
content?: Uint8Array;
|
|
10
10
|
children?: Map<string, FSNode>;
|
|
11
|
+
mtime: number;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
// Simple EventEmitter for VFS change notifications
|
|
@@ -111,6 +112,7 @@ export class VirtualFS {
|
|
|
111
112
|
this.root = {
|
|
112
113
|
type: 'directory',
|
|
113
114
|
children: new Map(),
|
|
115
|
+
mtime: Date.now(),
|
|
114
116
|
};
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -252,6 +254,7 @@ export class VirtualFS {
|
|
|
252
254
|
parent.children!.set(basename, {
|
|
253
255
|
type: 'file',
|
|
254
256
|
content,
|
|
257
|
+
mtime: Date.now(),
|
|
255
258
|
});
|
|
256
259
|
|
|
257
260
|
if (emitEvent) {
|
|
@@ -344,7 +347,7 @@ export class VirtualFS {
|
|
|
344
347
|
|
|
345
348
|
let child = current.children.get(segment);
|
|
346
349
|
if (!child) {
|
|
347
|
-
child = { type: 'directory', children: new Map() };
|
|
350
|
+
child = { type: 'directory', children: new Map(), mtime: Date.now() };
|
|
348
351
|
current.children.set(segment, child);
|
|
349
352
|
} else if (child.type !== 'directory') {
|
|
350
353
|
throw new Error(`ENOTDIR: not a directory, '${path}'`);
|
|
@@ -372,8 +375,8 @@ export class VirtualFS {
|
|
|
372
375
|
throw createNodeError('ENOENT', 'stat', path);
|
|
373
376
|
}
|
|
374
377
|
|
|
375
|
-
const now = Date.now();
|
|
376
378
|
const size = node.type === 'file' ? (node.content?.length || 0) : 0;
|
|
379
|
+
const mtime = node.mtime;
|
|
377
380
|
|
|
378
381
|
return {
|
|
379
382
|
isFile: () => node.type === 'file',
|
|
@@ -385,14 +388,14 @@ export class VirtualFS {
|
|
|
385
388
|
isSocket: () => false,
|
|
386
389
|
size,
|
|
387
390
|
mode: node.type === 'directory' ? 0o755 : 0o644,
|
|
388
|
-
mtime: new Date(
|
|
389
|
-
atime: new Date(
|
|
390
|
-
ctime: new Date(
|
|
391
|
-
birthtime: new Date(
|
|
392
|
-
mtimeMs:
|
|
393
|
-
atimeMs:
|
|
394
|
-
ctimeMs:
|
|
395
|
-
birthtimeMs:
|
|
391
|
+
mtime: new Date(mtime),
|
|
392
|
+
atime: new Date(mtime),
|
|
393
|
+
ctime: new Date(mtime),
|
|
394
|
+
birthtime: new Date(mtime),
|
|
395
|
+
mtimeMs: mtime,
|
|
396
|
+
atimeMs: mtime,
|
|
397
|
+
ctimeMs: mtime,
|
|
398
|
+
birthtimeMs: mtime,
|
|
396
399
|
nlink: 1,
|
|
397
400
|
uid: 1000,
|
|
398
401
|
gid: 1000,
|
|
@@ -478,6 +481,7 @@ export class VirtualFS {
|
|
|
478
481
|
parent.children!.set(basename, {
|
|
479
482
|
type: 'directory',
|
|
480
483
|
children: new Map(),
|
|
484
|
+
mtime: Date.now(),
|
|
481
485
|
});
|
|
482
486
|
}
|
|
483
487
|
|