Skip to content

Commit 4de6135

Browse files
Merge pull request #700 from denoland/main
Create a new pull request by comparing changes across two branches
2 parents a2c4a6b + 64c304a commit 4de6135

File tree

44 files changed

+612
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+612
-260
lines changed

Cargo.lock

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/args/flags.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ pub fn flags_from_vec(args: Vec<OsString>) -> clap::error::Result<Flags> {
13421342
}
13431343

13441344
match subcommand.as_str() {
1345-
"add" => add_parse(&mut flags, &mut m),
1345+
"add" => add_parse(&mut flags, &mut m)?,
13461346
"remove" => remove_parse(&mut flags, &mut m),
13471347
"bench" => bench_parse(&mut flags, &mut m)?,
13481348
"bundle" => bundle_parse(&mut flags, &mut m),
@@ -1675,6 +1675,7 @@ You can add multiple dependencies at once:
16751675
.action(ArgAction::Append),
16761676
)
16771677
.arg(add_dev_arg())
1678+
.arg(allow_scripts_arg())
16781679
})
16791680
}
16801681

@@ -1717,7 +1718,7 @@ If you specify a directory instead of a file, the path is expanded to all contai
17171718
UnstableArgsConfig::ResolutionAndRuntime,
17181719
)
17191720
.defer(|cmd| {
1720-
runtime_args(cmd, true, false)
1721+
runtime_args(cmd, true, false, true)
17211722
.arg(check_arg(true))
17221723
.arg(
17231724
Arg::new("json")
@@ -1881,7 +1882,7 @@ On the first invocation with deno will download the proper binary and cache it i
18811882
UnstableArgsConfig::ResolutionAndRuntime,
18821883
)
18831884
.defer(|cmd| {
1884-
runtime_args(cmd, true, false)
1885+
runtime_args(cmd, true, false, true)
18851886
.arg(check_arg(true))
18861887
.arg(
18871888
Arg::new("include")
@@ -2202,7 +2203,7 @@ This command has implicit access to all permissions.
22022203
UnstableArgsConfig::ResolutionAndRuntime,
22032204
)
22042205
.defer(|cmd| {
2205-
runtime_args(cmd, false, true)
2206+
runtime_args(cmd, false, true, true)
22062207
.arg(check_arg(false))
22072208
.arg(executable_ext_arg())
22082209
.arg(
@@ -2501,7 +2502,7 @@ The installation root is determined, in order of precedence:
25012502
These must be added to the path manually if required."), UnstableArgsConfig::ResolutionAndRuntime)
25022503
.visible_alias("i")
25032504
.defer(|cmd| {
2504-
permission_args(runtime_args(cmd, false, true), Some("global"))
2505+
permission_args(runtime_args(cmd, false, true, false), Some("global"))
25052506
.arg(check_arg(true))
25062507
.arg(allow_scripts_arg())
25072508
.arg(
@@ -2767,7 +2768,7 @@ It is especially useful for quick prototyping and checking snippets of code.
27672768
27682769
TypeScript is supported, however it is not type-checked, only transpiled."
27692770
), UnstableArgsConfig::ResolutionAndRuntime)
2770-
.defer(|cmd| runtime_args(cmd, true, true)
2771+
.defer(|cmd| runtime_args(cmd, true, true, true)
27712772
.arg(check_arg(false))
27722773
.arg(
27732774
Arg::new("eval-file")
@@ -2799,7 +2800,7 @@ TypeScript is supported, however it is not type-checked, only transpiled."
27992800
}
28002801

28012802
fn run_args(command: Command, top_level: bool) -> Command {
2802-
runtime_args(command, true, true)
2803+
runtime_args(command, true, true, true)
28032804
.arg(check_arg(false))
28042805
.arg(watch_arg(true))
28052806
.arg(hmr_arg(true))
@@ -2855,7 +2856,7 @@ Start a server defined in server.ts:
28552856
Start a server defined in server.ts, watching for changes and running on port 5050:
28562857
<p(245)>deno serve --watch --port 5050 server.ts</>
28572858
2858-
<y>Read more:</> <c>https://docs.deno.com/go/serve</>"), UnstableArgsConfig::ResolutionAndRuntime), true, true)
2859+
<y>Read more:</> <c>https://docs.deno.com/go/serve</>"), UnstableArgsConfig::ResolutionAndRuntime), true, true, true)
28592860
.arg(
28602861
Arg::new("port")
28612862
.long("port")
@@ -2929,7 +2930,7 @@ or <c>**/__tests__/**</>:
29292930
UnstableArgsConfig::ResolutionAndRuntime
29302931
)
29312932
.defer(|cmd|
2932-
runtime_args(cmd, true, true)
2933+
runtime_args(cmd, true, true, true)
29332934
.arg(check_arg(true))
29342935
.arg(
29352936
Arg::new("ignore")
@@ -3642,6 +3643,7 @@ fn runtime_args(
36423643
app: Command,
36433644
include_perms: bool,
36443645
include_inspector: bool,
3646+
include_allow_scripts: bool,
36453647
) -> Command {
36463648
let app = compile_args(app);
36473649
let app = if include_perms {
@@ -3654,6 +3656,11 @@ fn runtime_args(
36543656
} else {
36553657
app
36563658
};
3659+
let app = if include_allow_scripts {
3660+
app.arg(allow_scripts_arg())
3661+
} else {
3662+
app
3663+
};
36573664
app
36583665
.arg(frozen_lockfile_arg())
36593666
.arg(cached_only_arg())
@@ -4235,8 +4242,13 @@ fn allow_scripts_arg_parse(
42354242
Ok(())
42364243
}
42374244

4238-
fn add_parse(flags: &mut Flags, matches: &mut ArgMatches) {
4245+
fn add_parse(
4246+
flags: &mut Flags,
4247+
matches: &mut ArgMatches,
4248+
) -> clap::error::Result<()> {
4249+
allow_scripts_arg_parse(flags, matches)?;
42394250
flags.subcommand = DenoSubcommand::Add(add_parse_inner(matches, None));
4251+
Ok(())
42404252
}
42414253

42424254
fn add_parse_inner(
@@ -4262,7 +4274,7 @@ fn bench_parse(
42624274
) -> clap::error::Result<()> {
42634275
flags.type_check_mode = TypeCheckMode::Local;
42644276

4265-
runtime_args_parse(flags, matches, true, false)?;
4277+
runtime_args_parse(flags, matches, true, false, true)?;
42664278
ext_arg_parse(flags, matches);
42674279

42684280
// NOTE: `deno bench` always uses `--no-prompt`, tests shouldn't ever do
@@ -4352,7 +4364,7 @@ fn compile_parse(
43524364
matches: &mut ArgMatches,
43534365
) -> clap::error::Result<()> {
43544366
flags.type_check_mode = TypeCheckMode::Local;
4355-
runtime_args_parse(flags, matches, true, false)?;
4367+
runtime_args_parse(flags, matches, true, false, true)?;
43564368

43574369
let mut script = matches.remove_many::<String>("script_arg").unwrap();
43584370
let source_file = script.next().unwrap();
@@ -4527,7 +4539,7 @@ fn eval_parse(
45274539
flags: &mut Flags,
45284540
matches: &mut ArgMatches,
45294541
) -> clap::error::Result<()> {
4530-
runtime_args_parse(flags, matches, false, true)?;
4542+
runtime_args_parse(flags, matches, false, true, false)?;
45314543
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime);
45324544
flags.allow_all();
45334545

@@ -4620,7 +4632,7 @@ fn install_parse(
46204632
flags: &mut Flags,
46214633
matches: &mut ArgMatches,
46224634
) -> clap::error::Result<()> {
4623-
runtime_args_parse(flags, matches, true, true)?;
4635+
runtime_args_parse(flags, matches, true, true, false)?;
46244636

46254637
let global = matches.get_flag("global");
46264638
if global {
@@ -4846,7 +4858,7 @@ fn repl_parse(
48464858
flags: &mut Flags,
48474859
matches: &mut ArgMatches,
48484860
) -> clap::error::Result<()> {
4849-
runtime_args_parse(flags, matches, true, true)?;
4861+
runtime_args_parse(flags, matches, true, true, true)?;
48504862
unsafely_ignore_certificate_errors_parse(flags, matches);
48514863

48524864
let eval_files = matches
@@ -4879,7 +4891,7 @@ fn run_parse(
48794891
mut app: Command,
48804892
bare: bool,
48814893
) -> clap::error::Result<()> {
4882-
runtime_args_parse(flags, matches, true, true)?;
4894+
runtime_args_parse(flags, matches, true, true, true)?;
48834895
ext_arg_parse(flags, matches);
48844896

48854897
flags.code_cache_enabled = !matches.get_flag("no-code-cache");
@@ -4920,7 +4932,7 @@ fn serve_parse(
49204932

49214933
let worker_count = parallel_arg_parse(matches).map(|v| v.get());
49224934

4923-
runtime_args_parse(flags, matches, true, true)?;
4935+
runtime_args_parse(flags, matches, true, true, true)?;
49244936
// If the user didn't pass --allow-net, add this port to the network
49254937
// allowlist. If the host is 0.0.0.0, we add :{port} and allow the same network perms
49264938
// as if it was passed to --allow-net directly.
@@ -5015,7 +5027,7 @@ fn test_parse(
50155027
matches: &mut ArgMatches,
50165028
) -> clap::error::Result<()> {
50175029
flags.type_check_mode = TypeCheckMode::Local;
5018-
runtime_args_parse(flags, matches, true, true)?;
5030+
runtime_args_parse(flags, matches, true, true, true)?;
50195031
ext_arg_parse(flags, matches);
50205032

50215033
// NOTE: `deno test` always uses `--no-prompt`, tests shouldn't ever do
@@ -5380,6 +5392,7 @@ fn runtime_args_parse(
53805392
matches: &mut ArgMatches,
53815393
include_perms: bool,
53825394
include_inspector: bool,
5395+
include_allow_scripts: bool,
53835396
) -> clap::error::Result<()> {
53845397
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime);
53855398
compile_args_parse(flags, matches)?;
@@ -5391,6 +5404,9 @@ fn runtime_args_parse(
53915404
if include_inspector {
53925405
inspect_arg_parse(flags, matches);
53935406
}
5407+
if include_allow_scripts {
5408+
allow_scripts_arg_parse(flags, matches)?;
5409+
}
53945410
location_arg_parse(flags, matches);
53955411
v8_flags_arg_parse(flags, matches);
53965412
seed_arg_parse(flags, matches);
@@ -8862,8 +8878,12 @@ mod tests {
88628878

88638879
#[test]
88648880
fn test_no_colon_in_value_name() {
8865-
let app =
8866-
runtime_args(Command::new("test_inspect_completion_value"), true, true);
8881+
let app = runtime_args(
8882+
Command::new("test_inspect_completion_value"),
8883+
true,
8884+
true,
8885+
false,
8886+
);
88678887
let inspect_args = app
88688888
.get_arguments()
88698889
.filter(|arg| arg.get_id() == "inspect")

cli/npm/managed/resolvers/common/lifecycle_scripts.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use super::bin_entries::BinEntries;
44
use crate::args::LifecycleScriptsConfig;
5+
use crate::task_runner::TaskStdio;
6+
use crate::util::progress_bar::ProgressBar;
57
use deno_core::anyhow::Context;
68
use deno_npm::resolution::NpmResolutionSnapshot;
79
use deno_runtime::deno_io::FromRawIoHandle;
@@ -148,6 +150,7 @@ impl<'a> LifecycleScripts<'a> {
148150
snapshot: &NpmResolutionSnapshot,
149151
packages: &[NpmResolutionPackage],
150152
root_node_modules_dir_path: Option<&Path>,
153+
progress_bar: &ProgressBar,
151154
) -> Result<(), AnyError> {
152155
self.warn_not_run_scripts()?;
153156
let get_package_path =
@@ -201,7 +204,15 @@ impl<'a> LifecycleScripts<'a> {
201204
{
202205
continue;
203206
}
204-
let exit_code = crate::task_runner::run_task(
207+
let _guard = progress_bar.update_with_prompt(
208+
crate::util::progress_bar::ProgressMessagePrompt::Initialize,
209+
&format!("{}: running '{script_name}' script", package.id.nv),
210+
);
211+
let crate::task_runner::TaskResult {
212+
exit_code,
213+
stderr,
214+
stdout,
215+
} = crate::task_runner::run_task(
205216
crate::task_runner::RunTaskOptions {
206217
task_name: script_name,
207218
script,
@@ -211,15 +222,37 @@ impl<'a> LifecycleScripts<'a> {
211222
init_cwd,
212223
argv: &[],
213224
root_node_modules_dir: root_node_modules_dir_path,
225+
stdio: Some(crate::task_runner::TaskIo {
226+
stderr: TaskStdio::piped(),
227+
stdout: TaskStdio::piped(),
228+
}),
214229
},
215230
)
216231
.await?;
232+
let stdout = stdout.unwrap();
233+
let stderr = stderr.unwrap();
217234
if exit_code != 0 {
218235
log::warn!(
219-
"error: script '{}' in '{}' failed with exit code {}",
236+
"error: script '{}' in '{}' failed with exit code {}{}{}",
220237
script_name,
221238
package.id.nv,
222239
exit_code,
240+
if !stdout.trim_ascii().is_empty() {
241+
format!(
242+
"\nstdout:\n{}\n",
243+
String::from_utf8_lossy(&stdout).trim()
244+
)
245+
} else {
246+
String::new()
247+
},
248+
if !stderr.trim_ascii().is_empty() {
249+
format!(
250+
"\nstderr:\n{}\n",
251+
String::from_utf8_lossy(&stderr).trim()
252+
)
253+
} else {
254+
String::new()
255+
},
223256
);
224257
failed_packages.push(&package.id.nv);
225258
// assume if earlier script fails, later ones will fail too

cli/npm/managed/resolvers/local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ async fn sync_resolution_with_fs(
713713
snapshot,
714714
&package_partitions.packages,
715715
Some(root_node_modules_dir_path),
716+
progress_bar,
716717
)
717718
.await?;
718719

0 commit comments

Comments
 (0)