alchemy 0.63.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/bin/alchemy.js +97 -87
  2. package/bin/commands/init.ts +1 -1
  3. package/bin/services/github-workflow.ts +2 -2
  4. package/lib/alchemy.d.ts +4 -0
  5. package/lib/alchemy.d.ts.map +1 -1
  6. package/lib/alchemy.js +10 -4
  7. package/lib/alchemy.js.map +1 -1
  8. package/lib/apply.d.ts +3 -0
  9. package/lib/apply.d.ts.map +1 -1
  10. package/lib/apply.js +11 -1
  11. package/lib/apply.js.map +1 -1
  12. package/lib/cloudflare/bindings.d.ts +3 -1
  13. package/lib/cloudflare/bindings.d.ts.map +1 -1
  14. package/lib/cloudflare/bucket.d.ts +2 -1
  15. package/lib/cloudflare/bucket.d.ts.map +1 -1
  16. package/lib/cloudflare/bucket.js.map +1 -1
  17. package/lib/cloudflare/bundle/cloudflare-internal.d.ts +6 -0
  18. package/lib/cloudflare/bundle/cloudflare-internal.d.ts.map +1 -0
  19. package/lib/cloudflare/bundle/cloudflare-internal.js +39 -0
  20. package/lib/cloudflare/bundle/cloudflare-internal.js.map +1 -0
  21. package/lib/cloudflare/bundle/nodejs-builtin-modules.d.ts +2 -0
  22. package/lib/cloudflare/bundle/nodejs-builtin-modules.d.ts.map +1 -0
  23. package/lib/cloudflare/bundle/nodejs-builtin-modules.js +9 -0
  24. package/lib/cloudflare/bundle/nodejs-builtin-modules.js.map +1 -0
  25. package/lib/cloudflare/bundle/plugin-als-external.d.ts +6 -0
  26. package/lib/cloudflare/bundle/plugin-als-external.d.ts.map +1 -0
  27. package/lib/cloudflare/bundle/plugin-als-external.js +12 -0
  28. package/lib/cloudflare/bundle/plugin-als-external.js.map +1 -0
  29. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.d.ts +4 -1
  30. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.d.ts.map +1 -1
  31. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.js +23 -23
  32. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.js.map +1 -1
  33. package/lib/cloudflare/bundle/plugin-node-compat.d.ts +11 -0
  34. package/lib/cloudflare/bundle/plugin-node-compat.d.ts.map +1 -0
  35. package/lib/cloudflare/bundle/plugin-node-compat.js +93 -0
  36. package/lib/cloudflare/bundle/plugin-node-compat.js.map +1 -0
  37. package/lib/cloudflare/cloudflare-env-proxy.js +1 -1
  38. package/lib/cloudflare/cloudflare-env-proxy.js.map +1 -1
  39. package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
  40. package/lib/cloudflare/compatibility-date.gen.js +1 -1
  41. package/lib/cloudflare/d1-local-migrations.js.map +1 -1
  42. package/lib/cloudflare/durable-object-namespace.d.ts +1 -0
  43. package/lib/cloudflare/durable-object-namespace.d.ts.map +1 -1
  44. package/lib/cloudflare/hyperdrive.js +1 -1
  45. package/lib/cloudflare/hyperdrive.js.map +1 -1
  46. package/lib/cloudflare/website.d.ts.map +1 -1
  47. package/lib/cloudflare/website.js +80 -82
  48. package/lib/cloudflare/website.js.map +1 -1
  49. package/lib/cloudflare/worker-bundle.d.ts +6 -0
  50. package/lib/cloudflare/worker-bundle.d.ts.map +1 -1
  51. package/lib/cloudflare/worker-bundle.js +34 -10
  52. package/lib/cloudflare/worker-bundle.js.map +1 -1
  53. package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
  54. package/lib/cloudflare/worker-metadata.js +2 -1
  55. package/lib/cloudflare/worker-metadata.js.map +1 -1
  56. package/lib/cloudflare/worker.d.ts.map +1 -1
  57. package/lib/cloudflare/worker.js +24 -6
  58. package/lib/cloudflare/worker.js.map +1 -1
  59. package/lib/cloudflare/wrangler.json.d.ts +2 -4
  60. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  61. package/lib/cloudflare/wrangler.json.js +16 -14
  62. package/lib/cloudflare/wrangler.json.js.map +1 -1
  63. package/lib/context.d.ts +3 -1
  64. package/lib/context.d.ts.map +1 -1
  65. package/lib/context.js +2 -2
  66. package/lib/context.js.map +1 -1
  67. package/lib/destroy.d.ts +8 -0
  68. package/lib/destroy.d.ts.map +1 -1
  69. package/lib/destroy.js +20 -4
  70. package/lib/destroy.js.map +1 -1
  71. package/lib/neon/project.d.ts.map +1 -1
  72. package/lib/neon/project.js +4 -5
  73. package/lib/neon/project.js.map +1 -1
  74. package/lib/planetscale/api/client.gen.d.ts +1750 -0
  75. package/lib/planetscale/api/client.gen.d.ts.map +1 -0
  76. package/lib/planetscale/api/client.gen.js +2401 -0
  77. package/lib/planetscale/api/client.gen.js.map +1 -0
  78. package/lib/planetscale/api/index.d.ts +3 -0
  79. package/lib/planetscale/api/index.d.ts.map +1 -0
  80. package/lib/planetscale/api/index.js +4 -0
  81. package/lib/planetscale/api/index.js.map +1 -0
  82. package/lib/planetscale/api/types.gen.d.ts +12156 -0
  83. package/lib/planetscale/api/types.gen.d.ts.map +1 -0
  84. package/lib/planetscale/api/types.gen.js +2 -0
  85. package/lib/planetscale/api/types.gen.js.map +1 -0
  86. package/lib/planetscale/branch.d.ts +5 -8
  87. package/lib/planetscale/branch.d.ts.map +1 -1
  88. package/lib/planetscale/branch.js +111 -97
  89. package/lib/planetscale/branch.js.map +1 -1
  90. package/lib/planetscale/database.d.ts +2 -6
  91. package/lib/planetscale/database.d.ts.map +1 -1
  92. package/lib/planetscale/database.js +157 -118
  93. package/lib/planetscale/database.js.map +1 -1
  94. package/lib/planetscale/index.d.ts +1 -1
  95. package/lib/planetscale/index.d.ts.map +1 -1
  96. package/lib/planetscale/index.js +1 -1
  97. package/lib/planetscale/index.js.map +1 -1
  98. package/lib/planetscale/password.d.ts +4 -7
  99. package/lib/planetscale/password.d.ts.map +1 -1
  100. package/lib/planetscale/password.js +71 -56
  101. package/lib/planetscale/password.js.map +1 -1
  102. package/lib/planetscale/utils.d.ts +8 -6
  103. package/lib/planetscale/utils.d.ts.map +1 -1
  104. package/lib/planetscale/utils.js +85 -70
  105. package/lib/planetscale/utils.js.map +1 -1
  106. package/lib/scope.d.ts +5 -1
  107. package/lib/scope.d.ts.map +1 -1
  108. package/lib/scope.js +11 -3
  109. package/lib/scope.js.map +1 -1
  110. package/lib/upstash/redis.js +1 -1
  111. package/lib/upstash/redis.js.map +1 -1
  112. package/lib/util/dedent.d.ts +3 -14
  113. package/lib/util/dedent.d.ts.map +1 -1
  114. package/lib/util/dedent.js +28 -52
  115. package/lib/util/dedent.js.map +1 -1
  116. package/lib/util/idempotent-spawn.d.ts.map +1 -1
  117. package/lib/util/idempotent-spawn.js +21 -2
  118. package/lib/util/idempotent-spawn.js.map +1 -1
  119. package/lib/util/xml.js +1 -1
  120. package/lib/util/xml.js.map +1 -1
  121. package/package.json +4 -3
  122. package/src/alchemy.ts +14 -6
  123. package/src/apply.ts +13 -1
  124. package/src/cloudflare/bindings.ts +3 -1
  125. package/src/cloudflare/bucket.ts +3 -1
  126. package/src/cloudflare/bundle/cloudflare-internal.ts +42 -0
  127. package/src/cloudflare/bundle/nodejs-builtin-modules.ts +14 -0
  128. package/src/cloudflare/bundle/plugin-als-external.ts +13 -0
  129. package/src/cloudflare/bundle/plugin-hybrid-node-compat.ts +29 -28
  130. package/src/cloudflare/bundle/plugin-node-compat.ts +114 -0
  131. package/src/cloudflare/cloudflare-env-proxy.ts +1 -1
  132. package/src/cloudflare/compatibility-date.gen.ts +1 -1
  133. package/src/cloudflare/d1-local-migrations.ts +2 -2
  134. package/src/cloudflare/durable-object-namespace.ts +1 -1
  135. package/src/cloudflare/hyperdrive.ts +1 -1
  136. package/src/cloudflare/website.ts +88 -89
  137. package/src/cloudflare/worker-bundle.ts +46 -9
  138. package/src/cloudflare/worker-metadata.ts +3 -1
  139. package/src/cloudflare/worker.ts +35 -7
  140. package/src/cloudflare/wrangler.json.ts +108 -110
  141. package/src/context.ts +5 -3
  142. package/src/destroy.ts +26 -8
  143. package/src/neon/project.ts +4 -5
  144. package/src/planetscale/api/client.gen.ts +2882 -0
  145. package/src/planetscale/api/index.ts +4 -0
  146. package/src/planetscale/api/types.gen.ts +13041 -0
  147. package/src/planetscale/branch.ts +152 -169
  148. package/src/planetscale/database.ts +195 -204
  149. package/src/planetscale/index.ts +1 -1
  150. package/src/planetscale/password.ts +86 -85
  151. package/src/planetscale/utils.ts +141 -122
  152. package/src/scope.ts +12 -3
  153. package/src/upstash/redis.ts +1 -1
  154. package/src/util/dedent.ts +33 -61
  155. package/src/util/idempotent-spawn.ts +23 -2
  156. package/src/util/xml.ts +1 -1
  157. package/templates/astro/alchemy.run.ts +1 -3
  158. package/templates/hono/alchemy.run.ts +0 -1
  159. package/templates/nuxt/alchemy.run.ts +1 -3
  160. package/templates/react-router/alchemy.run.ts +1 -3
  161. package/templates/rwsdk/alchemy.run.ts +0 -2
  162. package/templates/sveltekit/alchemy.run.ts +1 -3
  163. package/templates/tanstack-start/alchemy.run.ts +1 -3
  164. package/templates/typescript/alchemy.run.ts +0 -1
  165. package/templates/vite/alchemy.run.ts +0 -1
  166. package/workers/cloudflare-state-store.js +58 -58
  167. package/lib/cloudflare/bundle/externals.d.ts +0 -3
  168. package/lib/cloudflare/bundle/externals.d.ts.map +0 -1
  169. package/lib/cloudflare/bundle/externals.js +0 -35
  170. package/lib/cloudflare/bundle/externals.js.map +0 -1
  171. package/lib/cloudflare/bundle/plugin-compat-warning.d.ts +0 -10
  172. package/lib/cloudflare/bundle/plugin-compat-warning.d.ts.map +0 -1
  173. package/lib/cloudflare/bundle/plugin-compat-warning.js +0 -67
  174. package/lib/cloudflare/bundle/plugin-compat-warning.js.map +0 -1
  175. package/lib/planetscale/api.d.ts +0 -53
  176. package/lib/planetscale/api.d.ts.map +0 -1
  177. package/lib/planetscale/api.js +0 -84
  178. package/lib/planetscale/api.js.map +0 -1
  179. package/src/cloudflare/bundle/externals.ts +0 -36
  180. package/src/cloudflare/bundle/plugin-compat-warning.ts +0 -94
  181. package/src/planetscale/api.ts +0 -115
@@ -1,53 +0,0 @@
1
- /**
2
- * Options for PlanetScale API requests
3
- */
4
- export interface PlanetScaleApiOptions {
5
- /**
6
- * PlanetScale API token (overrides environment variable)
7
- */
8
- apiKey?: string;
9
- }
10
- /**
11
- * Minimal API client for PlanetScale using raw fetch
12
- */
13
- export declare class PlanetScaleApi {
14
- /** Base URL for API */
15
- readonly baseUrl: string;
16
- /** API token */
17
- readonly apiToken: string;
18
- /**
19
- * Create a new API client
20
- *
21
- * @param options API options
22
- */
23
- constructor(options?: PlanetScaleApiOptions);
24
- /**
25
- * Make a request to the API
26
- *
27
- * @param path API path (without base URL)
28
- * @param init Fetch init options
29
- * @returns Raw Response object from fetch
30
- */
31
- private fetch;
32
- /**
33
- * Helper for GET requests
34
- */
35
- get(path: string, init?: RequestInit): Promise<Response>;
36
- /**
37
- * Helper for POST requests
38
- */
39
- post(path: string, body?: any, init?: RequestInit): Promise<Response>;
40
- /**
41
- * Helper for PUT requests
42
- */
43
- put(path: string, body?: any, init?: RequestInit): Promise<Response>;
44
- /**
45
- * Helper for PATCH requests
46
- */
47
- patch(path: string, body?: any, init?: RequestInit): Promise<Response>;
48
- /**
49
- * Helper for DELETE requests
50
- */
51
- delete(path: string, init?: RequestInit): Promise<Response>;
52
- }
53
- //# sourceMappingURL=api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/planetscale/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,uBAAuB;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,gBAAgB;IAChB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;gBACS,OAAO,GAAE,qBAA0B;IAQ/C;;;;;;OAMG;YACW,KAAK;IAgBnB;;OAEG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlE;;OAEG;IACG,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,QAAQ,CAAC;IAQpB;;OAEG;IACG,GAAG,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,QAAQ,CAAC;IAQpB;;OAEG;IACG,KAAK,CACT,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,EACV,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,QAAQ,CAAC;IAQpB;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGtE"}
@@ -1,84 +0,0 @@
1
- /**
2
- * Minimal API client for PlanetScale using raw fetch
3
- */
4
- export class PlanetScaleApi {
5
- /** Base URL for API */
6
- baseUrl;
7
- /** API token */
8
- apiToken;
9
- /**
10
- * Create a new API client
11
- *
12
- * @param options API options
13
- */
14
- constructor(options = {}) {
15
- this.baseUrl = "https://api.planetscale.com/v1";
16
- this.apiToken = options.apiKey || process.env.PLANETSCALE_API_TOKEN || "";
17
- if (!this.apiToken) {
18
- throw new Error("PLANETSCALE_API_TOKEN environment variable is required");
19
- }
20
- }
21
- /**
22
- * Make a request to the API
23
- *
24
- * @param path API path (without base URL)
25
- * @param init Fetch init options
26
- * @returns Raw Response object from fetch
27
- */
28
- async fetch(path, init = {}) {
29
- const headers = {
30
- Authorization: `${this.apiToken}`,
31
- "Content-Type": "application/json",
32
- };
33
- if (init.headers) {
34
- Object.assign(headers, init.headers);
35
- }
36
- return fetch(`${this.baseUrl}${path}`, {
37
- ...init,
38
- headers,
39
- });
40
- }
41
- /**
42
- * Helper for GET requests
43
- */
44
- async get(path, init = {}) {
45
- return this.fetch(path, { ...init, method: "GET" });
46
- }
47
- /**
48
- * Helper for POST requests
49
- */
50
- async post(path, body, init = {}) {
51
- return this.fetch(path, {
52
- ...init,
53
- method: "POST",
54
- body: body ? JSON.stringify(body) : undefined,
55
- });
56
- }
57
- /**
58
- * Helper for PUT requests
59
- */
60
- async put(path, body, init = {}) {
61
- return this.fetch(path, {
62
- ...init,
63
- method: "PUT",
64
- body: body ? JSON.stringify(body) : undefined,
65
- });
66
- }
67
- /**
68
- * Helper for PATCH requests
69
- */
70
- async patch(path, body, init = {}) {
71
- return this.fetch(path, {
72
- ...init,
73
- method: "PATCH",
74
- body: body ? JSON.stringify(body) : undefined,
75
- });
76
- }
77
- /**
78
- * Helper for DELETE requests
79
- */
80
- async delete(path, init = {}) {
81
- return this.fetch(path, { ...init, method: "DELETE" });
82
- }
83
- }
84
- //# sourceMappingURL=api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/planetscale/api.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,OAAO,cAAc;IACzB,uBAAuB;IACd,OAAO,CAAS;IAEzB,gBAAgB;IACP,QAAQ,CAAS;IAE1B;;;;OAIG;IACH,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,gCAAgC,CAAC;QAChD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC;QAC1E,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,KAAK,CAAC,IAAY,EAAE,OAAoB,EAAE;QACtD,MAAM,OAAO,GAA2B;YACtC,aAAa,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;YACjC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QAEF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;YACrC,GAAG,IAAI;YACP,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,OAAoB,EAAE;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CACR,IAAY,EACZ,IAAU,EACV,OAAoB,EAAE;QAEtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,GAAG,IAAI;YACP,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CACP,IAAY,EACZ,IAAU,EACV,OAAoB,EAAE;QAEtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,GAAG,IAAI;YACP,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CACT,IAAY,EACZ,IAAU,EACV,OAAoB,EAAE;QAEtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;YACtB,GAAG,IAAI;YACP,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAAoB,EAAE;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzD,CAAC;CACF"}
@@ -1,36 +0,0 @@
1
- // https://developers.cloudflare.com/workers/runtime-apis/nodejs/#supported-nodejs-apis
2
- const nodejs_compat = [
3
- "node:async_hooks",
4
- "node:assert",
5
- "node:buffer",
6
- "node:console",
7
- "node:crypto",
8
- "node:debug",
9
- "node:diagnostics_channel",
10
- "node:dns",
11
- "node:events",
12
- "node:inspector",
13
- "node:net",
14
- "node:path",
15
- "node:perf_hooks", // partially supported
16
- "node:process",
17
- "node:querystring",
18
- "node:stream",
19
- "node:string_decoder",
20
- "node:timers",
21
- "node:tls", // partially supported
22
- "node:url",
23
- "node:util",
24
- "node:zlib",
25
- // "node:*",
26
- ];
27
-
28
- export const external = [
29
- ...nodejs_compat,
30
- ...nodejs_compat.map((p) => p.split(":")[1]),
31
- "cloudflare:workers",
32
- "cloudflare:workflows",
33
- "cloudflare:*",
34
- ];
35
-
36
- export const external_als = ["node:async_hooks", "async_hooks", "cloudflare:*"];
@@ -1,94 +0,0 @@
1
- import type { Plugin, PluginBuild } from "esbuild";
2
- import module from "node:module";
3
- import path from "node:path";
4
- import pc from "picocolors";
5
- import { logger } from "../../util/logger.ts";
6
-
7
- const NODE_REGEX = new RegExp(
8
- `^(node:)?(${module.builtinModules.filter((m) => m !== "async_hooks").join("|")})$`,
9
- );
10
-
11
- /**
12
- * ESBuild plugin to detect node:* imports and warn about missing compatibility flags.
13
- *
14
- * This plugin warns when:
15
- * - Any node:* import is found without nodejs_compat flag
16
- * - node:async_hooks is imported without nodejs_compat or nodejs_als flags
17
- */
18
- export function esbuildPluginCompatWarning(mode: "als" | null): Plugin {
19
- return {
20
- name: "nodejs-import-warning",
21
- setup(build: PluginBuild) {
22
- const packages = new Set<string>();
23
- const nodeImporters = new Set<string>();
24
- const alsImporters = new Set<string>();
25
-
26
- build.onStart(() => {
27
- packages.clear();
28
- nodeImporters.clear();
29
- alsImporters.clear();
30
- });
31
-
32
- build.onResolve(
33
- {
34
- filter: NODE_REGEX,
35
- },
36
- (args) => {
37
- packages.add(args.path);
38
- nodeImporters.add(args.importer);
39
- return null;
40
- },
41
- );
42
-
43
- build.onResolve(
44
- {
45
- filter: /^(node:)?async_hooks$/,
46
- },
47
- (args) => {
48
- alsImporters.add(args.importer);
49
- return null;
50
- },
51
- );
52
-
53
- build.onEnd(() => {
54
- if (packages.size > 0) {
55
- const formattedImports = Array.from(packages)
56
- .sort()
57
- .map((imp) => pc.yellow(imp))
58
- .join(", ");
59
-
60
- logger.warn(
61
- [
62
- `Detected Node.js imports (${formattedImports}) but ${pc.red("nodejs_compat")} compatibility flag is not set. `,
63
- `Add ${pc.blue("nodejs_compat")} to your compatibility flags and ensure compatibilityDate >= 2024-09-23. Imported from:`,
64
- formatImporters(
65
- nodeImporters,
66
- build.initialOptions.absWorkingDir ?? process.cwd(),
67
- ),
68
- ].join("\n"),
69
- );
70
- }
71
-
72
- if (alsImporters.size > 0 && !mode) {
73
- logger.warn(
74
- [
75
- `Detected import of ${pc.yellow("node:async_hooks")} but ${pc.red("nodejs_als")} compatibility flag is not set. `,
76
- `Add ${pc.blue("nodejs_als")} or ${pc.blue("nodejs_compat")} to your compatibility flags. Imported from:`,
77
- formatImporters(
78
- alsImporters,
79
- build.initialOptions.absWorkingDir ?? process.cwd(),
80
- ),
81
- ].join("\n"),
82
- );
83
- }
84
- });
85
- },
86
- };
87
- }
88
-
89
- function formatImporters(importers: Set<string>, cwd: string) {
90
- return Array.from(importers)
91
- .sort()
92
- .map((imp) => `- ${pc.yellow(path.relative(cwd, imp))}`)
93
- .join("\n");
94
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * Options for PlanetScale API requests
3
- */
4
- export interface PlanetScaleApiOptions {
5
- /**
6
- * PlanetScale API token (overrides environment variable)
7
- */
8
- apiKey?: string;
9
- }
10
-
11
- /**
12
- * Minimal API client for PlanetScale using raw fetch
13
- */
14
- export class PlanetScaleApi {
15
- /** Base URL for API */
16
- readonly baseUrl: string;
17
-
18
- /** API token */
19
- readonly apiToken: string;
20
-
21
- /**
22
- * Create a new API client
23
- *
24
- * @param options API options
25
- */
26
- constructor(options: PlanetScaleApiOptions = {}) {
27
- this.baseUrl = "https://api.planetscale.com/v1";
28
- this.apiToken = options.apiKey || process.env.PLANETSCALE_API_TOKEN || "";
29
- if (!this.apiToken) {
30
- throw new Error("PLANETSCALE_API_TOKEN environment variable is required");
31
- }
32
- }
33
-
34
- /**
35
- * Make a request to the API
36
- *
37
- * @param path API path (without base URL)
38
- * @param init Fetch init options
39
- * @returns Raw Response object from fetch
40
- */
41
- private async fetch(path: string, init: RequestInit = {}): Promise<Response> {
42
- const headers: Record<string, string> = {
43
- Authorization: `${this.apiToken}`,
44
- "Content-Type": "application/json",
45
- };
46
-
47
- if (init.headers) {
48
- Object.assign(headers, init.headers);
49
- }
50
-
51
- return fetch(`${this.baseUrl}${path}`, {
52
- ...init,
53
- headers,
54
- });
55
- }
56
-
57
- /**
58
- * Helper for GET requests
59
- */
60
- async get(path: string, init: RequestInit = {}): Promise<Response> {
61
- return this.fetch(path, { ...init, method: "GET" });
62
- }
63
-
64
- /**
65
- * Helper for POST requests
66
- */
67
- async post(
68
- path: string,
69
- body?: any,
70
- init: RequestInit = {},
71
- ): Promise<Response> {
72
- return this.fetch(path, {
73
- ...init,
74
- method: "POST",
75
- body: body ? JSON.stringify(body) : undefined,
76
- });
77
- }
78
-
79
- /**
80
- * Helper for PUT requests
81
- */
82
- async put(
83
- path: string,
84
- body?: any,
85
- init: RequestInit = {},
86
- ): Promise<Response> {
87
- return this.fetch(path, {
88
- ...init,
89
- method: "PUT",
90
- body: body ? JSON.stringify(body) : undefined,
91
- });
92
- }
93
-
94
- /**
95
- * Helper for PATCH requests
96
- */
97
- async patch(
98
- path: string,
99
- body?: any,
100
- init: RequestInit = {},
101
- ): Promise<Response> {
102
- return this.fetch(path, {
103
- ...init,
104
- method: "PATCH",
105
- body: body ? JSON.stringify(body) : undefined,
106
- });
107
- }
108
-
109
- /**
110
- * Helper for DELETE requests
111
- */
112
- async delete(path: string, init: RequestInit = {}): Promise<Response> {
113
- return this.fetch(path, { ...init, method: "DELETE" });
114
- }
115
- }