@varlock/cloudflare-integration 1.1.0 → 1.1.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +194 -44
- package/dist/index.js.map +1 -1
- package/dist/sveltekit.js +50 -38
- package/dist/sveltekit.js.map +1 -1
- package/package.json +2 -2
package/dist/sveltekit.js
CHANGED
|
@@ -33,7 +33,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
mod
|
|
34
34
|
));
|
|
35
35
|
var require_ast_matcher = __commonJS({
|
|
36
|
-
"../../../node_modules/.bun/ast-matcher@1.2.0/node_modules/ast-matcher/index.js"(exports
|
|
36
|
+
"../../../node_modules/.bun/ast-matcher@1.2.0/node_modules/ast-matcher/index.js"(exports, module) {
|
|
37
37
|
var STOP = false;
|
|
38
38
|
var SKIP_BRANCH = 1;
|
|
39
39
|
var IGNORED_KEYS = ["start", "end", "loc", "location", "locations", "line", "column", "range", "ranges", "raw", "extra"];
|
|
@@ -1438,10 +1438,46 @@ function reloadConfig(cwd) {
|
|
|
1438
1438
|
resetStaticReplacements();
|
|
1439
1439
|
}
|
|
1440
1440
|
reloadConfig();
|
|
1441
|
+
var VARLOCK_INIT_MODULE_ID = "\0varlock-ssr-init";
|
|
1441
1442
|
function varlockVitePlugin(vitePluginOptions) {
|
|
1443
|
+
function buildInitModuleCode() {
|
|
1444
|
+
const ssrInjectMode = vitePluginOptions?.ssrInjectMode ?? "init-only";
|
|
1445
|
+
const lines = [
|
|
1446
|
+
"// Virtual module generated by @varlock/vite-integration",
|
|
1447
|
+
"// Runs before any user code to ensure ENV is available at module top-level",
|
|
1448
|
+
"globalThis.__varlockThrowOnMissingKeys = true;"
|
|
1449
|
+
];
|
|
1450
|
+
if (ssrInjectMode === "auto-load") {
|
|
1451
|
+
lines.push("import 'varlock/auto-load';");
|
|
1452
|
+
} else {
|
|
1453
|
+
if (ssrInjectMode === "resolved-env") {
|
|
1454
|
+
lines.push(`globalThis.__varlockLoadedEnv = ${JSON.stringify(varlockLoadedEnv)};`);
|
|
1455
|
+
}
|
|
1456
|
+
if (vitePluginOptions?.ssrEntryCode?.length) {
|
|
1457
|
+
lines.push(...vitePluginOptions.ssrEntryCode);
|
|
1458
|
+
}
|
|
1459
|
+
lines.push(
|
|
1460
|
+
"import { initVarlockEnv } from 'varlock/env';",
|
|
1461
|
+
"import { patchGlobalConsole } from 'varlock/patch-console';",
|
|
1462
|
+
"import { patchGlobalResponse } from 'varlock/patch-response';"
|
|
1463
|
+
);
|
|
1464
|
+
lines.push(
|
|
1465
|
+
"initVarlockEnv();",
|
|
1466
|
+
"patchGlobalConsole();"
|
|
1467
|
+
);
|
|
1468
|
+
lines.push("patchGlobalResponse();");
|
|
1469
|
+
}
|
|
1470
|
+
return lines.join("\n");
|
|
1471
|
+
}
|
|
1442
1472
|
return {
|
|
1443
1473
|
name: "inject-varlock-config",
|
|
1444
1474
|
enforce: "post",
|
|
1475
|
+
resolveId(id) {
|
|
1476
|
+
if (id === VARLOCK_INIT_MODULE_ID) return id;
|
|
1477
|
+
},
|
|
1478
|
+
load(id) {
|
|
1479
|
+
if (id === VARLOCK_INIT_MODULE_ID) return buildInitModuleCode();
|
|
1480
|
+
},
|
|
1445
1481
|
// hook to modify config before it is resolved
|
|
1446
1482
|
async config(config, env) {
|
|
1447
1483
|
debug("vite plugin - config fn called");
|
|
@@ -1521,51 +1557,27 @@ See https://varlock.dev/integrations/vite/ for more details.
|
|
|
1521
1557
|
const fileExt = id.split("?")[0].split("#")[0].split(".").pop() || "";
|
|
1522
1558
|
let isEntry = false;
|
|
1523
1559
|
if (SUPPORTED_FILES.includes(fileExt)) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1560
|
+
try {
|
|
1561
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
1562
|
+
if (moduleInfo?.isEntry) isEntry = true;
|
|
1563
|
+
} catch {
|
|
1564
|
+
}
|
|
1565
|
+
if (!isEntry) {
|
|
1566
|
+
const moduleIds = Array.from(this.getModuleIds());
|
|
1567
|
+
if (moduleIds[0] === id) isEntry = true;
|
|
1568
|
+
}
|
|
1526
1569
|
}
|
|
1527
1570
|
if (vitePluginOptions?.ssrEntryModuleIds?.includes(id)) isEntry = true;
|
|
1528
1571
|
if (isEntry) {
|
|
1529
1572
|
debug(`detected entry: ${id}`);
|
|
1530
|
-
|
|
1531
|
-
if (this.environment) {
|
|
1532
|
-
isDevEnv = this.environment.mode === "dev";
|
|
1533
|
-
} else {
|
|
1534
|
-
isDevEnv = isDevCommand;
|
|
1535
|
-
}
|
|
1536
|
-
const injectCode = [
|
|
1537
|
-
"// INJECTED BY @varlock/vite-integration ----",
|
|
1538
|
-
"globalThis.__varlockThrowOnMissingKeys = true;"
|
|
1539
|
-
];
|
|
1573
|
+
const injectCode = ["// INJECTED BY @varlock/vite-integration ----"];
|
|
1540
1574
|
if (options?.ssr) {
|
|
1541
|
-
|
|
1542
|
-
debug("ssrInjectMode =", ssrInjectMode, "isDev =", isDevEnv);
|
|
1543
|
-
if (ssrInjectMode === "auto-load") {
|
|
1544
|
-
injectCode.push(
|
|
1545
|
-
"import 'varlock/auto-load';"
|
|
1546
|
-
);
|
|
1547
|
-
} else {
|
|
1548
|
-
if (ssrInjectMode === "resolved-env") {
|
|
1549
|
-
injectCode.push(`globalThis.__varlockLoadedEnv = ${JSON.stringify(varlockLoadedEnv)};`);
|
|
1550
|
-
}
|
|
1551
|
-
if (vitePluginOptions?.ssrEntryCode?.length) {
|
|
1552
|
-
injectCode.push(...vitePluginOptions.ssrEntryCode);
|
|
1553
|
-
}
|
|
1554
|
-
injectCode.push(
|
|
1555
|
-
"import { initVarlockEnv } from 'varlock/env';",
|
|
1556
|
-
"import { patchGlobalConsole } from 'varlock/patch-console';",
|
|
1557
|
-
"import { patchGlobalResponse } from 'varlock/patch-response';"
|
|
1558
|
-
);
|
|
1559
|
-
injectCode.push(
|
|
1560
|
-
"initVarlockEnv();",
|
|
1561
|
-
"patchGlobalConsole();"
|
|
1562
|
-
);
|
|
1563
|
-
injectCode.push("patchGlobalResponse();");
|
|
1564
|
-
}
|
|
1575
|
+
injectCode.push(`import '${VARLOCK_INIT_MODULE_ID}';`);
|
|
1565
1576
|
} else {
|
|
1577
|
+
injectCode.push("globalThis.__varlockThrowOnMissingKeys = true;");
|
|
1578
|
+
const isDevEnv = this.environment ? this.environment.mode === "dev" : isDevCommand;
|
|
1566
1579
|
if (isDevEnv) {
|
|
1567
1580
|
injectCode.push(
|
|
1568
|
-
"// NOTE - __varlockValidKeys is only injected during development",
|
|
1569
1581
|
`globalThis.__varlockValidKeys = ${JSON.stringify(Object.keys(varlockLoadedEnv?.config || {}))};`
|
|
1570
1582
|
);
|
|
1571
1583
|
}
|