@powerlines/plugin-cloudflare 0.6.30 → 0.6.33
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/components/cloudflare-builtin.cjs +846 -792
- package/dist/components/cloudflare-builtin.d.cts +1 -2
- package/dist/components/cloudflare-builtin.d.cts.map +1 -1
- package/dist/components/cloudflare-builtin.d.mts +1 -2
- package/dist/components/cloudflare-builtin.d.mts.map +1 -1
- package/dist/components/cloudflare-builtin.mjs +846 -792
- package/dist/components/cloudflare-builtin.mjs.map +1 -1
- package/dist/components/env-builtin.cjs +14 -10
- package/dist/components/env-builtin.d.cts +1 -2
- package/dist/components/env-builtin.d.cts.map +1 -1
- package/dist/components/env-builtin.d.mts +1 -2
- package/dist/components/env-builtin.d.mts.map +1 -1
- package/dist/components/env-builtin.mjs +14 -10
- package/dist/components/env-builtin.mjs.map +1 -1
- package/dist/components/worker-entry.cjs +142 -118
- package/dist/components/worker-entry.d.cts +1 -2
- package/dist/components/worker-entry.d.cts.map +1 -1
- package/dist/components/worker-entry.d.mts +1 -2
- package/dist/components/worker-entry.d.mts.map +1 -1
- package/dist/components/worker-entry.mjs +142 -118
- package/dist/components/worker-entry.mjs.map +1 -1
- package/dist/helpers/wrangler.mjs.map +1 -1
- package/dist/index.cjs +8 -5
- package/dist/index.mjs +8 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/wrangler.cjs +19 -0
- package/dist/types/wrangler.mjs +19 -0
- package/dist/types/wrangler.mjs.map +1 -1
- package/package.json +11 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
1
2
|
import { Show, code, computed, splitProps } from "@alloy-js/core";
|
|
2
3
|
import defu from "defu";
|
|
3
4
|
import { Spacing } from "@powerlines/plugin-alloy/core/components";
|
|
4
|
-
import { jsx, jsxs } from "@alloy-js/core/jsx-runtime";
|
|
5
5
|
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts";
|
|
6
6
|
import { EntryFile } from "@powerlines/plugin-alloy/typescript/components/entry-file";
|
|
7
7
|
import { murmurhash } from "@stryke/hash";
|
|
@@ -21,155 +21,179 @@ function WorkerEntry(props) {
|
|
|
21
21
|
]);
|
|
22
22
|
const context = usePowerlines();
|
|
23
23
|
const entryPath = computed(() => `./${replaceExtension(relativePath(context.entryPath, worker.metadata.entry.input?.file || worker.metadata.entry.file))}`);
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
imports
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
24
|
+
return createComponent(EntryFile, mergeProps({ get path() {
|
|
25
|
+
return `worker-${murmurhash(worker.metadata.entry, { maxLength: 8 })}-entry.ts`;
|
|
26
|
+
} }, rest, {
|
|
27
|
+
get imports() {
|
|
28
|
+
return defu({
|
|
29
|
+
"@cloudflare/workers-types": [
|
|
30
|
+
{
|
|
31
|
+
name: "Request",
|
|
32
|
+
type: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "Response",
|
|
36
|
+
type: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "ExecutionContext",
|
|
40
|
+
type: true
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "IncomingRequestCfProperties",
|
|
44
|
+
type: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "ScheduledController",
|
|
48
|
+
type: true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "ForwardableEmailMessage",
|
|
52
|
+
type: true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "MessageBatch",
|
|
56
|
+
type: true
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "TailStream",
|
|
60
|
+
type: true
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "TraceItem",
|
|
64
|
+
type: true
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "TailStream.TailEvent",
|
|
68
|
+
type: true
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "TailStream.Onset",
|
|
72
|
+
type: true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "TailStream.TailEventHandlerType",
|
|
76
|
+
type: true
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
[entryPath.value]: "worker"
|
|
80
|
+
}, imports ?? {});
|
|
81
|
+
},
|
|
82
|
+
get builtinImports() {
|
|
83
|
+
return defu({ cloudflare: [
|
|
84
|
+
"withFetchContext",
|
|
85
|
+
"withTailContext",
|
|
86
|
+
"withTraceContext",
|
|
87
|
+
"withTailStreamContext",
|
|
88
|
+
"withScheduledContext",
|
|
89
|
+
"withTestContext",
|
|
90
|
+
"withEmailContext",
|
|
91
|
+
"withQueueContext"
|
|
92
|
+
] }, builtinImports ?? {});
|
|
93
|
+
},
|
|
94
|
+
get children() {
|
|
95
|
+
return [
|
|
96
|
+
code`export default { `,
|
|
97
|
+
createIntrinsic("hbr", {}),
|
|
98
|
+
createComponent(Show, {
|
|
99
|
+
get when() {
|
|
100
|
+
return worker.fetch;
|
|
101
|
+
},
|
|
102
|
+
children: code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {
|
|
96
103
|
return await withFetchContext({ request, env, ctx }, async (context) => {
|
|
97
104
|
return worker.fetch(context.request, context.env, context.ctx);
|
|
98
105
|
});
|
|
99
106
|
}, `
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
}),
|
|
108
|
+
createIntrinsic("hbr", {}),
|
|
109
|
+
createComponent(Show, {
|
|
110
|
+
get when() {
|
|
111
|
+
return worker.tail;
|
|
112
|
+
},
|
|
113
|
+
children: code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
105
114
|
return withTailContext({ events, env, ctx }, async (context) => {
|
|
106
115
|
return worker.tail(context.events, context.env, context.ctx);
|
|
107
116
|
});
|
|
108
117
|
}, `
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
}),
|
|
119
|
+
createIntrinsic("hbr", {}),
|
|
120
|
+
createComponent(Show, {
|
|
121
|
+
get when() {
|
|
122
|
+
return worker.trace;
|
|
123
|
+
},
|
|
124
|
+
children: code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
114
125
|
return withTraceContext({ traces, env, ctx }, async (context) => {
|
|
115
126
|
return worker.trace(context.traces, context.env, context.ctx);
|
|
116
127
|
});
|
|
117
128
|
}, `
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
}),
|
|
130
|
+
createIntrinsic("hbr", {}),
|
|
131
|
+
createComponent(Show, {
|
|
132
|
+
get when() {
|
|
133
|
+
return worker.tailStream;
|
|
134
|
+
},
|
|
135
|
+
children: code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {
|
|
123
136
|
return await withTailStreamContext({ event, env, ctx }, async (context) => {
|
|
124
137
|
return await worker.tailStream(context.event, context.env, context.ctx);
|
|
125
138
|
});
|
|
126
139
|
}, `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
}),
|
|
141
|
+
createIntrinsic("hbr", {}),
|
|
142
|
+
createComponent(Show, {
|
|
143
|
+
get when() {
|
|
144
|
+
return worker.scheduled;
|
|
145
|
+
},
|
|
146
|
+
children: code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
132
147
|
return withScheduledContext({ controller, env, ctx }, async (context) => {
|
|
133
148
|
return worker.scheduled(context.controller, context.env, context.ctx);
|
|
134
149
|
});
|
|
135
150
|
}, `
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
}),
|
|
152
|
+
createIntrinsic("hbr", {}),
|
|
153
|
+
createComponent(Show, {
|
|
154
|
+
get when() {
|
|
155
|
+
return worker.test;
|
|
156
|
+
},
|
|
157
|
+
children: code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
141
158
|
return withTestContext({ controller, env, ctx }, async (context) => {
|
|
142
159
|
return worker.test(context.controller, context.env, context.ctx);
|
|
143
160
|
});
|
|
144
161
|
}, `
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
162
|
+
}),
|
|
163
|
+
createIntrinsic("hbr", {}),
|
|
164
|
+
createComponent(Show, {
|
|
165
|
+
get when() {
|
|
166
|
+
return worker.email;
|
|
167
|
+
},
|
|
168
|
+
children: code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
150
169
|
return withEmailContext({ message, env, ctx }, async (context) => {
|
|
151
170
|
return worker.email(context.message, context.env, context.ctx);
|
|
152
171
|
});
|
|
153
172
|
}, `
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
173
|
+
}),
|
|
174
|
+
createIntrinsic("hbr", {}),
|
|
175
|
+
createComponent(Show, {
|
|
176
|
+
get when() {
|
|
177
|
+
return worker.queue;
|
|
178
|
+
},
|
|
179
|
+
children: code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
|
|
159
180
|
return withQueueContext({ batch, env, ctx }, async (context) => {
|
|
160
181
|
return worker.queue(context.batch, context.env, context.ctx);
|
|
161
182
|
});
|
|
162
183
|
}, `
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
184
|
+
}),
|
|
185
|
+
createIntrinsic("hbr", {}),
|
|
186
|
+
code` } satisfies ExportedHandler<CloudflareBindings>; `,
|
|
187
|
+
createComponent(Spacing, {}),
|
|
188
|
+
createComponent(Show, {
|
|
189
|
+
get when() {
|
|
190
|
+
return Boolean(children);
|
|
191
|
+
},
|
|
192
|
+
children
|
|
193
|
+
})
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
}));
|
|
173
197
|
}
|
|
174
198
|
|
|
175
199
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-entry.mjs","names":[],"sources":["../../src/components/worker-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, Show, splitProps } from \"@alloy-js/core\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts\";\nimport {\n EntryFile,\n EntryFileProps\n} from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { relativePath } from \"@stryke/path/find\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport defu from \"defu\";\nimport { CloudflarePluginContext, CloudflareWorkerEntryModule } from \"../types\";\n\nexport type WorkerEntryProps = Partial<EntryFileProps> &\n Omit<EntryFileProps, \"path\"> & {\n worker: CloudflareWorkerEntryModule;\n };\n\n/**\n * Generates a [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/handlers/) entry module for the Powerlines project, providing a runtime context and utilities for integrating with Cloudflare services. This module defines a `CloudflareContext` interface, an `AsyncLocalStorage` instance for managing the context, and helper functions for retrieving and running code within the context. The generated module is designed to be used as a built-in file within the Powerlines environment, allowing developers to easily access Cloudflare-specific functionality in their applications.\n */\nexport function WorkerEntry(props: WorkerEntryProps) {\n const [{ worker, children, imports, builtinImports }, rest] = splitProps(\n props,\n [\"worker\", \"children\", \"imports\", \"builtinImports\"]\n );\n\n const context = usePowerlines<CloudflarePluginContext>();\n const entryPath = computed(\n () =>\n `./${replaceExtension(\n relativePath(\n context.entryPath,\n worker.metadata.entry.input?.file || worker.metadata.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.metadata.entry, {\n maxLength: 8\n })}-entry.ts`}\n {...rest}\n imports={defu(\n {\n \"@cloudflare/workers-types\": [\n { name: \"Request\", type: true },\n { name: \"Response\", type: true },\n { name: \"ExecutionContext\", type: true },\n { name: \"IncomingRequestCfProperties\", type: true },\n { name: \"ScheduledController\", type: true },\n { name: \"ForwardableEmailMessage\", type: true },\n { name: \"MessageBatch\", type: true },\n { name: \"TailStream\", type: true },\n { name: \"TraceItem\", type: true },\n { name: \"TailStream.TailEvent\", type: true },\n { name: \"TailStream.Onset\", type: true },\n { name: \"TailStream.TailEventHandlerType\", type: true }\n ],\n [entryPath.value]: \"worker\"\n },\n imports ?? {}\n )}\n builtinImports={defu(\n {\n cloudflare: [\n \"withFetchContext\",\n \"withTailContext\",\n \"withTraceContext\",\n \"withTailStreamContext\",\n \"withScheduledContext\",\n \"withTestContext\",\n \"withEmailContext\",\n \"withQueueContext\"\n ]\n },\n builtinImports ?? {}\n )}>\n {code`export default { `}\n <hbr />\n <Show when={worker.fetch}>\n {code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {\n return await withFetchContext({ request, env, ctx }, async (context) => {\n return worker.fetch(context.request, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tail}>\n {code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTailContext({ events, env, ctx }, async (context) => {\n return worker.tail(context.events, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.trace}>\n {code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTraceContext({ traces, env, ctx }, async (context) => {\n return worker.trace(context.traces, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tailStream}>\n {code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {\n return await withTailStreamContext({ event, env, ctx }, async (context) => {\n return await worker.tailStream(context.event, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.scheduled}>\n {code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withScheduledContext({ controller, env, ctx }, async (context) => {\n return worker.scheduled(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.test}>\n {code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTestContext({ controller, env, ctx }, async (context) => {\n return worker.test(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.email}>\n {code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withEmailContext({ message, env, ctx }, async (context) => {\n return worker.email(context.message, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.queue}>\n {code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withQueueContext({ batch, env, ctx }, async (context) => {\n return worker.queue(context.batch, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n {code` } satisfies ExportedHandler<CloudflareBindings>; `}\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </EntryFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"worker-entry.mjs","names":[],"sources":["../../src/components/worker-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, Show, splitProps } from \"@alloy-js/core\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts\";\nimport {\n EntryFile,\n EntryFileProps\n} from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { relativePath } from \"@stryke/path/find\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport defu from \"defu\";\nimport { CloudflarePluginContext, CloudflareWorkerEntryModule } from \"../types\";\n\nexport type WorkerEntryProps = Partial<EntryFileProps> &\n Omit<EntryFileProps, \"path\"> & {\n worker: CloudflareWorkerEntryModule;\n };\n\n/**\n * Generates a [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/handlers/) entry module for the Powerlines project, providing a runtime context and utilities for integrating with Cloudflare services. This module defines a `CloudflareContext` interface, an `AsyncLocalStorage` instance for managing the context, and helper functions for retrieving and running code within the context. The generated module is designed to be used as a built-in file within the Powerlines environment, allowing developers to easily access Cloudflare-specific functionality in their applications.\n */\nexport function WorkerEntry(props: WorkerEntryProps) {\n const [{ worker, children, imports, builtinImports }, rest] = splitProps(\n props,\n [\"worker\", \"children\", \"imports\", \"builtinImports\"]\n );\n\n const context = usePowerlines<CloudflarePluginContext>();\n const entryPath = computed(\n () =>\n `./${replaceExtension(\n relativePath(\n context.entryPath,\n worker.metadata.entry.input?.file || worker.metadata.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.metadata.entry, {\n maxLength: 8\n })}-entry.ts`}\n {...rest}\n imports={defu(\n {\n \"@cloudflare/workers-types\": [\n { name: \"Request\", type: true },\n { name: \"Response\", type: true },\n { name: \"ExecutionContext\", type: true },\n { name: \"IncomingRequestCfProperties\", type: true },\n { name: \"ScheduledController\", type: true },\n { name: \"ForwardableEmailMessage\", type: true },\n { name: \"MessageBatch\", type: true },\n { name: \"TailStream\", type: true },\n { name: \"TraceItem\", type: true },\n { name: \"TailStream.TailEvent\", type: true },\n { name: \"TailStream.Onset\", type: true },\n { name: \"TailStream.TailEventHandlerType\", type: true }\n ],\n [entryPath.value]: \"worker\"\n },\n imports ?? {}\n )}\n builtinImports={defu(\n {\n cloudflare: [\n \"withFetchContext\",\n \"withTailContext\",\n \"withTraceContext\",\n \"withTailStreamContext\",\n \"withScheduledContext\",\n \"withTestContext\",\n \"withEmailContext\",\n \"withQueueContext\"\n ]\n },\n builtinImports ?? {}\n )}>\n {code`export default { `}\n <hbr />\n <Show when={worker.fetch}>\n {code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {\n return await withFetchContext({ request, env, ctx }, async (context) => {\n return worker.fetch(context.request, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tail}>\n {code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTailContext({ events, env, ctx }, async (context) => {\n return worker.tail(context.events, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.trace}>\n {code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTraceContext({ traces, env, ctx }, async (context) => {\n return worker.trace(context.traces, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tailStream}>\n {code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {\n return await withTailStreamContext({ event, env, ctx }, async (context) => {\n return await worker.tailStream(context.event, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.scheduled}>\n {code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withScheduledContext({ controller, env, ctx }, async (context) => {\n return worker.scheduled(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.test}>\n {code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTestContext({ controller, env, ctx }, async (context) => {\n return worker.test(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.email}>\n {code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withEmailContext({ message, env, ctx }, async (context) => {\n return worker.email(context.message, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.queue}>\n {code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withQueueContext({ batch, env, ctx }, async (context) => {\n return worker.queue(context.batch, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n {code` } satisfies ExportedHandler<CloudflareBindings>; `}\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </EntryFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAY,YAAgB,OAAG;CAC7B,MAAK,CAAA,EACH,QACD,mBAED,kBACC,QAAU,WAAG,OAAW;EAAA;EAAe;EAAY;EAAW;EAAY,CAAA;CAC3E,MAAA,UAAA,eAAA;CACF,MAAO,YAAS,eAAmB,KAAA,iBAAkB,aAAA,QAAA,WAAA,OAAA,SAAA,MAAA,OAAA,QAAA,OAAA,SAAA,MAAA,KAAA,CAAA,GAAA;AACnD,QAAO,gBAAkB,WAAW,WAAA,EAClC,IAAA,OAAK;AACH,SAAO,UAAG,WAAY,OAAW,SAAA,OAAe,EACnD,WAAA;IAGD,EAAA,MAAM;EACJ,IAAI,UAAA;AACF,UAAK,KAAA;IACH,6BAAY;KAAA;MACV,MAAA;MACA,MAAM;MACR;KAAA;MACA,MAAA;MACL,MAAA;;;MAEM,MAAA;MACJ,MAAA;MACC;KAAK;MACH,MAAA;MACE,MAAM;MACP;KAAC;MACJ,MAAS;MACP,MAAA;MACC;KAAE;MACD,MAAI;MACJ,MAAI;MACL;K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AO;AACP,aAAA,OAAA;;KAEF,UAAI,IAAA;;;;;KAKL,CAAC;IAAE,gBAAc,OAAM,EAAO,CAAC;IAAA,gBAAoB,MAAA;KAClD,IAAE,OAAA;AACA,aAAA,OAAA;;KAEH,UAAK,IAAA;;;;;KAKT,CAAA;IAAA,gBAAA,OAAA,EAAA,CAAA;IAAA,IAAA;IAAA,gBAAA,SAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACH,IAAA,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrangler.mjs","names":[],"sources":["../../src/helpers/wrangler.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path\";\nimport { UnresolvedContext } from \"powerlines\";\n\nexport interface ResolveConfigPathOptions {\n useRedirectIfAvailable?: boolean;\n}\n\nexport interface ConfigPaths {\n /**\n * Absolute path to the actual configuration being used (possibly redirected from the user's config).\n */\n configPath: string | undefined;\n /**\n * Absolute path to the user's configuration, which may not be the same as `configPath` if it was redirected.\n */\n userConfigPath: string | undefined;\n /**\n * Absolute path to the deploy config path used\n */\n deployConfigPath: string | undefined;\n /**\n * Was a redirected config file read?\n */\n redirected: boolean;\n}\n\n/**\n * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.\n *\n * @param context - The Cloudflare plugin context containing the configuration and file system access.\n * @returns The absolute path to the found configuration file, or undefined if no file is found.\n */\nexport function resolveWranglerConfigPath(\n context: UnresolvedContext\n): string | undefined {\n for (const extension of [\"jsonc\", \"json\", \"toml\"]) {\n if (\n context.fs.existsSync(\n joinPaths(context.config.root, `wrangler.${extension}`)\n )\n ) {\n return joinPaths(context.config.root, `wrangler.${extension}`);\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"wrangler.mjs","names":[],"sources":["../../src/helpers/wrangler.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path\";\nimport { UnresolvedContext } from \"powerlines\";\n\nexport interface ResolveConfigPathOptions {\n useRedirectIfAvailable?: boolean;\n}\n\nexport interface ConfigPaths {\n /**\n * Absolute path to the actual configuration being used (possibly redirected from the user's config).\n */\n configPath: string | undefined;\n /**\n * Absolute path to the user's configuration, which may not be the same as `configPath` if it was redirected.\n */\n userConfigPath: string | undefined;\n /**\n * Absolute path to the deploy config path used\n */\n deployConfigPath: string | undefined;\n /**\n * Was a redirected config file read?\n */\n redirected: boolean;\n}\n\n/**\n * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.\n *\n * @param context - The Cloudflare plugin context containing the configuration and file system access.\n * @returns The absolute path to the found configuration file, or undefined if no file is found.\n */\nexport function resolveWranglerConfigPath(\n context: UnresolvedContext\n): string | undefined {\n for (const extension of [\"jsonc\", \"json\", \"toml\"]) {\n if (\n context.fs.existsSync(\n joinPaths(context.config.root, `wrangler.${extension}`)\n )\n ) {\n return joinPaths(context.config.root, `wrangler.${extension}`);\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAI,0BAAA,SAAA;AACF,MAAG,MAAQ,aAAa;EAAA;EAAO;EAAA;EAAc,CAC3C,KAAA,QAAA,GAAA,WAAA,UAAA,QAAA,OAAA,MAAA,YAAA,YAAA,CAAA,CACF,QAAW,UAAU,QAAA,OAAS,MAAA,YAAA,YAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const require_components_env_builtin = require('./components/env-builtin.cjs');
|
|
|
5
5
|
const require_components_worker_entry = require('./components/worker-entry.cjs');
|
|
6
6
|
require('./components/index.cjs');
|
|
7
7
|
const require_helpers_wrangler = require('./helpers/wrangler.cjs');
|
|
8
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
8
9
|
let _alloy_js_core = require("@alloy-js/core");
|
|
9
10
|
let _cloudflare_unenv_preset = require("@cloudflare/unenv-preset");
|
|
10
11
|
let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
|
|
@@ -23,7 +24,6 @@ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function")
|
|
|
23
24
|
let defu = require("defu");
|
|
24
25
|
defu = require_runtime.__toESM(defu);
|
|
25
26
|
let wrangler = require("wrangler");
|
|
26
|
-
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
27
27
|
|
|
28
28
|
//#region src/index.tsx
|
|
29
29
|
/**
|
|
@@ -55,11 +55,12 @@ function plugin(options = {}) {
|
|
|
55
55
|
},
|
|
56
56
|
async prepare() {
|
|
57
57
|
const result = await (0, _powerlines_plugin_env_helpers.readEnvTypeReflection)(this, "env");
|
|
58
|
-
return (0, _powerlines_plugin_alloy_render.render)(this,
|
|
58
|
+
return (0, _powerlines_plugin_alloy_render.render)(this, [(0, _alloy_js_core_jsx_runtime.createComponent)(require_components_cloudflare_builtin.CloudflareBuiltin, {}), (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_env_builtin.CloudflareEnvBuiltin, { reflection: result })]);
|
|
59
59
|
},
|
|
60
60
|
build: {
|
|
61
61
|
order: "pre",
|
|
62
62
|
async handler() {
|
|
63
|
+
const _self$ = this;
|
|
63
64
|
this.cloudflare ??= { workers: [] };
|
|
64
65
|
this.cloudflare.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
|
|
65
66
|
if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
|
|
@@ -82,9 +83,11 @@ function plugin(options = {}) {
|
|
|
82
83
|
queue: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.queue)
|
|
83
84
|
};
|
|
84
85
|
}));
|
|
85
|
-
return (0, _powerlines_plugin_alloy_render.render)(this,
|
|
86
|
-
each
|
|
87
|
-
|
|
86
|
+
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
|
|
87
|
+
get each() {
|
|
88
|
+
return _self$.cloudflare.workers;
|
|
89
|
+
},
|
|
90
|
+
children: (worker) => (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_worker_entry.WorkerEntry, { worker })
|
|
88
91
|
}));
|
|
89
92
|
}
|
|
90
93
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { CloudflareEnvBuiltin } from "./components/env-builtin.mjs";
|
|
|
3
3
|
import { WorkerEntry } from "./components/worker-entry.mjs";
|
|
4
4
|
import "./components/index.mjs";
|
|
5
5
|
import { resolveWranglerConfigPath } from "./helpers/wrangler.mjs";
|
|
6
|
+
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
6
7
|
import { For } from "@alloy-js/core";
|
|
7
8
|
import { getCloudflarePreset } from "@cloudflare/unenv-preset";
|
|
8
9
|
import { render } from "@powerlines/plugin-alloy/render";
|
|
@@ -17,7 +18,6 @@ import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
|
17
18
|
import { isFunction } from "@stryke/type-checks/is-function";
|
|
18
19
|
import defu from "defu";
|
|
19
20
|
import { unstable_readConfig } from "wrangler";
|
|
20
|
-
import { Fragment, jsx, jsxs } from "@alloy-js/core/jsx-runtime";
|
|
21
21
|
|
|
22
22
|
//#region src/index.tsx
|
|
23
23
|
/**
|
|
@@ -49,11 +49,12 @@ function plugin(options = {}) {
|
|
|
49
49
|
},
|
|
50
50
|
async prepare() {
|
|
51
51
|
const result = await readEnvTypeReflection(this, "env");
|
|
52
|
-
return render(this,
|
|
52
|
+
return render(this, [createComponent(CloudflareBuiltin, {}), createComponent(CloudflareEnvBuiltin, { reflection: result })]);
|
|
53
53
|
},
|
|
54
54
|
build: {
|
|
55
55
|
order: "pre",
|
|
56
56
|
async handler() {
|
|
57
|
+
const _self$ = this;
|
|
57
58
|
this.cloudflare ??= { workers: [] };
|
|
58
59
|
this.cloudflare.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
|
|
59
60
|
if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
|
|
@@ -76,9 +77,11 @@ function plugin(options = {}) {
|
|
|
76
77
|
queue: isFunction(workerModule.default.queue)
|
|
77
78
|
};
|
|
78
79
|
}));
|
|
79
|
-
return render(this,
|
|
80
|
-
each
|
|
81
|
-
|
|
80
|
+
return render(this, createComponent(For, {
|
|
81
|
+
get each() {
|
|
82
|
+
return _self$.cloudflare.workers;
|
|
83
|
+
},
|
|
84
|
+
children: (worker) => createComponent(WorkerEntry, { worker })
|
|
82
85
|
}));
|
|
83
86
|
}
|
|
84
87
|
},
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport pulumi from \"@powerlines/plugin-pulumi\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { PartialKeys } from \"@stryke/types\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\n\nimport { unstable_readConfig } from \"wrangler\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport { resolveWranglerConfigPath } from \"./helpers/wrangler\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\nimport { WranglerResolvedConfig, WranglerUserConfig } from \"./types/wrangler\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}): Plugin<TContext>[] {\n return [\n unenv<TContext>(options.unenv),\n ...pulumi<TContext>(options.pulumi),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\", \"pulumi\"]), {\n configPath: resolveWranglerConfigPath(this)\n }),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n\n const config: PartialKeys<WranglerUserConfig, \"build\" | \"define\"> =\n unstable_readConfig(\n { config: this.config.cloudflare?.configPath },\n { preserveOriginalMain: true, hideWarnings: true }\n );\n this.cloudflare.wrangler = structuredClone(\n config\n ) as WranglerResolvedConfig;\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.cloudflare ??= { workers: [] };\n this.cloudflare.workers = (await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n };\n })\n )) as CloudflareWorkerEntryModule[];\n\n return render(\n this,\n <For each={this.cloudflare.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deploy() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n // for (const worker of this.cloudflare.workers) {\n // }\n },\n pulumi: {\n async deploy() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const provider = new pulumiCloudflare.Provider(\n \"cloudflare-provider\",\n {\n apiToken\n }\n );\n\n const zone = await pulumiCloudflare.getZone(\n {\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n },\n { provider }\n );\n\n const workers = [] as pulumiCloudflare.Worker[];\n const workerVersions = [] as pulumiCloudflare.WorkerVersion[];\n const workersDeployments = [] as pulumiCloudflare.WorkersDeployment[];\n const workersRoutes = [] as pulumiCloudflare.WorkersRoute[];\n const dnsRecords = [] as pulumiCloudflare.DnsRecord[];\n for (const worker of this.cloudflare.workers) {\n const resource = new pulumiCloudflare.Worker(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n name: worker.metadata.name,\n tags: [\n `project:${kebabCase(this.config.name)}`,\n this.config.organization\n ? `organization:${kebabCase(this.config.organization)}`\n : undefined,\n this.config.mode\n ? `mode:${kebabCase(this.config.mode)}`\n : undefined\n ].filter(Boolean) as string[]\n },\n worker.metadata\n ),\n { provider }\n );\n workers.push(resource);\n\n const workerVersion = new pulumiCloudflare.WorkerVersion(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-version`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n workerId: resource.id,\n mainModule: joinPaths(this.config.output.path, \"index.mjs\"),\n modules: [\n {\n name: joinPaths(this.config.output.path, \"index.mjs\"),\n contentType: \"application/javascript+module\",\n contentFile: joinPaths(\n this.config.output.path,\n \"index.mjs\"\n )\n }\n ]\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkerVersionArgs,\n { provider }\n );\n workerVersions.push(workerVersion);\n\n const workersDeployment = new pulumiCloudflare.WorkersDeployment(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.workers-deployment`,\n defu({\n accountId: this.config.cloudflare.accountId,\n zoneId: zone.id,\n strategy: \"percentage\",\n scriptName: resource.name,\n versions: [\n {\n percentage: 100,\n versionId: workerVersion.id\n }\n ]\n }),\n { provider }\n );\n workersDeployments.push(workersDeployment);\n\n const workersRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.workers-route`,\n defu({\n accountId: this.config.cloudflare.accountId,\n zoneId: zone.id,\n pattern: worker.metadata.pattern\n .replace(\"{domain}\", this.config.cloudflare.domain)\n .replace(\"{scriptName}\", worker.metadata.name)\n .replace(\"{mode}\", this.config.mode),\n script: resource.name\n }),\n { provider }\n );\n workersRoutes.push(workersRoute);\n\n const dnsRecord = new pulumiCloudflare.DnsRecord(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.dns-record`,\n {\n name: workersRoute.pattern,\n type: \"A\",\n content: \"192.0.2.1\",\n zoneId: zone.id,\n proxied: true,\n ttl: 1\n },\n { provider }\n );\n dnsRecords.push(dnsRecord);\n }\n\n return {\n workers,\n workerVersions,\n workersDeployments,\n workersRoutes,\n dnsRecords\n };\n }\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,OAEd,UAAmC,EAAE,EAAsB;AAC3D,QAAO;EACL,MAAgB,QAAQ,MAAM;EAC9B,GAAG,OAAiB,QAAQ,OAAO;EACnC;GACE,MAAM;GACN,SAAS;AACP,WAAO;KACL,YAAY,KAAK,KAAK,SAAS,CAAC,SAAS,SAAS,CAAC,EAAE,EACnD,YAAY,0BAA0B,KAAK,EAC5C,CAAC;KACF,SAAS,EACP,uBAAuB,OACxB;KACD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O,SAAS,KACjB,GACN,GAAG,UAAU,KAAK,OAAO,KAAK,CAAC,cAChC;MACE,MAAM,aAAa;MACnB,MAAM;MACN,SAAS;MACT,QAAQ,KAAK;MACb,SAAS;MACT,KAAK;MACN,EACD,EAAE,UAAU,CACb;AACD,gBAAW,KAAK,UAAU;;AAG5B,WAAO;KACL;KACA;KACA;KACA;KACA;KACD;MAEJ;GACF;EACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport pulumi from \"@powerlines/plugin-pulumi\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { PartialKeys } from \"@stryke/types\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\n\nimport { unstable_readConfig } from \"wrangler\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport { resolveWranglerConfigPath } from \"./helpers/wrangler\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\nimport { WranglerResolvedConfig, WranglerUserConfig } from \"./types/wrangler\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}): Plugin<TContext>[] {\n return [\n unenv<TContext>(options.unenv),\n ...pulumi<TContext>(options.pulumi),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\", \"pulumi\"]), {\n configPath: resolveWranglerConfigPath(this)\n }),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n\n const config: PartialKeys<WranglerUserConfig, \"build\" | \"define\"> =\n unstable_readConfig(\n { config: this.config.cloudflare?.configPath },\n { preserveOriginalMain: true, hideWarnings: true }\n );\n this.cloudflare.wrangler = structuredClone(\n config\n ) as WranglerResolvedConfig;\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.cloudflare ??= { workers: [] };\n this.cloudflare.workers = (await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \\`ExportedHandler\\` interface from \"@cloudflare/workers-types\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n };\n })\n )) as CloudflareWorkerEntryModule[];\n\n return render(\n this,\n <For each={this.cloudflare.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deploy() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n // for (const worker of this.cloudflare.workers) {\n // }\n },\n pulumi: {\n async deploy() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const provider = new pulumiCloudflare.Provider(\n \"cloudflare-provider\",\n {\n apiToken\n }\n );\n\n const zone = await pulumiCloudflare.getZone(\n {\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n },\n { provider }\n );\n\n const workers = [] as pulumiCloudflare.Worker[];\n const workerVersions = [] as pulumiCloudflare.WorkerVersion[];\n const workersDeployments = [] as pulumiCloudflare.WorkersDeployment[];\n const workersRoutes = [] as pulumiCloudflare.WorkersRoute[];\n const dnsRecords = [] as pulumiCloudflare.DnsRecord[];\n for (const worker of this.cloudflare.workers) {\n const resource = new pulumiCloudflare.Worker(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n name: worker.metadata.name,\n tags: [\n `project:${kebabCase(this.config.name)}`,\n this.config.organization\n ? `organization:${kebabCase(this.config.organization)}`\n : undefined,\n this.config.mode\n ? `mode:${kebabCase(this.config.mode)}`\n : undefined\n ].filter(Boolean) as string[]\n },\n worker.metadata\n ),\n { provider }\n );\n workers.push(resource);\n\n const workerVersion = new pulumiCloudflare.WorkerVersion(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-version`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n workerId: resource.id,\n mainModule: joinPaths(this.config.output.path, \"index.mjs\"),\n modules: [\n {\n name: joinPaths(this.config.output.path, \"index.mjs\"),\n contentType: \"application/javascript+module\",\n contentFile: joinPaths(\n this.config.output.path,\n \"index.mjs\"\n )\n }\n ]\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkerVersionArgs,\n { provider }\n );\n workerVersions.push(workerVersion);\n\n const workersDeployment = new pulumiCloudflare.WorkersDeployment(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.workers-deployment`,\n defu({\n accountId: this.config.cloudflare.accountId,\n zoneId: zone.id,\n strategy: \"percentage\",\n scriptName: resource.name,\n versions: [\n {\n percentage: 100,\n versionId: workerVersion.id\n }\n ]\n }),\n { provider }\n );\n workersDeployments.push(workersDeployment);\n\n const workersRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.workers-route`,\n defu({\n accountId: this.config.cloudflare.accountId,\n zoneId: zone.id,\n pattern: worker.metadata.pattern\n .replace(\"{domain}\", this.config.cloudflare.domain)\n .replace(\"{scriptName}\", worker.metadata.name)\n .replace(\"{mode}\", this.config.mode),\n script: resource.name\n }),\n { provider }\n );\n workersRoutes.push(workersRoute);\n\n const dnsRecord = new pulumiCloudflare.DnsRecord(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.dns-record`,\n {\n name: workersRoute.pattern,\n type: \"A\",\n content: \"192.0.2.1\",\n zoneId: zone.id,\n proxied: true,\n ttl: 1\n },\n { provider }\n );\n dnsRecords.push(dnsRecord);\n }\n\n return {\n workers,\n workerVersions,\n workersDeployments,\n workersRoutes,\n dnsRecords\n };\n }\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,QAAS;EAAA,MAAO,QAAC,MAAW;EAAA,GAAA,OAAA,QAAA,OAAA;EAAA;GAC5B,MAAO;;AAEP,WAAQ;KACN,YAAiB,KAAA,KAAA,SAAA,CAAA,SAAA,SAAA,CAAA,EAAA,EACf,YAAa,0BAAuB,KAAA,EACtC,CAAA;KACF,SAAA,gCAEE;KACG,OAAU,EACb,SAAA,CAAA,oBAAA;MACK,mBAAe,KAAA,OAAA,mBAAA,UAAA;MACX,oBAAQ,CAAA,aAA0B;MAClC,CAAA,CAAA,EACF;KACL;;GAEA,iBAAA;AACE,SAAK,gBAAa,+BAAA;IAClB,MAAM,SAAG,oBAAA,EACP,QAAO,KAAA,OAAA,YAAA,YACR,EAAE;KACD,sBAAgB;KAChB,cAAI;KACL,CAAC;AACF,SAAK,WAAC,WAAqB,gBAAE,OAAA;;GAE/B,MAAM,UAAO;IACX,MAAM,SAAS,MAAA,sBAAA,MAAA,MAAA;AACf,WAAO,OAAC,MAAA,CAAA,gBAAoB,mBAAA,EAAA,CAAA,EAAA,gBAAA,sBAAA,EAC1B,YAAQ,QACT,CAAC,CAAC,CAAC;;GAEN,OAAO;IACL,OAAI;IACJ,MAAG,UAAA;KACF,MAAA,SAAA;AACD,UAAA,eAAiB,EACf,SAAK,EAAA;AAEL,UAAK,WAAS,UAAY,MAAA,QAAA,IAAkB,KAAG,MAAQ,IAAE,OAAS,OAAA,GAAA,QAAA;AAChE,UAAA,CAAA,MAAA,MACE,OAAE,IAAQ,MAAK,4BAA6B,MAAE,KAAA,6BAAA;MAEhD,MAAC,eAAA,MAAA,cA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AAA,gBAAA,OAAA,SAAA,KAAA,CAAA,QAAA,UAAA,KAAA,OAAA,KAAA;MACzC,QAAA,SAAA;MACD,CAAC,EAAE,EACF,UACD,CAAC;AACF,mBAAI,KAAA,aAAA;KACJ,MAAG,YAAA,IAAA,iBAAA,UAAA,GAAA,KAAA,OAAA,eAAA,GAAA,KAAA,OAAA,aAAA,KAAA,KAAA,UAAA,KAAA,OAAA,KAAA,KAAA,UAAA,OAAA,SAAA,KAAA,GAAA,UAAA,KAAA,OAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,GAAA,UAAA,OAAA,SAAA,KAAA,GAAA,GAAA,UAAA,KAAA,OAAA,KAAA,CAAA,cAAA;MACD,MAAE,aAAS;MACZ,MAAA;;MAED,QAAM,KAAS;MACf,SAAM;MACN,KAAM;MACN,EAAA,EACA,UACA,CAAA;AACA,gBAAQ,KAAQ,UAAO;;AAEzB,WAAO;KACL;KACA;KACA;KACA;KACA;KACD;MAEJ;GACF;EAAC"}
|
package/dist/types/wrangler.cjs
CHANGED
|
@@ -42,6 +42,20 @@ function isCyclic(value, seen = /* @__PURE__ */ new Set()) {
|
|
|
42
42
|
}
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* This is the static type definition for the configuration object.
|
|
47
|
+
*
|
|
48
|
+
* It reflects a normalized and validated version of the configuration that you can write in a Wrangler configuration file,
|
|
49
|
+
* and optionally augment with arguments passed directly to wrangler.
|
|
50
|
+
*
|
|
51
|
+
* For more information about the configuration object, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* - Fields that are only specified in `ConfigFields` and not `Environment` can only appear
|
|
55
|
+
* in the top level config and should not appear in any environments.
|
|
56
|
+
* - Fields that are specified in `PagesConfigFields` are only relevant for Pages projects
|
|
57
|
+
* - All top level fields in config and environments are optional in the Wrangler configuration file.
|
|
58
|
+
*/
|
|
45
59
|
const defaultWranglerConfig = {
|
|
46
60
|
configPath: void 0,
|
|
47
61
|
userConfigPath: void 0,
|
|
@@ -62,11 +76,13 @@ const defaultWranglerConfig = {
|
|
|
62
76
|
container_engine: void 0,
|
|
63
77
|
generate_types: false
|
|
64
78
|
},
|
|
79
|
+
/** INHERITABLE ENVIRONMENT FIELDS */
|
|
65
80
|
name: void 0,
|
|
66
81
|
compatibility_date: void 0,
|
|
67
82
|
compatibility_flags: [],
|
|
68
83
|
limits: void 0,
|
|
69
84
|
placement: void 0,
|
|
85
|
+
/** NON-INHERITABLE ENVIRONMENT FIELDS */
|
|
70
86
|
vars: {},
|
|
71
87
|
durable_objects: { bindings: [] },
|
|
72
88
|
kv_namespaces: [],
|
|
@@ -97,6 +113,7 @@ const defaultWranglerConfig = {
|
|
|
97
113
|
data_blobs: void 0,
|
|
98
114
|
keep_vars: void 0,
|
|
99
115
|
alias: void 0,
|
|
116
|
+
/** INHERITABLE ENVIRONMENT FIELDS */
|
|
100
117
|
account_id: void 0,
|
|
101
118
|
main: void 0,
|
|
102
119
|
find_additional_modules: void 0,
|
|
@@ -128,8 +145,10 @@ const defaultWranglerConfig = {
|
|
|
128
145
|
assets: void 0,
|
|
129
146
|
observability: { enabled: true },
|
|
130
147
|
cache: void 0,
|
|
148
|
+
/** The default here is undefined so that we can delegate to the CLOUDFLARE_COMPLIANCE_REGION environment variable. */
|
|
131
149
|
compliance_region: void 0,
|
|
132
150
|
python_modules: { exclude: ["**/*.pyc"] },
|
|
151
|
+
/** NON-INHERITABLE ENVIRONMENT FIELDS */
|
|
133
152
|
define: {},
|
|
134
153
|
cloudchamber: {},
|
|
135
154
|
containers: void 0,
|