Skip to content

[Replacement]: desm #645

@ghostdevv

Description

@ghostdevv

Package to replace

desm

Suggested replacement(s)

Node >=20, Deno, Bun:

- import { join } from 'desm';
+ import { join } from 'node:path';

- desm('./foo.ts');
+ join(import.meta.dirname, './foo.ts');
- import { dirname } from 'desm'; // or import desm from 'desm'

- dirname(import.meta.url);
+ import.meta.dirname;
- import { filename } from 'desm';

- filename(import.meta.url);
+ import.meta.filename;

Node <=20:

- import { join } from 'desm';
+ import { dirname, join } from 'node:path';
+ import { fileURLToPath } from 'node:url';

- desm('./foo.ts');
+ join(dirname(fileURLToPath(import.meta.url)), './foo.ts');
- import { dirname } from 'desm'; // or import desm from 'desm'
+ import { dirname } from 'node:path';
+ import { fileURLToPath } from 'node:url';

- dirname(import.meta.url);
+ dirname(fileURLToPath(import.meta.url));
- import { filename } from 'desm';
+ import { fileURLToPath } from 'node:url';

- filename(import.meta.url)l
+ fileURLToPath(import.meta.url);

You can also do something like

new URL("./foo.ts", import.meta.url).pathname;

Manifest type

native (replaceable by a built-in platform feature)

Rationale

micro utility to avoid fairly simple syntax historically, but now we have even smaller way of doing it

Availability

import.meta.dirname/filename added in Node v20.11.0,

Code example (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedUsed to signal if a suggested replacement has been accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions