Skip to content

Commit f8aa40b

Browse files
committed
add warning about platform
1 parent 1c517b6 commit f8aa40b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.changeset/eighty-trees-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"esbuild-cf-functions-plugin": minor
3+
---
4+
5+
Added warning about configuring `platform`

src/plugin.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatMessages } from "esbuild"
12
import type { Plugin } from "esbuild"
23

34
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-javascript-runtime-features.html
@@ -18,7 +19,7 @@ const config = {
1819
export const CloudFrontFunctionsPlugin = (): Plugin => ({
1920
name: "cloudfront",
2021

21-
setup: (build) => {
22+
setup: async (build) => {
2223
build.initialOptions.target = "es5"
2324
build.initialOptions.format = "esm"
2425

@@ -33,5 +34,21 @@ export const CloudFrontFunctionsPlugin = (): Plugin => ({
3334
...config,
3435
...build.initialOptions.supported,
3536
}
37+
38+
if (build.initialOptions.platform != null) {
39+
;(
40+
await formatMessages(
41+
[
42+
{
43+
text: `'platform' has been set: '${build.initialOptions.platform}'\n CloudFront Functions run on a platform that is neither 'node' or 'browser', so configuring your code to build for them is pointless.`,
44+
},
45+
],
46+
{
47+
color: true,
48+
kind: "warning",
49+
},
50+
)
51+
).forEach((msg) => console.log(msg))
52+
}
3653
},
3754
})

0 commit comments

Comments
 (0)