New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@import-maps/resolve

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@import-maps/resolve

Read and resolve urls via an import map

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
102K
decreased by-19%
Maintainers
1
Weekly downloads
 
Created
Source

Resolve import-maps

Part of Open Web Components

Open Web Components provides a set of defaults, recommendations and tools to help facilitate your web component project. Our recommendations include: developing, linting, testing, building, tooling, demoing, publishing and automating.

CircleCI BrowserStack Status Renovate enabled

This will allow you to parse and resolve urls by a given import-map.

Usage

yarn add @import-maps/resolve

You may then override a resolve method in your build process.

import { parseFromString, resolve } from '@import-maps/resolve';

// you probably want to cache the map processing and not redo it for every resolve
// a simple example
const mapCache = null;

function myResolve(specifier) {
  const currentDir = process.cwd();
  if (!mapCache) {
    const mapString = fs.readFileSync(path.join(currentDir, 'import-map.json'), 'utf-8');
    mapCache = parseFromString(mapString, currentDir);
  }

  return specifier => resolve(specifier, mapCache, path.join(`${currentDir}::`, 'index.html');
}

Additional info

The 3rd parameter of resolve is the "baseUrl/basePath" and it's format is /path/to/root::/subdir/foo. You can compare it with an url http://example.com/subdir/foo.

  • Everything before the :: is sort of the domain e.g. http://example.com/
  • Everything after is the path/directory to your appliaction

Such a path is needed as import maps support relative pathes as values.

Acknowledgments

This implementation is heavily based on the import-maps reference implementation. Thanks to @domenic and @guybedford for sharing that prototype.

Some adjustments have been made

  • Allow to process/resolve node pathes besides urls
  • Use mocha/chai for testing (already available in our setup)

Keywords

FAQs

Package last updated on 23 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc