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

@jspm/resolve

v1.0.0

Published

jspm 2.0 resolver

Downloads

2,646

Readme

JSPM 2 Resolver

This implements the jspm_packages/[registry]/[name]@[version]/ module resolution lookup while checking the rules defined in package.json and json.json for jspm.

For the full detailed specification of jspm resolution, see the jspm 2.0 resolver specification.

The resolver is fully backwards-compatible with the Node.js --experimental-modules resolver, which in turn is fully-backwards compatible with the traditional CommonJS resolver.

Usage

Install with:

npm install @jspm/resolve

Then basic usage is:

import jspmResolve from '@jspm/resolve';

const { resolved, format } = await jspmResolve('specifier', '/path/to/parent/module.js');

The jspm resolver works on file paths that are /-separated. It will still correctly handle the URL normalization rules of the ES Module resolver though, but works on file paths for convenience and performance.

Format, like the Node.js --experimental-modules resolver, is one of commonjs, module, json, builtin, addon or unknown for asset files.

API

Cache

A cache object can be passed to the resolution function that will maintain all the lookup state for fast resolution:

const cache = {};
jspmResolve(name, parent, { cache });

Environment

A custom environment can be provided to jspmResolve, representing the conditional paths to take in the resolver.

The default environment is the Node.js development environment:

{
  browser: false,
  node: true,
  production: false,
  dev: true,
  'react-native': false,
  electron: false,
  deno: false,
  default: true
}

So a browser production resolution can be made with eg:

jspmResolve(name, parent, {
  env: {
    browser: true,
    production: true
  }
});

The browser main and map will then be respected, as well as any custom production mappings.

CommonJS Resolve

By default the jspm resolver assumes resolution is coming from an ES module context.

CommonJS modules in Node.js always load all dependencies as CommonJS and this can also be supported in the jspm resolve options by passing the cjsResolve: true option.

This then implements automatic file extension searching as well as always loading the CommonJS format if not an addon or json path.

Synchronous Resolution

jspmResolve.sync can be used to perform synchronous resolution, with an otherwise identical API.

Loader

A loader.mjs file is provided which supports the Node.js --experimental-modules loader API:

node --experimental-modules --loader @jspm/resolve/loader.mjs x.js

This applies the jspm resolution to Node.js.

License

Apache 2.0