devflare 1.0.0-next.39 → 1.0.0-next.40
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/_chunks/account-BtWcv3X9.js +462 -0
- package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
- package/dist/_chunks/ai-CBEuLdoP.js +322 -0
- package/dist/_chunks/api-TzdliH-6.js +568 -0
- package/dist/_chunks/build-3T6O4uIg.js +24 -0
- package/dist/_chunks/build-artifacts-8TqBSQkG.js +483 -0
- package/dist/_chunks/cli-BTF1X4SG.js +1128 -0
- package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
- package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
- package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
- package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
- package/dist/_chunks/config-D5u-bEkn.js +78 -0
- package/dist/_chunks/config-path-DCPto4XB.js +42 -0
- package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
- package/dist/_chunks/decorators-QmV57ixr.js +19 -0
- package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
- package/dist/_chunks/deploy-DMTr6JeR.js +915 -0
- package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
- package/dist/_chunks/doctor-DIG8DoFU.js +219 -0
- package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
- package/dist/_chunks/env-S0_nMVz1.js +125 -0
- package/dist/_chunks/family-DXC5SdFK.js +143 -0
- package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
- package/dist/_chunks/glob-CmQOvunB.js +56 -0
- package/dist/_chunks/init-3moXTgpb.js +165 -0
- package/dist/_chunks/loader-DLXO60RO.js +1153 -0
- package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
- package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
- package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
- package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
- package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
- package/dist/_chunks/login-BmnDzDlH.js +51 -0
- package/dist/_chunks/package-metadata-DAuCkyvK.js +39 -0
- package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
- package/dist/_chunks/preview-BhqDmq8I.js +456 -0
- package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
- package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
- package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
- package/dist/_chunks/productions-D3AnOHac.js +411 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
- package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
- package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-C3FqES2W.js +796 -0
- package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
- package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
- package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
- package/dist/_chunks/token-kguIDmej.js +333 -0
- package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
- package/dist/_chunks/types-OrLbzv4I.js +476 -0
- package/dist/_chunks/ui-BUoZApvE.js +103 -0
- package/dist/_chunks/usage-BBTGzjon.js +272 -0
- package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
- package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
- package/dist/_chunks/worker-CS1jgNFE.js +410 -0
- package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
- package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
- package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
- package/dist/bridge/index.d.ts +6 -6
- package/dist/bridge/miniflare.d.ts +2 -2
- package/dist/bridge/proxy.d.ts +1 -1
- package/dist/bridge/v2/body-streams.d.ts +1 -1
- package/dist/bridge/v2/codec.d.ts +4 -4
- package/dist/bridge/v2/index.d.ts +10 -10
- package/dist/bridge/v2/serialization.d.ts +1 -1
- package/dist/bridge/v2/value-codec.d.ts +1 -1
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -1
- package/dist/bridge/v2/ws-relay.d.ts +3 -3
- package/dist/browser-shim/index.d.ts +2 -2
- package/dist/browser.d.ts +70 -70
- package/dist/browser.js +74 -2462
- package/dist/bundler/do-bundler.d.ts +1 -1
- package/dist/bundler/index.d.ts +3 -3
- package/dist/bundler/rolldown-shared.d.ts +1 -1
- package/dist/bundler/worker-bundler.d.ts +1 -1
- package/dist/cli/build-manifest.d.ts +1 -1
- package/dist/cli/command-utils.d.ts +1 -1
- package/dist/cli/commands/account.d.ts +1 -1
- package/dist/cli/commands/ai.d.ts +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +5 -5
- package/dist/cli/commands/build.d.ts +1 -1
- package/dist/cli/commands/config.d.ts +1 -1
- package/dist/cli/commands/deploy/prepare.d.ts +2 -2
- package/dist/cli/commands/deploy/runtime.d.ts +1 -1
- package/dist/cli/commands/deploy/verification.d.ts +1 -1
- package/dist/cli/commands/deploy.d.ts +1 -1
- package/dist/cli/commands/dev.d.ts +1 -1
- package/dist/cli/commands/doctor.d.ts +1 -1
- package/dist/cli/commands/init.d.ts +1 -1
- package/dist/cli/commands/login.d.ts +1 -1
- package/dist/cli/commands/previews-support/cleanup.d.ts +1 -1
- package/dist/cli/commands/previews-support/family.d.ts +3 -3
- package/dist/cli/commands/previews-support/render.d.ts +3 -3
- package/dist/cli/commands/previews-support/theme.d.ts +2 -2
- package/dist/cli/commands/previews-support/types.d.ts +2 -2
- package/dist/cli/commands/previews.d.ts +1 -1
- package/dist/cli/commands/productions.d.ts +1 -1
- package/dist/cli/commands/remote.d.ts +1 -1
- package/dist/cli/commands/secrets.d.ts +1 -1
- package/dist/cli/commands/token.d.ts +1 -1
- package/dist/cli/commands/type-generation/discovery.d.ts +2 -2
- package/dist/cli/commands/type-generation/generator.d.ts +3 -3
- package/dist/cli/commands/type-generation/models.d.ts +1 -1
- package/dist/cli/commands/types.d.ts +1 -1
- package/dist/cli/commands/worker.d.ts +1 -1
- package/dist/cli/deploy-strategy.d.ts +1 -1
- package/dist/cli/deploy-target.d.ts +1 -1
- package/dist/cli/help-pages/pages/account.d.ts +1 -1
- package/dist/cli/help-pages/pages/core.d.ts +1 -1
- package/dist/cli/help-pages/pages/index.d.ts +1 -1
- package/dist/cli/help-pages/pages/misc.d.ts +1 -1
- package/dist/cli/help-pages/pages/previews.d.ts +1 -1
- package/dist/cli/help-pages/pages/productions.d.ts +1 -1
- package/dist/cli/help-pages/render.d.ts +2 -2
- package/dist/cli/help-pages/shared.d.ts +1 -1
- package/dist/cli/help.d.ts +2 -2
- package/dist/cli/index.js +2 -1383
- package/dist/cli/preview-bindings.d.ts +3 -3
- package/dist/cli/preview.d.ts +1 -1
- package/dist/cli/wrangler-auth.d.ts +1 -1
- package/dist/cloudflare/account-core.d.ts +2 -2
- package/dist/cloudflare/account-resources.d.ts +2 -2
- package/dist/cloudflare/account-status.d.ts +1 -1
- package/dist/cloudflare/account-workers.d.ts +2 -2
- package/dist/cloudflare/account.d.ts +7 -7
- package/dist/cloudflare/auth.d.ts +1 -1
- package/dist/cloudflare/index.d.ts +13 -13
- package/dist/cloudflare/index.js +4 -59
- package/dist/cloudflare/kv-namespace.d.ts +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +1 -1
- package/dist/cloudflare/preview-registry-inference.d.ts +2 -2
- package/dist/cloudflare/preview-registry-records.d.ts +3 -3
- package/dist/cloudflare/preview-registry-shape.d.ts +2 -2
- package/dist/cloudflare/preview-registry-store.d.ts +3 -3
- package/dist/cloudflare/preview-registry-transport.d.ts +2 -2
- package/dist/cloudflare/preview-registry-types.d.ts +2 -2
- package/dist/cloudflare/preview-registry.d.ts +5 -5
- package/dist/cloudflare/tokens.d.ts +2 -2
- package/dist/cloudflare/usage.d.ts +2 -2
- package/dist/config/binding-resolution-helpers.d.ts +1 -1
- package/dist/config/compiler/bindings.d.ts +2 -2
- package/dist/config/compiler/core-helpers.d.ts +2 -2
- package/dist/config/compiler/do-workers.d.ts +2 -2
- package/dist/config/compiler/paths.d.ts +1 -1
- package/dist/config/compiler.d.ts +6 -6
- package/dist/config/define.d.ts +2 -2
- package/dist/config/deploy-resources.d.ts +5 -5
- package/dist/config/env-vars.d.ts +1 -1
- package/dist/config/framework-providers.d.ts +1 -1
- package/dist/config/index.d.ts +12 -12
- package/dist/config/loader.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts +1 -1
- package/dist/config/preview-resources.d.ts +4 -4
- package/dist/config/preview.d.ts +1 -1
- package/dist/config/ref.d.ts +2 -2
- package/dist/config/resolve-phased.d.ts +4 -4
- package/dist/config/resolve.d.ts +1 -1
- package/dist/config/resource-resolution.d.ts +6 -6
- package/dist/config/schema-env.d.ts +20 -20
- package/dist/config/schema-normalization.d.ts +1 -1
- package/dist/config/schema-types-bindings.d.ts +4 -4
- package/dist/config/schema-types-build.d.ts +1 -1
- package/dist/config/schema-types.d.ts +7 -7
- package/dist/config/schema.d.ts +46 -46
- package/dist/config/service-bindings-validation.d.ts +1 -1
- package/dist/config-entry.d.ts +6 -6
- package/dist/config-entry.js +3 -8
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -9
- package/dist/dev-server/d1-migrations.d.ts +1 -1
- package/dist/dev-server/dev-server-state.d.ts +6 -6
- package/dist/dev-server/gateway-script.d.ts +1 -1
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +1 -1
- package/dist/dev-server/miniflare-dev-config.d.ts +5 -5
- package/dist/dev-server/miniflare-worker-config.d.ts +3 -3
- package/dist/dev-server/server-startup-helpers.d.ts +6 -6
- package/dist/dev-server/worker-surface-paths.d.ts +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -22
- package/dist/runtime/context-events.d.ts +1 -1
- package/dist/runtime/context.d.ts +3 -3
- package/dist/runtime/exports.d.ts +2 -2
- package/dist/runtime/index.d.ts +10 -10
- package/dist/runtime/index.js +5 -57
- package/dist/runtime/middleware.d.ts +1 -1
- package/dist/runtime/router/index.d.ts +3 -3
- package/dist/runtime/validation.d.ts +1 -1
- package/dist/secrets/local-secrets.d.ts +1 -1
- package/dist/shims/local-media-bindings.d.ts +1 -1
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +327 -9
- package/dist/sveltekit/local-bindings.d.ts +1 -1
- package/dist/sveltekit/platform.d.ts +1 -1
- package/dist/test/binding-hints.d.ts +2 -2
- package/dist/test/cf.d.ts +19 -19
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +4495 -46
- package/dist/test/offline-bindings.d.ts +3 -3
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/simple-context-bindings.d.ts +1 -1
- package/dist/test/simple-context-durable-objects.d.ts +1 -1
- package/dist/test/simple-context-env.d.ts +2 -2
- package/dist/test/simple-context-handlers.d.ts +2 -2
- package/dist/test/simple-context-lifecycle.d.ts +2 -2
- package/dist/test/simple-context-mfconfig.d.ts +1 -1
- package/dist/test/simple-context-multi-worker.d.ts +2 -2
- package/dist/test/simple-context-runtime.d.ts +1 -1
- package/dist/test/simple-context-startup.d.ts +1 -1
- package/dist/test/simple-context.d.ts +1 -1
- package/dist/test/utilities/env.d.ts +3 -3
- package/dist/test/utilities.d.ts +10 -10
- package/dist/test/worker.d.ts +1 -1
- package/dist/transform/index.d.ts +2 -2
- package/dist/utils/send-email.js +163 -19
- package/dist/vite/config-file.d.ts +2 -2
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.js +2 -31
- package/dist/vite/plugin-config-hook.d.ts +1 -1
- package/dist/vite/plugin-context.d.ts +3 -3
- package/dist/vite/plugin-durable-objects.d.ts +2 -2
- package/dist/vite/plugin-programmatic.d.ts +1 -1
- package/dist/vite/plugin-service-bindings.d.ts +2 -2
- package/dist/vite/plugin.d.ts +3 -3
- package/dist/worker-entry/composed-worker.d.ts +1 -1
- package/dist/worker-entry/routes.d.ts +2 -2
- package/dist/worker-entry/surface-paths.d.ts +1 -1
- package/dist/workflows/local-workflow-entrypoints.d.ts +1 -1
- package/package.json +5 -3
- package/dist/account-4tgh03a8.js +0 -484
- package/dist/ai-r3zqmxan.js +0 -261
- package/dist/api-6z01z734.js +0 -33
- package/dist/build-kw625v84.js +0 -51
- package/dist/config-ghk2bxj3.js +0 -102
- package/dist/deploy-9kee65n9.js +0 -1062
- package/dist/dev-x8zr249a.js +0 -3569
- package/dist/doctor-0ng5qrr1.js +0 -258
- package/dist/durable-object-0ybmg08a.js +0 -13
- package/dist/index-04wh9bxx.js +0 -514
- package/dist/index-0cc05hzv.js +0 -74
- package/dist/index-2yv7w548.js +0 -185
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-3cpzsr47.js +0 -125
- package/dist/index-3t6rypgc.js +0 -13
- package/dist/index-4mmpccrb.js +0 -309
- package/dist/index-5dkjffqz.js +0 -25
- package/dist/index-5hy7jmv3.js +0 -890
- package/dist/index-627srx16.js +0 -45
- package/dist/index-7m557715.js +0 -283
- package/dist/index-a8pnvg3r.js +0 -52
- package/dist/index-aabgympv.js +0 -39
- package/dist/index-atwc3csp.js +0 -256
- package/dist/index-cv4cvrxe.js +0 -2046
- package/dist/index-h7r11y4a.js +0 -539
- package/dist/index-hvtd936d.js +0 -1229
- package/dist/index-kcp7y951.js +0 -136
- package/dist/index-maw0jjnn.js +0 -147
- package/dist/index-mek9msfv.js +0 -705
- package/dist/index-n4xkaymm.js +0 -236
- package/dist/index-nkk59p3y.js +0 -579
- package/dist/index-phcrvs6d.js +0 -342
- package/dist/index-se4kw8tm.js +0 -460
- package/dist/index-x8s9rwfh.js +0 -2020
- package/dist/index-y7w3x9p1.js +0 -18
- package/dist/index-z9gy8w6b.js +0 -57
- package/dist/index-zdd0d9qa.js +0 -199
- package/dist/init-tb8jqgvr.js +0 -180
- package/dist/login-4h1sfsed.js +0 -75
- package/dist/previews-qr7c5j8h.js +0 -1336
- package/dist/productions-xpmd6bw8.js +0 -505
- package/dist/remote-kqcvhnfx.js +0 -192
- package/dist/secrets-6wbdsdek.js +0 -89
- package/dist/token-yp1qa70y.js +0 -419
- package/dist/types-15yv4cj3.js +0 -701
- package/dist/worker-1yg72jxg.js +0 -510
- package/dist/worker-entrypoint-y8s9kdcx.js +0 -15
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
//#region src/cloudflare/remote-config.ts
|
|
5
|
+
/** Minimum duration in minutes */
|
|
6
|
+
const MIN_MINUTES = 1;
|
|
7
|
+
/** Maximum duration in minutes (24 hours) */
|
|
8
|
+
const MAX_MINUTES = 1440;
|
|
9
|
+
function getConfigDir() {
|
|
10
|
+
return join(homedir(), ".devflare");
|
|
11
|
+
}
|
|
12
|
+
function getConfigPath() {
|
|
13
|
+
return join(getConfigDir(), "remote.json");
|
|
14
|
+
}
|
|
15
|
+
function readConfig() {
|
|
16
|
+
const path = getConfigPath();
|
|
17
|
+
if (!existsSync(path)) return null;
|
|
18
|
+
try {
|
|
19
|
+
const content = readFileSync(path, "utf-8");
|
|
20
|
+
return JSON.parse(content);
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function writeConfig(config) {
|
|
26
|
+
const dir = getConfigDir();
|
|
27
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
28
|
+
writeFileSync(getConfigPath(), JSON.stringify(config, null, " "));
|
|
29
|
+
}
|
|
30
|
+
function deleteConfig() {
|
|
31
|
+
const path = getConfigPath();
|
|
32
|
+
if (existsSync(path)) try {
|
|
33
|
+
unlinkSync(path);
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Enable remote mode for a given duration.
|
|
38
|
+
* @param minutes Duration in minutes (default: 30, clamped to 1-1440)
|
|
39
|
+
* @returns The validated minutes value actually used
|
|
40
|
+
*/
|
|
41
|
+
function enableRemoteMode(minutes = 30) {
|
|
42
|
+
const validMinutes = Math.max(MIN_MINUTES, Math.min(MAX_MINUTES, Math.floor(minutes) || 30));
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
writeConfig({
|
|
45
|
+
enabledAt: now,
|
|
46
|
+
expiresAt: now + validMinutes * 60 * 1e3,
|
|
47
|
+
durationMinutes: validMinutes
|
|
48
|
+
});
|
|
49
|
+
return validMinutes;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Disable remote mode immediately.
|
|
53
|
+
*/
|
|
54
|
+
function disableRemoteMode() {
|
|
55
|
+
deleteConfig();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the current remote mode status from stored config.
|
|
59
|
+
* Note: Use getEffectiveRemoteModeStatus() to also include env var override.
|
|
60
|
+
* @returns Status object with isEnabled, remainingMinutes, and expiresAt
|
|
61
|
+
*/
|
|
62
|
+
function getRemoteModeStatus() {
|
|
63
|
+
const config = readConfig();
|
|
64
|
+
if (!config) return {
|
|
65
|
+
isEnabled: false,
|
|
66
|
+
remainingMinutes: 0,
|
|
67
|
+
expiresAt: null
|
|
68
|
+
};
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
if (now >= config.expiresAt) {
|
|
71
|
+
deleteConfig();
|
|
72
|
+
return {
|
|
73
|
+
isEnabled: false,
|
|
74
|
+
remainingMinutes: 0,
|
|
75
|
+
expiresAt: null
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const remainingMs = config.expiresAt - now;
|
|
79
|
+
return {
|
|
80
|
+
isEnabled: true,
|
|
81
|
+
remainingMinutes: Math.ceil(remainingMs / 6e4),
|
|
82
|
+
expiresAt: new Date(config.expiresAt)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the effective remote mode status including env var override.
|
|
87
|
+
* @returns Status object with isActive, source, and config details
|
|
88
|
+
*/
|
|
89
|
+
function getEffectiveRemoteModeStatus() {
|
|
90
|
+
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
91
|
+
if ([
|
|
92
|
+
"1",
|
|
93
|
+
"true",
|
|
94
|
+
"yes"
|
|
95
|
+
].includes(envValue.toLowerCase())) return {
|
|
96
|
+
isActive: true,
|
|
97
|
+
source: "env",
|
|
98
|
+
remainingMinutes: Number.POSITIVE_INFINITY,
|
|
99
|
+
expiresAt: null,
|
|
100
|
+
envVarSet: true
|
|
101
|
+
};
|
|
102
|
+
const status = getRemoteModeStatus();
|
|
103
|
+
if (status.isEnabled) return {
|
|
104
|
+
isActive: true,
|
|
105
|
+
source: "config",
|
|
106
|
+
remainingMinutes: status.remainingMinutes,
|
|
107
|
+
expiresAt: status.expiresAt,
|
|
108
|
+
envVarSet: false
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
isActive: false,
|
|
112
|
+
source: "none",
|
|
113
|
+
remainingMinutes: 0,
|
|
114
|
+
expiresAt: null,
|
|
115
|
+
envVarSet: false
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if remote mode is currently enabled.
|
|
120
|
+
* Checks both env var (DEVFLARE_REMOTE=1) and stored config.
|
|
121
|
+
*/
|
|
122
|
+
function isRemoteModeActive() {
|
|
123
|
+
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
124
|
+
if ([
|
|
125
|
+
"1",
|
|
126
|
+
"true",
|
|
127
|
+
"yes"
|
|
128
|
+
].includes(envValue.toLowerCase())) return true;
|
|
129
|
+
return getRemoteModeStatus().isEnabled;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { isRemoteModeActive as a, getRemoteModeStatus as i, enableRemoteMode as n, getEffectiveRemoteModeStatus as r, disableRemoteMode as t };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { a as findFilesSync, i as findFiles, n as DEFAULT_ENTRYPOINT_PATTERN } from "./glob-CmQOvunB.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, resolve } from "pathe";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { readFileSync as readFileSync$1 } from "fs";
|
|
7
|
+
//#region src/utils/entrypoint-discovery.ts
|
|
8
|
+
/**
|
|
9
|
+
* Regex pattern to find WorkerEntrypoint class exports
|
|
10
|
+
* Matches: export class ClassName extends WorkerEntrypoint
|
|
11
|
+
*/
|
|
12
|
+
const ENTRYPOINT_CLASS_PATTERN = /export\s+class\s+(\w+)\s+extends\s+WorkerEntrypoint/g;
|
|
13
|
+
/**
|
|
14
|
+
* Find WorkerEntrypoint classes in source code
|
|
15
|
+
* @param code - Source code to search
|
|
16
|
+
* @returns Array of class names found
|
|
17
|
+
*/
|
|
18
|
+
function findEntrypointClasses(code) {
|
|
19
|
+
const classes = [];
|
|
20
|
+
ENTRYPOINT_CLASS_PATTERN.lastIndex = 0;
|
|
21
|
+
let match = ENTRYPOINT_CLASS_PATTERN.exec(code);
|
|
22
|
+
while (match !== null) {
|
|
23
|
+
classes.push(match[1]);
|
|
24
|
+
match = ENTRYPOINT_CLASS_PATTERN.exec(code);
|
|
25
|
+
}
|
|
26
|
+
return classes;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Discover entrypoint classes from a glob pattern synchronously.
|
|
30
|
+
* Respects `.gitignore` automatically.
|
|
31
|
+
*
|
|
32
|
+
* @param cwd - Working directory for glob resolution
|
|
33
|
+
* @param pattern - Glob pattern for entrypoint files (default: recursive `ep.*.{ts,js}` matching)
|
|
34
|
+
* @returns Array of discovered entrypoints
|
|
35
|
+
*/
|
|
36
|
+
function discoverEntrypointsSync(cwd, pattern = DEFAULT_ENTRYPOINT_PATTERN) {
|
|
37
|
+
const discovered = [];
|
|
38
|
+
try {
|
|
39
|
+
const files = findFilesSync(pattern, { cwd });
|
|
40
|
+
for (const file of files) try {
|
|
41
|
+
const classNames = findEntrypointClasses(readFileSync$1(file, "utf-8"));
|
|
42
|
+
for (const className of classNames) discovered.push({
|
|
43
|
+
className,
|
|
44
|
+
filePath: file
|
|
45
|
+
});
|
|
46
|
+
} catch {}
|
|
47
|
+
} catch {}
|
|
48
|
+
return discovered;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Discover entrypoint classes from ep.*.ts files using glob pattern (async).
|
|
52
|
+
* Respects .gitignore automatically.
|
|
53
|
+
*
|
|
54
|
+
* @param cwd - Working directory for glob
|
|
55
|
+
* @param pattern - Glob pattern for ep.*.ts files (default: **/ep.*.{ts,js})
|
|
56
|
+
* @returns Array of discovered entrypoints
|
|
57
|
+
*/
|
|
58
|
+
async function discoverEntrypointsAsync(cwd, pattern = DEFAULT_ENTRYPOINT_PATTERN) {
|
|
59
|
+
const fs = await import("node:fs/promises");
|
|
60
|
+
const discovered = [];
|
|
61
|
+
const files = await findFiles(pattern, { cwd });
|
|
62
|
+
for (const filePath of files) try {
|
|
63
|
+
const classNames = findEntrypointClasses(await fs.readFile(filePath, "utf-8"));
|
|
64
|
+
for (const className of classNames) discovered.push({
|
|
65
|
+
className,
|
|
66
|
+
filePath
|
|
67
|
+
});
|
|
68
|
+
} catch {}
|
|
69
|
+
return discovered;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/utils/resolve-package.ts
|
|
73
|
+
const NOT_FOUND_CODES = new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
|
|
74
|
+
function isNotFoundError(error) {
|
|
75
|
+
if (!error || typeof error !== "object") return false;
|
|
76
|
+
const code = error.code;
|
|
77
|
+
return typeof code === "string" && NOT_FOUND_CODES.has(code);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve `specifier` from `fromDir` using ESM-first resolution.
|
|
81
|
+
*
|
|
82
|
+
* Chain:
|
|
83
|
+
* 1. `import.meta.resolve` (Bun exposes this synchronously for ESM packages)
|
|
84
|
+
* 2. `createRequire(fromDir).resolve` (CommonJS fallback)
|
|
85
|
+
*
|
|
86
|
+
* Only swallows MODULE_NOT_FOUND / ERR_MODULE_NOT_FOUND. Any other error
|
|
87
|
+
* (syntax, permission, etc.) is re-thrown.
|
|
88
|
+
*/
|
|
89
|
+
function resolveSpecifier(specifier, fromDir) {
|
|
90
|
+
const fromFileUrl = pathToFileURL(resolve(fromDir, "package.json")).href;
|
|
91
|
+
const importMetaResolve = import.meta.resolve;
|
|
92
|
+
if (typeof importMetaResolve === "function") try {
|
|
93
|
+
const resolved = importMetaResolve(specifier, fromFileUrl);
|
|
94
|
+
if (typeof resolved === "string") return resolved.startsWith("file:") ? fileURLToPath(resolved) : resolved;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (!isNotFoundError(error)) throw error;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return createRequire(fromFileUrl).resolve(specifier);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (isNotFoundError(error)) return null;
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolve a package specifier to a filesystem path
|
|
107
|
+
* Handles workspace packages like '@devflare/case11-do-shared/devflare.config'
|
|
108
|
+
*
|
|
109
|
+
* @param specifier - Package specifier (e.g., '@scope/pkg/path' or './relative/path')
|
|
110
|
+
* @param fromDir - Directory to resolve relative paths from
|
|
111
|
+
* @returns Resolved filesystem path
|
|
112
|
+
*/
|
|
113
|
+
function resolvePackageSpecifier(specifier, fromDir) {
|
|
114
|
+
if (specifier.startsWith(".") || specifier.startsWith("/") || /^[A-Za-z]:/.test(specifier)) return resolve(fromDir, specifier);
|
|
115
|
+
const parts = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
|
|
116
|
+
const subpath = specifier.startsWith("@") ? specifier.split("/").slice(2).join("/") : specifier.split("/").slice(1).join("/");
|
|
117
|
+
const pkgJsonPath = resolveSpecifier(`${parts}/package.json`, fromDir);
|
|
118
|
+
if (!pkgJsonPath) return resolve(fromDir, specifier);
|
|
119
|
+
const pkgDir = dirname(pkgJsonPath);
|
|
120
|
+
if (subpath) {
|
|
121
|
+
const exportPath = JSON.parse(readFileSync(pkgJsonPath, "utf-8")).exports?.[`./${subpath}`];
|
|
122
|
+
if (exportPath) return resolve(pkgDir, typeof exportPath === "string" ? exportPath : exportPath.default || exportPath.import);
|
|
123
|
+
const directPath = resolve(pkgDir, `${subpath}.ts`);
|
|
124
|
+
if (existsSync(directPath)) return directPath;
|
|
125
|
+
const withExt = resolve(pkgDir, subpath);
|
|
126
|
+
if (existsSync(withExt)) return withExt;
|
|
127
|
+
if (existsSync(`${withExt}.ts`)) return `${withExt}.ts`;
|
|
128
|
+
if (existsSync(`${withExt}.js`)) return `${withExt}.js`;
|
|
129
|
+
}
|
|
130
|
+
return pkgDir;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { discoverEntrypointsAsync as n, discoverEntrypointsSync as r, resolvePackageSpecifier as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __exportAll = (all, no_symbols) => {
|
|
5
|
+
let target = {};
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
|
+
return target;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { __exportAll as t };
|