diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-23 23:51:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-23 23:51:07 +0100 |
commit | 60688c563e6d02813b021ad91132fe1eb3f103b6 (patch) | |
tree | 89e7862fa34a8e93cebed984ee5cfa44011d4230 /cli/tests/testdata/run | |
parent | 13d5c6420e3fe7f34e7c02a96922fe8db381503e (diff) |
feat: import.meta.filename and import.meta.dirname (#22061)
This commit adds `import.meta.filename` and `import.meta.dirname` APIs.
These APIs return string representation of filename and containing
dirname.
They are only defined for local modules (modules that have `file:///`
scheme).
Example:
```ts
console.log(import.meta.filename, import.meta.dirname)
```
Unix:
```
$ deno run /dev/my_module.ts
/dev/my_module.ts /dev/
```
Windows:
```
$ deno run C:\dev\my_module.ts
C:\dev\my_module.ts C:\
```
Diffstat (limited to 'cli/tests/testdata/run')
-rw-r--r-- | cli/tests/testdata/run/import_meta/main.out | 5 | ||||
-rw-r--r-- | cli/tests/testdata/run/import_meta/main.ts | 12 | ||||
-rw-r--r-- | cli/tests/testdata/run/import_meta/other.ts | 8 |
3 files changed, 19 insertions, 6 deletions
diff --git a/cli/tests/testdata/run/import_meta/main.out b/cli/tests/testdata/run/import_meta/main.out index 0329dea8a..5a86d6240 100644 --- a/cli/tests/testdata/run/import_meta/main.out +++ b/cli/tests/testdata/run/import_meta/main.out @@ -1,5 +1,6 @@ -other [WILDCARD]other.ts false -main [WILDCARD]main.ts true +other remote [WILDCARD]other.ts false undefined undefined +other [WILDCARD]other.ts false [WILDCARD]other.ts [WILDCARD] +main [WILDCARD]main.ts true [WILDCARD]main.ts [WILDCARD] Resolving ./foo.js file:///[WILDCARD]/foo.js Resolving bare from import map https://example.com/ Resolving https://example.com/rewrite from import map https://example.com/rewritten diff --git a/cli/tests/testdata/run/import_meta/main.ts b/cli/tests/testdata/run/import_meta/main.ts index 96d63ba78..fb859e250 100644 --- a/cli/tests/testdata/run/import_meta/main.ts +++ b/cli/tests/testdata/run/import_meta/main.ts @@ -1,9 +1,15 @@ import { assertThrows } from "../../../../../test_util/std/assert/mod.ts"; - -console.log("main", import.meta.url, import.meta.main); - +import "http://localhost:4545/run/import_meta/other.ts"; import "./other.ts"; +console.log( + "main", + import.meta.url, + import.meta.main, + import.meta.filename, + import.meta.dirname, +); + console.log("Resolving ./foo.js", import.meta.resolve("./foo.js")); console.log("Resolving bare from import map", import.meta.resolve("bare")); console.log( diff --git a/cli/tests/testdata/run/import_meta/other.ts b/cli/tests/testdata/run/import_meta/other.ts index 47d7527cd..5da6a4936 100644 --- a/cli/tests/testdata/run/import_meta/other.ts +++ b/cli/tests/testdata/run/import_meta/other.ts @@ -1 +1,7 @@ -console.log("other", import.meta.url, import.meta.main); +console.log( + import.meta.url.startsWith("http") ? "other remote" : "other", + import.meta.url, + import.meta.main, + import.meta.filename, + import.meta.dirname, +); |