zero-com 1.6.6 → 1.7.1
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.
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = turbopackLoader;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const common_1 = require("./common");
|
|
9
|
+
// Module-level cache: registry is built once and reused across invocations
|
|
10
|
+
let cachedRegistry = null;
|
|
11
|
+
let cachedRootDir = null;
|
|
12
|
+
function turbopackLoader(source) {
|
|
13
|
+
var _a;
|
|
14
|
+
const options = this.getOptions();
|
|
15
|
+
const filePath = this.resourcePath;
|
|
16
|
+
const rootDir = options.rootDir || this.rootContext || process.cwd();
|
|
17
|
+
const development = (_a = options.development) !== null && _a !== void 0 ? _a : true;
|
|
18
|
+
// Lazily build and cache the registry on first invocation or if rootDir changes
|
|
19
|
+
if (!cachedRegistry || cachedRootDir !== rootDir) {
|
|
20
|
+
cachedRegistry = new Map();
|
|
21
|
+
cachedRootDir = rootDir;
|
|
22
|
+
(0, common_1.buildRegistry)(rootDir, cachedRegistry);
|
|
23
|
+
console.log(`[TurbopackLoader] Found ${cachedRegistry.size} files with server functions`);
|
|
24
|
+
}
|
|
25
|
+
const result = (0, common_1.transformSourceFile)(filePath, source, cachedRegistry, { development });
|
|
26
|
+
if (!result.transformed) {
|
|
27
|
+
this.callback(null, source);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
console.log(`[TurbopackLoader] Transformed: ${path_1.default.basename(filePath)}`);
|
|
31
|
+
this.callback(null, result.content, result.map);
|
|
32
|
+
}
|