Skip to content

Commit 549e998

Browse files
authored
Merge branch 'main' into merge_deno_bc_into_deno_webn
2 parents 49b2cdc + 42cca89 commit 549e998

Some content is hidden

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

47 files changed

+960
-102
lines changed

.github/workflows/ci.generate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,12 @@ const ci = {
11811181
needs: ["pre_build"],
11821182
if: "${{ needs.pre_build.outputs.skip_build != 'true' }}",
11831183
"runs-on": "${{ matrix.runner }}",
1184+
"timeout-minutes": 30,
1185+
defaults: {
1186+
run: {
1187+
shell: "bash",
1188+
},
1189+
},
11841190
strategy: {
11851191
matrix: {
11861192
include: [{

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ jobs:
748748
- pre_build
749749
if: '${{ needs.pre_build.outputs.skip_build != ''true'' }}'
750750
runs-on: '${{ matrix.runner }}'
751+
timeout-minutes: 30
752+
defaults:
753+
run:
754+
shell: bash
751755
strategy:
752756
matrix:
753757
include:

cli/args/flags.rs

Lines changed: 217 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use deno_config::glob::PathOrPatternSet;
3838
use deno_core::anyhow::Context;
3939
use deno_core::anyhow::bail;
4040
use deno_core::error::AnyError;
41+
use deno_core::serde_json;
4142
use deno_core::url::Url;
4243
use deno_graph::GraphKind;
4344
use deno_lib::args::CaData;
@@ -50,6 +51,8 @@ use deno_path_util::resolve_url_or_path;
5051
use deno_path_util::url_to_file_path;
5152
use deno_runtime::UnstableFeatureKind;
5253
use deno_runtime::deno_permissions::SysDescriptor;
54+
use deno_semver::jsr::JsrDepPackageReq;
55+
use deno_semver::package::PackageKind;
5356
use deno_telemetry::OtelConfig;
5457
use deno_telemetry::OtelConsoleConfig;
5558
use deno_telemetry::OtelPropagators;
@@ -1298,45 +1301,173 @@ impl Flags {
12981301
}
12991302
}
13001303

1301-
static ENV_VARIABLES_HELP: &str = cstr!(
1302-
r#"<y>Environment variables:</>
1304+
#[derive(Serialize)]
1305+
struct EnvVar {
1306+
name: &'static str,
1307+
description: &'static str,
1308+
example: Option<&'static str>,
1309+
}
1310+
1311+
static ENV_VARS: &[EnvVar] = &[
1312+
EnvVar {
1313+
name: "DENO_AUTH_TOKENS",
1314+
description: "A semi-colon separated list of bearer tokens and hostnames\nto use when fetching remote modules from private repositories",
1315+
example: Some(r#"(e.g. "[email protected];[email protected]")"#),
1316+
},
1317+
EnvVar {
1318+
name: "DENO_CACHE_DB_MODE",
1319+
description: "Controls whether Web cache should use disk based or in-memory database.",
1320+
example: None,
1321+
},
1322+
EnvVar {
1323+
name: "DENO_CERT",
1324+
description: "Load certificate authorities from PEM encoded file.",
1325+
example: None,
1326+
},
1327+
EnvVar {
1328+
name: "DENO_COMPAT",
1329+
description: "Enable Node.js compatibility mode - extensionless imports, built-in\nNode.js modules, CommonJS detection and more.",
1330+
example: None,
1331+
},
1332+
EnvVar {
1333+
name: "DENO_DIR",
1334+
description: "Set the cache directory",
1335+
example: None,
1336+
},
1337+
EnvVar {
1338+
name: "DENO_INSTALL_ROOT",
1339+
description: "Set deno install's output directory",
1340+
example: Some("(defaults to $HOME/.deno/bin)"),
1341+
},
1342+
EnvVar {
1343+
name: "DENO_KV_DB_MODE",
1344+
description: "Controls whether Deno.openKv() API should use disk based or in-memory\ndatabase.",
1345+
example: None,
1346+
},
1347+
EnvVar {
1348+
name: "DENO_EMIT_CACHE_MODE",
1349+
description: "Control if the transpiled sources should be cached.",
1350+
example: None,
1351+
},
1352+
EnvVar {
1353+
name: "DENO_NO_PACKAGE_JSON",
1354+
description: "Disables auto-resolution of package.json.",
1355+
example: None,
1356+
},
1357+
EnvVar {
1358+
name: "DENO_NO_UPDATE_CHECK",
1359+
description: "Set to disable checking if a newer Deno version is available",
1360+
example: None,
1361+
},
1362+
EnvVar {
1363+
name: "DENO_SERVE_ADDRESS",
1364+
description: "Override address for Deno.serve",
1365+
example: Some(
1366+
r#"("tcp:0.0.0.0:8080", "unix:/tmp/deno.sock", or "vsock:1234:5678")"#,
1367+
),
1368+
},
1369+
EnvVar {
1370+
name: "DENO_AUTO_SERVE",
1371+
description: "If the entrypoint contains export default { fetch }, `deno run`\nbehaves like `deno serve`.",
1372+
example: None,
1373+
},
1374+
EnvVar {
1375+
name: "DENO_TLS_CA_STORE",
1376+
description: cstr!(
1377+
"Comma-separated list of order dependent certificate stores.\nPossible values: \"system\", \"mozilla\" <p(245)>(defaults to \"mozilla\")</>"
1378+
),
1379+
example: None,
1380+
},
1381+
EnvVar {
1382+
name: "DENO_TRACE_PERMISSIONS",
1383+
description: "Environmental variable to enable stack traces in permission prompts.",
1384+
example: None,
1385+
},
1386+
EnvVar {
1387+
name: "DENO_USE_CGROUPS",
1388+
description: "Use cgroups to determine V8 memory limit.",
1389+
example: None,
1390+
},
1391+
EnvVar {
1392+
name: "FORCE_COLOR",
1393+
description: "Set force color output even if stdout isn't a tty.",
1394+
example: None,
1395+
},
1396+
EnvVar {
1397+
name: "HTTP_PROXY",
1398+
description: "Proxy address for HTTP requests.",
1399+
example: Some("(module downloads, fetch)"),
1400+
},
1401+
EnvVar {
1402+
name: "HTTPS_PROXY",
1403+
description: "Proxy address for HTTPS requests.",
1404+
example: Some("(module downloads, fetch)"),
1405+
},
1406+
EnvVar {
1407+
name: "NO_COLOR",
1408+
description: "Set to disable color.",
1409+
example: None,
1410+
},
1411+
EnvVar {
1412+
name: "NO_PROXY",
1413+
description: "Comma-separated list of hosts which do not use a proxy.",
1414+
example: Some("(module downloads, fetch)"),
1415+
},
1416+
EnvVar {
1417+
name: "NPM_CONFIG_REGISTRY",
1418+
description: "URL to use for the npm registry.",
1419+
example: None,
1420+
},
1421+
EnvVar {
1422+
name: "DENO_TRUST_PROXY_HEADERS",
1423+
description: "If specified, removes X-deno-client-address header when serving HTTP.",
1424+
example: None,
1425+
},
1426+
EnvVar {
1427+
name: "DENO_USR2_MEMORY_TRIM",
1428+
description: "If specified, listen for SIGUSR2 signal to try and free memory (Linux only).",
1429+
example: None,
1430+
},
1431+
];
1432+
1433+
static ENV_VARIABLES_HELP: LazyLock<String> = LazyLock::new(|| {
1434+
let mut out = cstr!(
1435+
r#"<y>Environment variables:</>
13031436
<y>Docs:</> <c>https://docs.deno.com/go/env-vars</>
13041437
1305-
<g>DENO_AUTH_TOKENS</> A semi-colon separated list of bearer tokens and hostnames
1306-
to use when fetching remote modules from private repositories
1307-
1308-
<g>DENO_CACHE_DB_MODE</> Controls whether Web cache should use disk based or in-memory database.
1309-
<g>DENO_CERT</> Load certificate authorities from PEM encoded file
1310-
<g>DENO_COMPAT</> Enable Node.js compatibility mode - extensionless imports, built-in
1311-
Node.js modules, CommonJS detection and more.
1312-
<g>DENO_DIR</> Set the cache directory
1313-
<g>DENO_INSTALL_ROOT</> Set deno install's output directory
1314-
<p(245)>(defaults to $HOME/.deno/bin)</>
1315-
<g>DENO_KV_DB_MODE</> Controls whether Deno.openKv() API should use disk based or in-memory
1316-
database.
1317-
<g>DENO_EMIT_CACHE_MODE</> Control if the transpiled sources should be cached.
1318-
<g>DENO_NO_PACKAGE_JSON</> Disables auto-resolution of package.json
1319-
<g>DENO_NO_UPDATE_CHECK</> Set to disable checking if a newer Deno version is available
1320-
<g>DENO_SERVE_ADDRESS</> Override address for Deno.serve
1321-
Example: "tcp:0.0.0.0:8080", "unix:/tmp/deno.sock", or "vsock:1234:5678"
1322-
<g>DENO_AUTO_SERVE</> If the entrypoint contains export default { fetch }, `deno run`
1323-
behaves like `deno serve`.
1324-
<g>DENO_TLS_CA_STORE</> Comma-separated list of order dependent certificate stores.
1325-
Possible values: "system", "mozilla" <p(245)>(defaults to "mozilla")</>
1326-
<g>DENO_TRACE_PERMISSIONS</> Environmental variable to enable stack traces in permission prompts.
1327-
<g>DENO_USE_CGROUPS</> Use cgroups to determine V8 memory limit
1328-
<g>FORCE_COLOR</> Set force color output even if stdout isn't a tty
1329-
<g>HTTP_PROXY</> Proxy address for HTTP requests
1330-
<p(245)>(module downloads, fetch)</>
1331-
<g>HTTPS_PROXY</> Proxy address for HTTPS requests
1332-
<p(245)>(module downloads, fetch)</>
1333-
<g>NO_COLOR</> Set to disable color
1334-
<g>NO_PROXY</> Comma-separated list of hosts which do not use a proxy
1335-
<p(245)>(module downloads, fetch)</>
1336-
<g>NPM_CONFIG_REGISTRY</> URL to use for the npm registry.
1337-
<g>DENO_TRUST_PROXY_HEADERS</> If specified, removes X-deno-client-address header when serving HTTP.
1338-
<g>DENO_USR2_MEMORY_TRIM</> If specified, listen for SIGUSR2 signal to try and free memory (Linux only)."#
1339-
);
1438+
"#
1439+
)
1440+
.to_string();
1441+
1442+
let longest = ENV_VARS.iter().map(|var| var.name.len()).max().unwrap() + 1;
1443+
1444+
out.push_str(
1445+
&ENV_VARS
1446+
.iter()
1447+
.map(|var| {
1448+
let mut output = color_print::cformat!(
1449+
" <g>{}</>{}{}",
1450+
var.name,
1451+
" ".repeat(longest - var.name.len()),
1452+
var
1453+
.description
1454+
.replace("\n", &format!("\n {}", " ".repeat(longest)))
1455+
);
1456+
if let Some(example) = var.example {
1457+
output.push_str(&color_print::cformat!(
1458+
"\n {}<p(245)>{}</>",
1459+
" ".repeat(longest + 1),
1460+
example
1461+
));
1462+
}
1463+
output
1464+
})
1465+
.collect::<Vec<_>>()
1466+
.join("\n"),
1467+
);
1468+
1469+
out
1470+
});
13401471

13411472
static DENO_HELP: &str = cstr!(
13421473
"Deno: <g>A modern JavaScript and TypeScript runtime</>
@@ -1838,7 +1969,7 @@ pub fn clap_root() -> Command {
18381969
cmd.subcommand(help)
18391970
})
18401971
.help_template(DENO_HELP)
1841-
.after_help(ENV_VARIABLES_HELP)
1972+
.after_help(&*ENV_VARIABLES_HELP)
18421973
.next_line_help(false)
18431974
}
18441975

@@ -1909,7 +2040,7 @@ fn audit_subcommand() -> Command {
19092040
cstr!(
19102041
"Audit currently installed dependencies.
19112042
<p(245)>deno audit</>
1912-
2043+
19132044
Show only high and critical severity vulnerabilities
19142045
<p(245)>deno audit --level=high</>
19152046
@@ -5102,6 +5233,25 @@ fn allow_scripts_arg_parse(
51025233
flags.allow_scripts = PackagesAllowedScripts::Some(
51035234
parts
51045235
.flat_map(flat_escape_split_commas)
5236+
.map(|result| {
5237+
let value = result?;
5238+
let dep = JsrDepPackageReq::from_str_loose(&value).map_err(|e| {
5239+
clap::Error::raw(clap::error::ErrorKind::InvalidValue, e)
5240+
})?;
5241+
if dep.kind != PackageKind::Npm {
5242+
return Err(clap::Error::raw(
5243+
clap::error::ErrorKind::InvalidValue,
5244+
format!("Only npm package constraints are supported: {}", value),
5245+
));
5246+
}
5247+
if dep.req.version_req.tag().is_some() {
5248+
return Err(clap::Error::raw(
5249+
clap::error::ErrorKind::InvalidValue,
5250+
format!("Tags are not supported in --allow-scripts: {}", value),
5251+
));
5252+
}
5253+
Ok(dep.req)
5254+
})
51055255
.collect::<Result<_, _>>()?,
51065256
);
51075257
}
@@ -5819,13 +5969,22 @@ fn json_reference_parse(
58195969
})
58205970
.collect::<Vec<_>>();
58215971

5822-
json!({
5972+
let mut out = json!({
58235973
"name": name,
58245974
"about": about,
58255975
"args": args,
58265976
"subcommands": subcommands,
58275977
"usage": usage,
5828-
})
5978+
});
5979+
5980+
if top_level {
5981+
out
5982+
.as_object_mut()
5983+
.unwrap()
5984+
.insert("env".to_string(), serde_json::to_value(ENV_VARS).unwrap());
5985+
}
5986+
5987+
out
58295988
}
58305989

58315990
flags.subcommand = DenoSubcommand::JSONReference(JSONReferenceFlags {
@@ -6889,6 +7048,7 @@ pub fn resolve_urls(urls: Vec<String>) -> Vec<String> {
68897048

68907049
#[cfg(test)]
68917050
mod tests {
7051+
use deno_semver::package::PackageReq;
68927052
use pretty_assertions::assert_eq;
68937053

68947054
use super::*;
@@ -12516,13 +12676,26 @@ mod tests {
1251612676
(None, Ok(PackagesAllowedScripts::None)),
1251712677
(
1251812678
Some("--allow-scripts=npm:foo"),
12519-
Ok(PackagesAllowedScripts::Some(svec!["npm:foo"])),
12679+
Ok(PackagesAllowedScripts::Some(vec![
12680+
PackageReq::from_str("foo").unwrap(),
12681+
])),
1252012682
),
1252112683
(
12522-
Some("--allow-scripts=npm:foo,npm:bar"),
12523-
Ok(PackagesAllowedScripts::Some(svec!["npm:foo", "npm:bar"])),
12684+
Some("--allow-scripts=npm:foo,npm:bar@2"),
12685+
Ok(PackagesAllowedScripts::Some(vec![
12686+
PackageReq::from_str("foo").unwrap(),
12687+
PackageReq::from_str("bar@2").unwrap(),
12688+
])),
1252412689
),
1252512690
(Some("--allow-scripts=foo"), Err("Invalid package")),
12691+
(
12692+
Some("--allow-scripts=npm:foo@next"),
12693+
Err("Tags are not supported in --allow-scripts: npm:foo@next"),
12694+
),
12695+
(
12696+
Some("--allow-scripts=jsr:@foo/bar"),
12697+
Err("An 'npm:' specifier is required"),
12698+
),
1252612699
];
1252712700
for (flag, value) in cases {
1252812701
let mut args = svec!["deno", "cache"];

cli/args/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ impl CliOptions {
13481348
pub fn lifecycle_scripts_config(&self) -> LifecycleScriptsConfig {
13491349
LifecycleScriptsConfig {
13501350
allowed: self.flags.allow_scripts.clone(),
1351+
denied: Default::default(),
13511352
initial_cwd: self.initial_cwd.clone(),
13521353
root_dir: self.workspace().root_dir_path(),
13531354
explicit_install: matches!(

cli/lsp/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ impl<'a> ResolverFactory<'a> {
978978
tarball_cache.clone(),
979979
maybe_lockfile,
980980
maybe_node_modules_path.clone(),
981-
LifecycleScriptsConfig::default(),
981+
Arc::new(LifecycleScriptsConfig::default()),
982982
NpmSystemInfo::default(),
983983
link_packages,
984984
None,

0 commit comments

Comments
 (0)