mirror of
https://github.com/denoland/deno.git
synced 2025-01-20 20:42:19 -05:00
Compare commits
3 commits
086dab496a
...
8f52dda4a5
Author | SHA1 | Date | |
---|---|---|---|
|
8f52dda4a5 | ||
|
0d3d4f5466 | ||
|
d69a1ce9b1 |
9 changed files with 182 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,6 +15,7 @@ gclient_config.py_entries
|
|||
/tests/napi/node_modules
|
||||
/tests/napi/build
|
||||
/tests/napi/third_party_tests/node_modules
|
||||
.buildtool
|
||||
|
||||
# MacOS generated files
|
||||
.DS_Store
|
||||
|
|
|
@ -115,10 +115,16 @@ exec deno {} "$@"
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_installer_root() -> Result<PathBuf, io::Error> {
|
||||
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
|
||||
fn get_installer_root() -> Result<PathBuf, AnyError> {
|
||||
if let Some(env_dir) = env::var_os("DENO_INSTALL_ROOT") {
|
||||
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
|
||||
|
@ -587,11 +593,22 @@ async fn resolve_shim_data(
|
|||
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
|
||||
executable_args.push("--config".to_string());
|
||||
executable_args.push(copy_path.to_str().unwrap().to_string());
|
||||
extra_files.push((
|
||||
copy_path,
|
||||
fs::read_to_string(config_path)
|
||||
.with_context(|| format!("error reading {config_path}"))?,
|
||||
));
|
||||
let mut config_text = fs::read_to_string(config_path)
|
||||
.with_context(|| format!("error reading {config_path}"))?;
|
||||
// always remove the import map field because when someone specifies `--import-map` we
|
||||
// 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 {
|
||||
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 {
|
||||
// use a dot file to prevent the file from showing up in some
|
||||
// users shell auto-complete since this directory is on the PATH
|
||||
|
@ -1585,4 +1612,17 @@ mod tests {
|
|||
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(),
|
||||
"{}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
29
tools/buildtools/Dockerfile
Normal file
29
tools/buildtools/Dockerfile
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Use Ubuntu 24.04 LTS as the base image
|
||||
FROM ubuntu:24.04
|
||||
|
||||
WORKDIR /mnt
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl \
|
||||
build-essential \
|
||||
libssl-dev \
|
||||
pkg-config \
|
||||
wget \
|
||||
cmake \
|
||||
libglib2.0-dev \
|
||||
lsb-release \
|
||||
software-properties-common \
|
||||
gnupg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
|
||||
# Add the Cargo and Rust binaries to the PATH
|
||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||
|
||||
# Verify the installation
|
||||
RUN rustc --version && cargo --version
|
||||
|
||||
RUN wget https://apt.llvm.org/llvm.sh && \
|
||||
chmod +x llvm.sh && \
|
||||
./llvm.sh 17 && \
|
||||
apt-get install --install-recommends -y cmake libglib2.0-dev
|
90
tools/buildtools/denobuild
Executable file
90
tools/buildtools/denobuild
Executable file
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
|
||||
is_debian_based() {
|
||||
if [ -f /etc/os-release ]; then
|
||||
source /etc/os-release
|
||||
if [[ "$ID_LIKE" == *debian* || "$ID" == *debian* ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! is_debian_based; then
|
||||
echo "Only works on debian based systems"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
buildtools_folder="$(realpath $(dirname "$0"))"
|
||||
deno_root="$(realpath "$buildtools_folder/../..")"
|
||||
|
||||
if command -v docker &> /dev/null
|
||||
then
|
||||
echo "Docker is installed."
|
||||
docker --version
|
||||
else
|
||||
echo "Docker is not installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DOCKERFILE="$buildtools_folder/Dockerfile"
|
||||
IMAGE_NAME="denobuildtool"
|
||||
IMAGE_TAG="current"
|
||||
BUILD_TOOL_WORKING_DIR="$deno_root/.buildtool"
|
||||
STORED_DOCKER_FILE_CHECKSUM_FILE="$BUILD_TOOL_WORKING_DIR/dockerfile_check_sum"
|
||||
|
||||
if [ ! -d "$BUILD_TOOL_WORKING_DIR" ]; then
|
||||
mkdir -p "$BUILD_TOOL_WORKING_DIR"
|
||||
fi
|
||||
|
||||
DOCKERFILE_CHECKSUM=$(sha256sum "$DOCKERFILE" | awk '{ print $1 }')
|
||||
|
||||
run_with_docker() {
|
||||
if [[ $# != 0 ]]; then
|
||||
args=("$@")
|
||||
else
|
||||
args=(/bin/bash -i)
|
||||
fi
|
||||
|
||||
docker_args=()
|
||||
if [ "$PWD" != "$deno_root" ]; then
|
||||
docker_args+=(-v "$deno_root:$deno_root")
|
||||
fi
|
||||
|
||||
image="$IMAGE_NAME:$IMAGE_TAG"
|
||||
docker_args+=(
|
||||
--network host \
|
||||
--privileged \
|
||||
-v "$PWD:$PWD" \
|
||||
-v /etc/localtime:/etc/localtime:ro \
|
||||
--env CARGO_HOME \
|
||||
-v "${CARGO_HOME}:${CARGO_HOME}" \
|
||||
-w "$PWD" \
|
||||
-e HOME="$HOME" \
|
||||
"$image" \
|
||||
"${args[@]}"
|
||||
)
|
||||
|
||||
docker run --rm "${docker_args[@]}"
|
||||
}
|
||||
|
||||
if [ -f "$STORED_DOCKER_FILE_CHECKSUM_FILE" ]; then
|
||||
STORED_DOCKERFILE_CHECKSUM=$(cat "$STORED_DOCKER_FILE_CHECKSUM_FILE")
|
||||
|
||||
# Compare the current checksums with the stored checksums
|
||||
if [ "$DOCKERFILE_CHECKSUM" == "$STORED_DOCKERFILE_CHECKSUM" ]; then
|
||||
echo "Dockerfile not changed, no need to rebuild"
|
||||
run_with_docker "$@"
|
||||
else
|
||||
echo "Dockerfile changed Proceeding with building docker image..."
|
||||
docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" "$buildtools_folder" &&
|
||||
echo "$DOCKERFILE_CHECKSUM" > "$STORED_DOCKER_FILE_CHECKSUM_FILE"
|
||||
fi
|
||||
else
|
||||
echo "No previous checksum found. Building the image..."
|
||||
docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" "$buildtools_folder" &&
|
||||
echo "$DOCKERFILE_CHECKSUM" > "$STORED_DOCKER_FILE_CHECKSUM_FILE"
|
||||
fi
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue