Skip to content

Consider changing the sigil of deno test --doc temp files from $ to # #29684

@lowlighter

Description

@lowlighter

deno 2.3.3 (stable, release, x86_64-unknown-linux-gnu)

Currently the suffix used in temporary generated files is $, but because of this it makes it impossible to use import.meta.url/import.meta.filename properly in the examples if you want to reference the file itself.

It'd be better to use # (url anchor) so when manipulating the url with either new URL() or fromFileUrl() you can get back the original filename easily without hacks like .replace("$", "#")

Also conceptually using the anchor spec would make sense too
# is supported in windows path, and unix basically supports anything, so it shouldn't be a breaking change too

For example :

import { fromFileUrl } from "@std/path"
const path = fromFileUrl(import.meta.url)
console.log(path)
// file:///workspaces/mod.ts$97-101.ts 
//  → /workspaces/mod.ts$97-101.ts
await Deno.readTextFile(path) // throws not found error

Suggested :

import { fromFileUrl } from "@std/path"
const path = fromFileUrl(import.meta.url)
console.log(path)
// file:///workspaces/mod.ts#97-101.ts 
//  → /workspaces/mod.ts
await Deno.readTextFile(path) // OK!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions