devflare 1.0.0-next.21 → 1.0.0-next.22
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/bridge/gateway-runtime.d.ts +1 -1
- package/dist/bridge/gateway-runtime.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +2 -0
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/browser.js +2 -2
- package/dist/build-qsgnme4z.js +54 -0
- package/dist/cli/index.js +1 -1
- package/dist/deploy-nh5tbv45.js +1055 -0
- package/dist/dev-cme5de75.js +2551 -0
- package/dist/index-35bmgpfw.js +573 -0
- package/dist/index-4se6krdj.js +574 -0
- package/dist/index-c1cj9085.js +2250 -0
- package/dist/index-hbxkmb1q.js +1426 -0
- package/dist/index-jwd3fanx.js +412 -0
- package/dist/index-s9q605sq.js +1033 -0
- package/dist/index-w36q6819.js +895 -0
- package/dist/index-xp0qkkxf.js +68 -0
- package/dist/index-zawn5tte.js +109 -0
- package/dist/index-zpy9caxn.js +1193 -0
- package/dist/index.js +3 -3
- package/dist/runtime/index.js +3 -3
- package/dist/sveltekit/index.js +4 -3
- package/dist/sveltekit/local-bindings.d.ts.map +1 -1
- package/dist/test/index.js +6 -6
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/vite/index.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bridgeEnv,
|
|
3
|
+
getContextOrNull
|
|
4
|
+
} from "./index-c1cj9085.js";
|
|
5
|
+
|
|
6
|
+
// src/env.ts
|
|
7
|
+
var testContextEnv = null;
|
|
8
|
+
var testContextDispose = null;
|
|
9
|
+
function __setTestContext(envBindings, dispose) {
|
|
10
|
+
testContextEnv = envBindings;
|
|
11
|
+
testContextDispose = dispose;
|
|
12
|
+
}
|
|
13
|
+
function __clearTestContext() {
|
|
14
|
+
testContextEnv = null;
|
|
15
|
+
testContextDispose = null;
|
|
16
|
+
}
|
|
17
|
+
var env = new Proxy({}, {
|
|
18
|
+
get(_target, prop) {
|
|
19
|
+
if (prop === "dispose") {
|
|
20
|
+
return async () => {
|
|
21
|
+
if (testContextDispose) {
|
|
22
|
+
await testContextDispose();
|
|
23
|
+
__clearTestContext();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ctx = getContextOrNull();
|
|
28
|
+
if (ctx?.env) {
|
|
29
|
+
return ctx.env[prop];
|
|
30
|
+
}
|
|
31
|
+
if (testContextEnv) {
|
|
32
|
+
return testContextEnv[prop];
|
|
33
|
+
}
|
|
34
|
+
return bridgeEnv[prop];
|
|
35
|
+
},
|
|
36
|
+
has(_target, prop) {
|
|
37
|
+
if (prop === "dispose")
|
|
38
|
+
return true;
|
|
39
|
+
const ctx = getContextOrNull();
|
|
40
|
+
if (ctx?.env) {
|
|
41
|
+
return prop in ctx.env;
|
|
42
|
+
}
|
|
43
|
+
if (testContextEnv) {
|
|
44
|
+
return prop in testContextEnv;
|
|
45
|
+
}
|
|
46
|
+
return prop in bridgeEnv;
|
|
47
|
+
},
|
|
48
|
+
ownKeys(_target) {
|
|
49
|
+
const ctx = getContextOrNull();
|
|
50
|
+
if (ctx?.env) {
|
|
51
|
+
return Reflect.ownKeys(ctx.env);
|
|
52
|
+
}
|
|
53
|
+
if (testContextEnv) {
|
|
54
|
+
return Reflect.ownKeys(testContextEnv);
|
|
55
|
+
}
|
|
56
|
+
return Reflect.ownKeys(bridgeEnv);
|
|
57
|
+
},
|
|
58
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
59
|
+
if (prop === "dispose") {
|
|
60
|
+
return { configurable: true, enumerable: false, writable: false };
|
|
61
|
+
}
|
|
62
|
+
const ctx = getContextOrNull();
|
|
63
|
+
const source = ctx?.env ?? testContextEnv ?? bridgeEnv;
|
|
64
|
+
return Reflect.getOwnPropertyDescriptor(source, prop);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export { __setTestContext, __clearTestContext, env };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bundleWorkerEntry
|
|
3
|
+
} from "./index-w36q6819.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_WORKFLOW_PATTERN,
|
|
6
|
+
findFiles
|
|
7
|
+
} from "./index-qwgr4q7s.js";
|
|
8
|
+
import {
|
|
9
|
+
normalizeWorkflowBinding
|
|
10
|
+
} from "./index-syscwrjp.js";
|
|
11
|
+
|
|
12
|
+
// src/workflows/local-workflow-entrypoints.ts
|
|
13
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
14
|
+
import { join, relative, resolve } from "pathe";
|
|
15
|
+
function findExportedClasses(code) {
|
|
16
|
+
const classes = [];
|
|
17
|
+
const classPattern = /export\s+class\s+(\w+)/g;
|
|
18
|
+
let match;
|
|
19
|
+
while ((match = classPattern.exec(code)) !== null) {
|
|
20
|
+
classes.push(match[1]);
|
|
21
|
+
}
|
|
22
|
+
return classes;
|
|
23
|
+
}
|
|
24
|
+
function toImportSpecifier(fromDir, filePath) {
|
|
25
|
+
const relativePath = relative(fromDir, filePath).replace(/\\/g, "/");
|
|
26
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
27
|
+
}
|
|
28
|
+
async function discoverWorkflowClasses(config, configDir) {
|
|
29
|
+
const classToFilePath = new Map;
|
|
30
|
+
const workflowPatternConfig = config.files?.workflows;
|
|
31
|
+
const workflowPattern = typeof workflowPatternConfig === "string" ? workflowPatternConfig : DEFAULT_WORKFLOW_PATTERN;
|
|
32
|
+
if (workflowPatternConfig === false) {
|
|
33
|
+
return classToFilePath;
|
|
34
|
+
}
|
|
35
|
+
const files = await findFiles(workflowPattern, { cwd: configDir });
|
|
36
|
+
for (const filePath of files) {
|
|
37
|
+
try {
|
|
38
|
+
const code = await readFile(filePath, "utf-8");
|
|
39
|
+
for (const className of findExportedClasses(code)) {
|
|
40
|
+
classToFilePath.set(className, filePath);
|
|
41
|
+
}
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
return classToFilePath;
|
|
45
|
+
}
|
|
46
|
+
async function resolveLocalWorkflowEntrypoints(config, configDir) {
|
|
47
|
+
const workflows = config.bindings?.workflows;
|
|
48
|
+
if (!workflows || Object.keys(workflows).length === 0) {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const classToFilePath = await discoverWorkflowClasses(config, configDir);
|
|
52
|
+
const entrypoints = [];
|
|
53
|
+
for (const [bindingName, binding] of Object.entries(workflows)) {
|
|
54
|
+
const normalized = normalizeWorkflowBinding(binding);
|
|
55
|
+
if (normalized.scriptName) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const scriptPath = classToFilePath.get(normalized.className);
|
|
59
|
+
if (!scriptPath) {
|
|
60
|
+
throw new Error(`Workflow binding ${bindingName} (className: '${normalized.className}') not found.
|
|
61
|
+
` + `Either set files.workflows to match the workflow source file, or set scriptName when the workflow lives in another worker.`);
|
|
62
|
+
}
|
|
63
|
+
entrypoints.push({
|
|
64
|
+
bindingName,
|
|
65
|
+
className: normalized.className,
|
|
66
|
+
scriptPath
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return entrypoints;
|
|
70
|
+
}
|
|
71
|
+
function buildWorkflowVirtualEntry(entrypoints, entryDir) {
|
|
72
|
+
const imports = entrypoints.map((entrypoint, index) => {
|
|
73
|
+
const importName = `__DevflareWorkflow${index}`;
|
|
74
|
+
const importPath = toImportSpecifier(entryDir, entrypoint.scriptPath);
|
|
75
|
+
return {
|
|
76
|
+
importName,
|
|
77
|
+
className: entrypoint.className,
|
|
78
|
+
line: `import { ${entrypoint.className} as ${importName} } from '${importPath}'`
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const exports = imports.map((entrypoint) => {
|
|
82
|
+
return `export { ${entrypoint.importName} as ${entrypoint.className} }`;
|
|
83
|
+
});
|
|
84
|
+
return [...imports.map((entrypoint) => entrypoint.line), "", ...exports].join(`
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
async function bundleWorkflowEntrypointScript(config, configDir, options = {}) {
|
|
88
|
+
const entrypoints = await resolveLocalWorkflowEntrypoints(config, configDir);
|
|
89
|
+
if (entrypoints.length === 0) {
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
const entryDir = resolve(configDir, ".devflare", "workflow-entrypoints");
|
|
93
|
+
const entryPath = join(entryDir, "__entry.ts");
|
|
94
|
+
const outFile = join(entryDir, "index.js");
|
|
95
|
+
await mkdir(entryDir, { recursive: true });
|
|
96
|
+
await writeFile(entryPath, buildWorkflowVirtualEntry(entrypoints, entryDir));
|
|
97
|
+
await bundleWorkerEntry({
|
|
98
|
+
cwd: configDir,
|
|
99
|
+
inputFile: entryPath,
|
|
100
|
+
outFile,
|
|
101
|
+
rolldownOptions: config.rolldown?.options,
|
|
102
|
+
sourcemap: config.rolldown?.sourcemap,
|
|
103
|
+
minify: config.rolldown?.minify,
|
|
104
|
+
logger: options.logger
|
|
105
|
+
});
|
|
106
|
+
return await readFile(outFile, "utf-8");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { bundleWorkflowEntrypointScript };
|