fix(npm): always require --unstable flag even for esm (#15583)

This commit is contained in:
David Sherret 2022-08-24 13:44:38 -04:00 committed by GitHub
parent 18fcef8b29
commit 348291f5ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 2 deletions

View file

@ -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
}