@powerlines/plugin-cloudflare 0.2.21 → 0.2.23

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.
@@ -1,4 +1,3 @@
1
- import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
2
1
  import { Show, code, computed, splitProps } from "@alloy-js/core";
3
2
  import defu from "defu";
4
3
  import { Spacing } from "@powerlines/plugin-alloy/core/components";
@@ -21,179 +20,138 @@ function WorkerEntry(props) {
21
20
  ]);
22
21
  const context = usePowerlines();
23
22
  const entryPath = computed(() => `./${replaceExtension(relativePath(context.entryPath, worker.entry.input?.file || worker.entry.file))}`);
24
- return createComponent(EntryFile, mergeProps({ get path() {
25
- return `worker-${murmurhash(worker.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> {
23
+ return <EntryFile path={`worker-${murmurhash(worker.entry, { maxLength: 8 })}-entry.ts`} {...rest} imports={defu({
24
+ "@cloudflare/workers-types": [
25
+ {
26
+ name: "Request",
27
+ type: true
28
+ },
29
+ {
30
+ name: "Response",
31
+ type: true
32
+ },
33
+ {
34
+ name: "ExecutionContext",
35
+ type: true
36
+ },
37
+ {
38
+ name: "IncomingRequestCfProperties",
39
+ type: true
40
+ },
41
+ {
42
+ name: "ScheduledController",
43
+ type: true
44
+ },
45
+ {
46
+ name: "ForwardableEmailMessage",
47
+ type: true
48
+ },
49
+ {
50
+ name: "MessageBatch",
51
+ type: true
52
+ },
53
+ {
54
+ name: "TailStream",
55
+ type: true
56
+ },
57
+ {
58
+ name: "TraceItem",
59
+ type: true
60
+ },
61
+ {
62
+ name: "TailStream.TailEvent",
63
+ type: true
64
+ },
65
+ {
66
+ name: "TailStream.Onset",
67
+ type: true
68
+ },
69
+ {
70
+ name: "TailStream.TailEventHandlerType",
71
+ type: true
72
+ }
73
+ ],
74
+ [entryPath.value]: "worker"
75
+ }, imports ?? {})} builtinImports={defu({ cloudflare: [
76
+ "withFetchContext",
77
+ "withTailContext",
78
+ "withTraceContext",
79
+ "withTailStreamContext",
80
+ "withScheduledContext",
81
+ "withTestContext",
82
+ "withEmailContext",
83
+ "withQueueContext"
84
+ ] }, builtinImports ?? {})}>
85
+ {code`export default { `}
86
+ <hbr />
87
+ <Show when={worker.fetch}>
88
+ {code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {
103
89
  return await withFetchContext({ request, env, ctx }, async (context) => {
104
90
  return worker.fetch(context.request, context.env, context.ctx);
105
91
  });
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> {
92
+ }, `}
93
+ </Show>
94
+ <hbr />
95
+ <Show when={worker.tail}>
96
+ {code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
114
97
  return withTailContext({ events, env, ctx }, async (context) => {
115
98
  return worker.tail(context.events, context.env, context.ctx);
116
99
  });
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> {
100
+ }, `}
101
+ </Show>
102
+ <hbr />
103
+ <Show when={worker.trace}>
104
+ {code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
125
105
  return withTraceContext({ traces, env, ctx }, async (context) => {
126
106
  return worker.trace(context.traces, context.env, context.ctx);
127
107
  });
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> {
108
+ }, `}
109
+ </Show>
110
+ <hbr />
111
+ <Show when={worker.tailStream}>
112
+ {code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {
136
113
  return await withTailStreamContext({ event, env, ctx }, async (context) => {
137
114
  return await worker.tailStream(context.event, context.env, context.ctx);
138
115
  });
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> {
116
+ }, `}
117
+ </Show>
118
+ <hbr />
119
+ <Show when={worker.scheduled}>
120
+ {code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
147
121
  return withScheduledContext({ controller, env, ctx }, async (context) => {
148
122
  return worker.scheduled(context.controller, context.env, context.ctx);
149
123
  });
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> {
124
+ }, `}
125
+ </Show>
126
+ <hbr />
127
+ <Show when={worker.test}>
128
+ {code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
158
129
  return withTestContext({ controller, env, ctx }, async (context) => {
159
130
  return worker.test(context.controller, context.env, context.ctx);
160
131
  });
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> {
132
+ }, `}
133
+ </Show>
134
+ <hbr />
135
+ <Show when={worker.email}>
136
+ {code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
169
137
  return withEmailContext({ message, env, ctx }, async (context) => {
170
138
  return worker.email(context.message, context.env, context.ctx);
171
139
  });
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> {
140
+ }, `}
141
+ </Show>
142
+ <hbr />
143
+ <Show when={worker.queue}>
144
+ {code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
180
145
  return withQueueContext({ batch, env, ctx }, async (context) => {
181
146
  return worker.queue(context.batch, context.env, context.ctx);
182
147
  });
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
- }));
148
+ }, `}
149
+ </Show>
150
+ <hbr />
151
+ {code` } satisfies ExportedHandler<CloudflareBindings>; `}
152
+ <Spacing />
153
+ <Show when={Boolean(children)}>{children}</Show>
154
+ </EntryFile>;
197
155
  }
198
156
 
199
157
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.mjs","names":["code","computed","Show","splitProps","Spacing","usePowerlines","EntryFile","murmurhash","relativePath","replaceExtension","defu","WorkerEntry","props","worker","children","imports","builtinImports","rest","context","entryPath","entry","input","file","_$createComponent","_$mergeProps","path","maxLength","name","type","value","cloudflare","_$createIntrinsic","when","fetch","tail","trace","tailStream","scheduled","test","email","queue","Boolean"],"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.entry.input?.file || worker.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.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":";;;;;;;;;;;;;;AAuCA,SAAgBW,YAAYC,OAAyB;CACnD,MAAM,CAAC,EAAEC,QAAQC,UAAUC,SAASC,kBAAkBC,QAAQd,WAC5DS,OACA;EAAC;EAAU;EAAY;EAAW;EACpC,CAAC;CAED,MAAMM,UAAUb,eAAwC;CACxD,MAAMc,YAAYlB,eAEd,KAAKQ,iBACHD,aACEU,QAAQC,WACRN,OAAOO,MAAMC,OAAOC,QAAQT,OAAOO,MAAME,KAE7C,CAAC,GACJ;AAED,QAAAC,gBACGjB,WAASkB,WAAA,EAAA,IACRC,OAAI;AAAA,SAAE,UAAUlB,WAAWM,OAAOO,OAAO,EACvCM,WAAW,GACZ,CAAC,CAAA;IAAW,EACTT,MAAI;EAAA,IACRF,UAAO;AAAA,UAAEL,KACP;IACE,6BAA6B;KAC3B;MAAEiB,MAAM;MAAWC,MAAM;MAAM;KAC/B;MAAED,MAAM;MAAYC,MAAM;MAAM;KAChC;MAAED,MAAM;MAAoBC,MAAM;MAAM;KACxC;MAAED,MAAM;MAA+BC,MAAM;MAAM;KACnD;MAAED,MAAM;MAAuBC,MAAM;MAAM;KAC3C;MAAED,MAAM;MAA2BC,MAAM;MAAM;KAC/C;MAAED,MAAM;MAAgBC,MAAM;MAAM;KACpC;MAAED,MAAM;MAAcC,MAAM;MAAM;KAClC;MAAED,MAAM;MAAaC,MAAM;MAAM;KACjC;MAAED,MAAM;MAAwBC,MAAM;MAAM;KAC5C;MAAED,MAAM;MAAoBC,MAAM;MAAM;KACxC;MAAED,MA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A;IAAA+B,gBAAA,OAAA,EAAA,CAAA;IAAAR,gBAGHrB,MAAI;KAAA,IAAC8B,OAAI;AAAA,aAAEnB,OAAO2B;;KAAK1B,UACrBd,IAAI;;;;;KAIH,CAAA;IAAA+B,gBAAA,OAAA,EAAA,CAAA;IAGH/B,IAAI;IAAoDuB,gBACxDnB,SAAO,EAAA,CAAA;IAAAmB,gBACPrB,MAAI;KAAA,IAAC8B,OAAI;AAAA,aAAES,QAAQ3B,SAAS;;KAAGA;KAAQ,CAAA;IAAA;;EAAA,CAAA,CAAA"}
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.entry.input?.file || worker.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.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={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;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,OAAO;SACvB,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,YAAY;SAC5B,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,WAAW;SAC3B,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,MAAM;SACtB,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,OAAO;SACvB,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;MACP,CAAC,KAAK,MAAM,OAAO,OAAO;SACvB,IAAI;;;;WAIF;MACL,EAAE,KAAK;MACP,CAAC,MAAM;OACN,IAAI,qDAAqD;MAC1D,CAAC,UAAU;MACX,CAAC,KAAK,MAAM,QAAQ,SAAS,GAAG,SAAS,EAAE,KAAK;IAClD,EAAE"}
package/dist/index.cjs CHANGED
@@ -4,7 +4,6 @@ const require_components_cloudflare_builtin = require('./components/cloudflare-b
4
4
  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
- let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
8
7
  let _alloy_js_core = require("@alloy-js/core");
9
8
  let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
10
9
  let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
@@ -32,12 +31,14 @@ function plugin(options = {}) {
32
31
  },
33
32
  async prepare() {
34
33
  const result = await (0, _powerlines_plugin_env_helpers.readEnvTypeReflection)(this, "env");
35
- 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 })]);
34
+ return (0, _powerlines_plugin_alloy_render.render)(this, <>
35
+ <require_components_cloudflare_builtin.CloudflareBuiltin />
36
+ <require_components_env_builtin.CloudflareEnvBuiltin reflection={result} />
37
+ </>);
36
38
  },
37
39
  build: {
38
40
  order: "pre",
39
41
  async handler() {
40
- const _self$ = this;
41
42
  this.workers = await Promise.all(this.entry.map(async (entry) => {
42
43
  if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.name}" is missing an input file.`);
43
44
  const workerModule = await (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(this, entry.input);
@@ -54,12 +55,9 @@ function plugin(options = {}) {
54
55
  queue: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.queue)
55
56
  };
56
57
  }));
57
- return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
58
- get each() {
59
- return _self$.workers;
60
- },
61
- children: (worker) => (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_worker_entry.WorkerEntry, { worker })
62
- }));
58
+ return (0, _powerlines_plugin_alloy_render.render)(this, <_alloy_js_core.For each={this.workers}>
59
+ {(worker) => <require_components_worker_entry.WorkerEntry worker={worker} />}
60
+ </_alloy_js_core.For>);
63
61
  }
64
62
  },
65
63
  async deployPulumi() {
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ import { CloudflareBuiltin } from "./components/cloudflare-builtin.mjs";
2
2
  import { CloudflareEnvBuiltin } from "./components/env-builtin.mjs";
3
3
  import { WorkerEntry } from "./components/worker-entry.mjs";
4
4
  import "./components/index.mjs";
5
- import { createComponent } from "@alloy-js/core/jsx-runtime";
6
5
  import { For } from "@alloy-js/core";
7
6
  import { render } from "@powerlines/plugin-alloy/render";
8
7
  import { readEnvTypeReflection } from "@powerlines/plugin-env/helpers";
@@ -28,12 +27,14 @@ function plugin(options = {}) {
28
27
  },
29
28
  async prepare() {
30
29
  const result = await readEnvTypeReflection(this, "env");
31
- return render(this, [createComponent(CloudflareBuiltin, {}), createComponent(CloudflareEnvBuiltin, { reflection: result })]);
30
+ return render(this, <>
31
+ <CloudflareBuiltin />
32
+ <CloudflareEnvBuiltin reflection={result} />
33
+ </>);
32
34
  },
33
35
  build: {
34
36
  order: "pre",
35
37
  async handler() {
36
- const _self$ = this;
37
38
  this.workers = await Promise.all(this.entry.map(async (entry) => {
38
39
  if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.name}" is missing an input file.`);
39
40
  const workerModule = await resolveModule(this, entry.input);
@@ -50,12 +51,9 @@ function plugin(options = {}) {
50
51
  queue: isFunction(workerModule.default.queue)
51
52
  };
52
53
  }));
53
- return render(this, createComponent(For, {
54
- get each() {
55
- return _self$.workers;
56
- },
57
- children: (worker) => createComponent(WorkerEntry, { worker })
58
- }));
54
+ return render(this, <For each={this.workers}>
55
+ {(worker) => <WorkerEntry worker={worker} />}
56
+ </For>);
59
57
  }
60
58
  },
61
59
  async deployPulumi() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["For","render","readEnvTypeReflection","resolveModule","pulumiCloudflare","joinPaths","kebabCase","isFunction","defu","CloudflareEnvBuiltin","CloudflareBuiltin","WorkerEntry","plugin","options","name","config","cloudflare","configResolved","devDependencies","prepare","result","_$createComponent","reflection","build","order","handler","_self$","workers","Promise","all","entry","map","input","Error","workerModule","default","fetch","tail","trace","tailStream","scheduled","test","email","queue","each","children","worker","deployPulumi","apiToken","process","env","CLOUDFLARE_API_TOKEN","warn","pulumi","setConfig","value","WorkersScript","accountId","scriptName","contentFile","output","outputPath"],"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 { ExportedHandler } from \"@cloudflare/workers-types\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { joinPaths } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions\n} from \"./types/plugin\";\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 = {}) {\n return [\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(options, {})\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\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.workers = await Promise.all(\n this.entry.map(async entry => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.name}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<{\n default: ExportedHandler;\n }>(this, entry.input);\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.name\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 return {\n entry,\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 );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\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 worker = new pulumiCloudflare.WorkersScript(\n `${kebabCase(this.config.name)}-worker`,\n {\n accountId: this.config.cloudflare.accountId,\n scriptName:\n this.config.cloudflare.scriptName || kebabCase(this.config.name),\n contentFile: joinPaths(this.config.output.outputPath, \"index.js\")\n }\n );\n\n return {\n worker\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiDA,SAAgBY,OAEdC,UAAmC,EAAE,EAAE;AACvC,QAAO,CACL;EACEC,MAAM;EACNC,SAAS;AACP,UAAO,EACLC,Y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AWC,QAAQC,IAAIC;AAC3B,OAAI,CAACH,UAAU;AACbA,eAAW,KAAKjC,OAAOC,WAAWgC;AAClC,QAAIA,SACF,MAAKI,KACH,oNACD;QAED,OAAM,IAAInB,MACR,4GACD;;AAIL,SAAM,KAAKoB,OAAOC,UAAU,uBAAuB,EACjDC,OAAOP,UACR,CAAC;AAYF,UAAO,EACLF,QAXa,IAAI1C,iBAAiBoD,cAClC,GAAGlD,UAAU,KAAKS,OAAOD,KAAK,CAAA,UAC9B;IACE2C,WAAW,KAAK1C,OAAOC,WAAWyC;IAClCC,YACE,KAAK3C,OAAOC,WAAW0C,cAAcpD,UAAU,KAAKS,OAAOD,KAAK;IAClE6C,aAAatD,UAAU,KAAKU,OAAO6C,OAAOC,YAAY,WAAU;IAEpE,CAAC,EAIA;;EAEJ,CACF"}
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 { ExportedHandler } from \"@cloudflare/workers-types\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { joinPaths } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions\n} from \"./types/plugin\";\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 = {}) {\n return [\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(options, {})\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\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.workers = await Promise.all(\n this.entry.map(async entry => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.name}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<{\n default: ExportedHandler;\n }>(this, entry.input);\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.name\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 return {\n entry,\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 );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\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 worker = new pulumiCloudflare.WorkersScript(\n `${kebabCase(this.config.name)}-worker`,\n {\n accountId: this.config.cloudflare.accountId,\n scriptName:\n this.config.cloudflare.scriptName || kebabCase(this.config.name),\n contentFile: joinPaths(this.config.output.outputPath, \"index.js\")\n }\n );\n\n return {\n worker\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiDA,SAAgB,OAEd,UAAmC,EAAE,EAAE;AACvC,QAAO,CACL;EACE,MAAM;EACN,SAAS;AACP,UAAO,EACL,YAAY,KAAK,SAAS,EAAE,CAAC,EAC9B;;EAEH,iBAAiB;AACf,QAAK,gBAAgB,+BAA+B;;EAEtD,MAAM,UAAU;GACd,MAAM,SAAS,MAAM,sBAAsB,MAAM,MAAM;AAEvD,UAAO,OACL,MACA,EAAE;YACA,CAAC,oBAAoB;YACrB,CAAC,qBAAqB,YAAY,UAAU;UAC9C,IACD;;EAEH,OAAO;GACL,OAAO;GACP,MAAM,UAAU;AACd,SAAK,UAAU,MAAM,QAAQ,IAC3B,KAAK,MAAM,IAAI,OAAM,UAAS;AAC5B,SAAI,CAAC,MAAM,MACT,OAAM,IAAI,MACR,4BAA4B,MAAM,KAAK,6BACxC;KAGH,MAAM,eAAe,MAAM,cAExB,MAAM,MAAM,MAAM;AACrB,SAAI,CAAC,cAAc,QACjB,OAAM,IAAI,MACR,4BACE,MAAM,KACP,gNACF;AAGH,YAAO;MACL;MACA,OAAO,WAAW,aAAa,QAAQ,MAAM;MAC7C,MAAM,WAAW,aAAa,QAAQ,KAAK;MAC3C,OAAO,WAAW,aAAa,QAAQ,MAAM;MAC7C,YAAY,WAAW,aAAa,QAAQ,WAAW;MACvD,WAAW,WAAW,aAAa,QAAQ,UAAU;MACrD,MAAM,WAAW,aAAa,QAAQ,KAAK;MAC3C,OAAO,WAAW,aAAa,QAAQ,MAAM;MAC7C,OAAO,WAAW,aAAa,QAAQ,MAAM;MAC9C;MACD,CACH;AAED,WAAO,OACL,MACA,CAAC,IAAI,MAAM,KAAK,SAAS;gBACtB,WAAU,CAAC,YAAY,QAAQ,WAAW;YAC7C,EAAE,KACH;;GAEJ;EACD,MAAM,eAAe;GACnB,IAAI,WAAW,QAAQ,IAAI;AAC3B,OAAI,CAAC,UAAU;AACb,eAAW,KAAK,OAAO,WAAW;AAClC,QAAI,SACF,MAAK,KACH,oNACD;QAED,OAAM,IAAI,MACR,4GACD;;AAIL,SAAM,KAAK,OAAO,UAAU,uBAAuB,EACjD,OAAO,UACR,CAAC;AAYF,UAAO,EACL,QAXa,IAAI,iBAAiB,cAClC,GAAG,UAAU,KAAK,OAAO,KAAK,CAAC,UAC/B;IACE,WAAW,KAAK,OAAO,WAAW;IAClC,YACE,KAAK,OAAO,WAAW,cAAc,UAAU,KAAK,OAAO,KAAK;IAClE,aAAa,UAAU,KAAK,OAAO,OAAO,YAAY,WAAW;IAClE,CACF,EAIA;;EAEJ,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-cloudflare",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "private": false,
5
5
  "description": "A Powerlines plugin that provides integration with Cloudflare services.",
