feat: don't require --unstable flag for npm programs (#16520)

This PR adds copies of several unstable APIs that are available
in "Deno[Deno.internal].nodeUnstable" namespace.

These copies do not perform unstable check (ie. don't require
"--unstable" flag to be present). Otherwise they work exactly
the same, including permission checks.

These APIs are not meant to be used by users directly and
can change at any time.

Copies of following APIs are available in that namespace:
- Deno.spawnChild
- Deno.spawn
- Deno.spawnSync
- Deno.serve
- Deno.upgradeHttpRaw
- Deno.listenDatagram
This commit is contained in:
Bartek Iwańczuk 2022-11-10 22:03:28 +01:00 committed by GitHub
parent 53e974b276
commit 8d5c0112fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 576 additions and 329 deletions

View file

@ -1,7 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use crate::proc_state::ProcState;
use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::op;
use deno_core::Extension;
@ -27,10 +26,5 @@ fn init_proc_state(ps: ProcState) -> Extension {
#[op]
fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
let proc_state = state.borrow_mut::<ProcState>();
if !proc_state.options.unstable() {
bail!(
"Unstable use of npm process state. The --unstable flag must be provided."
)
}
Ok(proc_state.npm_resolver.get_npm_process_state())
}

View file

@ -274,6 +274,7 @@ impl ProcState {
/// module before attempting to `load()` it from a `JsRuntime`. It will
/// populate `self.graph_data` in memory with the necessary source code, write
/// emits where necessary or report any module graph / type checking errors.
#[allow(clippy::too_many_arguments)]
pub async fn prepare_module_load(
&self,
roots: Vec<ModuleSpecifier>,

View file

@ -103,7 +103,7 @@ itest!(dual_cjs_esm {
});
itest!(child_process_fork_test {
args: "run --unstable -A --quiet npm/child_process_fork_test/main.ts",
args: "run -A --quiet npm/child_process_fork_test/main.ts",
output: "npm/child_process_fork_test/main.out",
envs: env_vars(),
http_server: true,
@ -621,7 +621,7 @@ itest!(node_modules_dir_with_deps {
});
itest!(node_modules_dir_yargs {
args: "run --allow-read --allow-env --unstable --node-modules-dir $TESTDATA/npm/cjs_yargs/main.js",
args: "run --allow-read --allow-env --node-modules-dir $TESTDATA/npm/cjs_yargs/main.js",
output: "npm/cjs_yargs/main.out",
envs: env_vars(),
http_server: true,
@ -1050,7 +1050,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("-A")
.arg("main.ts")
.envs(env_vars())
@ -1082,7 +1081,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("-A")
.arg("main.ts")
.envs(env_vars())
@ -1097,7 +1095,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("--reload")
.arg("-A")
.arg("main.ts")
@ -1114,7 +1111,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("--node-modules-dir")
.arg("-A")
.arg("main.ts")
@ -1139,7 +1135,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("--node-modules-dir")
.arg("-A")
.arg("main.ts")
@ -1156,7 +1151,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("--node-modules-dir")
.arg("--reload")
.arg("-A")
@ -1174,7 +1168,6 @@ fn peer_deps_with_copied_folders_and_lockfile() {
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
.current_dir(temp_dir.path())
.arg("run")
.arg("--unstable")
.arg("--node-modules-dir")
.arg("--no-lock")
.arg("--reload")