devflare 1.0.0-next.4 → 1.0.0-next.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.
|
@@ -21,7 +21,7 @@ import { createConsola } from "consola";
|
|
|
21
21
|
import { resolve as resolve3 } from "pathe";
|
|
22
22
|
|
|
23
23
|
// src/dev-server/server.ts
|
|
24
|
-
import { resolve as resolve2 } from "pathe";
|
|
24
|
+
import { dirname as dirname2, resolve as resolve2 } from "pathe";
|
|
25
25
|
|
|
26
26
|
// src/bundler/do-bundler.ts
|
|
27
27
|
import { resolve, dirname, relative } from "pathe";
|
|
@@ -1093,8 +1093,60 @@ async function checkRemoteBindingRequirements(config) {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
|
|
1095
1095
|
// src/dev-server/server.ts
|
|
1096
|
-
|
|
1096
|
+
var DEFAULT_FETCH_ENTRY_FILES = [
|
|
1097
|
+
"src/fetch.ts",
|
|
1098
|
+
"src/fetch.js",
|
|
1099
|
+
"src/fetch.mts",
|
|
1100
|
+
"src/fetch.mjs"
|
|
1101
|
+
];
|
|
1102
|
+
var INTERNAL_APP_SERVICE_BINDING = "__DEVFLARE_APP";
|
|
1103
|
+
async function resolveMainWorkerScriptPath(cwd, config) {
|
|
1104
|
+
if (config.files?.fetch === false) {
|
|
1105
|
+
return null;
|
|
1106
|
+
}
|
|
1107
|
+
const fs = await import("node:fs/promises");
|
|
1108
|
+
const candidates = new Set;
|
|
1109
|
+
if (typeof config.files?.fetch === "string" && config.files.fetch) {
|
|
1110
|
+
candidates.add(config.files.fetch);
|
|
1111
|
+
}
|
|
1112
|
+
for (const defaultEntry of DEFAULT_FETCH_ENTRY_FILES) {
|
|
1113
|
+
candidates.add(defaultEntry);
|
|
1114
|
+
}
|
|
1115
|
+
for (const candidate of candidates) {
|
|
1116
|
+
const absolutePath = resolve2(cwd, candidate);
|
|
1117
|
+
try {
|
|
1118
|
+
await fs.access(absolutePath);
|
|
1119
|
+
return absolutePath;
|
|
1120
|
+
} catch {
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return null;
|
|
1125
|
+
}
|
|
1126
|
+
function collectWorkerWatchRoots(cwd, config, mainWorkerScriptPath) {
|
|
1127
|
+
const roots = new Set;
|
|
1128
|
+
const addFileParent = (filePath) => {
|
|
1129
|
+
if (typeof filePath !== "string" || !filePath) {
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
roots.add(dirname2(resolve2(cwd, filePath)));
|
|
1133
|
+
};
|
|
1134
|
+
if (mainWorkerScriptPath) {
|
|
1135
|
+
roots.add(dirname2(mainWorkerScriptPath));
|
|
1136
|
+
}
|
|
1137
|
+
addFileParent(config.files?.fetch);
|
|
1138
|
+
addFileParent(config.files?.queue);
|
|
1139
|
+
addFileParent(config.files?.scheduled);
|
|
1140
|
+
addFileParent(config.files?.email);
|
|
1141
|
+
addFileParent(config.files?.transport);
|
|
1142
|
+
if (config.files?.routes && typeof config.files.routes === "object") {
|
|
1143
|
+
roots.add(resolve2(cwd, config.files.routes.dir));
|
|
1144
|
+
}
|
|
1145
|
+
return [...roots];
|
|
1146
|
+
}
|
|
1147
|
+
function getGatewayScript(wsRoutes = [], debug = false, appServiceBindingName = null) {
|
|
1097
1148
|
const wsRoutesJson = JSON.stringify(wsRoutes);
|
|
1149
|
+
const appServiceBindingJson = JSON.stringify(appServiceBindingName);
|
|
1098
1150
|
return `
|
|
1099
1151
|
// Bridge Gateway Worker — RPC Handler
|
|
1100
1152
|
// Handles all binding operations via WebSocket RPC
|
|
@@ -1109,6 +1161,7 @@ const incomingStreams = new Map()
|
|
|
1109
1161
|
|
|
1110
1162
|
// WebSocket routes configuration (injected at build time)
|
|
1111
1163
|
const WS_ROUTES = ${wsRoutesJson}
|
|
1164
|
+
const APP_SERVICE_BINDING = ${appServiceBindingJson}
|
|
1112
1165
|
|
|
1113
1166
|
export default {
|
|
1114
1167
|
async fetch(request, env, ctx) {
|
|
@@ -1149,6 +1202,13 @@ export default {
|
|
|
1149
1202
|
}), { headers: { 'Content-Type': 'application/json' } })
|
|
1150
1203
|
}
|
|
1151
1204
|
|
|
1205
|
+
if (APP_SERVICE_BINDING) {
|
|
1206
|
+
const appWorker = env[APP_SERVICE_BINDING]
|
|
1207
|
+
if (appWorker && typeof appWorker.fetch === 'function') {
|
|
1208
|
+
return appWorker.fetch(request)
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1152
1212
|
return new Response('Devflare Bridge Gateway', { status: 200 })
|
|
1153
1213
|
}
|
|
1154
1214
|
}
|
|
@@ -1676,15 +1736,63 @@ function createDevServer(options) {
|
|
|
1676
1736
|
} = options;
|
|
1677
1737
|
let miniflare = null;
|
|
1678
1738
|
let doBundler = null;
|
|
1739
|
+
let workerSourceWatcher = null;
|
|
1679
1740
|
let viteProcess = null;
|
|
1680
1741
|
let config = null;
|
|
1681
1742
|
let browserShim = null;
|
|
1682
1743
|
let browserShimPort = 8788;
|
|
1744
|
+
let mainWorkerScriptPath = null;
|
|
1745
|
+
let bundledMainWorkerScriptPath = null;
|
|
1746
|
+
let currentDoResult = null;
|
|
1747
|
+
let reloadChain = Promise.resolve();
|
|
1748
|
+
async function bundleMainWorker() {
|
|
1749
|
+
if (!mainWorkerScriptPath) {
|
|
1750
|
+
bundledMainWorkerScriptPath = null;
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
if (typeof Bun === "undefined" || typeof Bun.build !== "function") {
|
|
1754
|
+
throw new Error("Worker-only dev mode requires the Bun runtime for main worker bundling");
|
|
1755
|
+
}
|
|
1756
|
+
const fs = await import("node:fs/promises");
|
|
1757
|
+
const outDir = resolve2(cwd, ".devflare", "worker-bundles");
|
|
1758
|
+
await fs.rm(outDir, { recursive: true, force: true });
|
|
1759
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
1760
|
+
const result = await Bun.build({
|
|
1761
|
+
entrypoints: [mainWorkerScriptPath],
|
|
1762
|
+
outdir: outDir,
|
|
1763
|
+
target: "browser",
|
|
1764
|
+
format: "esm",
|
|
1765
|
+
minify: false,
|
|
1766
|
+
splitting: false,
|
|
1767
|
+
external: ["cloudflare:workers", "cloudflare:*"]
|
|
1768
|
+
});
|
|
1769
|
+
if (!result.success || result.outputs.length === 0) {
|
|
1770
|
+
const logs = result.logs.map((log) => ("message" in log) ? log.message : String(log)).join(`
|
|
1771
|
+
`);
|
|
1772
|
+
throw new Error(`Failed to bundle main worker:
|
|
1773
|
+
${logs}`);
|
|
1774
|
+
}
|
|
1775
|
+
bundledMainWorkerScriptPath = result.outputs[0].path;
|
|
1776
|
+
logger?.debug(`Bundled main worker → ${bundledMainWorkerScriptPath}`);
|
|
1777
|
+
}
|
|
1683
1778
|
function buildMiniflareConfig(doResult) {
|
|
1684
1779
|
if (!config)
|
|
1685
1780
|
throw new Error("Config not loaded");
|
|
1686
|
-
const
|
|
1781
|
+
const loadedConfig = config;
|
|
1782
|
+
const bindings = loadedConfig.bindings ?? {};
|
|
1687
1783
|
const persistPath = resolve2(cwd, ".devflare/data");
|
|
1784
|
+
const appWorkerName = loadedConfig.name;
|
|
1785
|
+
const shouldRunMainWorker = !enableVite && !!mainWorkerScriptPath;
|
|
1786
|
+
const queueProducers = (() => {
|
|
1787
|
+
if (!bindings.queues?.producers) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
const producers = {};
|
|
1791
|
+
for (const [bindingName, queueName] of Object.entries(bindings.queues.producers)) {
|
|
1792
|
+
producers[bindingName] = { queueName };
|
|
1793
|
+
}
|
|
1794
|
+
return producers;
|
|
1795
|
+
})();
|
|
1688
1796
|
const sharedOptions = {
|
|
1689
1797
|
port: miniflarePort,
|
|
1690
1798
|
host: "127.0.0.1",
|
|
@@ -1693,19 +1801,67 @@ function createDevServer(options) {
|
|
|
1693
1801
|
d1Persist: persist ? `${persistPath}/d1` : undefined,
|
|
1694
1802
|
durableObjectsPersist: persist ? `${persistPath}/do` : undefined
|
|
1695
1803
|
};
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1804
|
+
const createServiceBindings = (extraBindings = {}) => {
|
|
1805
|
+
const serviceBindings = {};
|
|
1806
|
+
if (bindings.services) {
|
|
1807
|
+
for (const [bindingName, serviceConfig] of Object.entries(bindings.services)) {
|
|
1808
|
+
serviceBindings[bindingName] = {
|
|
1809
|
+
name: serviceConfig.service,
|
|
1810
|
+
...serviceConfig.entrypoint && { entrypoint: serviceConfig.entrypoint }
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
for (const [bindingName, target] of Object.entries(extraBindings)) {
|
|
1815
|
+
serviceBindings[bindingName] = target;
|
|
1816
|
+
}
|
|
1817
|
+
return Object.keys(serviceBindings).length > 0 ? serviceBindings : undefined;
|
|
1818
|
+
};
|
|
1819
|
+
const createWorkerConfig = (options2) => {
|
|
1820
|
+
const baseFlags = loadedConfig.compatibilityFlags ?? [];
|
|
1821
|
+
const compatFlags = baseFlags.includes("nodejs_compat") ? baseFlags : [...baseFlags, "nodejs_compat"];
|
|
1822
|
+
const workerConfig = {
|
|
1823
|
+
name: options2.name,
|
|
1824
|
+
modules: true,
|
|
1825
|
+
compatibilityDate: loadedConfig.compatibilityDate,
|
|
1826
|
+
compatibilityFlags: compatFlags,
|
|
1827
|
+
...bindings.kv && { kvNamespaces: bindings.kv },
|
|
1828
|
+
...bindings.r2 && { r2Buckets: bindings.r2 },
|
|
1829
|
+
...bindings.d1 && { d1Databases: bindings.d1 },
|
|
1830
|
+
...loadedConfig.vars && Object.keys(loadedConfig.vars).length > 0 && { bindings: loadedConfig.vars },
|
|
1831
|
+
...queueProducers && { queueProducers }
|
|
1832
|
+
};
|
|
1833
|
+
if (options2.scriptPath) {
|
|
1834
|
+
workerConfig.scriptPath = options2.scriptPath;
|
|
1835
|
+
workerConfig.modulesRoot = cwd;
|
|
1836
|
+
workerConfig.modulesRules = [
|
|
1837
|
+
{ type: "ESModule", include: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.mjs"] },
|
|
1838
|
+
{ type: "CommonJS", include: ["**/*.js", "**/*.cjs"] },
|
|
1839
|
+
{ type: "ESModule", include: ["**/*.jsx"] }
|
|
1840
|
+
];
|
|
1841
|
+
}
|
|
1842
|
+
if (options2.script) {
|
|
1843
|
+
workerConfig.script = options2.script;
|
|
1844
|
+
}
|
|
1845
|
+
if (options2.durableObjects && Object.keys(options2.durableObjects).length > 0) {
|
|
1846
|
+
workerConfig.durableObjects = options2.durableObjects;
|
|
1847
|
+
}
|
|
1848
|
+
if (options2.serviceBindings && Object.keys(options2.serviceBindings).length > 0) {
|
|
1849
|
+
workerConfig.serviceBindings = options2.serviceBindings;
|
|
1850
|
+
}
|
|
1851
|
+
return workerConfig;
|
|
1707
1852
|
};
|
|
1708
|
-
|
|
1853
|
+
const gatewayWorker = createWorkerConfig({
|
|
1854
|
+
name: "gateway",
|
|
1855
|
+
script: getGatewayScript(loadedConfig.wsRoutes, debug, shouldRunMainWorker ? INTERNAL_APP_SERVICE_BINDING : null),
|
|
1856
|
+
serviceBindings: shouldRunMainWorker ? createServiceBindings({
|
|
1857
|
+
[INTERNAL_APP_SERVICE_BINDING]: { name: appWorkerName }
|
|
1858
|
+
}) : createServiceBindings()
|
|
1859
|
+
});
|
|
1860
|
+
gatewayWorker.routes = ["*"];
|
|
1861
|
+
const hasDurableObjectBundles = !!doResult && doResult.bundles.size > 0;
|
|
1862
|
+
const browserBindingName = bindings.browser?.binding;
|
|
1863
|
+
const needsBrowserWorker = Boolean(browserBindingName && (hasDurableObjectBundles || shouldRunMainWorker));
|
|
1864
|
+
if (!shouldRunMainWorker && !hasDurableObjectBundles && !needsBrowserWorker) {
|
|
1709
1865
|
return {
|
|
1710
1866
|
...sharedOptions,
|
|
1711
1867
|
...gatewayWorker
|
|
@@ -1714,56 +1870,62 @@ function createDevServer(options) {
|
|
|
1714
1870
|
const workers = [];
|
|
1715
1871
|
const durableObjects = {};
|
|
1716
1872
|
const browserShimUrl = `http://127.0.0.1:${browserShimPort}`;
|
|
1717
|
-
const browserBindingName = bindings.browser?.binding;
|
|
1718
1873
|
const browserWorkerName = "browser-binding";
|
|
1719
|
-
|
|
1720
|
-
const
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1874
|
+
if (shouldRunMainWorker && mainWorkerScriptPath) {
|
|
1875
|
+
const mainWorkerServiceBindings = createServiceBindings(browserBindingName ? {
|
|
1876
|
+
[browserBindingName]: { name: browserWorkerName }
|
|
1877
|
+
} : {});
|
|
1878
|
+
const mainWorkerConfig = createWorkerConfig({
|
|
1879
|
+
name: appWorkerName,
|
|
1880
|
+
scriptPath: bundledMainWorkerScriptPath ?? mainWorkerScriptPath,
|
|
1881
|
+
serviceBindings: mainWorkerServiceBindings
|
|
1882
|
+
});
|
|
1883
|
+
workers.push(mainWorkerConfig);
|
|
1884
|
+
}
|
|
1885
|
+
if (doResult) {
|
|
1886
|
+
for (const [bindingName, bundlePath] of doResult.bundles) {
|
|
1887
|
+
const className = doResult.classes.get(bindingName);
|
|
1888
|
+
if (!className)
|
|
1889
|
+
continue;
|
|
1890
|
+
const workerName = `do-${bindingName.toLowerCase()}`;
|
|
1891
|
+
const workerConfig = createWorkerConfig({
|
|
1892
|
+
name: workerName,
|
|
1893
|
+
scriptPath: bundlePath,
|
|
1894
|
+
durableObjects: {
|
|
1895
|
+
[bindingName]: className
|
|
1896
|
+
},
|
|
1897
|
+
serviceBindings: createServiceBindings(browserBindingName ? {
|
|
1898
|
+
[browserBindingName]: { name: browserWorkerName }
|
|
1899
|
+
} : {})
|
|
1900
|
+
});
|
|
1901
|
+
if (browserBindingName) {
|
|
1902
|
+
logger?.debug(`DO ${workerName} has browser service binding: ${browserBindingName} → ${browserWorkerName}`);
|
|
1739
1903
|
}
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1904
|
+
logger?.debug(`DO ${workerName} config:`, JSON.stringify(workerConfig, null, 2));
|
|
1905
|
+
workers.push(workerConfig);
|
|
1906
|
+
durableObjects[bindingName] = {
|
|
1907
|
+
className,
|
|
1908
|
+
scriptName: workerName
|
|
1745
1909
|
};
|
|
1746
|
-
logger?.debug(`DO ${workerName} has browser service binding: ${browserBindingName} → ${browserWorkerName}`);
|
|
1747
1910
|
}
|
|
1748
|
-
logger?.debug(`DO ${workerName} config:`, JSON.stringify(workerConfig, null, 2));
|
|
1749
|
-
workers.push(workerConfig);
|
|
1750
|
-
durableObjects[bindingName] = {
|
|
1751
|
-
className,
|
|
1752
|
-
scriptName: workerName
|
|
1753
|
-
};
|
|
1754
1911
|
}
|
|
1755
|
-
if (
|
|
1756
|
-
const browserWorker = {
|
|
1912
|
+
if (needsBrowserWorker) {
|
|
1913
|
+
const browserWorker = createWorkerConfig({
|
|
1757
1914
|
name: browserWorkerName,
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
compatibilityDate: config.compatibilityDate,
|
|
1761
|
-
compatibilityFlags: config.compatibilityFlags ?? []
|
|
1762
|
-
};
|
|
1915
|
+
script: getBrowserBindingScript(browserShimUrl, debug)
|
|
1916
|
+
});
|
|
1763
1917
|
workers.push(browserWorker);
|
|
1764
1918
|
logger?.info(`Browser binding worker configured: ${browserBindingName} → ${browserShimUrl}`);
|
|
1765
1919
|
}
|
|
1766
|
-
|
|
1920
|
+
if (Object.keys(durableObjects).length > 0) {
|
|
1921
|
+
gatewayWorker.durableObjects = durableObjects;
|
|
1922
|
+
if (shouldRunMainWorker) {
|
|
1923
|
+
const mainWorker = workers.find((worker) => worker.name === appWorkerName);
|
|
1924
|
+
if (mainWorker) {
|
|
1925
|
+
mainWorker.durableObjects = durableObjects;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1767
1929
|
return {
|
|
1768
1930
|
...sharedOptions,
|
|
1769
1931
|
workers: [gatewayWorker, ...workers]
|
|
@@ -1817,14 +1979,93 @@ function createDevServer(options) {
|
|
|
1817
1979
|
}
|
|
1818
1980
|
}
|
|
1819
1981
|
async function reloadMiniflare(doResult) {
|
|
1820
|
-
|
|
1982
|
+
currentDoResult = doResult;
|
|
1983
|
+
const queuedReload = reloadChain.then(async () => {
|
|
1984
|
+
if (!miniflare)
|
|
1985
|
+
return;
|
|
1986
|
+
const { Log, LogLevel } = await import("miniflare");
|
|
1987
|
+
const mfConfig = buildMiniflareConfig(currentDoResult);
|
|
1988
|
+
mfConfig.log = new Log(LogLevel.DEBUG);
|
|
1989
|
+
logger?.info("Reloading Miniflare...");
|
|
1990
|
+
await miniflare.setOptions(mfConfig);
|
|
1991
|
+
logger?.success("Miniflare reloaded");
|
|
1992
|
+
});
|
|
1993
|
+
reloadChain = queuedReload.catch(() => {});
|
|
1994
|
+
await queuedReload;
|
|
1995
|
+
}
|
|
1996
|
+
async function startWorkerSourceWatcher() {
|
|
1997
|
+
if (enableVite || !config || !mainWorkerScriptPath) {
|
|
1821
1998
|
return;
|
|
1822
|
-
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1999
|
+
}
|
|
2000
|
+
const watchRoots = collectWorkerWatchRoots(cwd, config, mainWorkerScriptPath);
|
|
2001
|
+
if (watchRoots.length === 0) {
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const chokidar = await import("chokidar");
|
|
2005
|
+
const isWindows = process.platform === "win32";
|
|
2006
|
+
const ignoredSegments = ["/node_modules/", "/.git/", "/.devflare/", "/dist/"];
|
|
2007
|
+
const normalizePath = (filePath) => filePath.replace(/\\/g, "/");
|
|
2008
|
+
const isIgnoredPath = (filePath) => {
|
|
2009
|
+
const normalizedPath = normalizePath(filePath);
|
|
2010
|
+
return ignoredSegments.some((segment) => normalizedPath.includes(segment));
|
|
2011
|
+
};
|
|
2012
|
+
let reloadTimeout = null;
|
|
2013
|
+
let reloadInProgress = false;
|
|
2014
|
+
let pendingReloadPath = null;
|
|
2015
|
+
const triggerReload = async (filePath) => {
|
|
2016
|
+
if (reloadInProgress) {
|
|
2017
|
+
pendingReloadPath = filePath;
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
reloadInProgress = true;
|
|
2021
|
+
try {
|
|
2022
|
+
logger?.info(`Worker source changed: ${filePath}`);
|
|
2023
|
+
await bundleMainWorker();
|
|
2024
|
+
await reloadMiniflare(currentDoResult);
|
|
2025
|
+
} catch (error) {
|
|
2026
|
+
logger?.error("Worker source reload failed:", error);
|
|
2027
|
+
} finally {
|
|
2028
|
+
reloadInProgress = false;
|
|
2029
|
+
if (pendingReloadPath) {
|
|
2030
|
+
const nextPath = pendingReloadPath;
|
|
2031
|
+
pendingReloadPath = null;
|
|
2032
|
+
await triggerReload(nextPath);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
const scheduleReload = (filePath) => {
|
|
2037
|
+
if (reloadTimeout) {
|
|
2038
|
+
clearTimeout(reloadTimeout);
|
|
2039
|
+
}
|
|
2040
|
+
reloadTimeout = setTimeout(() => {
|
|
2041
|
+
triggerReload(filePath);
|
|
2042
|
+
}, 150);
|
|
2043
|
+
};
|
|
2044
|
+
workerSourceWatcher = chokidar.watch(watchRoots, {
|
|
2045
|
+
ignoreInitial: true,
|
|
2046
|
+
usePolling: isWindows,
|
|
2047
|
+
interval: isWindows ? 300 : undefined,
|
|
2048
|
+
awaitWriteFinish: {
|
|
2049
|
+
stabilityThreshold: 100,
|
|
2050
|
+
pollInterval: 50
|
|
2051
|
+
},
|
|
2052
|
+
ignored: (filePath) => isIgnoredPath(filePath)
|
|
2053
|
+
});
|
|
2054
|
+
const onFileEvent = (filePath) => {
|
|
2055
|
+
if (isIgnoredPath(filePath)) {
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
scheduleReload(filePath);
|
|
2059
|
+
};
|
|
2060
|
+
workerSourceWatcher.on("change", onFileEvent);
|
|
2061
|
+
workerSourceWatcher.on("add", onFileEvent);
|
|
2062
|
+
workerSourceWatcher.on("unlink", onFileEvent);
|
|
2063
|
+
workerSourceWatcher.on("ready", () => {
|
|
2064
|
+
logger?.info(`Worker source watcher ready (${watchRoots.length} root(s))`);
|
|
2065
|
+
});
|
|
2066
|
+
workerSourceWatcher.on("error", (error) => {
|
|
2067
|
+
logger?.error("Worker source watcher error:", error);
|
|
2068
|
+
});
|
|
1828
2069
|
}
|
|
1829
2070
|
async function runD1Migrations() {
|
|
1830
2071
|
if (!miniflare || !config?.bindings?.d1)
|
|
@@ -1911,6 +2152,13 @@ function createDevServer(options) {
|
|
|
1911
2152
|
logger?.info("Starting unified dev server...");
|
|
1912
2153
|
config = await loadConfig({ cwd, configFile: configPath });
|
|
1913
2154
|
logger?.debug("Loaded config:", config.name);
|
|
2155
|
+
mainWorkerScriptPath = await resolveMainWorkerScriptPath(cwd, config);
|
|
2156
|
+
if (!enableVite && mainWorkerScriptPath) {
|
|
2157
|
+
logger?.info(`Worker entry detected: ${mainWorkerScriptPath}`);
|
|
2158
|
+
await bundleMainWorker();
|
|
2159
|
+
} else if (!enableVite) {
|
|
2160
|
+
logger?.warn("No local fetch worker entry was found for worker-only mode");
|
|
2161
|
+
}
|
|
1914
2162
|
const remoteCheck = await checkRemoteBindingRequirements(config);
|
|
1915
2163
|
if (remoteCheck.hasRemoteBindings) {
|
|
1916
2164
|
logger?.info("");
|
|
@@ -1961,9 +2209,12 @@ function createDevServer(options) {
|
|
|
1961
2209
|
}
|
|
1962
2210
|
});
|
|
1963
2211
|
doResult = await doBundler.build();
|
|
2212
|
+
currentDoResult = doResult;
|
|
1964
2213
|
await doBundler.watch();
|
|
1965
2214
|
}
|
|
2215
|
+
currentDoResult = doResult;
|
|
1966
2216
|
await startMiniflare(doResult);
|
|
2217
|
+
await startWorkerSourceWatcher();
|
|
1967
2218
|
if (enableVite) {
|
|
1968
2219
|
await startVite();
|
|
1969
2220
|
} else {
|
|
@@ -1977,6 +2228,10 @@ function createDevServer(options) {
|
|
|
1977
2228
|
await doBundler.close();
|
|
1978
2229
|
doBundler = null;
|
|
1979
2230
|
}
|
|
2231
|
+
if (workerSourceWatcher) {
|
|
2232
|
+
await workerSourceWatcher.close();
|
|
2233
|
+
workerSourceWatcher = null;
|
|
2234
|
+
}
|
|
1980
2235
|
if (miniflare) {
|
|
1981
2236
|
await miniflare.dispose();
|
|
1982
2237
|
miniflare = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/dev-server/server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAc3D,MAAM,WAAW,gBAAgB;IAChC,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,sBAAsB;IACtB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,SAAS;IACzB,2BAA2B;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,0BAA0B;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,yCAAyC;IACzC,YAAY,IAAI,aAAa,GAAG,IAAI,CAAA;CACpC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/dev-server/server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAA;AAc3D,MAAM,WAAW,gBAAgB;IAChC,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,sBAAsB;IACtB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,SAAS;IACzB,2BAA2B;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,0BAA0B;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,yCAAyC;IACzC,YAAY,IAAI,aAAa,GAAG,IAAI,CAAA;CACpC;AAmqBD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAkuBpE"}
|
package/dist/index.js
CHANGED
|
@@ -216,7 +216,7 @@ async function runInit(parsed, logger, options) {
|
|
|
216
216
|
return runInitCommand(parsed, logger, options);
|
|
217
217
|
}
|
|
218
218
|
async function runDev(parsed, logger, options) {
|
|
219
|
-
const { runDevCommand } = await import("./dev-
|
|
219
|
+
const { runDevCommand } = await import("./dev-b9dmrj7b.js");
|
|
220
220
|
return runDevCommand(parsed, logger, options);
|
|
221
221
|
}
|
|
222
222
|
async function runBuild(parsed, logger, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devflare",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.5",
|
|
4
4
|
"description": "Devflare is a developer-first toolkit for Cloudflare Workers that sits on top of Miniflare and Wrangler-compatible config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|