devflare 1.0.0-next.5 → 1.0.0-next.7
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/LLM.md +7 -2
- package/README.md +4 -2
- package/dist/browser.d.ts +50 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +149 -0
- package/dist/{build-mnf6v8gd.js → build-9myaxf07.js} +22 -5
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/{deploy-nhceck39.js → deploy-h1wz5p7m.js} +29 -13
- package/dist/{dev-b9dmrj7b.js → dev-rsdssknb.js} +381 -91
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/index-62b3gt2g.js +12 -0
- package/dist/index-9ats0s83.js +70 -0
- package/dist/index-a0fjkq68.js +198 -0
- package/dist/{index-pf5s73n9.js → index-ccrh4w3t.js} +1 -281
- package/dist/{index-ep3445yc.js → index-f8qh2tyh.js} +34 -107
- package/dist/index-k7r18na8.js +0 -0
- package/dist/{index-m2q41jwa.js → index-n3np2d6t.js} +1 -1
- package/dist/index-npc1c8jx.js +44 -0
- package/dist/index-p7g30wd2.js +281 -0
- package/dist/{index-07q6yxyc.js → index-v8vvsn9x.js} +1 -0
- package/dist/index.js +25 -26
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +73 -0
- package/dist/sveltekit/index.js +5 -3
- package/dist/test/index.js +10 -5
- package/dist/test/simple-context.d.ts +1 -1
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/{types-5nyrz1sz.js → types-wdcpnfvy.js} +44 -11
- package/dist/vite/index.js +118 -50
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/worker-entry/composed-worker.d.ts +10 -0
- package/dist/worker-entry/composed-worker.d.ts.map +1 -0
- package/package.json +3 -2
- package/dist/{doctor-fmgb3d28.js → doctor-v7jy4s3r.js} +3 -3
package/dist/runtime/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContextUnavailableError,
|
|
3
|
+
getContext,
|
|
4
|
+
getContextOrNull,
|
|
5
|
+
hasContext,
|
|
6
|
+
runWithContext
|
|
7
|
+
} from "../index-npc1c8jx.js";
|
|
1
8
|
import {
|
|
2
9
|
durableObject,
|
|
3
10
|
getDurableObjectOptions
|
|
@@ -62,6 +69,63 @@ function createContextProxy(getter, name) {
|
|
|
62
69
|
}
|
|
63
70
|
});
|
|
64
71
|
}
|
|
72
|
+
|
|
73
|
+
// src/runtime/exports.ts
|
|
74
|
+
function createReadonlyProxy(getter, name) {
|
|
75
|
+
return new Proxy({}, {
|
|
76
|
+
get(_target, prop) {
|
|
77
|
+
const ctx = getter();
|
|
78
|
+
if (ctx === undefined) {
|
|
79
|
+
throw new ContextAccessError(name, String(prop));
|
|
80
|
+
}
|
|
81
|
+
return ctx[prop];
|
|
82
|
+
},
|
|
83
|
+
set(_target, prop) {
|
|
84
|
+
throw new TypeError(`Cannot assign to '${String(prop)}' on '${name}' because it is read-only.
|
|
85
|
+
` + `Use 'locals' for mutable request-scoped data.`);
|
|
86
|
+
},
|
|
87
|
+
deleteProperty(_target, prop) {
|
|
88
|
+
throw new TypeError(`Cannot delete property '${String(prop)}' from '${name}' because it is read-only.`);
|
|
89
|
+
},
|
|
90
|
+
has(_target, prop) {
|
|
91
|
+
const ctx = getter();
|
|
92
|
+
if (ctx === undefined) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return prop in ctx;
|
|
96
|
+
},
|
|
97
|
+
ownKeys(_target) {
|
|
98
|
+
const ctx = getter();
|
|
99
|
+
if (ctx === undefined) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
return Reflect.ownKeys(ctx);
|
|
103
|
+
},
|
|
104
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
105
|
+
const ctx = getter();
|
|
106
|
+
if (ctx === undefined) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(ctx, prop);
|
|
110
|
+
if (descriptor) {
|
|
111
|
+
return { ...descriptor, writable: false };
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var env = createReadonlyProxy(() => getContextOrNull()?.env, "env");
|
|
118
|
+
var ctx = createReadonlyProxy(() => getContextOrNull()?.ctx, "ctx");
|
|
119
|
+
var event = createReadonlyProxy(() => {
|
|
120
|
+
const context = getContextOrNull();
|
|
121
|
+
if (!context)
|
|
122
|
+
return;
|
|
123
|
+
return {
|
|
124
|
+
request: context.request,
|
|
125
|
+
type: context.type
|
|
126
|
+
};
|
|
127
|
+
}, "event");
|
|
128
|
+
var locals = createContextProxy(() => getContextOrNull()?.locals, "locals");
|
|
65
129
|
// src/runtime/middleware.ts
|
|
66
130
|
function sequence(...middlewares) {
|
|
67
131
|
return (handler) => {
|
|
@@ -102,10 +166,19 @@ function pipe(middlewares, handlers) {
|
|
|
102
166
|
}
|
|
103
167
|
export {
|
|
104
168
|
sequence,
|
|
169
|
+
runWithContext,
|
|
105
170
|
resolve,
|
|
106
171
|
pipe,
|
|
172
|
+
locals,
|
|
173
|
+
hasContext,
|
|
107
174
|
getDurableObjectOptions,
|
|
175
|
+
getContextOrNull,
|
|
176
|
+
getContext,
|
|
177
|
+
event,
|
|
178
|
+
env,
|
|
108
179
|
durableObject,
|
|
180
|
+
ctx,
|
|
109
181
|
createContextProxy,
|
|
182
|
+
ContextUnavailableError,
|
|
110
183
|
ContextAccessError
|
|
111
184
|
};
|
package/dist/sveltekit/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import"../index-
|
|
1
|
+
import"../index-n3np2d6t.js";
|
|
2
|
+
import"../index-p7g30wd2.js";
|
|
3
|
+
import"../index-k7r18na8.js";
|
|
2
4
|
import {
|
|
3
5
|
createEnvProxy,
|
|
4
6
|
getClient
|
|
5
|
-
} from "../index-
|
|
6
|
-
import"../index-
|
|
7
|
+
} from "../index-ccrh4w3t.js";
|
|
8
|
+
import"../index-v8vvsn9x.js";
|
|
7
9
|
import"../index-67qcae0f.js";
|
|
8
10
|
import {
|
|
9
11
|
loadConfig
|
package/dist/test/index.js
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
createMultiWorkerContext,
|
|
13
13
|
createTestContext,
|
|
14
14
|
email,
|
|
15
|
-
env,
|
|
16
15
|
getBridgeTestContext,
|
|
17
16
|
hasCrossWorkerDOs,
|
|
18
17
|
hasServiceBindings,
|
|
@@ -27,14 +26,20 @@ import {
|
|
|
27
26
|
testEnv,
|
|
28
27
|
withTestContext,
|
|
29
28
|
worker
|
|
30
|
-
} from "../index-
|
|
29
|
+
} from "../index-f8qh2tyh.js";
|
|
30
|
+
import"../index-d8bdkx2h.js";
|
|
31
31
|
import"../index-z14anrqp.js";
|
|
32
32
|
import"../index-tk6ej9dj.js";
|
|
33
|
-
import
|
|
33
|
+
import {
|
|
34
|
+
env
|
|
35
|
+
} from "../index-9ats0s83.js";
|
|
36
|
+
import"../index-npc1c8jx.js";
|
|
34
37
|
import"../index-rbht7m9r.js";
|
|
35
38
|
import"../index-gz1gndna.js";
|
|
36
|
-
import"../index-
|
|
37
|
-
import"../index-
|
|
39
|
+
import"../index-p7g30wd2.js";
|
|
40
|
+
import"../index-k7r18na8.js";
|
|
41
|
+
import"../index-ccrh4w3t.js";
|
|
42
|
+
import"../index-v8vvsn9x.js";
|
|
38
43
|
import"../index-67qcae0f.js";
|
|
39
44
|
import"../index-hcex3rgh.js";
|
|
40
45
|
import"../index-tfyxa77h.js";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* This starts Miniflare with the configured bindings and sets up the bridge.
|
|
4
4
|
*
|
|
5
5
|
* @param configPath - Optional path to config file. If not provided, searches
|
|
6
|
-
* upward from the test file for devflare
|
|
6
|
+
* upward from the test file for a supported devflare config.
|
|
7
7
|
* If provided, path is resolved relative to the test file.
|
|
8
8
|
*/
|
|
9
9
|
export declare function createTestContext(configPath?: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-context.d.ts","sourceRoot":"","sources":["../../src/test/simple-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"simple-context.d.ts","sourceRoot":"","sources":["../../src/test/simple-context.ts"],"names":[],"mappings":"AA8JA;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAue1E;AA+BD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACvB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACxB;AAED;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,WAAW;CAAI;AAEhC;;;;;;;;GAQG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDependencies
|
|
3
|
+
} from "./index-1xpj0m4r.js";
|
|
1
4
|
import {
|
|
2
5
|
discoverEntrypointsAsync,
|
|
3
6
|
resolvePackageSpecifier
|
|
@@ -10,21 +13,48 @@ import {
|
|
|
10
13
|
import {
|
|
11
14
|
findDurableObjectClasses
|
|
12
15
|
} from "./index-gz1gndna.js";
|
|
13
|
-
import"./index-
|
|
16
|
+
import"./index-k7r18na8.js";
|
|
17
|
+
import"./index-v8vvsn9x.js";
|
|
14
18
|
import"./index-67qcae0f.js";
|
|
15
19
|
import {
|
|
16
20
|
loadConfig,
|
|
17
|
-
normalizeDOBinding
|
|
21
|
+
normalizeDOBinding,
|
|
22
|
+
resolveConfigPath
|
|
18
23
|
} from "./index-hcex3rgh.js";
|
|
19
|
-
import {
|
|
20
|
-
getDependencies
|
|
21
|
-
} from "./index-1xpj0m4r.js";
|
|
22
24
|
import {
|
|
23
25
|
__require
|
|
24
26
|
} from "./index-37x76zdn.js";
|
|
25
27
|
|
|
26
28
|
// src/cli/commands/types.ts
|
|
27
29
|
import { resolve, relative, dirname } from "pathe";
|
|
30
|
+
var CONFIG_FILE_EXTENSIONS = [".ts", ".mts", ".js", ".mjs"];
|
|
31
|
+
function hasKnownConfigExtension(filePath) {
|
|
32
|
+
return CONFIG_FILE_EXTENSIONS.some((extension) => filePath.endsWith(extension));
|
|
33
|
+
}
|
|
34
|
+
async function resolveConfigCandidatePath(candidatePath) {
|
|
35
|
+
const fs = await import("node:fs/promises");
|
|
36
|
+
const candidates = [candidatePath];
|
|
37
|
+
const getExistingFilePath = async (filePath) => {
|
|
38
|
+
try {
|
|
39
|
+
const stat = await fs.stat(filePath);
|
|
40
|
+
return stat.isFile() ? filePath : null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (!hasKnownConfigExtension(candidatePath)) {
|
|
46
|
+
for (const extension of CONFIG_FILE_EXTENSIONS) {
|
|
47
|
+
candidates.push(`${candidatePath}${extension}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const candidate of candidates) {
|
|
51
|
+
const existingFilePath = await getExistingFilePath(candidate);
|
|
52
|
+
if (existingFilePath) {
|
|
53
|
+
return existingFilePath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return await resolveConfigPath(candidatePath) ?? null;
|
|
57
|
+
}
|
|
28
58
|
async function parseConfigForRefs(configPath) {
|
|
29
59
|
const fs = await import("node:fs/promises");
|
|
30
60
|
const refs = [];
|
|
@@ -98,7 +128,6 @@ async function findInterfaceTypes(searchDirs) {
|
|
|
98
128
|
return interfaces;
|
|
99
129
|
}
|
|
100
130
|
async function resolveReferencedConfigs(configPath, cwd) {
|
|
101
|
-
const fs = await import("node:fs/promises");
|
|
102
131
|
const referenced = [];
|
|
103
132
|
const { refs, serviceBindings, doBindings } = await parseConfigForRefs(configPath);
|
|
104
133
|
if (refs.length === 0) {
|
|
@@ -106,12 +135,12 @@ async function resolveReferencedConfigs(configPath, cwd) {
|
|
|
106
135
|
}
|
|
107
136
|
const configDir = dirname(configPath);
|
|
108
137
|
for (const ref of refs) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
const refImportPath = resolvePackageSpecifier(ref.importPath, configDir);
|
|
139
|
+
const refConfigPath = await resolveConfigCandidatePath(refImportPath);
|
|
140
|
+
if (!refConfigPath) {
|
|
141
|
+
continue;
|
|
112
142
|
}
|
|
113
143
|
try {
|
|
114
|
-
await fs.access(refConfigPath);
|
|
115
144
|
const refDir = dirname(refConfigPath);
|
|
116
145
|
const entrypoints = await discoverEntrypointsAsync(refDir, DEFAULT_ENTRYPOINT_PATTERN);
|
|
117
146
|
const refDOs = await discoverDurableObjects(refDir, DEFAULT_DO_PATTERN);
|
|
@@ -370,8 +399,12 @@ async function runTypesCommand(parsed, logger, options) {
|
|
|
370
399
|
const outputPath = parsed.options.output || "env.d.ts";
|
|
371
400
|
logger.info("Generating TypeScript types...");
|
|
372
401
|
try {
|
|
373
|
-
const actualConfigPath = configPath ? resolve(cwd, configPath) : resolve(cwd, "devflare.config.ts");
|
|
374
402
|
const config = await loadConfig({ cwd, configFile: configPath });
|
|
403
|
+
const requestedConfigPath = configPath ? resolve(cwd, configPath) : cwd;
|
|
404
|
+
const actualConfigPath = await resolveConfigCandidatePath(requestedConfigPath);
|
|
405
|
+
if (!actualConfigPath) {
|
|
406
|
+
throw new Error("Could not resolve the loaded devflare config file path");
|
|
407
|
+
}
|
|
375
408
|
const doPattern = typeof config.files?.durableObjects === "string" ? config.files.durableObjects : DEFAULT_DO_PATTERN;
|
|
376
409
|
let discoveredDOs = [];
|
|
377
410
|
if (config.files?.durableObjects !== false) {
|
package/dist/vite/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
prepareComposedWorkerEntrypoint
|
|
3
|
+
} from "../index-a0fjkq68.js";
|
|
1
4
|
import {
|
|
2
5
|
DEFAULT_DO_PATTERN,
|
|
3
6
|
findFiles
|
|
@@ -11,14 +14,15 @@ import {
|
|
|
11
14
|
writeWranglerConfig
|
|
12
15
|
} from "../index-67qcae0f.js";
|
|
13
16
|
import {
|
|
14
|
-
loadConfig
|
|
17
|
+
loadConfig,
|
|
18
|
+
resolveConfigPath
|
|
15
19
|
} from "../index-hcex3rgh.js";
|
|
16
20
|
import {
|
|
17
21
|
__require
|
|
18
22
|
} from "../index-37x76zdn.js";
|
|
19
23
|
|
|
20
24
|
// src/vite/plugin.ts
|
|
21
|
-
import { resolve } from "pathe";
|
|
25
|
+
import { isAbsolute, relative, resolve } from "pathe";
|
|
22
26
|
var CONFIG_DIR = ".devflare";
|
|
23
27
|
var VIRTUAL_DO_ENTRY = "virtual:devflare-do-entry";
|
|
24
28
|
var RESOLVED_VIRTUAL_DO_ENTRY = "\x00" + VIRTUAL_DO_ENTRY;
|
|
@@ -89,6 +93,89 @@ function createAuxiliaryWorkerConfig(wranglerConfig, discovery) {
|
|
|
89
93
|
}
|
|
90
94
|
};
|
|
91
95
|
}
|
|
96
|
+
function rebaseMainPathForConfigDir(projectRoot, configDir, mainEntry) {
|
|
97
|
+
if (!mainEntry) {
|
|
98
|
+
return mainEntry;
|
|
99
|
+
}
|
|
100
|
+
const absoluteMainPath = isAbsolute(mainEntry) ? mainEntry : resolve(projectRoot, mainEntry);
|
|
101
|
+
return relative(configDir, absoluteMainPath).replace(/\\/g, "/");
|
|
102
|
+
}
|
|
103
|
+
function logDiscoveredDurableObjects(projectRoot, discovery) {
|
|
104
|
+
if (!discovery || discovery.files.size === 0) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
console.log(`[devflare] Discovered ${discovery.files.size} DO file(s):`);
|
|
108
|
+
for (const [filePath, classes] of discovery.files) {
|
|
109
|
+
console.log(` • ${filePath.replace(projectRoot, ".")} → ${classes.join(", ")}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function buildPluginContextState(projectRoot, devflareConfig, environment) {
|
|
113
|
+
const wranglerConfig = compileConfig(devflareConfig, environment);
|
|
114
|
+
const cloudflareConfig = compileToProgrammaticConfig(devflareConfig, environment);
|
|
115
|
+
const composedMainEntry = await prepareComposedWorkerEntrypoint(projectRoot, devflareConfig, environment);
|
|
116
|
+
if (composedMainEntry) {
|
|
117
|
+
wranglerConfig.main = composedMainEntry;
|
|
118
|
+
cloudflareConfig.main = composedMainEntry;
|
|
119
|
+
}
|
|
120
|
+
let durableObjects = null;
|
|
121
|
+
let auxiliaryWorkerConfig = null;
|
|
122
|
+
const doPatternConfig = devflareConfig.files?.durableObjects;
|
|
123
|
+
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
124
|
+
if (doPatternConfig !== false) {
|
|
125
|
+
const doWorkerName = `${wranglerConfig.name}-do`;
|
|
126
|
+
const discovery = await discoverDurableObjects(projectRoot, doPattern, doWorkerName);
|
|
127
|
+
if (discovery.files.size > 0) {
|
|
128
|
+
durableObjects = discovery;
|
|
129
|
+
if (wranglerConfig.durable_objects?.bindings) {
|
|
130
|
+
for (const binding of wranglerConfig.durable_objects.bindings) {
|
|
131
|
+
binding.script_name = doWorkerName;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (cloudflareConfig.durable_objects) {
|
|
135
|
+
const doConfig = cloudflareConfig.durable_objects;
|
|
136
|
+
for (const binding of doConfig.bindings) {
|
|
137
|
+
binding.script_name = doWorkerName;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
auxiliaryWorkerConfig = createAuxiliaryWorkerConfig(wranglerConfig, discovery);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
wranglerConfig,
|
|
145
|
+
cloudflareConfig,
|
|
146
|
+
durableObjects,
|
|
147
|
+
auxiliaryWorkerConfig
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function ensureGeneratedConfigDir(projectRoot) {
|
|
151
|
+
const configDir = resolve(projectRoot, CONFIG_DIR);
|
|
152
|
+
const fs = await import("node:fs/promises");
|
|
153
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
154
|
+
const gitignorePath = resolve(configDir, ".gitignore");
|
|
155
|
+
try {
|
|
156
|
+
await fs.access(gitignorePath);
|
|
157
|
+
} catch {
|
|
158
|
+
await fs.writeFile(gitignorePath, `*
|
|
159
|
+
`, "utf-8");
|
|
160
|
+
}
|
|
161
|
+
return configDir;
|
|
162
|
+
}
|
|
163
|
+
async function writeGeneratedWranglerConfig(projectRoot, wranglerConfig) {
|
|
164
|
+
const configDir = await ensureGeneratedConfigDir(projectRoot);
|
|
165
|
+
const wranglerFileConfig = {
|
|
166
|
+
...wranglerConfig,
|
|
167
|
+
...wranglerConfig.main && {
|
|
168
|
+
main: rebaseMainPathForConfigDir(projectRoot, configDir, wranglerConfig.main)
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
await writeWranglerConfig(configDir, wranglerFileConfig, "wrangler.jsonc");
|
|
172
|
+
}
|
|
173
|
+
async function resolvePluginConfigPath(projectRoot, configPath) {
|
|
174
|
+
if (configPath) {
|
|
175
|
+
return isAbsolute(configPath) ? configPath : resolve(projectRoot, configPath);
|
|
176
|
+
}
|
|
177
|
+
return await resolveConfigPath(projectRoot) ?? null;
|
|
178
|
+
}
|
|
92
179
|
function devflarePlugin(options = {}) {
|
|
93
180
|
const {
|
|
94
181
|
configPath,
|
|
@@ -100,6 +187,7 @@ function devflarePlugin(options = {}) {
|
|
|
100
187
|
} = options;
|
|
101
188
|
let projectRoot;
|
|
102
189
|
let devflareConfig;
|
|
190
|
+
let resolvedPluginConfigPath = null;
|
|
103
191
|
return {
|
|
104
192
|
name: "devflare",
|
|
105
193
|
enforce: "pre",
|
|
@@ -175,54 +263,22 @@ export default { fetch: () => new Response("No DOs") }`;
|
|
|
175
263
|
async configResolved(config) {
|
|
176
264
|
projectRoot = config.root;
|
|
177
265
|
pluginContext.projectRoot = projectRoot;
|
|
266
|
+
resolvedPluginConfigPath = await resolvePluginConfigPath(projectRoot, configPath);
|
|
178
267
|
try {
|
|
179
268
|
devflareConfig = await loadConfig({
|
|
180
269
|
cwd: projectRoot,
|
|
181
270
|
configFile: configPath
|
|
182
271
|
});
|
|
183
|
-
const
|
|
184
|
-
pluginContext
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const doWorkerName = `${wranglerConfig.name}-do`;
|
|
191
|
-
const discovery = await discoverDurableObjects(projectRoot, doPattern, doWorkerName);
|
|
192
|
-
pluginContext.durableObjects = discovery;
|
|
193
|
-
if (discovery.files.size > 0) {
|
|
194
|
-
if (wranglerConfig.durable_objects?.bindings) {
|
|
195
|
-
for (const binding of wranglerConfig.durable_objects.bindings) {
|
|
196
|
-
binding.script_name = doWorkerName;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (cloudflareConfig.durable_objects) {
|
|
200
|
-
const doConfig = cloudflareConfig.durable_objects;
|
|
201
|
-
for (const binding of doConfig.bindings) {
|
|
202
|
-
binding.script_name = doWorkerName;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
pluginContext.auxiliaryWorkerConfig = createAuxiliaryWorkerConfig(wranglerConfig, discovery);
|
|
206
|
-
console.log(`[devflare] Discovered ${discovery.files.size} DO file(s):`);
|
|
207
|
-
for (const [filePath, classes] of discovery.files) {
|
|
208
|
-
console.log(` • ${filePath.replace(projectRoot, ".")} → ${classes.join(", ")}`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const configDir = resolve(projectRoot, CONFIG_DIR);
|
|
213
|
-
const fs = await import("node:fs/promises");
|
|
214
|
-
await fs.mkdir(configDir, { recursive: true });
|
|
215
|
-
const gitignorePath = resolve(configDir, ".gitignore");
|
|
216
|
-
try {
|
|
217
|
-
await fs.access(gitignorePath);
|
|
218
|
-
} catch {
|
|
219
|
-
await fs.writeFile(gitignorePath, `*
|
|
220
|
-
`, "utf-8");
|
|
221
|
-
}
|
|
222
|
-
await writeWranglerConfig(configDir, wranglerConfig, "wrangler.jsonc");
|
|
272
|
+
const pluginState = await buildPluginContextState(projectRoot, devflareConfig, environment);
|
|
273
|
+
Object.assign(pluginContext, {
|
|
274
|
+
projectRoot,
|
|
275
|
+
...pluginState
|
|
276
|
+
});
|
|
277
|
+
logDiscoveredDurableObjects(projectRoot, pluginState.durableObjects);
|
|
278
|
+
await writeGeneratedWranglerConfig(projectRoot, pluginState.wranglerConfig);
|
|
223
279
|
if (config.command === "serve") {
|
|
224
280
|
console.log("[devflare] Config generated to .devflare/wrangler.jsonc");
|
|
225
|
-
if (
|
|
281
|
+
if (pluginState.auxiliaryWorkerConfig) {
|
|
226
282
|
console.log("[devflare] ✓ Auxiliary DO worker configured");
|
|
227
283
|
}
|
|
228
284
|
}
|
|
@@ -239,8 +295,7 @@ export default { fetch: () => new Response("No DOs") }`;
|
|
|
239
295
|
configureServer(server) {
|
|
240
296
|
if (!watchConfig)
|
|
241
297
|
return;
|
|
242
|
-
const
|
|
243
|
-
const fullConfigPath = resolve(projectRoot, configFileName);
|
|
298
|
+
const fullConfigPath = resolvedPluginConfigPath ?? resolve(projectRoot, configPath || "devflare.config.ts");
|
|
244
299
|
server.watcher.add(fullConfigPath);
|
|
245
300
|
server.watcher.on("change", async (changedPath) => {
|
|
246
301
|
if (changedPath === fullConfigPath) {
|
|
@@ -250,10 +305,13 @@ export default { fetch: () => new Response("No DOs") }`;
|
|
|
250
305
|
cwd: projectRoot,
|
|
251
306
|
configFile: configPath
|
|
252
307
|
});
|
|
253
|
-
const
|
|
254
|
-
pluginContext
|
|
255
|
-
|
|
256
|
-
|
|
308
|
+
const pluginState = await buildPluginContextState(projectRoot, devflareConfig, environment);
|
|
309
|
+
Object.assign(pluginContext, {
|
|
310
|
+
projectRoot,
|
|
311
|
+
...pluginState
|
|
312
|
+
});
|
|
313
|
+
logDiscoveredDurableObjects(projectRoot, pluginState.durableObjects);
|
|
314
|
+
await writeGeneratedWranglerConfig(projectRoot, pluginState.wranglerConfig);
|
|
257
315
|
console.log("[devflare] Config reloaded");
|
|
258
316
|
server.ws.send({
|
|
259
317
|
type: "full-reload",
|
|
@@ -302,7 +360,12 @@ async function getCloudflareConfig(options = {}) {
|
|
|
302
360
|
cwd,
|
|
303
361
|
configFile: options.configPath
|
|
304
362
|
});
|
|
305
|
-
|
|
363
|
+
const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig, options.environment);
|
|
364
|
+
const cloudflareConfig = compileToProgrammaticConfig(devflareConfig, options.environment);
|
|
365
|
+
if (composedMainEntry) {
|
|
366
|
+
cloudflareConfig.main = composedMainEntry;
|
|
367
|
+
}
|
|
368
|
+
return cloudflareConfig;
|
|
306
369
|
}
|
|
307
370
|
async function getDevflareConfigs(options = {}) {
|
|
308
371
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -310,8 +373,13 @@ async function getDevflareConfigs(options = {}) {
|
|
|
310
373
|
cwd,
|
|
311
374
|
configFile: options.configPath
|
|
312
375
|
});
|
|
376
|
+
const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig, options.environment);
|
|
313
377
|
const wranglerConfig = compileConfig(devflareConfig, options.environment);
|
|
314
378
|
const cloudflareConfig = { ...wranglerConfig };
|
|
379
|
+
if (composedMainEntry) {
|
|
380
|
+
wranglerConfig.main = composedMainEntry;
|
|
381
|
+
cloudflareConfig.main = composedMainEntry;
|
|
382
|
+
}
|
|
315
383
|
const auxiliaryWorkers = [];
|
|
316
384
|
const doPatternConfig = devflareConfig.files?.durableObjects;
|
|
317
385
|
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAA;AAGjE,OAAO,EAIN,KAAK,cAAc,EACnB,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAA;AAGjE,OAAO,EAIN,KAAK,cAAc,EACnB,MAAM,oBAAoB,CAAA;AAY3B,MAAM,WAAW,qBAAqB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,cAAc,EAAE,cAAc,GAAG,IAAI,CAAA;IAErC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAEhD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,qBAAqB,EAAE,qBAAqB,GAAG,IAAI,CAAA;IAEnD;;OAEG;IACH,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CACxC;AAED,MAAM,WAAW,iBAAiB;IACjC,gDAA8C;IAC9C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAC5B,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAkBD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAExD;AAwND;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAuO1E;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,GAAE;IAClD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAaxC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,GAAE;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,gBAAgB,EAAE,qBAAqB,EAAE,CAAA;CACzC,CAAC,CAsCD;AAGD,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DevflareConfig } from '../config';
|
|
2
|
+
export interface WorkerSurfacePaths {
|
|
3
|
+
fetch: string | null;
|
|
4
|
+
queue: string | null;
|
|
5
|
+
scheduled: string | null;
|
|
6
|
+
email: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveWorkerSurfacePaths(cwd: string, config: DevflareConfig): Promise<WorkerSurfacePaths>;
|
|
9
|
+
export declare function prepareComposedWorkerEntrypoint(cwd: string, config: DevflareConfig, environment?: string): Promise<string | null>;
|
|
10
|
+
//# sourceMappingURL=composed-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed-worker.d.ts","sourceRoot":"","sources":["../../src/worker-entry/composed-worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AA8B/C,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AA8CD,wBAAsB,yBAAyB,CAC9C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,GACpB,OAAO,CAAC,kBAAkB,CAAC,CAO7B;AAiHD,wBAAsB,+BAA+B,CACpD,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA8BxB"}
|
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.7",
|
|
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",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
+
"browser": "./dist/browser.js",
|
|
11
12
|
"import": "./dist/index.js",
|
|
12
13
|
"default": "./dist/index.js"
|
|
13
14
|
},
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
],
|
|
54
55
|
"scripts": {
|
|
55
56
|
"prebuild": "node -e \"require('fs').rmSync('./dist', { recursive: true, force: true })\"",
|
|
56
|
-
"build": "bun build ./src/index.ts ./src/runtime/index.ts ./src/test/index.ts ./src/vite/index.ts ./src/sveltekit/index.ts ./src/cloudflare/index.ts ./src/decorators/index.ts --outdir ./dist --splitting --target node --packages=external && tsgo --declaration --emitDeclarationOnly --noEmit false --outDir ./dist",
|
|
57
|
+
"build": "bun build ./src/index.ts ./src/browser.ts ./src/runtime/index.ts ./src/test/index.ts ./src/vite/index.ts ./src/sveltekit/index.ts ./src/cloudflare/index.ts ./src/decorators/index.ts --outdir ./dist --splitting --target node --packages=external && tsgo --declaration --emitDeclarationOnly --noEmit false --outDir ./dist",
|
|
57
58
|
"dev": "bun --watch ./src/cli/index.ts",
|
|
58
59
|
"test": "bun test",
|
|
59
60
|
"test:watch": "bun test --watch",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectViteProject
|
|
3
3
|
} from "./index-18hvb6gb.js";
|
|
4
|
+
import {
|
|
5
|
+
getDependencies
|
|
6
|
+
} from "./index-1xpj0m4r.js";
|
|
4
7
|
import {
|
|
5
8
|
loadConfig,
|
|
6
9
|
resolveConfigPath
|
|
7
10
|
} from "./index-hcex3rgh.js";
|
|
8
|
-
import {
|
|
9
|
-
getDependencies
|
|
10
|
-
} from "./index-1xpj0m4r.js";
|
|
11
11
|
import"./index-37x76zdn.js";
|
|
12
12
|
|
|
13
13
|
// src/cli/commands/doctor.ts
|