devflare 1.0.0-next.13 → 1.0.0-next.15
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 +36 -1
- package/README.md +85 -0
- package/dist/{account-8psavtg6.js → account-spa7gzsn.js} +3 -2
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/browser.d.ts +7 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/{build-e6kgjwr8.js → build-zv25ke4s.js} +10 -9
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/worker-bundler.d.ts.map +1 -1
- package/dist/bundler/worker-compat.d.ts +4 -0
- package/dist/bundler/worker-compat.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts +4 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/config/compiler.d.ts.map +1 -1
- package/dist/config/index.d.ts +3 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts +1 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/resource-resolution.d.ts +44 -0
- package/dist/config/resource-resolution.d.ts.map +1 -0
- package/dist/config/schema.d.ts +193 -28
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config-v9tr4rts.js +57 -0
- package/dist/{deploy-eeaqwxaa.js → deploy-6xmqvv06.js} +10 -9
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/{dev-mqsffeeb.js → dev-ymtphbkg.js} +11 -5
- package/dist/{doctor-z4ffybce.js → doctor-xv4gm1h4.js} +3 -2
- package/dist/{index-nb0bqtx7.js → index-001mw014.js} +308 -2
- package/dist/{index-xxwbb2nt.js → index-0rsa2c1t.js} +5 -2
- package/dist/{index-0kzg8wed.js → index-3a4mmn57.js} +12 -6
- package/dist/{index-rfhx0yd5.js → index-5s1bz1e0.js} +12 -12
- package/dist/{index-n7rs26ft.js → index-6nb7w45m.js} +15 -13
- package/dist/index-7bq4xq84.js +197 -0
- package/dist/{index-dr6sbp8d.js → index-k8vh558d.js} +1 -1
- package/dist/{index-wyf3s77s.js → index-tksw7gpy.js} +162 -2
- package/dist/{index-8x16kn47.js → index-v43z02tr.js} +18 -8
- package/dist/{index-tfyxa77h.js → index-xdq9ery1.js} +1 -187
- package/dist/{index-zbvmtcn2.js → index-zvgc3e0c.js} +25 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/src/browser.js +17 -0
- package/dist/src/cli/index.js +1 -1
- package/dist/src/cloudflare/index.js +3 -2
- package/dist/src/index.js +16 -7
- package/dist/src/sveltekit/index.js +4 -3
- package/dist/src/test/index.js +6 -5
- package/dist/src/vite/index.js +4 -3
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/{types-sffr9681.js → types-158m16vd.js} +4 -3
- package/dist/vite/plugin.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,310 @@ import {
|
|
|
12
12
|
// src/bundler/worker-bundler.ts
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { dirname, resolve } from "pathe";
|
|
15
|
+
|
|
16
|
+
// src/bundler/worker-compat.ts
|
|
17
|
+
import MagicString from "magic-string";
|
|
18
|
+
import ts from "typescript";
|
|
19
|
+
var WORKER_DYNAMIC_IMPORT_ERROR = "Devflare worker bundles cannot contain unresolved dynamic import() expressions because Miniflare/workerd reject dynamic module specifiers";
|
|
20
|
+
function getScriptKind(id) {
|
|
21
|
+
if (id.endsWith(".tsx")) {
|
|
22
|
+
return ts.ScriptKind.TSX;
|
|
23
|
+
}
|
|
24
|
+
if (id.endsWith(".ts") || id.endsWith(".mts") || id.endsWith(".cts")) {
|
|
25
|
+
return ts.ScriptKind.TS;
|
|
26
|
+
}
|
|
27
|
+
if (id.endsWith(".jsx")) {
|
|
28
|
+
return ts.ScriptKind.JSX;
|
|
29
|
+
}
|
|
30
|
+
return ts.ScriptKind.JS;
|
|
31
|
+
}
|
|
32
|
+
function createSourceFile(code, id) {
|
|
33
|
+
return ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true, getScriptKind(id));
|
|
34
|
+
}
|
|
35
|
+
function hasExportModifier(node) {
|
|
36
|
+
if (!ts.canHaveModifiers(node)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
40
|
+
}
|
|
41
|
+
function isConstVariableStatement(statement) {
|
|
42
|
+
return ts.isVariableStatement(statement) && (statement.declarationList.flags & ts.NodeFlags.Const) !== 0;
|
|
43
|
+
}
|
|
44
|
+
function quoteString(value) {
|
|
45
|
+
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, `\\'`)}'`;
|
|
46
|
+
}
|
|
47
|
+
function resolveLiteralImportSpecifier(expression, constStrings) {
|
|
48
|
+
if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {
|
|
49
|
+
return expression.text;
|
|
50
|
+
}
|
|
51
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
52
|
+
return resolveLiteralImportSpecifier(expression.expression, constStrings);
|
|
53
|
+
}
|
|
54
|
+
if (ts.isIdentifier(expression)) {
|
|
55
|
+
return constStrings.get(expression.text) ?? null;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function collectTopLevelConstStrings(sourceFile) {
|
|
60
|
+
const constStrings = new Map;
|
|
61
|
+
for (const statement of sourceFile.statements) {
|
|
62
|
+
if (!isConstVariableStatement(statement)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
66
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const literal = resolveLiteralImportSpecifier(declaration.initializer, constStrings);
|
|
70
|
+
if (literal !== null) {
|
|
71
|
+
constStrings.set(declaration.name.text, literal);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return constStrings;
|
|
76
|
+
}
|
|
77
|
+
function unwrapDynamicImportExpression(expression) {
|
|
78
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
79
|
+
return unwrapDynamicImportExpression(expression.expression);
|
|
80
|
+
}
|
|
81
|
+
if (ts.isAwaitExpression(expression)) {
|
|
82
|
+
return unwrapDynamicImportExpression(expression.expression);
|
|
83
|
+
}
|
|
84
|
+
if (!ts.isCallExpression(expression) || expression.expression.kind !== ts.SyntaxKind.ImportKeyword) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return expression;
|
|
88
|
+
}
|
|
89
|
+
function getWrapperBodyExpression(body) {
|
|
90
|
+
if (!body) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (!ts.isBlock(body)) {
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
if (body.statements.length !== 1) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const [statement] = body.statements;
|
|
100
|
+
if (!ts.isReturnStatement(statement) || !statement.expression) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return statement.expression;
|
|
104
|
+
}
|
|
105
|
+
function createImportWrapper(name, parameterName, body, sourceFile) {
|
|
106
|
+
const bodyExpression = getWrapperBodyExpression(body);
|
|
107
|
+
if (!bodyExpression) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const importExpression = unwrapDynamicImportExpression(bodyExpression);
|
|
111
|
+
if (!importExpression || importExpression.arguments.length < 1) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const [importArgument] = importExpression.arguments;
|
|
115
|
+
if (!ts.isIdentifier(importArgument) || importArgument.text !== parameterName || !body) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
name,
|
|
120
|
+
parameterName,
|
|
121
|
+
bodyStart: body.getStart(sourceFile),
|
|
122
|
+
bodyEnd: body.getEnd(),
|
|
123
|
+
specifiers: new Set,
|
|
124
|
+
hasUnsupportedCalls: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function collectImportWrappers(sourceFile) {
|
|
128
|
+
const wrappers = new Map;
|
|
129
|
+
for (const statement of sourceFile.statements) {
|
|
130
|
+
if (ts.isFunctionDeclaration(statement) && statement.name && !hasExportModifier(statement) && statement.parameters.length === 1 && ts.isIdentifier(statement.parameters[0]?.name)) {
|
|
131
|
+
const wrapper = createImportWrapper(statement.name.text, statement.parameters[0].name.text, statement.body, sourceFile);
|
|
132
|
+
if (wrapper) {
|
|
133
|
+
wrappers.set(wrapper.name, wrapper);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!isConstVariableStatement(statement) || hasExportModifier(statement)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
140
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!ts.isArrowFunction(declaration.initializer) && !ts.isFunctionExpression(declaration.initializer)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (declaration.initializer.parameters.length !== 1 || !ts.isIdentifier(declaration.initializer.parameters[0]?.name)) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const wrapper = createImportWrapper(declaration.name.text, declaration.initializer.parameters[0].name.text, declaration.initializer.body, sourceFile);
|
|
150
|
+
if (wrapper) {
|
|
151
|
+
wrappers.set(wrapper.name, wrapper);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return wrappers;
|
|
156
|
+
}
|
|
157
|
+
function collectWrapperCallSpecifiers(sourceFile, wrappers, constStrings) {
|
|
158
|
+
function visit(node) {
|
|
159
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
160
|
+
const wrapper = wrappers.get(node.expression.text);
|
|
161
|
+
if (wrapper) {
|
|
162
|
+
if (node.arguments.length !== 1) {
|
|
163
|
+
wrapper.hasUnsupportedCalls = true;
|
|
164
|
+
} else {
|
|
165
|
+
const specifier = resolveLiteralImportSpecifier(node.arguments[0], constStrings);
|
|
166
|
+
if (specifier === null) {
|
|
167
|
+
wrapper.hasUnsupportedCalls = true;
|
|
168
|
+
} else {
|
|
169
|
+
wrapper.specifiers.add(specifier);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
ts.forEachChild(node, visit);
|
|
175
|
+
}
|
|
176
|
+
visit(sourceFile);
|
|
177
|
+
}
|
|
178
|
+
function createImportIdentifier(specifierToIdentifier, specifier) {
|
|
179
|
+
const existing = specifierToIdentifier.get(specifier);
|
|
180
|
+
if (existing) {
|
|
181
|
+
return existing;
|
|
182
|
+
}
|
|
183
|
+
const identifier = `__devflareDynamicImport${specifierToIdentifier.size}`;
|
|
184
|
+
specifierToIdentifier.set(specifier, identifier);
|
|
185
|
+
return identifier;
|
|
186
|
+
}
|
|
187
|
+
function buildWrapperBody(wrapper, specifierToIdentifier) {
|
|
188
|
+
const cases = Array.from(wrapper.specifiers).sort((left, right) => left.localeCompare(right)).map((specifier) => {
|
|
189
|
+
const identifier = createImportIdentifier(specifierToIdentifier, specifier);
|
|
190
|
+
return ` case ${quoteString(specifier)}:
|
|
191
|
+
return Promise.resolve(${identifier})`;
|
|
192
|
+
}).join(`
|
|
193
|
+
`);
|
|
194
|
+
return `{
|
|
195
|
+
switch (${wrapper.parameterName}) {
|
|
196
|
+
${cases}
|
|
197
|
+
default:
|
|
198
|
+
return Promise.reject(new Error(\`Unsupported dynamic import in Devflare worker bundle: \${${wrapper.parameterName}}\`))
|
|
199
|
+
}
|
|
200
|
+
}`;
|
|
201
|
+
}
|
|
202
|
+
function findContainingWrapper(callExpression, wrappers, sourceFile) {
|
|
203
|
+
const start = callExpression.getStart(sourceFile);
|
|
204
|
+
const end = callExpression.getEnd();
|
|
205
|
+
for (const wrapper of wrappers) {
|
|
206
|
+
if (start >= wrapper.bodyStart && end <= wrapper.bodyEnd) {
|
|
207
|
+
return wrapper;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
function transformWorkerDynamicImports(code, id) {
|
|
213
|
+
const sourceFile = createSourceFile(code, id);
|
|
214
|
+
const constStrings = collectTopLevelConstStrings(sourceFile);
|
|
215
|
+
const wrappers = collectImportWrappers(sourceFile);
|
|
216
|
+
collectWrapperCallSpecifiers(sourceFile, wrappers, constStrings);
|
|
217
|
+
const transformableWrappers = Array.from(wrappers.values()).filter((wrapper) => {
|
|
218
|
+
return !wrapper.hasUnsupportedCalls && wrapper.specifiers.size > 0;
|
|
219
|
+
});
|
|
220
|
+
const replacements = [];
|
|
221
|
+
const specifierToIdentifier = new Map;
|
|
222
|
+
function visit(node) {
|
|
223
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
224
|
+
const containingWrapper = findContainingWrapper(node, transformableWrappers, sourceFile);
|
|
225
|
+
if (containingWrapper && node.arguments.length === 1 && ts.isIdentifier(node.arguments[0]) && node.arguments[0].text === containingWrapper.parameterName) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const [argument] = node.arguments;
|
|
229
|
+
if (!argument) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const specifier = resolveLiteralImportSpecifier(argument, constStrings);
|
|
233
|
+
if (specifier !== null) {
|
|
234
|
+
replacements.push({
|
|
235
|
+
start: node.getStart(sourceFile),
|
|
236
|
+
end: node.getEnd(),
|
|
237
|
+
text: `Promise.resolve(${createImportIdentifier(specifierToIdentifier, specifier)})`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
ts.forEachChild(node, visit);
|
|
242
|
+
}
|
|
243
|
+
visit(sourceFile);
|
|
244
|
+
if (replacements.length === 0 && transformableWrappers.length === 0) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
const s = new MagicString(code);
|
|
248
|
+
for (const replacement of replacements.sort((left, right) => right.start - left.start)) {
|
|
249
|
+
s.overwrite(replacement.start, replacement.end, replacement.text);
|
|
250
|
+
}
|
|
251
|
+
for (const wrapper of transformableWrappers.sort((left, right) => right.bodyStart - left.bodyStart)) {
|
|
252
|
+
s.overwrite(wrapper.bodyStart, wrapper.bodyEnd, buildWrapperBody(wrapper, specifierToIdentifier));
|
|
253
|
+
}
|
|
254
|
+
if (specifierToIdentifier.size > 0) {
|
|
255
|
+
const importBlock = Array.from(specifierToIdentifier.entries()).map(([specifier, identifier]) => `import * as ${identifier} from ${quoteString(specifier)}`).join(`
|
|
256
|
+
`);
|
|
257
|
+
const importInsertPosition = code.startsWith("#!") ? code.indexOf(`
|
|
258
|
+
`) === -1 ? code.length : code.indexOf(`
|
|
259
|
+
`) + 1 : 0;
|
|
260
|
+
s.appendLeft(importInsertPosition, `${importBlock}
|
|
261
|
+
`);
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
code: s.toString(),
|
|
265
|
+
map: s.generateMap({
|
|
266
|
+
source: id,
|
|
267
|
+
file: `${id}.map`,
|
|
268
|
+
includeContent: true
|
|
269
|
+
})
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function findDynamicImportCalls(sourceFile) {
|
|
273
|
+
const calls = [];
|
|
274
|
+
function visit(node) {
|
|
275
|
+
if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
276
|
+
calls.push(node);
|
|
277
|
+
}
|
|
278
|
+
ts.forEachChild(node, visit);
|
|
279
|
+
}
|
|
280
|
+
visit(sourceFile);
|
|
281
|
+
return calls;
|
|
282
|
+
}
|
|
283
|
+
async function assertWorkerBundleHasNoDynamicImports(bundlePath) {
|
|
284
|
+
const fs = await import("node:fs/promises");
|
|
285
|
+
const code = await fs.readFile(bundlePath, "utf-8");
|
|
286
|
+
const sourceFile = createSourceFile(code, bundlePath);
|
|
287
|
+
const dynamicImports = findDynamicImportCalls(sourceFile);
|
|
288
|
+
if (dynamicImports.length === 0) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const examples = dynamicImports.slice(0, 3).map((callExpression) => {
|
|
292
|
+
const start = callExpression.getStart(sourceFile);
|
|
293
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(start);
|
|
294
|
+
const snippet = code.slice(start, callExpression.getEnd()).replace(/\s+/g, " ").trim();
|
|
295
|
+
return `- ${line + 1}:${character + 1} ${snippet}`;
|
|
296
|
+
}).join(`
|
|
297
|
+
`);
|
|
298
|
+
throw new Error([
|
|
299
|
+
WORKER_DYNAMIC_IMPORT_ERROR,
|
|
300
|
+
`Bundle: ${bundlePath}`,
|
|
301
|
+
`Examples:
|
|
302
|
+
${examples}`,
|
|
303
|
+
"Devflare can normalize literal import() calls and simple helper wrappers whose call sites are literal strings, but truly runtime-computed specifiers must be converted to static imports for worker bundles."
|
|
304
|
+
].join(`
|
|
305
|
+
|
|
306
|
+
`));
|
|
307
|
+
}
|
|
308
|
+
function createWorkerDynamicImportPlugin() {
|
|
309
|
+
return {
|
|
310
|
+
name: "devflare-worker-dynamic-imports",
|
|
311
|
+
transform(code, id) {
|
|
312
|
+
const result = transformWorkerDynamicImports(code, id);
|
|
313
|
+
return result ?? null;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/bundler/worker-bundler.ts
|
|
15
319
|
function toArray(value) {
|
|
16
320
|
return Array.isArray(value) ? value : [value];
|
|
17
321
|
}
|
|
@@ -176,7 +480,7 @@ function resolveWorkerRolldownConfig(options) {
|
|
|
176
480
|
target: userTarget ?? options.target,
|
|
177
481
|
tsconfig: userTsconfig ?? resolve(options.cwd, "tsconfig.json"),
|
|
178
482
|
external: mergeExternalOptions(defaultExternalModules, userExternal),
|
|
179
|
-
plugins: mergePluginOptions(
|
|
483
|
+
plugins: mergePluginOptions(createWorkerDynamicImportPlugin(), userPlugins),
|
|
180
484
|
resolve: mergeResolveOptions({
|
|
181
485
|
alias: options.alias
|
|
182
486
|
}, userResolve)
|
|
@@ -214,6 +518,7 @@ async function bundleWorkerEntry(options) {
|
|
|
214
518
|
const bundle = await rolldown(inputOptions);
|
|
215
519
|
try {
|
|
216
520
|
await bundle.write(outputOptions);
|
|
521
|
+
await assertWorkerBundleHasNoDynamicImports(options.outFile);
|
|
217
522
|
} finally {
|
|
218
523
|
await bundle.close();
|
|
219
524
|
}
|
|
@@ -368,7 +673,7 @@ function resolveDOBundleRolldownConfig(options) {
|
|
|
368
673
|
platform: "neutral",
|
|
369
674
|
tsconfig: userTsconfig ?? resolve2(options.cwd, "tsconfig.json"),
|
|
370
675
|
external: mergeExternalOptions2(defaultExternalModules, userExternal),
|
|
371
|
-
plugins: mergePluginOptions2(
|
|
676
|
+
plugins: mergePluginOptions2(createWorkerDynamicImportPlugin(), userPlugins),
|
|
372
677
|
resolve: mergeResolveOptions2({
|
|
373
678
|
alias: {
|
|
374
679
|
debug: options.debugShimPath
|
|
@@ -437,6 +742,7 @@ export default createDebug
|
|
|
437
742
|
});
|
|
438
743
|
const bundle = await rolldown(inputOptions);
|
|
439
744
|
await bundle.write(outputOptions);
|
|
745
|
+
await assertWorkerBundleHasNoDynamicImports(outFile);
|
|
440
746
|
await bundle.close();
|
|
441
747
|
try {
|
|
442
748
|
await fs.unlink(tempFilePath);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getLocalD1DatabaseIdentifier,
|
|
2
3
|
normalizeDOBinding
|
|
3
|
-
} from "./index-
|
|
4
|
+
} from "./index-tksw7gpy.js";
|
|
4
5
|
import {
|
|
5
6
|
__require
|
|
6
7
|
} from "./index-37x76zdn.js";
|
|
@@ -288,7 +289,9 @@ async function startMiniflareFromConfig(config, options = {}) {
|
|
|
288
289
|
compatibilityFlags: config.compatibilityFlags,
|
|
289
290
|
kvNamespaces: bindings.kv ? bindings.kv : undefined,
|
|
290
291
|
r2Buckets: bindings.r2 ? bindings.r2 : undefined,
|
|
291
|
-
d1Databases: bindings.d1 ? bindings.d1
|
|
292
|
+
d1Databases: bindings.d1 ? Object.fromEntries(Object.entries(bindings.d1).map(([bindingName, bindingConfig]) => {
|
|
293
|
+
return [bindingName, getLocalD1DatabaseIdentifier(bindingConfig)];
|
|
294
|
+
})) : undefined,
|
|
292
295
|
queues: bindings.queues?.consumers?.map((c) => c.queue),
|
|
293
296
|
sendEmail: bindings.sendEmail ? bindings.sendEmail : undefined,
|
|
294
297
|
bindings: config.vars,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
import {
|
|
43
43
|
startMiniflare,
|
|
44
44
|
startMiniflareFromConfig
|
|
45
|
-
} from "./index-
|
|
45
|
+
} from "./index-0rsa2c1t.js";
|
|
46
46
|
import {
|
|
47
47
|
BridgeClient,
|
|
48
48
|
createEnvProxy,
|
|
@@ -53,17 +53,20 @@ import {
|
|
|
53
53
|
wrapEnvSendEmailBindings
|
|
54
54
|
} from "./index-fef08w43.js";
|
|
55
55
|
import {
|
|
56
|
+
getLocalD1DatabaseIdentifier,
|
|
56
57
|
loadConfig,
|
|
57
58
|
normalizeDOBinding,
|
|
58
59
|
resolveConfigPath
|
|
59
|
-
} from "./index-
|
|
60
|
+
} from "./index-tksw7gpy.js";
|
|
61
|
+
import {
|
|
62
|
+
canProceedWithTest
|
|
63
|
+
} from "./index-7bq4xq84.js";
|
|
60
64
|
import {
|
|
61
|
-
canProceedWithTest,
|
|
62
65
|
getApiToken,
|
|
63
66
|
getEffectiveAccountId,
|
|
64
67
|
getPrimaryAccount,
|
|
65
68
|
isAuthenticated
|
|
66
|
-
} from "./index-
|
|
69
|
+
} from "./index-xdq9ery1.js";
|
|
67
70
|
import {
|
|
68
71
|
__require
|
|
69
72
|
} from "./index-37x76zdn.js";
|
|
@@ -1350,8 +1353,11 @@ async function createTestContext(configPath) {
|
|
|
1350
1353
|
mfConfig.kvNamespaces = Object.keys(config.bindings.kv);
|
|
1351
1354
|
if (config.bindings?.r2)
|
|
1352
1355
|
mfConfig.r2Buckets = Object.keys(config.bindings.r2);
|
|
1353
|
-
if (config.bindings?.d1)
|
|
1354
|
-
mfConfig.d1Databases = Object.
|
|
1356
|
+
if (config.bindings?.d1) {
|
|
1357
|
+
mfConfig.d1Databases = Object.fromEntries(Object.entries(config.bindings.d1).map(([bindingName, bindingConfig]) => {
|
|
1358
|
+
return [bindingName, getLocalD1DatabaseIdentifier(bindingConfig)];
|
|
1359
|
+
}));
|
|
1360
|
+
}
|
|
1355
1361
|
if (config.bindings?.queues?.producers) {
|
|
1356
1362
|
const queueProducers = {};
|
|
1357
1363
|
for (const [bindingName, queueName] of Object.entries(config.bindings.queues.producers)) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
normalizeD1Binding,
|
|
3
|
+
normalizeDOBinding,
|
|
4
|
+
resolveConfigForEnvironment
|
|
5
|
+
} from "./index-tksw7gpy.js";
|
|
4
6
|
import {
|
|
5
7
|
__require
|
|
6
8
|
} from "./index-37x76zdn.js";
|
|
7
9
|
|
|
8
|
-
// src/config/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
10
|
+
// src/config/compiler.ts
|
|
11
|
+
function getWranglerD1DatabaseId(bindingName, bindingConfig) {
|
|
12
|
+
const normalized = normalizeD1Binding(bindingConfig);
|
|
13
|
+
if (normalized.databaseId) {
|
|
14
|
+
return normalized.databaseId;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
throw new Error(`D1 binding "${bindingName}" is configured by name (${normalized.name}) and must be resolved before compiling Wrangler config. Use loadResolvedConfig() or resolveConfigResources() for build/deploy/automation flows.`);
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
// src/config/compiler.ts
|
|
18
18
|
function compileConfig(config, environment) {
|
|
19
19
|
const mergedConfig = resolveConfigForEnvironment(config, environment);
|
|
20
20
|
const result = {
|
|
@@ -93,7 +93,7 @@ function compileBindings(bindings, result) {
|
|
|
93
93
|
if (bindings.d1) {
|
|
94
94
|
result.d1_databases = Object.entries(bindings.d1).map(([binding, database_id]) => ({
|
|
95
95
|
binding,
|
|
96
|
-
database_id
|
|
96
|
+
database_id: getWranglerD1DatabaseId(binding, database_id)
|
|
97
97
|
}));
|
|
98
98
|
}
|
|
99
99
|
if (bindings.r2) {
|
|
@@ -199,4 +199,4 @@ async function writeWranglerConfig(cwd, config, filename = "wrangler.jsonc") {
|
|
|
199
199
|
await fs.writeFile(wranglerPath, content, "utf-8");
|
|
200
200
|
return wranglerPath;
|
|
201
201
|
}
|
|
202
|
-
export {
|
|
202
|
+
export { compileConfig, compileToProgrammaticConfig, stringifyConfig, writeWranglerConfig };
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
2
|
canProceedWithTest,
|
|
3
|
+
getAllUsageSummaries,
|
|
4
|
+
getLimits,
|
|
5
|
+
getUsage,
|
|
6
|
+
getUsageSummary,
|
|
7
|
+
isWithinLimits,
|
|
8
|
+
recordTestUsage,
|
|
9
|
+
recordUsage,
|
|
10
|
+
resetUsage,
|
|
11
|
+
setLimits,
|
|
12
|
+
setLimitsEnabled,
|
|
13
|
+
shouldSkip
|
|
14
|
+
} from "./index-7bq4xq84.js";
|
|
15
|
+
import {
|
|
3
16
|
clearGlobalDefaultAccountId,
|
|
4
17
|
getAccountById,
|
|
5
18
|
getAccountSummary,
|
|
6
19
|
getAccounts,
|
|
7
20
|
getAllServiceStatus,
|
|
8
|
-
getAllUsageSummaries,
|
|
9
21
|
getApiToken,
|
|
10
22
|
getEffectiveAccountId,
|
|
11
23
|
getGlobalDefaultAccountId,
|
|
12
|
-
getLimits,
|
|
13
24
|
getPrimaryAccount,
|
|
14
25
|
getServiceStatus,
|
|
15
|
-
getUsage,
|
|
16
|
-
getUsageSummary,
|
|
17
26
|
getWorkspaceAccountId,
|
|
18
27
|
getWranglerAuth,
|
|
19
28
|
hasService,
|
|
20
29
|
hasWranglerConfig,
|
|
21
30
|
isAuthenticated,
|
|
22
|
-
isWithinLimits,
|
|
23
31
|
listAIModels,
|
|
24
32
|
listD1Databases,
|
|
25
33
|
listKVNamespaces,
|
|
26
34
|
listR2Buckets,
|
|
27
35
|
listVectorizeIndexes,
|
|
28
36
|
listWorkers,
|
|
29
|
-
recordTestUsage,
|
|
30
|
-
recordUsage,
|
|
31
|
-
resetUsage,
|
|
32
37
|
setGlobalDefaultAccountId,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
setWorkspaceAccountId,
|
|
36
|
-
shouldSkip
|
|
37
|
-
} from "./index-tfyxa77h.js";
|
|
38
|
+
setWorkspaceAccountId
|
|
39
|
+
} from "./index-xdq9ery1.js";
|
|
38
40
|
|
|
39
41
|
// src/cloudflare/index.ts
|
|
40
42
|
var account = {
|