6
6
  "keywords": ["powerlines", "storm-software", "powerlines-plugin"],
@@ -148,8 +148,8 @@
148
148
  "@alloy-js/core": "0.23.0-dev.8",
149
149
  "@alloy-js/typescript": "0.23.0-dev.4",
150
150
  "@cloudflare/workers-types": "^4.20260312.1",
151
- "@powerlines/plugin-env": "^0.16.61",
152
- "@powerlines/plugin-pulumi": "^0.5.23",
151
+ "@powerlines/plugin-env": "^0.16.63",
152
+ "@powerlines/plugin-pulumi": "^0.5.25",
153
153
  "@pulumi/cloudflare": "^6.13.0",
154
154
  "@pulumi/pulumi": "^3.225.1",
155
155
  "@storm-software/config-tools": "1.189.28",
@@ -158,14 +158,14 @@
158
158
  "@stryke/string-format": "^0.17.3",
159
159
  "@stryke/type-checks": "^0.5.38",
160
160
  "defu": "^6.1.4",
161
- "powerlines": "^0.41.7"
161
+ "powerlines": "^0.41.9"
162
162
  },
163
163
  "devDependencies": {
164
164
  "@cloudflare/workers-types": "^4.20260312.1",
165
- "@powerlines/plugin-alloy": "^0.25.26",
166
- "@powerlines/plugin-plugin": "^0.12.293",
167
- "@types/node": "^25.4.0"
165
+ "@powerlines/plugin-alloy": "^0.25.28",
166
+ "@powerlines/plugin-plugin": "^0.12.295",
167
+ "@types/node": "^25.5.0"
168
168
  },
169
169
  "publishConfig": { "access": "public" },
170
- "gitHead": "2fb48143904805988bac9bdbc04cdc4a35ff398b"
170
+ "gitHead": "74a26c533ea4d67ba1b3e297256309c2e23f6e62"
171
171
  }
@@ -1,3 +0,0 @@
1
- import "node:module";
2
-
3
- export { };