mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(cli): Check permissions for Deno.emit() (#9139)
This commit is contained in:
parent
2b5b93158c
commit
81d73f2987
5 changed files with 45 additions and 29 deletions
|
@ -29,6 +29,7 @@ use deno_core::error::AnyError;
|
||||||
|
|
||||||
use deno_core::error::anyhow;
|
use deno_core::error::anyhow;
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
|
use deno_core::error::get_custom_error_class;
|
||||||
use deno_core::error::Context;
|
use deno_core::error::Context;
|
||||||
use deno_core::futures::stream::FuturesUnordered;
|
use deno_core::futures::stream::FuturesUnordered;
|
||||||
use deno_core::futures::stream::StreamExt;
|
use deno_core::futures::stream::StreamExt;
|
||||||
|
@ -848,7 +849,7 @@ impl Graph {
|
||||||
info!("{} {}", colors::green("Check"), specifier);
|
info!("{} {}", colors::green("Check"), specifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
let root_names = self.get_root_names(!config.get_check_js());
|
let root_names = self.get_root_names(!config.get_check_js())?;
|
||||||
let maybe_tsbuildinfo = self.maybe_tsbuildinfo.clone();
|
let maybe_tsbuildinfo = self.maybe_tsbuildinfo.clone();
|
||||||
let hash_data =
|
let hash_data =
|
||||||
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
||||||
|
@ -975,7 +976,7 @@ impl Graph {
|
||||||
|
|
||||||
let mut emitted_files = HashMap::new();
|
let mut emitted_files = HashMap::new();
|
||||||
if options.check {
|
if options.check {
|
||||||
let root_names = self.get_root_names(!config.get_check_js());
|
let root_names = self.get_root_names(!config.get_check_js())?;
|
||||||
let hash_data =
|
let hash_data =
|
||||||
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
||||||
let graph = Arc::new(Mutex::new(self));
|
let graph = Arc::new(Mutex::new(self));
|
||||||
|
@ -1329,7 +1330,7 @@ impl Graph {
|
||||||
fn get_root_names(
|
fn get_root_names(
|
||||||
&self,
|
&self,
|
||||||
include_emittable: bool,
|
include_emittable: bool,
|
||||||
) -> Vec<(ModuleSpecifier, MediaType)> {
|
) -> Result<Vec<(ModuleSpecifier, MediaType)>, AnyError> {
|
||||||
let root_names: Vec<ModuleSpecifier> = if include_emittable {
|
let root_names: Vec<ModuleSpecifier> = if include_emittable {
|
||||||
// in situations where there is `allowJs` with tsc, but not `checkJs`,
|
// in situations where there is `allowJs` with tsc, but not `checkJs`,
|
||||||
// then tsc will not parse the whole module graph, meaning that any
|
// then tsc will not parse the whole module graph, meaning that any
|
||||||
|
@ -1355,32 +1356,38 @@ impl Graph {
|
||||||
} else {
|
} else {
|
||||||
self.roots.clone()
|
self.roots.clone()
|
||||||
};
|
};
|
||||||
root_names
|
let mut root_types = vec![];
|
||||||
.iter()
|
for ms in root_names {
|
||||||
.map(|ms| {
|
|
||||||
// if the root module has a types specifier, we should be sending that
|
// if the root module has a types specifier, we should be sending that
|
||||||
// to tsc instead of the original specifier
|
// to tsc instead of the original specifier
|
||||||
let specifier = self.resolve_specifier(ms);
|
let specifier = self.resolve_specifier(&ms);
|
||||||
let module =
|
let module = match self.get_module(specifier) {
|
||||||
if let ModuleSlot::Module(module) = self.get_module(specifier) {
|
ModuleSlot::Module(module) => module,
|
||||||
module
|
ModuleSlot::Err(error) => {
|
||||||
|
// It would be great if we could just clone the error here...
|
||||||
|
if let Some(class) = get_custom_error_class(error) {
|
||||||
|
return Err(custom_error(class, error.to_string()));
|
||||||
} else {
|
} else {
|
||||||
|
panic!("unsupported ModuleSlot error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
panic!("missing module");
|
panic!("missing module");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let specifier = if let Some((_, types_specifier)) = &module.maybe_types
|
let specifier = if let Some((_, types_specifier)) = &module.maybe_types {
|
||||||
{
|
|
||||||
self.resolve_specifier(types_specifier)
|
self.resolve_specifier(types_specifier)
|
||||||
} else {
|
} else {
|
||||||
specifier
|
specifier
|
||||||
};
|
};
|
||||||
(
|
root_types.push((
|
||||||
// root modules can be redirects, so before we pass it to tsc we need
|
// root modules can be redirects, so before we pass it to tsc we need
|
||||||
// to resolve the redirect
|
// to resolve the redirect
|
||||||
specifier.clone(),
|
specifier.clone(),
|
||||||
self.get_media_type(specifier).unwrap(),
|
self.get_media_type(specifier).unwrap(),
|
||||||
)
|
));
|
||||||
})
|
}
|
||||||
.collect()
|
Ok(root_types)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the source for a given module specifier. If the module is not part
|
/// Get the source for a given module specifier. If the module is not part
|
||||||
|
|
|
@ -66,9 +66,9 @@ async fn op_emit(
|
||||||
let mut is_dynamic = false;
|
let mut is_dynamic = false;
|
||||||
let handler: Arc<Mutex<dyn SpecifierHandler>> =
|
let handler: Arc<Mutex<dyn SpecifierHandler>> =
|
||||||
if let Some(sources) = args.sources {
|
if let Some(sources) = args.sources {
|
||||||
is_dynamic = true;
|
|
||||||
Arc::new(Mutex::new(MemoryHandler::new(sources)))
|
Arc::new(Mutex::new(MemoryHandler::new(sources)))
|
||||||
} else {
|
} else {
|
||||||
|
is_dynamic = true;
|
||||||
Arc::new(Mutex::new(FetchHandler::new(
|
Arc::new(Mutex::new(FetchHandler::new(
|
||||||
&program_state,
|
&program_state,
|
||||||
runtime_permissions,
|
runtime_permissions,
|
||||||
|
|
1
cli/tests/080_deno_emit_permissions.ts
Normal file
1
cli/tests/080_deno_emit_permissions.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
await Deno.emit(new URL("001_hello.js", import.meta.url).href);
|
2
cli/tests/080_deno_emit_permissions.ts.out
Normal file
2
cli/tests/080_deno_emit_permissions.ts.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[WILDCARD]error: Uncaught (in promise) PermissionDenied: read access to "[WILDCARD]001_hello.js", run again with the --allow-read flag
|
||||||
|
[WILDCARD]
|
|
@ -2656,6 +2656,12 @@ itest!(_079_location_authentication {
|
||||||
output: "079_location_authentication.ts.out",
|
output: "079_location_authentication.ts.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(_080_deno_emit_permissions {
|
||||||
|
args: "run --unstable 080_deno_emit_permissions.ts",
|
||||||
|
output: "080_deno_emit_permissions.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(js_import_detect {
|
itest!(js_import_detect {
|
||||||
args: "run --quiet --reload js_import_detect.ts",
|
args: "run --quiet --reload js_import_detect.ts",
|
||||||
output: "js_import_detect.ts.out",
|
output: "js_import_detect.ts.out",
|
||||||
|
|
Loading…
Reference in a new issue