1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat: hash file names in gen cache (#6911)

This commit is contained in:
Luca Casonato 2020-08-03 14:55:03 +02:00 committed by GitHub
parent d54d4d21bd
commit 9d50c5c1a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 9 deletions

View file

@ -1,4 +1,5 @@
use crate::fs as deno_fs;
use crate::http_cache::url_to_filename;
use std::ffi::OsStr;
use std::fs;
use std::io;
@ -50,7 +51,7 @@ impl DiskCache {
out.push(scheme);
match scheme {
"http" | "https" | "wasm" => {
"wasm" => {
let host = url.host_str().unwrap();
let host_port = match url.port() {
// Windows doesn't support ":" in filenames, so we represent port using a
@ -64,6 +65,7 @@ impl DiskCache {
out.push(path_seg);
}
}
"http" | "https" => out = url_to_filename(url),
"file" => {
let path = url.to_file_path().unwrap();
let mut path_components = path.components();
@ -194,15 +196,15 @@ mod tests {
let mut test_cases = vec![
(
"http://deno.land/std/http/file_server.ts",
"http/deno.land/std/http/file_server.ts",
"http/deno.land/d8300752800fe3f0beda9505dc1c3b5388beb1ee45afd1f1e2c9fc0866df15cf",
),
(
"http://localhost:8000/std/http/file_server.ts",
"http/localhost_PORT8000/std/http/file_server.ts",
"http/localhost_PORT8000/d8300752800fe3f0beda9505dc1c3b5388beb1ee45afd1f1e2c9fc0866df15cf",
),
(
"https://deno.land/std/http/file_server.ts",
"https/deno.land/std/http/file_server.ts",
"https/deno.land/d8300752800fe3f0beda9505dc1c3b5388beb1ee45afd1f1e2c9fc0866df15cf",
),
("wasm://wasm/d1c677ea", "wasm/wasm/d1c677ea"),
];
@ -251,12 +253,12 @@ mod tests {
(
"http://deno.land/std/http/file_server.ts",
"js",
"http/deno.land/std/http/file_server.ts.js",
"http/deno.land/d8300752800fe3f0beda9505dc1c3b5388beb1ee45afd1f1e2c9fc0866df15cf.js",
),
(
"http://deno.land/std/http/file_server.ts",
"js.map",
"http/deno.land/std/http/file_server.ts.js.map",
"http/deno.land/d8300752800fe3f0beda9505dc1c3b5388beb1ee45afd1f1e2c9fc0866df15cf.js.map",
),
];

View file

@ -1,7 +1,7 @@
[WILDCARD]
local: [WILDCARD]http[WILDCARD]127.0.0.1_PORT4545[WILDCARD]
type: TypeScript
compiled: [WILDCARD]048_media_types_jsx.ts.js
compiled: [WILDCARD].js
deps:
http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts
├── http://localhost:4545/cli/tests/subdir/mt_text_typescript_tsx.t1.tsx

View file

@ -1,6 +1,6 @@
local: [WILDCARD]005_more_imports.ts
type: TypeScript
compiled: [WILDCARD]005_more_imports.ts.js
compiled: [WILDCARD].js
deps:
file://[WILDCARD]/005_more_imports.ts
└─┬ file://[WILDCARD]/subdir/mod1.ts

View file

@ -1,7 +1,7 @@
{
"local": "[WILDCARD]005_more_imports.ts",
"fileType": "TypeScript",
"compiled": "[WILDCARD]005_more_imports.ts.js",
"compiled": "[WILDCARD].js",
"map": null,
"deps": [
"file://[WILDCARD]/005_more_imports.ts",

View file

@ -0,0 +1 @@
import "http://localhost:4545/cli/tests/subdir/file_with_:_in_name.ts";

View file

@ -0,0 +1 @@
Hello from file_with_:_in_name.ts

View file

@ -2220,6 +2220,12 @@ itest!(compiler_js_error {
exit_code: 1,
});
itest!(import_file_with_colon {
args: "run --quiet --reload import_file_with_colon.ts",
output: "import_file_with_colon.ts.out",
http_server: true,
});
#[test]
fn cafile_env_fetch() {
use url::Url;

View file

@ -354,6 +354,17 @@ pub async fn run_all_servers() {
HeaderValue::from_static("application/javascript"),
);
res
}))
.or(warp::path!("cli"/"tests"/"subdir"/"file_with_:_in_name.ts").map(|| {
let mut res = Response::new(Body::from(
"console.log('Hello from file_with_:_in_name.ts');",
));
let h = res.headers_mut();
h.insert(
"Content-type",
HeaderValue::from_static("application/typescript"),
);
res
}));
let content_type_handler = warp::any()