diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-08-24 13:44:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 13:44:38 -0400 |
commit | 348291f5eccfa19fde67e16bc5d706b5f465da09 (patch) | |
tree | 30547118c514e138bcf674e8a950718b09d7c2c1 | |
parent | 18fcef8b294f98df5eb555fb166afafebeaed71f (diff) |
fix(npm): always require --unstable flag even for esm (#15583)
-rw-r--r-- | cli/npm/mod.rs | 10 | ||||
-rw-r--r-- | cli/proc_state.rs | 1 | ||||
-rw-r--r-- | cli/tests/integration/npm_tests.rs | 12 | ||||
-rw-r--r-- | cli/tests/testdata/npm/no_unstable/main.out | 1 | ||||
-rw-r--r-- | cli/tests/testdata/npm/no_unstable/main.ts | 3 |
5 files changed, 25 insertions, 2 deletions
diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 0e5c07914..bdbc5aca3 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -76,6 +76,7 @@ pub struct GlobalNpmPackageResolver { cache: NpmCache, resolution: Arc<NpmResolution>, registry_url: Url, + unstable: bool, } impl GlobalNpmPackageResolver { @@ -83,11 +84,13 @@ impl GlobalNpmPackageResolver { dir: &DenoDir, reload: bool, cache_setting: CacheSetting, + unstable: bool, ) -> Result<Self, AnyError> { Ok(Self::from_cache( NpmCache::from_deno_dir(dir, cache_setting.clone())?, reload, cache_setting, + unstable, )) } @@ -95,6 +98,7 @@ impl GlobalNpmPackageResolver { cache: NpmCache, reload: bool, cache_setting: CacheSetting, + unstable: bool, ) -> Self { let api = NpmRegistryApi::new(cache.clone(), reload, cache_setting); let registry_url = api.base_url().to_owned(); @@ -104,6 +108,7 @@ impl GlobalNpmPackageResolver { cache, resolution, registry_url, + unstable, } } @@ -117,6 +122,11 @@ impl GlobalNpmPackageResolver { &self, packages: Vec<NpmPackageReq>, ) -> Result<(), AnyError> { + if !self.unstable && !packages.is_empty() { + bail!( + "Unstable use of npm specifiers. The --unstable flag must be provided." + ) + } self.resolution.add_package_reqs(packages).await } diff --git a/cli/proc_state.rs b/cli/proc_state.rs index bc5c36e13..123c9f262 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -226,6 +226,7 @@ impl ProcState { &dir, cli_options.reload_flag(), cli_options.cache_setting(), + cli_options.unstable(), )?; Ok(ProcState(Arc::new(Inner { diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 98ab347b9..9c4b98241 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -10,7 +10,7 @@ use util::http_server; // by setting the DENO_TEST_UTIL_UPDATE_NPM=1 environment variable. itest!(esm_module { - args: "run --allow-read npm/esm/main.js", + args: "run --allow-read --unstable npm/esm/main.js", output: "npm/esm/main.out", envs: env_vars(), http_server: true, @@ -19,6 +19,7 @@ itest!(esm_module { itest!(esm_module_eval { args_vec: vec![ "eval", + "--unstable", "import chalk from 'npm:chalk@5'; console.log(chalk.green('chalk esm loads'));", ], output: "npm/esm/main.out", @@ -27,7 +28,7 @@ itest!(esm_module_eval { }); itest!(esm_module_deno_test { - args: "test --allow-read npm/esm/test.js", + args: "test --allow-read --unstable npm/esm/test.js", output: "npm/esm/test.out", envs: env_vars(), http_server: true, @@ -61,6 +62,13 @@ itest!(cached_only { exit_code: 1, }); +itest!(no_unstable { + args: "run npm/no_unstable/main.ts", + output: "npm/no_unstable/main.out", + envs: env_vars(), + exit_code: 1, +}); + itest!(import_map { args: "run --allow-read --unstable --import-map npm/import_map/import_map.json npm/import_map/main.js", output: "npm/import_map/main.out", diff --git a/cli/tests/testdata/npm/no_unstable/main.out b/cli/tests/testdata/npm/no_unstable/main.out new file mode 100644 index 000000000..5a5a4e5a7 --- /dev/null +++ b/cli/tests/testdata/npm/no_unstable/main.out @@ -0,0 +1 @@ +error: Unstable use of npm specifiers. The --unstable flag must be provided. diff --git a/cli/tests/testdata/npm/no_unstable/main.ts b/cli/tests/testdata/npm/no_unstable/main.ts new file mode 100644 index 000000000..bb14e62c5 --- /dev/null +++ b/cli/tests/testdata/npm/no_unstable/main.ts @@ -0,0 +1,3 @@ +import chalk from "npm:chalk@5"; + +console.log(chalk.green("hello")); |