npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

resolve-esm

v2.0.3

Published

Shim for `import.meta.resolve`

Downloads

3,778

Readme

Shim for import.meta.resolve.

npm downloads install size license node types vulnerabilities CodeQL

import.meta.resolve is currently Experimental, and is only available with the --experimental-import-meta-resolve command flag enabled. This module provides functions equivalent to import.meta.resolve without the experimental flag.

⚠️ BREAKING CHANGES at v2.0.0

Change return types from asynchronous to synchronous

Following the change at Node.js v20 that import.meta.resolve now returns synchronously, the functions in this module have also been changed to synchronous functions.

However, asynchronous functions equivalent to v1.x can also be imported from resolve-esm/async, so users can still use asynchronous functions in situations such as when blocking is undesirable.

Change supported Node.js versions

Node.js v14 (already EOL) is no longer supported and requires Node.js v16 or higher.

Differences from similar modules

This module is just a lightweight wrapper that internally calls the original import.meta.resolve and has no resolution logic of its own. Therefore, it will be easy to follow if the original specification changes, and easy to migrate when the original becomes Stable in the future.

Usage

Warning This module only works in Node.js (v16+) ES Modules.

$ npm i resolve-esm

Sync API

import { importMetaResolve } from 'resolve-esm'; // or 'resolve-esm/sync'
importMetaResolve('./other.js');
// => "file://path/to/__dirname/other.js"

importMetaResolve('./other.js', 'file://different/path/base.js');
// => "file://different/path/other.js"

importMetaResolve('dependency');
// => "file://path/to/node_modules/dependency/main.js"

importMetaResolve('dependency', 'file://different/path/base.js');
// => "file://different/path/node_modules/dependency/main.js"

importMetaResolve('fs');
// => "node:fs"

Async API

import { importMetaResolve } from 'resolve-esm/async';
await importMetaResolve('./other.js');
// => "file://path/to/__dirname/other.js"

await importMetaResolve('./other.js', 'file://different/path/base.js');
// => "file://different/path/other.js"

await importMetaResolve('dependency');
// => "file://path/to/node_modules/dependency/main.js"

await importMetaResolve('dependency', 'file://different/path/base.js');
// => "file://different/path/node_modules/dependency/main.js"

await importMetaResolve('fs');
// => "node:fs"

APIs

importMetaResolve

Resolve a (single) module specifier.

function importMetaResolve(specifier: string, parent?: string | URL): string;
function importMetaResolve(specifier: string, parent?: string | URL): Promise<string>;

Parameters

  • specifier (Type: string)
    • The module specifier to resolve relative to parent.
  • parent (Type: string | URL | undefined)
    • The absolute parent module URL to resolve from.
    • If none is specified, the value of import.meta.url is used as the default.

importMetaResolveAll

Resolve multiple module specifiers with the same parent.

function importMetaResolveAll(iterable: Readonly<Iterable<string>>, parent?: string | URL): string[];
function importMetaResolveAll(iterable: Readonly<Iterable<string>>, parent?: string | URL): Promise<string[]>;

Parameters

  • iterable (Type: Iterable<string>)
    • An iterable (such as an array) of module specifiers to resolve relative to parent.
  • parent (Type: string | URL | undefined)
    • The absolute parent module URL to resolve from.
    • If none is specified, the value of import.meta.url is used as the default.

What is this function for?

For internal implementation reasons, it is more efficient than calling importMetaResolve multiple times on your own.

  • works, but inefficient
    const results = [
        importMetaResolve('specifier1'),
        importMetaResolve('specifier2'),
        importMetaResolve('specifier3'),
    ];
  • better
    const results = importMetaResolveAll([
        'specifier1',
        'specifier2',
        'specifier3',
    ]);