@powerlines/plugin-cloudflare 0.6.82 → 0.6.83
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/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/components/cloudflare-builtin.cjs +893 -9
- package/dist/components/cloudflare-builtin.mjs +890 -9
- package/dist/components/cloudflare-builtin.mjs.map +1 -1
- package/dist/components/env-builtin.cjs +32 -1
- package/dist/components/env-builtin.mjs +29 -1
- package/dist/components/env-builtin.mjs.map +1 -1
- package/dist/components/index.cjs +8 -1
- package/dist/components/index.mjs +5 -1
- package/dist/components/worker-entry.cjs +179 -9
- package/dist/components/worker-entry.mjs +176 -9
- package/dist/components/worker-entry.mjs.map +1 -1
- package/dist/helpers/constants.cjs +7 -1
- package/dist/helpers/constants.mjs +5 -1
- package/dist/helpers/constants.mjs.map +1 -1
- package/dist/helpers/wrangler.cjs +21 -1
- package/dist/helpers/wrangler.mjs +19 -1
- package/dist/helpers/wrangler.mjs.map +1 -1
- package/dist/index.cjs +190 -1
- package/dist/index.mjs +180 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.cjs +9 -1
- package/dist/types/index.mjs +3 -1
- package/dist/types/plugin.mjs +1 -1
- package/dist/types/worker-module.mjs +1 -1
- package/dist/types/wrangler.cjs +172 -1
- package/dist/types/wrangler.mjs +162 -1
- package/dist/types/wrangler.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -1,34 +1,201 @@
|
|
|
1
|
-
import{createComponent
|
|
1
|
+
import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Show, code, computed, splitProps } from "@alloy-js/core";
|
|
3
|
+
import defu from "defu";
|
|
4
|
+
import { Spacing } from "@powerlines/plugin-alloy/core/components";
|
|
5
|
+
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts";
|
|
6
|
+
import { EntryFile } from "@powerlines/plugin-alloy/typescript/components/entry-file";
|
|
7
|
+
import { murmurhash } from "@stryke/hash";
|
|
8
|
+
import { relativePath } from "@stryke/path/find";
|
|
9
|
+
import { replaceExtension } from "@stryke/path/replace";
|
|
10
|
+
|
|
11
|
+
//#region src/components/worker-entry.tsx
|
|
12
|
+
/**
|
|
13
|
+
* 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.
|
|
14
|
+
*/
|
|
15
|
+
function WorkerEntry(props) {
|
|
16
|
+
const [{ worker, children, imports, builtinImports }, rest] = splitProps(props, [
|
|
17
|
+
"worker",
|
|
18
|
+
"children",
|
|
19
|
+
"imports",
|
|
20
|
+
"builtinImports"
|
|
21
|
+
]);
|
|
22
|
+
const context = usePowerlines();
|
|
23
|
+
const entryPath = computed(() => `./${replaceExtension(relativePath(context.entryPath, worker.metadata.entry.input?.file || worker.metadata.entry.file))}`);
|
|
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> {
|
|
2
103
|
return await withFetchContext({ request, env, ctx }, async (context) => {
|
|
3
104
|
return worker.fetch(context.request, context.env, context.ctx);
|
|
4
105
|
});
|
|
5
|
-
}, `
|
|
106
|
+
}, `
|
|
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> {
|
|
6
114
|
return withTailContext({ events, env, ctx }, async (context) => {
|
|
7
115
|
return worker.tail(context.events, context.env, context.ctx);
|
|
8
116
|
});
|
|
9
|
-
}, `
|
|
117
|
+
}, `
|
|
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> {
|
|
10
125
|
return withTraceContext({ traces, env, ctx }, async (context) => {
|
|
11
126
|
return worker.trace(context.traces, context.env, context.ctx);
|
|
12
127
|
});
|
|
13
|
-
}, `
|
|
128
|
+
}, `
|
|
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> {
|
|
14
136
|
return await withTailStreamContext({ event, env, ctx }, async (context) => {
|
|
15
137
|
return await worker.tailStream(context.event, context.env, context.ctx);
|
|
16
138
|
});
|
|
17
|
-
}, `
|
|
139
|
+
}, `
|
|
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> {
|
|
18
147
|
return withScheduledContext({ controller, env, ctx }, async (context) => {
|
|
19
148
|
return worker.scheduled(context.controller, context.env, context.ctx);
|
|
20
149
|
});
|
|
21
|
-
}, `
|
|
150
|
+
}, `
|
|
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> {
|
|
22
158
|
return withTestContext({ controller, env, ctx }, async (context) => {
|
|
23
159
|
return worker.test(context.controller, context.env, context.ctx);
|
|
24
160
|
});
|
|
25
|
-
}, `
|
|
161
|
+
}, `
|
|
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> {
|
|
26
169
|
return withEmailContext({ message, env, ctx }, async (context) => {
|
|
27
170
|
return worker.email(context.message, context.env, context.ctx);
|
|
28
171
|
});
|
|
29
|
-
}, `
|
|
172
|
+
}, `
|
|
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> {
|
|
30
180
|
return withQueueContext({ batch, env, ctx }, async (context) => {
|
|
31
181
|
return worker.queue(context.batch, context.env, context.ctx);
|
|
32
182
|
});
|
|
33
|
-
}, `
|
|
183
|
+
}, `
|
|
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
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//#endregion
|
|
200
|
+
export { WorkerEntry };
|
|
34
201
|
//# sourceMappingURL=worker-entry.mjs.map
|
|
@@ -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;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAC;MACD,MAAC;MACF;KAAA;MACD,MAAQ;MACT,MAAA;MACD;KAAA;MACE,MAAA;MACE,MAAA;MACD;KAAC;KACD,UAAI,QAAA;IACN,EAAE,WAAI,EAAA,CAAA;;EAET,IAAI,iBAAK;AACP,UAAO,KAAA,EACL,YAAK;IAAA;IAAiB;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA,EACvB,EAAE,kBAAI,EAAgB,CAAA;;EAEzB,IAAI,WAAC;AACH,UAAE;IAAA,IAAA;IAAmB,gBAAA,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACnB,IAAA,OAAA;AACD,aAAK,OAAO;;KAEZ,UAAW,IAAA;;;;;KAKX,CAAC;IAAE,gBAAA,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACF,IAAI,OAAA;AACF,aAAE,OAAA;;KAEJ,UAAO,IAAM;;;;;KAKd,CAAC;IAAA,gBAAI,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACL,IAAK,OAAA;AACL,aAAU,OAAO;;KAEhB,UAAO,IAAA;;;;;KAKR,CAAA;IAAG,gBAAE,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACL,IAAK,OAAM;AACT,aAAM,OAAM;;KAEb,UAAS,IAAK;;;;;KAKf,CAAA;IAAA,gBAAkB,OAAU,EAAA,CAAA;IAAA,gBAAA,MAAA;KAC3B,IAAC,OAAM;AACP,aAAO,OAAA;;KAEP,UAAE,IAAA;;;;;KAKH,CAAC;IAAC,gBAAiB,OAAA,EAAW,CAAC;IAAA,gBAAoB,MAAC;KACnD,IAAA,OAAO;AACL,aAAO,OAAO;;KAEhB,UAAE,IAAA;;;;;KAKH,CAAC;IAAA,gBAAO,OAAmB,EAAA,CAAA;IAAA,gBAAqB,MAAO;KACtD,IAAE,OAAO;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,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/constants.ts
|
|
4
|
+
const PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.PATH_TO_DEPLOY_CONFIG = PATH_TO_DEPLOY_CONFIG;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/helpers/constants.ts
|
|
2
|
+
const PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
|
|
3
|
+
|
|
4
|
+
//#endregion
|
|
5
|
+
export { PATH_TO_DEPLOY_CONFIG };
|
|
2
6
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/helpers/constants.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\nexport const PATH_TO_DEPLOY_CONFIG = \".wrangler/deploy/config.json\";\n"],"mappings":"AAkBA,MAAa,
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/helpers/constants.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\nexport const PATH_TO_DEPLOY_CONFIG = \".wrangler/deploy/config.json\";\n"],"mappings":";AAkBA,MAAa,wBAAwB"}
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _stryke_path = require("@stryke/path");
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/wrangler.ts
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.
|
|
8
|
+
*
|
|
9
|
+
* @param context - The Cloudflare plugin context containing the configuration and file system access.
|
|
10
|
+
* @returns The absolute path to the found configuration file, or undefined if no file is found.
|
|
11
|
+
*/
|
|
12
|
+
function resolveWranglerConfigPath(context) {
|
|
13
|
+
for (const extension of [
|
|
14
|
+
"jsonc",
|
|
15
|
+
"json",
|
|
16
|
+
"toml"
|
|
17
|
+
]) if (context.fs.existsSync((0, _stryke_path.joinPaths)(context.config.root, `wrangler.${extension}`))) return (0, _stryke_path.joinPaths)(context.config.root, `wrangler.${extension}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.resolveWranglerConfigPath = resolveWranglerConfigPath;
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import{joinPaths
|
|
1
|
+
import { joinPaths } from "@stryke/path";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/wrangler.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.
|
|
6
|
+
*
|
|
7
|
+
* @param context - The Cloudflare plugin context containing the configuration and file system access.
|
|
8
|
+
* @returns The absolute path to the found configuration file, or undefined if no file is found.
|
|
9
|
+
*/
|
|
10
|
+
function resolveWranglerConfigPath(context) {
|
|
11
|
+
for (const extension of [
|
|
12
|
+
"jsonc",
|
|
13
|
+
"json",
|
|
14
|
+
"toml"
|
|
15
|
+
]) if (context.fs.existsSync(joinPaths(context.config.root, `wrangler.${extension}`))) return joinPaths(context.config.root, `wrangler.${extension}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { resolveWranglerConfigPath };
|
|
2
20
|
//# sourceMappingURL=wrangler.mjs.map
|
|
@@ -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
|
@@ -1 +1,190 @@
|
|
|
1
|
-
Object.defineProperties(exports,
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_components_cloudflare_builtin = require('./components/cloudflare-builtin.cjs');
|
|
4
|
+
const require_components_env_builtin = require('./components/env-builtin.cjs');
|
|
5
|
+
const require_components_worker_entry = require('./components/worker-entry.cjs');
|
|
6
|
+
require('./components/index.cjs');
|
|
7
|
+
const require_helpers_wrangler = require('./helpers/wrangler.cjs');
|
|
8
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
9
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
10
|
+
let _cloudflare_unenv_preset = require("@cloudflare/unenv-preset");
|
|
11
|
+
let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
|
|
12
|
+
let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
|
|
13
|
+
let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
|
|
14
|
+
let _powerlines_plugin_pulumi = require("@powerlines/plugin-pulumi");
|
|
15
|
+
_powerlines_plugin_pulumi = require_runtime.__toESM(_powerlines_plugin_pulumi);
|
|
16
|
+
let _powerlines_plugin_unenv = require("@powerlines/plugin-unenv");
|
|
17
|
+
_powerlines_plugin_unenv = require_runtime.__toESM(_powerlines_plugin_unenv);
|
|
18
|
+
let _pulumi_cloudflare = require("@pulumi/cloudflare");
|
|
19
|
+
_pulumi_cloudflare = require_runtime.__toESM(_pulumi_cloudflare);
|
|
20
|
+
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
21
|
+
let _stryke_path = require("@stryke/path");
|
|
22
|
+
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
23
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
24
|
+
let defu = require("defu");
|
|
25
|
+
defu = require_runtime.__toESM(defu);
|
|
26
|
+
let wrangler = require("wrangler");
|
|
27
|
+
|
|
28
|
+
//#region src/index.tsx
|
|
29
|
+
/**
|
|
30
|
+
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
31
|
+
*/
|
|
32
|
+
function plugin(options = {}) {
|
|
33
|
+
return [
|
|
34
|
+
(0, _powerlines_plugin_unenv.default)(options.unenv),
|
|
35
|
+
...(0, _powerlines_plugin_pulumi.default)(options.pulumi),
|
|
36
|
+
{
|
|
37
|
+
name: "cloudflare",
|
|
38
|
+
config() {
|
|
39
|
+
return {
|
|
40
|
+
cloudflare: (0, defu.default)((0, _stryke_helpers_omit.omit)(options, ["unenv", "pulumi"]), { configPath: require_helpers_wrangler.resolveWranglerConfigPath(this) }),
|
|
41
|
+
resolve: { skipNodeModulesBundle: false },
|
|
42
|
+
unenv: { presets: [(0, _cloudflare_unenv_preset.getCloudflarePreset)({
|
|
43
|
+
compatibilityDate: this.config.compatibilityDate?.toString(),
|
|
44
|
+
compatibilityFlags: ["nodejs_als"]
|
|
45
|
+
})] }
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
configResolved() {
|
|
49
|
+
this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
|
|
50
|
+
const config = (0, wrangler.unstable_readConfig)({ config: this.config.cloudflare?.configPath }, {
|
|
51
|
+
preserveOriginalMain: true,
|
|
52
|
+
hideWarnings: true
|
|
53
|
+
});
|
|
54
|
+
this.cloudflare.wrangler = structuredClone(config);
|
|
55
|
+
},
|
|
56
|
+
async prepare() {
|
|
57
|
+
const result = await (0, _powerlines_plugin_env_helpers.readEnvTypeReflection)(this, "env");
|
|
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
|
+
},
|
|
60
|
+
build: {
|
|
61
|
+
order: "pre",
|
|
62
|
+
async handler() {
|
|
63
|
+
const _self$ = this;
|
|
64
|
+
this.cloudflare ??= { workers: [] };
|
|
65
|
+
this.cloudflare.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
|
|
66
|
+
if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
|
|
67
|
+
const workerModule = await (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(this, entry.input);
|
|
68
|
+
if (!workerModule?.default) throw new Error(`Cloudflare Worker entry "${entry.file}" 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".`);
|
|
69
|
+
const name = workerModule.metadata?.name || (0, _stryke_path.replaceExtension)(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
|
|
70
|
+
return {
|
|
71
|
+
metadata: {
|
|
72
|
+
name,
|
|
73
|
+
pattern: `${name}.{domain}`,
|
|
74
|
+
entry
|
|
75
|
+
},
|
|
76
|
+
fetch: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.fetch),
|
|
77
|
+
tail: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tail),
|
|
78
|
+
trace: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.trace),
|
|
79
|
+
tailStream: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tailStream),
|
|
80
|
+
scheduled: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.scheduled),
|
|
81
|
+
test: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.test),
|
|
82
|
+
email: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.email),
|
|
83
|
+
queue: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.queue)
|
|
84
|
+
};
|
|
85
|
+
}));
|
|
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 })
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
async deploy() {
|
|
95
|
+
let apiToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
96
|
+
if (!apiToken) {
|
|
97
|
+
apiToken = this.config.cloudflare.apiToken;
|
|
98
|
+
if (apiToken) this.warn("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.");
|
|
99
|
+
else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
pulumi: { async deploy() {
|
|
103
|
+
let apiToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
104
|
+
if (!apiToken) {
|
|
105
|
+
apiToken = this.config.cloudflare.apiToken;
|
|
106
|
+
if (apiToken) this.warn("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.");
|
|
107
|
+
else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
|
|
108
|
+
}
|
|
109
|
+
await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
|
|
110
|
+
const provider = new _pulumi_cloudflare.Provider("cloudflare-provider", { apiToken });
|
|
111
|
+
const zone = await _pulumi_cloudflare.getZone({ filter: {
|
|
112
|
+
account: { id: this.config.cloudflare.accountId },
|
|
113
|
+
name: this.config.cloudflare.domain
|
|
114
|
+
} }, { provider });
|
|
115
|
+
const workers = [];
|
|
116
|
+
const workerVersions = [];
|
|
117
|
+
const workersDeployments = [];
|
|
118
|
+
const workersRoutes = [];
|
|
119
|
+
const dnsRecords = [];
|
|
120
|
+
for (const worker of this.cloudflare.workers) {
|
|
121
|
+
const resource = new _pulumi_cloudflare.Worker(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker`, (0, defu.default)({
|
|
122
|
+
accountId: this.config.cloudflare.accountId,
|
|
123
|
+
name: worker.metadata.name,
|
|
124
|
+
tags: [
|
|
125
|
+
`project:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}`,
|
|
126
|
+
this.config.organization ? `organization:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.organization)}` : void 0,
|
|
127
|
+
this.config.mode ? `mode:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}` : void 0
|
|
128
|
+
].filter(Boolean)
|
|
129
|
+
}, worker.metadata), { provider });
|
|
130
|
+
workers.push(resource);
|
|
131
|
+
const workerVersion = new _pulumi_cloudflare.WorkerVersion(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-version`, (0, defu.default)({
|
|
132
|
+
accountId: this.config.cloudflare.accountId,
|
|
133
|
+
workerId: resource.id,
|
|
134
|
+
mainModule: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs"),
|
|
135
|
+
modules: [{
|
|
136
|
+
name: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs"),
|
|
137
|
+
contentType: "application/javascript+module",
|
|
138
|
+
contentFile: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs")
|
|
139
|
+
}]
|
|
140
|
+
}, worker.metadata, {
|
|
141
|
+
compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
|
|
142
|
+
compatibilityFlags: ["nodejs_als"]
|
|
143
|
+
}), { provider });
|
|
144
|
+
workerVersions.push(workerVersion);
|
|
145
|
+
const workersDeployment = new _pulumi_cloudflare.WorkersDeployment(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.workers-deployment`, (0, defu.default)({
|
|
146
|
+
accountId: this.config.cloudflare.accountId,
|
|
147
|
+
zoneId: zone.id,
|
|
148
|
+
strategy: "percentage",
|
|
149
|
+
scriptName: resource.name,
|
|
150
|
+
versions: [{
|
|
151
|
+
percentage: 100,
|
|
152
|
+
versionId: workerVersion.id
|
|
153
|
+
}]
|
|
154
|
+
}), { provider });
|
|
155
|
+
workersDeployments.push(workersDeployment);
|
|
156
|
+
const workersRoute = new _pulumi_cloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.workers-route`, (0, defu.default)({
|
|
157
|
+
accountId: this.config.cloudflare.accountId,
|
|
158
|
+
zoneId: zone.id,
|
|
159
|
+
pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain).replace("{scriptName}", worker.metadata.name).replace("{mode}", this.config.mode),
|
|
160
|
+
script: resource.name
|
|
161
|
+
}), { provider });
|
|
162
|
+
workersRoutes.push(workersRoute);
|
|
163
|
+
const dnsRecord = new _pulumi_cloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.dns-record`, {
|
|
164
|
+
name: workersRoute.pattern,
|
|
165
|
+
type: "A",
|
|
166
|
+
content: "192.0.2.1",
|
|
167
|
+
zoneId: zone.id,
|
|
168
|
+
proxied: true,
|
|
169
|
+
ttl: 1
|
|
170
|
+
}, { provider });
|
|
171
|
+
dnsRecords.push(dnsRecord);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
workers,
|
|
175
|
+
workerVersions,
|
|
176
|
+
workersDeployments,
|
|
177
|
+
workersRoutes,
|
|
178
|
+
dnsRecords
|
|
179
|
+
};
|
|
180
|
+
} }
|
|
181
|
+
}
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
exports.CloudflareBuiltin = require_components_cloudflare_builtin.CloudflareBuiltin;
|
|
187
|
+
exports.CloudflareEnvBuiltin = require_components_env_builtin.CloudflareEnvBuiltin;
|
|
188
|
+
exports.WorkerEntry = require_components_worker_entry.WorkerEntry;
|
|
189
|
+
exports.default = plugin;
|
|
190
|
+
exports.plugin = plugin;
|