mirror of
https://github.com/denoland/deno.git
synced 2025-01-20 20:42:19 -05:00
Compare commits
3 commits
ea2e80601c
...
8624f8356b
Author | SHA1 | Date | |
---|---|---|---|
|
8624f8356b | ||
|
0d3d4f5466 | ||
|
e817cd1c4f |
7 changed files with 96 additions and 23 deletions
|
@ -115,10 +115,16 @@ exec deno {} "$@"
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_installer_root() -> Result<PathBuf, io::Error> {
|
fn get_installer_root() -> Result<PathBuf, AnyError> {
|
||||||
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
|
if let Some(env_dir) = env::var_os("DENO_INSTALL_ROOT") {
|
||||||
if !env_dir.is_empty() {
|
if !env_dir.is_empty() {
|
||||||
return canonicalize_path_maybe_not_exists(&PathBuf::from(env_dir));
|
let env_dir = PathBuf::from(env_dir);
|
||||||
|
return canonicalize_path_maybe_not_exists(&env_dir).with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Canonicalizing DENO_INSTALL_ROOT ('{}').",
|
||||||
|
env_dir.display()
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note: on Windows, the $HOME environment variable may be set by users or by
|
// Note: on Windows, the $HOME environment variable may be set by users or by
|
||||||
|
@ -587,11 +593,22 @@ async fn resolve_shim_data(
|
||||||
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
|
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
|
||||||
executable_args.push("--config".to_string());
|
executable_args.push("--config".to_string());
|
||||||
executable_args.push(copy_path.to_str().unwrap().to_string());
|
executable_args.push(copy_path.to_str().unwrap().to_string());
|
||||||
extra_files.push((
|
let mut config_text = fs::read_to_string(config_path)
|
||||||
copy_path,
|
.with_context(|| format!("error reading {config_path}"))?;
|
||||||
fs::read_to_string(config_path)
|
// always remove the import map field because when someone specifies `--import-map` we
|
||||||
.with_context(|| format!("error reading {config_path}"))?,
|
// don't want that file to be attempted to be loaded and when they don't specify that
|
||||||
));
|
// (which is just something we haven't implemented yet)
|
||||||
|
if let Some(new_text) = remove_import_map_field_from_text(&config_text) {
|
||||||
|
if flags.import_map_path.is_none() {
|
||||||
|
log::warn!(
|
||||||
|
"{} \"importMap\" field in the specified config file we be ignored. Use the --import-map flag instead.",
|
||||||
|
crate::colors::yellow("Warning"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
config_text = new_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
extra_files.push((copy_path, config_text));
|
||||||
} else {
|
} else {
|
||||||
executable_args.push("--no-config".to_string());
|
executable_args.push("--no-config".to_string());
|
||||||
}
|
}
|
||||||
|
@ -631,6 +648,16 @@ async fn resolve_shim_data(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_import_map_field_from_text(config_text: &str) -> Option<String> {
|
||||||
|
let value =
|
||||||
|
jsonc_parser::cst::CstRootNode::parse(config_text, &Default::default())
|
||||||
|
.ok()?;
|
||||||
|
let root_value = value.object_value()?;
|
||||||
|
let import_map_value = root_value.get("importMap")?;
|
||||||
|
import_map_value.remove();
|
||||||
|
Some(value.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
|
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
|
||||||
// use a dot file to prevent the file from showing up in some
|
// use a dot file to prevent the file from showing up in some
|
||||||
// users shell auto-complete since this directory is on the PATH
|
// users shell auto-complete since this directory is on the PATH
|
||||||
|
@ -1585,4 +1612,17 @@ mod tests {
|
||||||
assert!(!file_path.exists());
|
assert!(!file_path.exists());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_remove_import_map_field_from_text() {
|
||||||
|
assert_eq!(
|
||||||
|
remove_import_map_field_from_text(
|
||||||
|
r#"{
|
||||||
|
"importMap": "./value.json"
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
"{}"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
// Copyright 2018-2025 the Deno authors. MIT license.
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||||
|
|
||||||
// TODO(petamoriken): enable prefer-primordials for node polyfills
|
|
||||||
// deno-lint-ignore-file prefer-primordials
|
|
||||||
|
|
||||||
import { inspect } from "ext:deno_node/internal/util/inspect.mjs";
|
import { inspect } from "ext:deno_node/internal/util/inspect.mjs";
|
||||||
|
import { primordials } from "ext:core/mod.js";
|
||||||
|
|
||||||
|
const {
|
||||||
|
ArrayPrototypeJoin,
|
||||||
|
ArrayPrototypeMap,
|
||||||
|
ObjectCreate,
|
||||||
|
ObjectDefineProperty,
|
||||||
|
SafeArrayIterator,
|
||||||
|
SafeRegExp,
|
||||||
|
String,
|
||||||
|
StringPrototypeToLowerCase,
|
||||||
|
StringPrototypeReplace,
|
||||||
|
StringPrototypeReplaceAll,
|
||||||
|
StringPrototypeToUpperCase,
|
||||||
|
} = primordials;
|
||||||
|
|
||||||
// `debugImpls` and `testEnabled` are deliberately not initialized so any call
|
// `debugImpls` and `testEnabled` are deliberately not initialized so any call
|
||||||
// to `debuglog()` before `initializeDebugEnv()` is called will throw.
|
// to `debuglog()` before `initializeDebugEnv()` is called will throw.
|
||||||
|
@ -13,13 +25,16 @@ let testEnabled: (str: string) => boolean;
|
||||||
|
|
||||||
// `debugEnv` is initial value of process.env.NODE_DEBUG
|
// `debugEnv` is initial value of process.env.NODE_DEBUG
|
||||||
export function initializeDebugEnv(debugEnv: string) {
|
export function initializeDebugEnv(debugEnv: string) {
|
||||||
debugImpls = Object.create(null);
|
debugImpls = ObjectCreate(null);
|
||||||
if (debugEnv) {
|
if (debugEnv) {
|
||||||
// This is run before any user code, it's OK not to use primordials.
|
debugEnv = StringPrototypeReplace(
|
||||||
debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, "\\$&")
|
debugEnv,
|
||||||
.replaceAll("*", ".*")
|
new SafeRegExp(/[|\\{}()[\]^$+?.]/g),
|
||||||
.replaceAll(",", "$|^");
|
"\\$&",
|
||||||
const debugEnvRegex = new RegExp(`^${debugEnv}$`, "i");
|
);
|
||||||
|
debugEnv = StringPrototypeReplaceAll(debugEnv, "*", ".*");
|
||||||
|
debugEnv = StringPrototypeReplaceAll(debugEnv, ",", "$|^");
|
||||||
|
const debugEnvRegex = new SafeRegExp(`^${debugEnv}$`, "i");
|
||||||
testEnabled = (str) => debugEnvRegex.exec(str) !== null;
|
testEnabled = (str) => debugEnvRegex.exec(str) !== null;
|
||||||
} else {
|
} else {
|
||||||
testEnabled = () => false;
|
testEnabled = () => false;
|
||||||
|
@ -33,7 +48,7 @@ function emitWarningIfNeeded(set: string) {
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-console
|
||||||
console.warn(
|
console.warn(
|
||||||
"Setting the NODE_DEBUG environment variable " +
|
"Setting the NODE_DEBUG environment variable " +
|
||||||
"to '" + set.toLowerCase() + "' can expose sensitive " +
|
"to '" + StringPrototypeToLowerCase(set) + "' can expose sensitive " +
|
||||||
"data (such as passwords, tokens and authentication headers) " +
|
"data (such as passwords, tokens and authentication headers) " +
|
||||||
"in the resulting log.",
|
"in the resulting log.",
|
||||||
);
|
);
|
||||||
|
@ -50,7 +65,10 @@ function debuglogImpl(
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
emitWarningIfNeeded(set);
|
emitWarningIfNeeded(set);
|
||||||
debugImpls[set] = function debug(...args: unknown[]) {
|
debugImpls[set] = function debug(...args: unknown[]) {
|
||||||
const msg = args.map((arg) => inspect(arg)).join(" ");
|
const msg = ArrayPrototypeJoin(
|
||||||
|
ArrayPrototypeMap(args, (arg) => inspect(arg)),
|
||||||
|
" ",
|
||||||
|
);
|
||||||
// deno-lint-ignore no-console
|
// deno-lint-ignore no-console
|
||||||
console.error("%s %s: %s", set, String(Deno.pid), msg);
|
console.error("%s %s: %s", set, String(Deno.pid), msg);
|
||||||
};
|
};
|
||||||
|
@ -71,7 +89,7 @@ export function debuglog(
|
||||||
cb?: (debug: (...args: unknown[]) => void) => void,
|
cb?: (debug: (...args: unknown[]) => void) => void,
|
||||||
) {
|
) {
|
||||||
function init() {
|
function init() {
|
||||||
set = set.toUpperCase();
|
set = StringPrototypeToUpperCase(set);
|
||||||
enabled = testEnabled(set);
|
enabled = testEnabled(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +103,7 @@ export function debuglog(
|
||||||
cb(debug);
|
cb(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
return debug(...args);
|
return debug(...new SafeArrayIterator(args));
|
||||||
};
|
};
|
||||||
|
|
||||||
let enabled: boolean;
|
let enabled: boolean;
|
||||||
|
@ -95,9 +113,10 @@ export function debuglog(
|
||||||
return enabled;
|
return enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
const logger = (...args: unknown[]) => debug(...args);
|
const logger = (...args: unknown[]) => debug(...new SafeArrayIterator(args));
|
||||||
|
|
||||||
Object.defineProperty(logger, "enabled", {
|
ObjectDefineProperty(logger, "enabled", {
|
||||||
|
__proto__: null,
|
||||||
get() {
|
get() {
|
||||||
return test();
|
return test();
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tempDir": true,
|
||||||
|
"args": "install -g --root ./folder --config deno.json main.ts --name my-cli",
|
||||||
|
"output": "install.out"
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"importMap": "./import_map.json"
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Warning "importMap" field in the specified config file we be ignored. Use the --import-map flag instead.
|
||||||
|
✅ Successfully installed my-cli
|
||||||
|
[WILDCARD]
|
|
@ -0,0 +1 @@
|
||||||
|
console.log(1);
|
Loading…
Add table
Reference in a new issue