mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
Merge branch 'main' into auto-config
This commit is contained in:
commit
28e4e71d68
10 changed files with 51 additions and 34 deletions
|
@ -1,7 +1,7 @@
|
||||||
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
|
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
|
||||||
|
|
||||||
# Update to Rust 1.56.1
|
# Update to Rust 1.58.0
|
||||||
RUN rustup update 1.56.1 && rustup default 1.56.1
|
RUN rustup update 1.58.0 && rustup default 1.58.0
|
||||||
|
|
||||||
# Install Deno
|
# Install Deno
|
||||||
ENV DENO_INSTALL=/usr/local
|
ENV DENO_INSTALL=/usr/local
|
||||||
|
|
11
.dprint.json
11
.dprint.json
|
@ -21,19 +21,20 @@
|
||||||
"cli/dts/lib.scripthost.d.ts",
|
"cli/dts/lib.scripthost.d.ts",
|
||||||
"cli/dts/lib.webworker*.d.ts",
|
"cli/dts/lib.webworker*.d.ts",
|
||||||
"cli/dts/typescript.d.ts",
|
"cli/dts/typescript.d.ts",
|
||||||
"cli/tests/testdata/encoding",
|
|
||||||
"cli/tests/testdata/inline_js_source_map*",
|
|
||||||
"cli/tests/testdata/badly_formatted.md",
|
|
||||||
"cli/tests/testdata/badly_formatted.json",
|
"cli/tests/testdata/badly_formatted.json",
|
||||||
|
"cli/tests/testdata/badly_formatted.md",
|
||||||
"cli/tests/testdata/byte_order_mark.ts",
|
"cli/tests/testdata/byte_order_mark.ts",
|
||||||
|
"cli/tests/testdata/encoding",
|
||||||
"cli/tests/testdata/fmt/*",
|
"cli/tests/testdata/fmt/*",
|
||||||
|
"cli/tests/testdata/import_assertions/json_with_shebang.json",
|
||||||
|
"cli/tests/testdata/inline_js_source_map*",
|
||||||
"cli/tests/testdata/malformed_config/*",
|
"cli/tests/testdata/malformed_config/*",
|
||||||
"cli/tests/testdata/test/markdown_windows.md",
|
"cli/tests/testdata/test/markdown_windows.md",
|
||||||
"cli/tsc/*typescript.js",
|
"cli/tsc/*typescript.js",
|
||||||
"test_util/std",
|
|
||||||
"test_util/wpt",
|
|
||||||
"gh-pages",
|
"gh-pages",
|
||||||
"target",
|
"target",
|
||||||
|
"test_util/std",
|
||||||
|
"test_util/wpt",
|
||||||
"third_party",
|
"third_party",
|
||||||
"tools/wpt/expectation.json",
|
"tools/wpt/expectation.json",
|
||||||
"tools/wpt/manifest.json"
|
"tools/wpt/manifest.json"
|
||||||
|
|
|
@ -148,7 +148,7 @@ fn fetch_local(specifier: &ModuleSpecifier) -> Result<File, AnyError> {
|
||||||
})?;
|
})?;
|
||||||
let bytes = fs::read(local.clone())?;
|
let bytes = fs::read(local.clone())?;
|
||||||
let charset = text_encoding::detect_charset(&bytes).to_string();
|
let charset = text_encoding::detect_charset(&bytes).to_string();
|
||||||
let source = strip_shebang(get_source_from_bytes(bytes, Some(charset))?);
|
let source = get_source_from_bytes(bytes, Some(charset))?;
|
||||||
let media_type = MediaType::from(specifier);
|
let media_type = MediaType::from(specifier);
|
||||||
|
|
||||||
Ok(File {
|
Ok(File {
|
||||||
|
@ -173,10 +173,7 @@ pub fn get_source_from_data_url(
|
||||||
let (bytes, _) = data_url
|
let (bytes, _) = data_url
|
||||||
.decode_to_vec()
|
.decode_to_vec()
|
||||||
.map_err(|e| uri_error(format!("{:?}", e)))?;
|
.map_err(|e| uri_error(format!("{:?}", e)))?;
|
||||||
Ok((
|
Ok((get_source_from_bytes(bytes, charset)?, format!("{}", mime)))
|
||||||
strip_shebang(get_source_from_bytes(bytes, charset)?),
|
|
||||||
format!("{}", mime),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a vector of bytes and optionally a charset, decode the bytes to a
|
/// Given a vector of bytes and optionally a charset, decode the bytes to a
|
||||||
|
@ -230,19 +227,6 @@ pub fn map_content_type(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove shebangs from the start of source code strings
|
|
||||||
fn strip_shebang(mut value: String) -> String {
|
|
||||||
if value.starts_with("#!") {
|
|
||||||
if let Some(mid) = value.find('\n') {
|
|
||||||
let (_, rest) = value.split_at(mid);
|
|
||||||
value = rest.to_string()
|
|
||||||
} else {
|
|
||||||
value.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A structure for resolving, fetching and caching source files.
|
/// A structure for resolving, fetching and caching source files.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FileFetcher {
|
pub struct FileFetcher {
|
||||||
|
@ -306,7 +290,7 @@ impl FileFetcher {
|
||||||
let maybe_content_type = headers.get("content-type").cloned();
|
let maybe_content_type = headers.get("content-type").cloned();
|
||||||
let (media_type, maybe_charset) =
|
let (media_type, maybe_charset) =
|
||||||
map_content_type(specifier, maybe_content_type);
|
map_content_type(specifier, maybe_content_type);
|
||||||
let source = strip_shebang(get_source_from_bytes(bytes, maybe_charset)?);
|
let source = get_source_from_bytes(bytes, maybe_charset)?;
|
||||||
let maybe_types = match media_type {
|
let maybe_types = match media_type {
|
||||||
MediaType::JavaScript
|
MediaType::JavaScript
|
||||||
| MediaType::Cjs
|
| MediaType::Cjs
|
||||||
|
@ -450,7 +434,7 @@ impl FileFetcher {
|
||||||
|
|
||||||
let (media_type, maybe_charset) =
|
let (media_type, maybe_charset) =
|
||||||
map_content_type(specifier, Some(content_type.clone()));
|
map_content_type(specifier, Some(content_type.clone()));
|
||||||
let source = strip_shebang(get_source_from_bytes(bytes, maybe_charset)?);
|
let source = get_source_from_bytes(bytes, maybe_charset)?;
|
||||||
|
|
||||||
let local =
|
let local =
|
||||||
self
|
self
|
||||||
|
@ -786,13 +770,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_strip_shebang() {
|
|
||||||
let value =
|
|
||||||
"#!/usr/bin/env deno\n\nconsole.log(\"hello deno!\");\n".to_string();
|
|
||||||
assert_eq!(strip_shebang(value), "\n\nconsole.log(\"hello deno!\");\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_map_content_type() {
|
fn test_map_content_type() {
|
||||||
let fixtures = vec![
|
let fixtures = vec![
|
||||||
|
|
|
@ -1600,6 +1600,28 @@ itest!(jsx_import_source_error {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(shebang_tsc {
|
||||||
|
args: "run --quiet shebang.ts",
|
||||||
|
output: "shebang.ts.out",
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(shebang_swc {
|
||||||
|
args: "run --quiet --no-check shebang.ts",
|
||||||
|
output: "shebang.ts.out",
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(shebang_with_json_imports_tsc {
|
||||||
|
args: "run --quiet import_assertions/json_with_shebang.ts",
|
||||||
|
output: "import_assertions/json_with_shebang.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(shebang_with_json_imports_swc {
|
||||||
|
args: "run --quiet --no-check import_assertions/json_with_shebang.ts",
|
||||||
|
output: "import_assertions/json_with_shebang.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_validate_asm() {
|
fn no_validate_asm() {
|
||||||
let output = util::deno_cmd()
|
let output = util::deno_cmd()
|
||||||
|
|
4
cli/tests/testdata/import_assertions/json_with_shebang.json
vendored
Normal file
4
cli/tests/testdata/import_assertions/json_with_shebang.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/env -S deno run
|
||||||
|
{
|
||||||
|
"test": null
|
||||||
|
}
|
3
cli/tests/testdata/import_assertions/json_with_shebang.ts
vendored
Normal file
3
cli/tests/testdata/import_assertions/json_with_shebang.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import json from "./json_with_shebang.json" assert { type: "json" };
|
||||||
|
|
||||||
|
console.log(json);
|
1
cli/tests/testdata/import_assertions/json_with_shebang.ts.out
vendored
Normal file
1
cli/tests/testdata/import_assertions/json_with_shebang.ts.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
error: Uncaught SyntaxError: Unexpected token # in JSON at position 0
|
5
cli/tests/testdata/shebang.ts
vendored
Normal file
5
cli/tests/testdata/shebang.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env -S deno run
|
||||||
|
|
||||||
|
import test from "./shebang2.ts";
|
||||||
|
|
||||||
|
console.log(test as number);
|
1
cli/tests/testdata/shebang.ts.out
vendored
Normal file
1
cli/tests/testdata/shebang.ts.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
42
|
3
cli/tests/testdata/shebang2.ts
vendored
Normal file
3
cli/tests/testdata/shebang2.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env -S deno run
|
||||||
|
|
||||||
|
export default 42;
|
Loading…
Reference in a new issue