fix(npm): allow to read package.json if permissions are granted (#17209)

This commit changes signature of "deno_core::ModuleLoader::resolve" to pass
an enum indicating whether or not we're resolving a specifier for dynamic import.

Additionally "CliModuleLoader" was changes to store both "parent permissions" (or
"root permissions") as well as "dynamic permissions" that allow to check for permissions
in top-level module load an dynamic imports.

Then all code paths that have anything to do with Node/npm compat are now checking
for permissions which are passed from module loader instance associated with given
worker.
This commit is contained in:
Bartek Iwańczuk 2023-01-10 14:35:44 +01:00 committed by GitHub
parent 45768f0e83
commit 636352e0ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 306 additions and 93 deletions

View file

@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::NodeModuleKind;
use crate::NodePermissions;
use super::RequireNpmResolver;
use deno_core::anyhow;
@ -47,9 +48,10 @@ impl PackageJson {
pub fn load(
resolver: &dyn RequireNpmResolver,
permissions: &mut dyn NodePermissions,
path: PathBuf,
) -> Result<PackageJson, AnyError> {
resolver.ensure_read_permission(&path)?;
resolver.ensure_read_permission(permissions, &path)?;
Self::load_skip_read_permission(path)
}