devflare 1.0.0-next.22 → 1.0.0-next.24

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.
Files changed (146) hide show
  1. package/LLM.md +221 -7
  2. package/dist/account-5nm1xn0v.js +475 -0
  3. package/dist/account-j8nfggg4.js +475 -0
  4. package/dist/account-qhe8vtds.js +475 -0
  5. package/dist/bridge/miniflare.d.ts +1 -1
  6. package/dist/bridge/miniflare.d.ts.map +1 -1
  7. package/dist/browser.d.ts +35 -15
  8. package/dist/browser.d.ts.map +1 -1
  9. package/dist/browser.js +4 -2
  10. package/dist/build-vctfnmsf.js +54 -0
  11. package/dist/build-vy95gy3f.js +54 -0
  12. package/dist/build-yzx0gsaj.js +54 -0
  13. package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
  14. package/dist/cli/commands/config.d.ts.map +1 -1
  15. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -1
  16. package/dist/cli/commands/deploy.d.ts.map +1 -1
  17. package/dist/cli/commands/type-generation/generator.d.ts +4 -2
  18. package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
  19. package/dist/cli/commands/types.d.ts.map +1 -1
  20. package/dist/cli/index.js +1 -1
  21. package/dist/config/compiler/types.d.ts +1 -1
  22. package/dist/config/compiler/types.d.ts.map +1 -1
  23. package/dist/config/define.d.ts +7 -4
  24. package/dist/config/define.d.ts.map +1 -1
  25. package/dist/config/env-vars.d.ts +309 -0
  26. package/dist/config/env-vars.d.ts.map +1 -0
  27. package/dist/config/index.d.ts +2 -1
  28. package/dist/config/index.d.ts.map +1 -1
  29. package/dist/config/loader.d.ts.map +1 -1
  30. package/dist/config/local-dev-vars.d.ts +2 -2
  31. package/dist/config/local-dev-vars.d.ts.map +1 -1
  32. package/dist/config/schema-env.d.ts +28 -8
  33. package/dist/config/schema-env.d.ts.map +1 -1
  34. package/dist/config/schema-runtime.d.ts +11 -1
  35. package/dist/config/schema-runtime.d.ts.map +1 -1
  36. package/dist/config/schema-types-bindings-platform.d.ts +378 -0
  37. package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
  38. package/dist/config/schema-types-bindings-resources.d.ts +551 -0
  39. package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
  40. package/dist/config/schema-types-bindings.d.ts +254 -0
  41. package/dist/config/schema-types-bindings.d.ts.map +1 -0
  42. package/dist/config/schema-types-build.d.ts +86 -0
  43. package/dist/config/schema-types-build.d.ts.map +1 -0
  44. package/dist/config/schema-types-runtime.d.ts +885 -0
  45. package/dist/config/schema-types-runtime.d.ts.map +1 -0
  46. package/dist/config/schema-types.d.ts +377 -0
  47. package/dist/config/schema-types.d.ts.map +1 -0
  48. package/dist/config/schema.d.ts +47 -18
  49. package/dist/config/schema.d.ts.map +1 -1
  50. package/dist/config-entry.d.ts +2 -0
  51. package/dist/config-entry.d.ts.map +1 -1
  52. package/dist/config-entry.js +3 -1
  53. package/dist/config-gq5jh4cx.js +105 -0
  54. package/dist/config-rq32csms.js +105 -0
  55. package/dist/config-vec13050.js +105 -0
  56. package/dist/deploy-01j0ep5n.js +1055 -0
  57. package/dist/deploy-krj3k9zm.js +1055 -0
  58. package/dist/deploy-mem96qyn.js +1066 -0
  59. package/dist/deploy-tjypkhg7.js +1055 -0
  60. package/dist/dev-apkr7cfv.js +2597 -0
  61. package/dist/dev-bh581ew3.js +2597 -0
  62. package/dist/dev-gn5y93z9.js +2597 -0
  63. package/dist/dev-server/server.d.ts.map +1 -1
  64. package/dist/doctor-9asw8x18.js +259 -0
  65. package/dist/doctor-h5q28qt1.js +259 -0
  66. package/dist/doctor-khk550tw.js +259 -0
  67. package/dist/env.d.ts +10 -0
  68. package/dist/env.d.ts.map +1 -1
  69. package/dist/index-0bv2qjs1.js +1555 -0
  70. package/dist/index-3tkzn06q.js +413 -0
  71. package/dist/index-4j9ah79n.js +1033 -0
  72. package/dist/index-8fyz6gcm.js +699 -0
  73. package/dist/index-97z629zr.js +109 -0
  74. package/dist/index-b28c4yr4.js +1205 -0
  75. package/dist/index-bfjpjs07.js +581 -0
  76. package/dist/index-c8p4njqy.js +479 -0
  77. package/dist/index-cna43592.js +1573 -0
  78. package/dist/index-cr06zrgw.js +1033 -0
  79. package/dist/index-cwjjdtgn.js +74 -0
  80. package/dist/index-d00njc1f.js +147 -0
  81. package/dist/index-dgeamyfk.js +1426 -0
  82. package/dist/index-dref9ecb.js +476 -0
  83. package/dist/index-e151t4ge.js +895 -0
  84. package/dist/index-e7kakw0j.js +1033 -0
  85. package/dist/index-f1g5jdm8.js +1426 -0
  86. package/dist/index-f46984zs.js +1554 -0
  87. package/dist/index-ftf7yqhs.js +74 -0
  88. package/dist/index-grk8pzhr.js +185 -0
  89. package/dist/index-h332fg62.js +1205 -0
  90. package/dist/index-hzmpecq9.js +52 -0
  91. package/dist/index-j1csb7gb.js +581 -0
  92. package/dist/index-j7x7f72h.js +185 -0
  93. package/dist/index-ja2rdbt0.js +476 -0
  94. package/dist/index-jkqbjwt2.js +476 -0
  95. package/dist/index-kc207nyr.js +52 -0
  96. package/dist/index-meq8ydc0.js +895 -0
  97. package/dist/index-mh5renra.js +895 -0
  98. package/dist/index-myfjejs0.js +185 -0
  99. package/dist/index-p9xq83p7.js +147 -0
  100. package/dist/index-q15nj71j.js +52 -0
  101. package/dist/index-qkfvd3cs.js +109 -0
  102. package/dist/index-qqp65pyv.js +699 -0
  103. package/dist/index-rnz879kf.js +1426 -0
  104. package/dist/index-s0fmwxbk.js +74 -0
  105. package/dist/index-s96e5dd9.js +699 -0
  106. package/dist/index-stzx8nc4.js +111 -0
  107. package/dist/index-th4vrnbk.js +1205 -0
  108. package/dist/index-vtcmsgaf.js +581 -0
  109. package/dist/index-x2k3awjs.js +147 -0
  110. package/dist/index-x8x547tz.js +1426 -0
  111. package/dist/index-xxxd0mvw.js +109 -0
  112. package/dist/index.d.ts +1 -1
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +8 -6
  115. package/dist/login-280p2cm9.js +77 -0
  116. package/dist/login-4n266whq.js +77 -0
  117. package/dist/login-g9rb7dj3.js +77 -0
  118. package/dist/previews-3m3ffpaw.js +1337 -0
  119. package/dist/previews-tr8sm03d.js +1337 -0
  120. package/dist/previews-ykamw25e.js +1337 -0
  121. package/dist/productions-4m1pd6ts.js +505 -0
  122. package/dist/productions-62y489ff.js +505 -0
  123. package/dist/productions-cgn3fz7d.js +505 -0
  124. package/dist/runtime/exports.d.ts +23 -0
  125. package/dist/runtime/exports.d.ts.map +1 -1
  126. package/dist/runtime/index.d.ts +1 -1
  127. package/dist/runtime/index.d.ts.map +1 -1
  128. package/dist/runtime/index.js +5 -3
  129. package/dist/secrets-4050kqf5.js +91 -0
  130. package/dist/secrets-gywxctdh.js +91 -0
  131. package/dist/secrets-p112cajt.js +91 -0
  132. package/dist/sveltekit/index.js +4 -4
  133. package/dist/test/index.js +23 -11
  134. package/dist/test/resolve-service-bindings.d.ts +1 -1
  135. package/dist/test/resolve-service-bindings.d.ts.map +1 -1
  136. package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
  137. package/dist/types-17kkqw37.js +705 -0
  138. package/dist/types-apmt10yj.js +705 -0
  139. package/dist/types-ttrrgdfj.js +705 -0
  140. package/dist/vite/index.js +5 -5
  141. package/dist/vite/plugin-context.d.ts.map +1 -1
  142. package/dist/vite/plugin-programmatic.d.ts.map +1 -1
  143. package/dist/worker-2k1jyr6p.js +513 -0
  144. package/dist/worker-4fd49jm0.js +513 -0
  145. package/dist/worker-jqgn6jyj.js +513 -0
  146. package/package.json +1 -1
