summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-11 13:43:46 -0400
committerGitHub <noreply@github.com>2024-07-11 17:43:46 +0000
commitba63740e7f390a5778baf01ba156f0b02c55a089 (patch)
treede095412d474c63ba2c300bbb027e48195e3b51a
parent4f15aada02450824a0a6e2602dde2fffdd9fd90a (diff)
chore: `@netlify/edge-bundler` workaround until Deno 2.0 (#24532)
Hack for a few months until Deno 2.0. See code for details
-rw-r--r--cli/args/flags.rs48
-rw-r--r--tests/specs/run/netlify_edge_bundler_hack/__test__.jsonc9
-rw-r--r--tests/specs/run/netlify_edge_bundler_hack/main.out1
-rw-r--r--tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/deno/config.ts1
-rw-r--r--tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/package.json5
-rw-r--r--tests/specs/run/netlify_edge_bundler_hack/package.json4
6 files changed, 68 insertions, 0 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 48cfb9240..3298d6f83 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -4246,6 +4246,53 @@ fn run_parse(
matches: &mut ArgMatches,
app: Command,
) -> clap::error::Result<()> {
+ // todo(dsherret): remove this in Deno 2.0
+ // This is a hack to make https://github.com/netlify/build/pull/5767 work
+ // for old versions of @netlify/edge-bundler with new versions of Deno
+ // where Deno has gotten smarter at resolving config files.
+ //
+ // It's an unfortuante scenario, but Netlify has the version at least
+ // pinned to 1.x in old versions so we can remove this in Deno 2.0 in
+ // a few months.
+ fn temp_netlify_deno_1_hack(flags: &mut Flags, script_arg: &str) {
+ fn is_netlify_edge_bundler_entrypoint(
+ flags: &Flags,
+ script_arg: &str,
+ ) -> bool {
+ // based on diff here: https://github.com/netlify/edge-bundler/blame/f1d33b74ca7aeec19a7c2149316d4547a94e43fb/node/config.ts#L85
+ if flags.permissions.allow_read.is_none()
+ || flags.permissions.allow_write.is_none()
+ || flags.config_flag != ConfigFlag::Discover
+ {
+ return false;
+ }
+ if !script_arg.contains("@netlify") {
+ return false;
+ }
+ let path = PathBuf::from(script_arg);
+ if !path.ends_with("deno/config.ts") {
+ return false;
+ }
+ let mut found_node_modules = false;
+ for component in path.components().filter_map(|c| c.as_os_str().to_str())
+ {
+ if !found_node_modules {
+ found_node_modules = component == "node_modules";
+ } else {
+ // make this work with pnpm and other package managers
+ if component.contains("@netlify") {
+ return true;
+ }
+ }
+ }
+ false
+ }
+
+ if is_netlify_edge_bundler_entrypoint(flags, script_arg) {
+ flags.config_flag = ConfigFlag::Disabled;
+ }
+ }
+
runtime_args_parse(flags, matches, true, true);
flags.code_cache_enabled = !matches.get_flag("no-code-cache");
@@ -4264,6 +4311,7 @@ fn run_parse(
flags.argv.extend(script_arg);
ext_arg_parse(flags, matches);
+ temp_netlify_deno_1_hack(flags, &script);
flags.subcommand = DenoSubcommand::Run(RunFlags {
script,
diff --git a/tests/specs/run/netlify_edge_bundler_hack/__test__.jsonc b/tests/specs/run/netlify_edge_bundler_hack/__test__.jsonc
new file mode 100644
index 000000000..4ae0ebe86
--- /dev/null
+++ b/tests/specs/run/netlify_edge_bundler_hack/__test__.jsonc
@@ -0,0 +1,9 @@
+{
+ "args": [
+ "run",
+ "--allow-read",
+ "--allow-write",
+ "node_modules/@netlify/edge-bundler/deno/config.ts"
+ ],
+ "output": "main.out"
+}
diff --git a/tests/specs/run/netlify_edge_bundler_hack/main.out b/tests/specs/run/netlify_edge_bundler_hack/main.out
new file mode 100644
index 000000000..35821117c
--- /dev/null
+++ b/tests/specs/run/netlify_edge_bundler_hack/main.out
@@ -0,0 +1 @@
+Success
diff --git a/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/deno/config.ts b/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/deno/config.ts
new file mode 100644
index 000000000..f1b207f5b
--- /dev/null
+++ b/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/deno/config.ts
@@ -0,0 +1 @@
+console.log("Success");
diff --git a/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/package.json b/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/package.json
new file mode 100644
index 000000000..d6043710f
--- /dev/null
+++ b/tests/specs/run/netlify_edge_bundler_hack/node_modules/@netlify/edge-bundler/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "@netlify/edge-bundler",
+ "version": "1.0.0",
+ "exports": "./index.js",
+} \ No newline at end of file
diff --git a/tests/specs/run/netlify_edge_bundler_hack/package.json b/tests/specs/run/netlify_edge_bundler_hack/package.json
new file mode 100644
index 000000000..bd0ecbc6e
--- /dev/null
+++ b/tests/specs/run/netlify_edge_bundler_hack/package.json
@@ -0,0 +1,4 @@
+{
+ "name": "my-package",
+ "version": "1.0.0"
+}