profile
viewpoint

issue commentdenoland/deno

deno cannot import file from url without context

Ok so I made a fix thanks to this piece of code:

for path_seg in url.path_segments().unwrap() {
    // There was no file name in the url, but we need one to cache the file
    let path_seg = match path_seg.len() {
      0 => "unnamed",
      _ => path_seg,
    };

    out.push(path_seg);
  }

I am not sure if it is the expected behavior ? What do you think ? @bartlomieju @ry

I also added this test :

#[test]
  fn test_resolve_module_empty_filename() {
    let (_temp_dir, deno_dir) = test_setup();

    let specifier = "http://localhost:4545/tests/subdir/";
    let referrer = add_root!("/deno/tests/006_url_imports.ts");
    let expected_module_name = "http://localhost:4545/tests/subdir/";
    let expected_filename = deno_fs::normalize_path(
      deno_dir
        .deps_http
        .join("localhost_PORT4545/tests/subdir/unnamed")
        .as_ref(),
    );

    let (module_name, filename) =
      deno_dir.resolve_module(specifier, referrer).unwrap();
    assert_eq!(module_name, expected_module_name);
    assert_eq!(filename, expected_filename);
  }

Do you think that an integration test like the fetch_test.py could be necessary ?

And do I need rights to push a new branch to be able to open a pull request ?

One last thing, It was hard for me to understand what the parameters specifier and referrer refer to. Could you explain me ?

Chococrok

comment created time in a month

issue commentdenoland/deno

deno cannot import file from url without context

@bartlomieju Thanks for asking, well I think I am making some progress, I have a test failling. But could you show me where the function get_source_code is used ?

Chococrok

comment created time in 2 months

issue commentdenoland/deno

deno cannot import file from url without context

Yes it helps, thank you for pointing me in the right direction. I will do my best although it's my first time reading some rust !

Chococrok

comment created time in 2 months

issue commentdenoland/deno

deno cannot import file from url without context

Extension doesn't seems to matter. It works if I serve my file at localhost:8080/too/test.blorg. Deno doesn't care about Content-type header neither.

The reason is that deno cache the scripts into ~/.cache/deno/http/localhost_PORT8080/*.whatever. If the file is served at the root URL then the file name is empty and deno try to execute the parent folder. Same happen if you serve the file at an url ending with '/' for example: localhost:8080/too/.

I think there should be a default name or an explicit error thrown.

If you could show me which part of the code is responsible of caching the imported files, I would be happy to contribute.

Chococrok

comment created time in 2 months

issue openeddenoland/deno

deno cannot import file from url without context

Description

As a test, I tried to serve a .ts file with a simple node application serving at http://localhost:8080. Then I tried to import it from an other ts file executed with deno. The result was an error hard to understand (See below)

Steps to reproduce

  • Serve a simple ts file at http://localhost:8080
  • Execute an other ts file with deno containing :
import  test from 'http://localhost:8080';

Logs

DEBUG TS - getScriptVersion() /home/chococrok/git_repos/deno/test1.ts 
DEBUG TS - getScriptKind() /home/chococrok/git_repos/deno/test1.ts
DEBUG TS - getCompilationSettings()
DEBUG TS - getDefaultLibFileName()
DEBUG TS - compiler._resolveModule { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - compiler._resolveFileName { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - resolveModule sourceCode length: 83663
DEBUG TS - resolveModule has media type: TypeScript
DEBUG TS - compiler._setFileName { moduleSpecifier: "$asset$/lib.deno_runtime.d.ts", containingFile: "" }
DEBUG TS - resolveModuleNames() { moduleNames: [ "http://localhost:8080", "https://deno.land/std/http/server.ts" ], containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - compiler._resolveModule { moduleSpecifier: "http://localhost:8080", containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - compiler._resolveFileName { moduleSpecifier: "http://localhost:8080", containingFile: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG TS - os.fetchModuleMetaData { specifier: "http://localhost:8080", referrer: "/home/chococrok/git_repos/deno/test1.ts" }
DEBUG RS - fetch_module_meta_data. specifier http://localhost:8080 referrer /home/chococrok/git_repos/deno/test1.ts
DEBUG RS - resolve_module specifier http://localhost:8080 referrer /home/chococrok/git_repos/deno/test1.ts
DEBUG RS - module_name: http://localhost:8080/, filename: /home/chococrok/.cache/deno/deps/http/localhost_PORT8080/
DEBUG RS - fetch local or reload http://localhost:8080/ is_module_remote true
DEBUG RS - msg_from_js FetchModuleMetaData sync true
DEBUG RS - op err Is a directory (os error 21)
DEBUG RS - msg_from_js WorkerPostMessage sync true
DEBUG RS - Got message from worker: {"success":false,"cmdId":1,"data":{"message":"Uncaught Other: Is a directory (os error 21)","sourceLine":"                    return new DenoError(kind, base.error());","scriptResourceName":"gen/cli/bundle/compiler.js","lineNumber":131177,"startPosition":9377027,"endPosition":9377028,"errorLevel":8,"startColumn":27,"endColumn":28,"isSharedCrossOrigin":false,"isOpaque":false,"frames":[{"line":131166,"column":21,"functionName":"DenoError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":true,"isWasm":false},{"line":131177,"column":28,"functionName":"maybeError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":131181,"column":29,"functionName":"maybeThrowError","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":132763,"column":21,"functionName":"sendSync","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133466,"column":33,"functionName":"fetchModuleMetaData","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133843,"column":56,"functionName":"_resolveModule","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":133984,"column":53,"functionName":"resolveModuleNames","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":127083,"column":150,"functionName":"compilerHost.resolveModuleNames","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":94303,"column":139,"functionName":"resolveModuleNamesWorker","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false},{"line":94545,"column":36,"functionName":"resolveModuleNamesReusingOldState","scriptName":"gen/cli/bundle/compiler.js","isEval":false,"isConstructor":false,"isWasm":false}]}}
DEBUG TS - getMessage
DEBUG RS - Cmd id for get message handler: 1
DEBUG RS - msg_from_js WorkerGetMessage sync false
DEBUG RS - Received message from worker
DEBUG RS - compiler error exiting!
Uncaught Other: Is a directory (os error 21)
    at DenoError (js/errors.ts:22:5)
    at maybeError (js/errors.ts:33:12)
    at maybeThrowError (js/errors.ts:39:15)
    at sendSync (js/dispatch.ts:86:5)
    at fetchModuleMetaData (js/os.ts:73:19)
    at _resolveModule (js/compiler.ts:255:38)
    at resolveModuleNames (js/compiler.ts:486:35)
    at compilerHost.resolveModuleNames (third_party/node_modules/typescript/lib/typescript.js:121106:138)
    at resolveModuleNamesWorker (third_party/node_modules/typescript/lib/typescript.js:88311:127)
    at resolveModuleNamesReusingOldState (third_party/node_modules/typescript/lib/typescript.js:88553:24)

created time in 2 months

more