@@ -0,0 +1,185 @@
1
+ import {
2
+ resolveConfigForEnvironment
3
+ } from "./index-cna43592.js";
4
+
5
+ // src/cli/commands/previews-support/family.ts
6
+ function compareConfiguredWorkerFamilies(left, right) {
7
+ if (left.role === "primary" && right.role !== "primary") {
8
+ return -1;
9
+ }
10
+ if (left.role !== "primary" && right.role === "primary") {
11
+ return 1;
12
+ }
13
+ return left.baseName.localeCompare(right.baseName);
14
+ }
15
+ function comparePreviewScopeRows(left, right) {
16
+ const leftTime = left.updatedAt?.getTime() ?? 0;
17
+ const rightTime = right.updatedAt?.getTime() ?? 0;
18
+ if (rightTime !== leftTime) {
19
+ return rightTime - leftTime;
20
+ }
21
+ return left.scope.localeCompare(right.scope);
22
+ }
23
+ function collectConfiguredWorkerFamilies(config, environment) {
24
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
25
+ const families = new Map;
26
+ families.set(resolvedConfig.name, {
27
+ baseName: resolvedConfig.name,
28
+ roleLabel: "primary",
29
+ role: "primary"
30
+ });
31
+ for (const [bindingName, binding] of Object.entries(resolvedConfig.bindings?.services ?? {})) {
32
+ const existing = families.get(binding.service);
33
+ if (existing) {
34
+ continue;
35
+ }
36
+ families.set(binding.service, {
37
+ baseName: binding.service,
38
+ roleLabel: bindingName,
39
+ role: "service"
40
+ });
41
+ }
42
+ return Array.from(families.values()).sort(compareConfiguredWorkerFamilies);
43
+ }
44
+ function getWorkerUrl(workerName, workersSubdomain) {
45
+ if (!workersSubdomain) {
46
+ return;
47
+ }
48
+ return `https://${workerName}.${workersSubdomain}.workers.dev`;
49
+ }
50
+ function getWorkerScopeSuffix(workerName, baseName) {
51
+ if (!workerName.startsWith(`${baseName}-`)) {
52
+ return;
53
+ }
54
+ const suffix = workerName.slice(baseName.length + 1).trim();
55
+ return suffix || undefined;
56
+ }
57
+ function buildStableWorkerRowsFromLiveWorkers(families, workers, workersSubdomain) {
58
+ const workersByName = new Map(workers.map((worker) => [worker.name, worker]));
59
+ return families.map((family) => {
60
+ const worker = workersByName.get(family.baseName);
61
+ const status = worker ? "active" : "missing";
62
+ return {
63
+ workerName: family.baseName,
64
+ role: family.roleLabel,
65
+ status,
66
+ updatedAt: worker?.modifiedOn,
67
+ url: worker ? getWorkerUrl(family.baseName, workersSubdomain) : undefined
68
+ };
69
+ });
70
+ }
71
+ function getDedicatedPreviewFamilyNamesFromWorkers(families, workers) {
72
+ const familyNames = new Set;
73
+ const workerNames = workers.map((worker) => worker.name);
74
+ for (const family of families) {
75
+ if (family.role === "primary") {
76
+ familyNames.add(family.baseName);
77
+ continue;
78
+ }
79
+ if (workerNames.some((workerName) => Boolean(getWorkerScopeSuffix(workerName, family.baseName)))) {
80
+ familyNames.add(family.baseName);
81
+ }
82
+ }
83
+ return familyNames;
84
+ }
85
+ function buildPreviewScopeRowsFromLiveWorkers(families, workers, workersSubdomain) {
86
+ const workersByName = new Map(workers.map((worker) => [worker.name, worker]));
87
+ const previewFamilyNames = getDedicatedPreviewFamilyNamesFromWorkers(families, workers);
88
+ const expectedFamilies = families.filter((family) => previewFamilyNames.has(family.baseName));
89
+ const workerCandidatesByScope = buildPreviewWorkerCandidatesByScope(families, workers);
90
+ return Array.from(workerCandidatesByScope.keys()).map((scope) => {
91
+ const resolvedFamilies = expectedFamilies.map((family) => ({
92
+ family,
93
+ worker: workersByName.get(`${family.baseName}-${scope}`)
94
+ }));
95
+ const presentFamilies = resolvedFamilies.filter((entry) => entry.worker);
96
+ const updatedAt = presentFamilies.reduce((latest, entry) => {
97
+ const currentDate = entry.worker?.modifiedOn;
98
+ if (!currentDate) {
99
+ return latest;
100
+ }
101
+ if (!latest || currentDate.getTime() > latest.getTime()) {
102
+ return currentDate;
103
+ }
104
+ return latest;
105
+ }, undefined);
106
+ const primaryEntry = resolvedFamilies.find((entry) => entry.family.role === "primary");
107
+ const entryWorker = primaryEntry?.worker ?? presentFamilies[0]?.worker;
108
+ const missingLabels = resolvedFamilies.filter((entry) => !entry.worker).map((entry) => entry.family.role === "primary" ? "primary" : entry.family.roleLabel);
109
+ const notes = [];
110
+ if (missingLabels.length > 0) {
111
+ notes.push(`missing ${missingLabels.join(", ")}`);
112
+ }
113
+ const strategy = "dedicated workers";
114
+ const status = presentFamilies.length === resolvedFamilies.length ? "ready" : "partial";
115
+ return {
116
+ scope,
117
+ strategy,
118
+ workersLabel: `${presentFamilies.length}/${resolvedFamilies.length}`,
119
+ status,
120
+ updatedAt,
121
+ notes: notes.length > 0 ? notes.join(" · ") : undefined,
122
+ entryUrl: entryWorker ? getWorkerUrl(entryWorker.name, workersSubdomain) : undefined
123
+ };
124
+ }).sort(comparePreviewScopeRows);
125
+ }
126
+ function buildPreviewWorkerCandidatesByScope(families, workers) {
127
+ const candidates = new Map;
128
+ for (const worker of workers) {
129
+ for (const family of families) {
130
+ const scope = getWorkerScopeSuffix(worker.name, family.baseName);
131
+ if (!scope) {
132
+ continue;
133
+ }
134
+ const names = candidates.get(scope) ?? new Set;
135
+ names.add(worker.name);
136
+ candidates.set(scope, names);
137
+ }
138
+ }
139
+ return new Map(Array.from(candidates.entries()).map(([scope, workerNames]) => {
140
+ return [scope, Array.from(workerNames).sort((left, right) => left.localeCompare(right))];
141
+ }));
142
+ }
143
+ function orderPreviewWorkerNamesForDeletion(workerNames, scope, families) {
144
+ const familyPriority = new Map;
145
+ for (const family of families) {
146
+ familyPriority.set(family.baseName, {
147
+ priority: family.role === "primary" ? 0 : 1,
148
+ roleLabel: family.roleLabel
149
+ });
150
+ }
151
+ const resolveFamilyForWorker = (workerName) => {
152
+ for (const family of families) {
153
+ if (getWorkerScopeSuffix(workerName, family.baseName) === scope) {
154
+ const resolved = familyPriority.get(family.baseName);
155
+ if (resolved) {
156
+ return {
157
+ priority: resolved.priority,
158
+ roleLabel: resolved.roleLabel,
159
+ baseName: family.baseName
160
+ };
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ priority: 2,
166
+ roleLabel: workerName
167
+ };
168
+ };
169
+ return [...workerNames].sort((left, right) => {
170
+ const leftFamily = resolveFamilyForWorker(left);
171
+ const rightFamily = resolveFamilyForWorker(right);
172
+ if (leftFamily.priority !== rightFamily.priority) {
173
+ return leftFamily.priority - rightFamily.priority;
174
+ }
175
+ if (leftFamily.roleLabel !== rightFamily.roleLabel) {
176
+ return leftFamily.roleLabel.localeCompare(rightFamily.roleLabel);
177
+ }
178
+ if (leftFamily.baseName && rightFamily.baseName && leftFamily.baseName !== rightFamily.baseName) {
179
+ return leftFamily.baseName.localeCompare(rightFamily.baseName);
180
+ }
181
+ return left.localeCompare(right);
182
+ });
183
+ }
184
+
185
+ export { collectConfiguredWorkerFamilies, buildStableWorkerRowsFromLiveWorkers, buildPreviewScopeRowsFromLiveWorkers, buildPreviewWorkerCandidatesByScope, orderPreviewWorkerNamesForDeletion };
@@ -0,0 +1,147 @@
1
+ import {
2
+ normalizeSecretsStoreBinding
3
+ } from "./index-f46984zs.js";
4
+
5
+ // src/secrets/local-secrets.ts
6
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ var LOCAL_SECRETS_PATH = join(".devflare", "secrets.local.json");
9
+ var LOCAL_SECRET_WRAPPED_BINDING_SCRIPT = `
10
+ class LocalSecretsStoreSecret {
11
+ constructor(env) {
12
+ this.value = env.value
13
+ }
14
+
15
+ async get() {
16
+ return this.value
17
+ }
18
+ }
19
+
20
+ export default function makeBinding(env) {
21
+ return new LocalSecretsStoreSecret(env)
22
+ }
23
+ `;
24
+ function createEmptyLocalSecretsFile() {
25
+ return {
26
+ version: 1,
27
+ stores: {}
28
+ };
29
+ }
30
+ function getLocalSecretsFilePath(cwd) {
31
+ return join(cwd, LOCAL_SECRETS_PATH);
32
+ }
33
+ function parseLocalSecretsFile(raw) {
34
+ const parsed = JSON.parse(raw);
35
+ if (parsed.version !== 1 || !parsed.stores || typeof parsed.stores !== "object") {
36
+ return createEmptyLocalSecretsFile();
37
+ }
38
+ return {
39
+ version: 1,
40
+ stores: parsed.stores
41
+ };
42
+ }
43
+ function readLocalSecretsFile(cwd) {
44
+ const filePath = getLocalSecretsFilePath(cwd);
45
+ if (!existsSync(filePath)) {
46
+ return createEmptyLocalSecretsFile();
47
+ }
48
+ return parseLocalSecretsFile(readFileSync(filePath, "utf8"));
49
+ }
50
+ function writeLocalSecretsFile(cwd, file) {
51
+ const filePath = getLocalSecretsFilePath(cwd);
52
+ mkdirSync(dirname(filePath), { recursive: true });
53
+ writeFileSync(filePath, `${JSON.stringify(file, null, "\t")}
54
+ `, {
55
+ encoding: "utf8",
56
+ mode: 384
57
+ });
58
+ }
59
+ function writeLocalSecret({ cwd, storeId, name, value }) {
60
+ const file = readLocalSecretsFile(cwd);
61
+ file.stores[storeId] ??= {};
62
+ file.stores[storeId][name] = {
63
+ value,
64
+ updatedAt: new Date().toISOString()
65
+ };
66
+ writeLocalSecretsFile(cwd, file);
67
+ }
68
+ function readLocalSecret({ cwd, storeId, name }) {
69
+ return readLocalSecretsFile(cwd).stores[storeId]?.[name]?.value;
70
+ }
71
+ function deleteLocalSecret({ cwd, storeId, name }) {
72
+ const file = readLocalSecretsFile(cwd);
73
+ const store = file.stores[storeId];
74
+ if (!store || !(name in store)) {
75
+ return false;
76
+ }
77
+ delete store[name];
78
+ if (Object.keys(store).length === 0) {
79
+ delete file.stores[storeId];
80
+ }
81
+ writeLocalSecretsFile(cwd, file);
82
+ return true;
83
+ }
84
+ function listLocalSecrets({ cwd, storeId }) {
85
+ const file = readLocalSecretsFile(cwd);
86
+ const stores = storeId ? { [storeId]: file.stores[storeId] ?? {} } : file.stores;
87
+ return Object.entries(stores).flatMap(([currentStoreId, secrets]) => Object.entries(secrets).map(([name, secret]) => ({
88
+ storeId: currentStoreId,
89
+ name,
90
+ hasValue: typeof secret.value === "string",
91
+ updatedAt: secret.updatedAt
92
+ })));
93
+ }
94
+ function resolveLocalSecretValuesForBindings(config, cwd) {
95
+ const values = {};
96
+ for (const [bindingName, binding] of Object.entries(config.bindings?.secretsStore ?? {})) {
97
+ const normalized = normalizeSecretsStoreBinding(binding, config.secretsStoreId, bindingName);
98
+ const value = readLocalSecret({
99
+ cwd,
100
+ storeId: normalized.storeId,
101
+ name: normalized.secretName
102
+ });
103
+ if (value !== undefined) {
104
+ values[bindingName] = value;
105
+ }
106
+ }
107
+ return values;
108
+ }
109
+ function toLocalSecretWorkerName(bindingName, index) {
110
+ const slug = bindingName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "secret";
111
+ return `devflare-local-secret-${index}-${slug}`;
112
+ }
113
+ function buildLocalSecretWrappedBindingConfig(config, cwd) {
114
+ const values = resolveLocalSecretValuesForBindings(config, cwd);
115
+ const entries = Object.entries(values);
116
+ return {
117
+ localBindingNames: entries.map(([bindingName]) => bindingName),
118
+ wrappedBindings: Object.fromEntries(entries.map(([bindingName, value], index) => {
119
+ const scriptName = toLocalSecretWorkerName(bindingName, index);
120
+ return [
121
+ bindingName,
122
+ {
123
+ scriptName,
124
+ bindings: { value }
125
+ }
126
+ ];
127
+ })),
128
+ workers: entries.map(([bindingName], index) => ({
129
+ name: toLocalSecretWorkerName(bindingName, index),
130
+ modules: true,
131
+ script: LOCAL_SECRET_WRAPPED_BINDING_SCRIPT
132
+ }))
133
+ };
134
+ }
135
+ function buildLocalSecretNodeBindings(config, cwd) {
136
+ const values = resolveLocalSecretValuesForBindings(config, cwd);
137
+ return Object.fromEntries(Object.entries(values).map(([bindingName, value]) => [
138
+ bindingName,
139
+ {
140
+ async get() {
141
+ return value;
142
+ }
143
+ }
144
+ ]));
145
+ }
146
+
147
+ export { writeLocalSecret, deleteLocalSecret, listLocalSecrets, resolveLocalSecretValuesForBindings, buildLocalSecretWrappedBindingConfig, buildLocalSecretNodeBindings };
@@ -0,0 +1,52 @@
1
+ import {
2
+ findFiles
3
+ } from "./index-qwgr4q7s.js";
4
+ import {
5
+ resolveConfigPath
6
+ } from "./index-f46984zs.js";
7
+
8
+ // src/cli/config-path.ts
9
+ import { stat } from "node:fs/promises";
10
+ var CONFIG_FILE_EXTENSIONS = [".ts", ".mts", ".js", ".mjs"];
11
+ var SUPPORTED_CONFIG_FILENAMES = CONFIG_FILE_EXTENSIONS.map((extension) => `devflare.config${extension}`);
12
+ function hasKnownConfigExtension(filePath) {
13
+ return CONFIG_FILE_EXTENSIONS.some((extension) => filePath.endsWith(extension));
14
+ }
15
+ async function getExistingFilePath(filePath) {
16
+ try {
17
+ const fileStat = await stat(filePath);
18
+ return fileStat.isFile() ? filePath : null;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ async function resolveConfigCandidatePath(candidatePath) {
24
+ const candidates = [candidatePath];
25
+ if (!hasKnownConfigExtension(candidatePath)) {
26
+ for (const extension of CONFIG_FILE_EXTENSIONS) {
27
+ candidates.push(`${candidatePath}${extension}`);
28
+ }
29
+ }
30
+ for (const candidate of candidates) {
31
+ const existingFilePath = await getExistingFilePath(candidate);
32
+ if (existingFilePath) {
33
+ return existingFilePath;
34
+ }
35
+ }
36
+ return await resolveConfigPath(candidatePath) ?? null;
37
+ }
38
+ async function findConfigPathsUnderDirectory(rootDir) {
39
+ const matches = await findFiles([
40
+ ...SUPPORTED_CONFIG_FILENAMES,
41
+ ...SUPPORTED_CONFIG_FILENAMES.map((filename) => `**/${filename}`)
42
+ ], {
43
+ cwd: rootDir,
44
+ absolute: true
45
+ });
46
+ return [...new Set(matches)].sort((left, right) => left.localeCompare(right));
47
+ }
48
+ function formatSupportedConfigFilenames() {
49
+ return SUPPORTED_CONFIG_FILENAMES.join(", ");
50
+ }
51
+
52
+ export { resolveConfigCandidatePath, findConfigPathsUnderDirectory, formatSupportedConfigFilenames };
@@ -0,0 +1,109 @@
1
+ import {
2
+ bundleWorkerEntry
3
+ } from "./index-meq8ydc0.js";
4
+ import {
5
+ DEFAULT_WORKFLOW_PATTERN,
6
+ findFiles
7
+ } from "./index-qwgr4q7s.js";
8
+ import {
9
+ normalizeWorkflowBinding
10
+ } from "./index-cna43592.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 };